Commit graph

256 commits

Author SHA1 Message Date
Hermet Park
16215c16dc renderer/loader: revamping the caching mechanism.
The previous loader cache mechanism encountered a problem
when the user changed the content of the cached data.

In such cases, a new request would not be processed
because the renderer would use the previously cached content.

So far, the TVG cache mechanism utilizes a pointer hash key
for the fastest hashing mechanism available.
One limitation is that it assumes the address is unique for the data.

To resolve this, we modified the caching policy.
Now, the renderer will not cache copied data;
it will only cache the given data when it is deemed shareable.

issue: https://github.com/thorvg/thorvg/issues/2020
2024-03-08 14:21:58 +09:00
Hermet Park
9ef2288ae7 api: promote to official APIs.
New API:
- SwCanvas::Colorspace::ABGR8888S
- SwCanvas::ColorSpace::ARGB8888S
2024-01-02 20:34:11 +09:00
Hermet Park
0553729818 doc: remove unnecessary doxy guide. 2024-01-02 20:34:11 +09:00
Hermet Park
54528b6ac9 renderer: introduce a ThorVG Text interface.
Introduced New APIs under the experimental tags.

- Result Text::font(const char* name, float size, const char* style = nullptr);
- Result Text::text(const char* text);
- Result Text::fill(uint8_t r, uint8_t g, uint8_t b);
- static Result Text::load(const std::string& path);
- static Result Text::unload(const std::string& path);
- static Text::std::unique_ptr<Text> gen();
- static Text::uint32_t identifier()

@Issue: https://github.com/thorvg/thorvg/issues/969
2024-01-02 20:34:11 +09:00
Hermet Park
83e3cb24ff doc: polish up the doxygen.
- applied @retval for those const values.
- applied @return for return value description.
2024-01-02 20:34:11 +09:00
Hermet Park
27843d2557 savers: provides a background setting.
Allow users to set a custom background with a saver.

API:
- Result Saver::background(std::unique_ptr<Paint> paint);
2023-12-26 18:30:06 +09:00
Hermet Park
a37649cd1f doc: make it up missing parameter information. 2023-12-26 18:21:01 +09:00
Hermet Park
2c382e3d9b doc: keep the style clean & neat 2023-12-26 18:17:41 +09:00
Jinny You
059a950d42 docs: Remove all warnings from doxygen 2023-12-26 18:17:41 +09:00
JunsuChoi
a20216045a saver GifSaver: Introduce GifSaver for animation
Add save() API that takes tvg::Animation as a parameter.
This API uses gif.h to create each animation frame as a gif frame.
Gif creation do not support threads because they must be added sequentially.
Please see example/GifSaver.cpp

ex)
auto animation = tvg::Animation::gen();
auto picture = animation->picture();
picture->load(EXAMPLE_DIR"/walker.json");
auto saver = tvg::Saver::gen();
saver->save(std::move(animation), EXAMPLE_DIR"/test.gif");
saver->sync();

New API:
Result Saver::save(std::unique_ptr<Animation> animation, const std::string& path, uint32_t quality = 100, uint32_t fps = 0);

Issue: https://github.com/thorvg/thorvg/issues/1712
2023-12-26 18:17:38 +09:00
Hermet Park
22c36b7069 wasm: fix a regression bug.
The Animation::frame() method has been modified.
It will now return InsufficientCondition,
if the frame value is the same as the previous one.

In addition to this change, we have also updated its usage accordingly.
2023-12-26 18:05:58 +09:00
Hermet Park
0832a188fe animation/lottie: updated the frame count unit.
replace the frame count unit from the int32_t to float
since animations could smoothly interpolate key-frames.

This notificably improve the animation smoothness in Lottie

Beta API changes:
Result Animation::frame(uint32_t no) -> Result Animation::frame(float no)
uint32_t Animation::curFrame() const -> float Animation::curFrame() const
uint32_t Animation::totalFrame() const -> float Animation::totalFrame() const
2023-12-26 17:51:53 +09:00
Hermet Park
1b15233aeb api: enhance the API usage.
Allow users to omit the default type casting for added convenience.
2023-12-26 17:50:36 +09:00
SergeyLebedkin
35b03c826e wg_engine: introduce a webgpu canvas(engine)
WebGPU is a Render Hardware Interface built on top of the various APIs 
provided by the driver/OS depending on your platform. 

WebGPU exposes an API for performing operations, 
such as rendering and computation, on a Graphics Processing Unit.

WebGPU official documentation: https://www.w3.org/TR/webgpu/

The new engine type introduced: tvg::CanvasEngine::Wg

The new canvas type introduced: tvg::WgCanvas

Example:
$meson setup build -Dengines=wg_beta

`
    // init engine webgpu
    tvg::Initializer::init(tvg::CanvasEngine::Wg, 0);

    // create wg canvas
    auto canvasWg = tvg::WgCanvas::gen();
    canvas_wg->target(glfwGetWin32Window(window), width, height);

    // ...

    // terminate engine and window
    tvg::Initializer::term(tvg::CanvasEngine::Wg);
`
Still this feature is under the beta

Issue: https://github.com/thorvg/thorvg/issues/1479
2023-12-26 17:49:16 +09:00
Hermet Park
0f5f43db1e apis: promote beta apis to the official ones.
- enum class CompositeMethod::InvLumaMask;
- template<typename T> std::unique_ptr<T> cast(Paint* paint);
- template<typename T> std::unique_ptr<T> cast(Fill* fill);

@Issue: https://github.com/thorvg/thorvg/issues/1669
2023-09-25 21:33:23 +09:00
Hermet Park
7430589586 keep the line space consistency. 2023-09-04 13:14:39 +09:00
Hermet Park
cdac27b1b5 apis: promote beta apis to official status
- Result Shape::strokeMiterlimit(float miterlimit)
- float Shape::strokeMiterlimit() const
2023-09-04 13:11:37 +09:00
Hermet Park
7d797ee548 Yet we don't break apis, this patch reverts the next:
cb36c25aff
8c0fc2b25a
c1e4e0808a

Those reverted changes sholud be in the bucket, the next issue item:

@Issue: https://github.com/thorvg/thorvg/issues/1372
2023-08-24 01:00:57 +09:00
Mira Grudzinska
478e45f9f3 common: stroke dash offset support added
The feature is supported also in the svg loader.

@Issue: https://github.com/thorvg/thorvg/issues/1591
2023-08-23 12:40:27 +09:00
Mira Grudzinska
c1e4e0808a Revert "api: enhance Shape::stroke() method usage."
This reverts commit 6cbc1de570.
Setting def value for 'a' makes it impossible to overload
the 'stroke' api with 3 values (needed for introducing dash offset).
2023-08-23 12:40:27 +09:00
Hermet Park
6a59e1b715 loader: avoid attempting forceful loading when the given MIME type is not correct.
Loading images when the MIME type is incorrect is unnecessary
and often results in failure, adding unnecessary processing overhead.

Pictures should have a clear MIME type assigned by users.
2023-08-11 15:00:09 +09:00
Hermet Park
c0cb8c0ce8 apis: remove a beta api.
- const uint32_t* Picture::data(uint32_t* w, uint32_t* h) const

Returning pixel data is not guaranteed as the picture may contain vector resources.
Remove it unless it's absolutely necessary.

@Issue: https://github.com/thorvg/thorvg/issues/1372
2023-08-08 10:47:37 +09:00
Hermet Park
0e97d21752 common canvas: Alter the concept of the Canvas::clear() API.
We've changed the behavior of Canvas::clear(false).

The canvas::clear(false) now retains the paints, allowing the user to update the next frame
more easily without having to recompose the paint list.

Previously, clear(false) removed the paint list from the canvas,
requiring the user to re-push all of them in the next frame.

Now, we offer the Canvas::paints() API, allowing users to modify the paint list directly instead.

This change will break compatibility with previous versions of Canvas.

Therefore, this update is included in ThorVG 1.0.

@Issue: https://github.com/thorvg/thorvg/issues/1372
2023-08-02 17:23:53 +09:00
Mira Grudzinska
5bb2eb06b4 docs: bounds api desc ++ 2023-08-01 14:53:12 +02:00
Hermet Park
93734fe673 infra: allow access to pImpl from the tvg internals.
Since pImpl is an ambiguous pointer, visibility is not practically effective.
On the other hand, this allows the tvg engine to easily pass data among instances.
2023-07-27 00:31:27 +09:00
Hermet Park
e7a94f5314 common Animation: introduce the Animation class.
This class serves as the base for Animation.
The main purpose of its APIs is to control the animation frames.

Its example will be provided in the upcoming commits.

@APIs:
Result Animation::frame(uint32_t no) noexcept;
Picture* Animation::picture() const noexcept;
uint32_t Animation::curFrame() const noexcept;
uint32_t Animation::totalFrame() const noexcept;
float Animation::duration() const noexcept;
static std::unique_ptr<Animation> Animation::gen() noexcept;

@Issue: https://github.com/thorvg/thorvg/pull/1450
2023-07-27 00:31:27 +09:00
Hermet Park
c50d2fde5f common sw_engine: support blending methods.
The blending feature allows user to combine colors to create visually appealing effects,
including transparency, lighting, shading, and color mixing, among others.

Its process involves the combination of colors or images from the source paint object
with the destination (the lower layer image) using blending operations.

The blending operation is determined by the chosen @p BlendMethod,
which specifies how the colors or images are combined.

@APIs:
 - enum class BlendMethod::Normal, Add, Screen, Multiply, Overlay, Lighten, Difference, Exclusion, SrcOver, Darken, Lighten, ColorDodge, ColorBurn
 - BlendMethod Paint::blend() const noexcept;
 - Result Paint::blend(BlendMethod method) const noexcept;

@Issue: https://github.com/thorvg/thorvg/issues/307

Co-authored-by: Peter Vullings <peter@projectitis.com>
Co-authored-by: Hermet Park <hermetpark@lottiefiles.com>
2023-06-20 11:30:18 +09:00
Hermet Park
e1d73b2c2e doc: fix wrong info by mistake 2023-06-14 12:17:50 +09:00
Hermet Park
9a494e0adb doc: update the CompositeMethod. 2023-06-14 12:06:39 +09:00
Hermet Park
4627daf6f7 api: enhance API usability
Set the default values of rx = 0 and ry = 0 for the shape.
Only the round rectangle shape requires the usage of these values.
2023-06-13 10:42:57 +09:00
Martin Capitanio
44a750ee5d API, CAPI, sw_engine: add suport for stroke-miterlimit. 2023-06-13 10:42:20 +09:00
Hermet Park
84b36e92df api: -- a redundant util func. 2023-06-09 18:50:37 +09:00
Hermet Park
b214fd23bc common canvas/scene: introduce paints() api that returns the list of the paints.
These new apis would enable users to easily modify the motion scene,
The data structure of the paints has been changed from an array to a list.

@APIs:
std::list<Paint*>& Canvas::paints() noexcept;
std::list<Paint*>& Scene::paints() noexcept;

@Deprecated:
Result Canvas::reserve(uint32_t size) noexcept;
Result Scene::reserve(uint32_t size) noexcept;

@Issue: https://github.com/thorvg/thorvg/issues/1203
2023-06-09 10:54:03 +09:00
Hermet Park
6cbc1de570 api: enhance Shape::stroke() method usage.
Designate a default value for alpha which is mostly optional.
2023-06-07 12:10:31 +09:00
Hermet Park
1ae92daa9d api: enhance Shape::fill() method usage.
Designate a default value for alpha which is mostly optional.
2023-06-07 12:10:31 +09:00
Hermet Park
fbf8e8dfce Revert "api: remove deprecated apis"
This reverts commit aa000f7c56.

TVG will move forward to v0.10, so we still need to keep the deprecated APIs.
2023-06-07 10:49:20 +09:00
Hermet Park
fddc409728 common sw_engine: adds missing composite methods.
Now tvg user could combine Mask Alpha & Mask Method like this:

paint->composite(target, tvg::CompositeMethod::AddMask);

binary size diff: 201307 -> 223399 (+22kb)

@APIs:
- CompositeMethod::AddMask
- CompositeMethod::SubtractMask
- CompositeMethod::IntersectMask
- CompositeMethod::DifferenceMask

@Issue: https://github.com/thorvg/thorvg/issues/404
2023-06-03 15:50:48 +09:00
Hermet Park
b45c8efd75 doc: ++Colorspace description
@Issue: https://github.com/thorvg/thorvg/issues/1372
2023-06-01 10:59:06 +09:00
Hermet Park
21c7debf14 composite: Support Inverse Luma Masking
The CompositeMethod now includes the newly supported InvLumaMask option:

The source pixels are converted to grayscale (luma values),
and the complement of the target's pixels is alpha blended.
As a result, only the part of the source where the grayscale
is not covered by the target is visible.

@APIs: CompositeMethod::InvLumaMask

@Example: examples/InvLumaMasking.cpp

@Issue: https://github.com/thorvg/thorvg/issues/404
2023-05-20 20:11:58 +09:00
Hermet Park
5ceeb32ef0 api: remove a beta api.
- Result Picture::viewbox(float* x, float* y, float* w, float* h) const;  //c++
- vg_Result tvg_picture_get_viewbox(const Tvg_Paint* paint, float* x, float* y, float* w, float* h);  //c

@Issue: https://github.com/thorvg/thorvg/issues/1372
2023-05-20 13:22:52 +09:00
Hermet Park
4c60415c0c apis: promote beta apis to offical ones.
- unique_ptr<Picture> Accessor::set(std::unique_ptr<Picture> picture, std::function<bool(const Paint* paint)> func);
- static Accessor::std::unique_ptr<Accessor> gen();
- Result Shape::order(bool strokeFirst);

@Issue: https://github.com/thorvg/thorvg/issues/1372
2023-05-20 13:22:52 +09:00
Hermet Park
fe14e4f499 api: rename beta apis.
- SwCanvas::Colorspace::ABGR8888_STRAIGHT -> SwCanvas::Colorspace::ABGR8888S
- SwCanvas::Colorspace::ARGB8888_STRAIGHT -> SwCanvas::Colorspace::ARGB8888S

@Issue: https://github.com/thorvg/thorvg/issues/1372
2023-05-20 13:22:52 +09:00
Hermet Park
6994925b9d common shape: fixing stroking composition issue.
When combining Shape, Stroke, and AlphaMasking, there is a missing
composition step which results in an incorrect output as expected by the user.

This problem is resolved by introducing shape fill and stroking composition.

@Issue: https://github.com/thorvg/thorvg/issues/209
2023-05-19 10:35:24 +09:00
Vincent Torri
be2de28312 portability: fix usage of TVG_API
Rule of thumb on Windows:
  * for a DLL:
    * if the library is built, set TVG_API to __declspec(dllexport)
    * if the library is used, set TVG_API to __declspec(dllimport)
  * for a static library, set TVG_API to nothing

To set TVG_API for a static library, TVG_STATIC is defined when the stataic library is built.
Otherwise, TVG_API is correctly set for a DLL.
Also sun and intel compilers are handled

@issue: https://github.com/thorvg/thorvg/issues/1446
2023-05-16 18:55:33 +09:00
Hermet Park
4d722623a6 api: introduce cast() template method.
The cast() method is a utility function used to
cast a 'Paint/Fill' to type 'T'.

This would help users to write code optimal.

@API Additions:
template<typename T> std::unique_ptr<T> cast(Paint* paint)
template<typename T> std::unique_ptr<T> cast(Fill* fill)
2023-05-15 12:07:55 +09:00
Hermet Park
0fb8ed38d7 api: remove extern "C"
Remove extern "C specifier. ThorVG has the C binding,
C++ apis doesn't need to be compatibile with a C compiler.
This limits the C++ style template interface.
2023-05-15 12:07:55 +09:00
Hermet Park
aa000f7c56 api: remove deprecated apis
- Result Paint::bounds(float* x, float* y, float* w, float* h) const noexcept;
- Result Picture::load(const char* data, uint32_t size, bool copy = false) noexcept;

@Issue: https://github.com/thorvg/thorvg/issues/1372
2023-05-13 18:30:11 +09:00
Hermet Park
ddc846289c apis: Let's promote the beta APIs to official ones.
- enum class CompositeMethod::LumaMask
- Result Picture::load(uint32_t* data, uint32_t w, uint32_t h, bool copy)
2023-05-09 23:19:15 +09:00
Hermet Park
84012651cc common engine: code refactoring
Introduce the RenderMesh structure to reduce the number of required parameters.
2023-04-27 10:16:12 +09:00
Hermet Park
69063d2405 infra: specify TVG_API for both static/dynamic linking.
The previous meson script was incomplete,
therefore this change requires it to be revised.

To enable static linking use the next meson option.
"-Ddefault_library=static"

Issue: https://github.com/thorvg/thorvg/issues/1234
2023-04-22 18:32:22 +09:00