Commit graph

292 commits

Author SHA1 Message Date
Hermet Park
730b0d23f0 renderer/paint: revise the Paint::bounds() behavior
The current Paint::bounds(transform=true) returns the coordinates
of the paint in its local coordinates after transformation.

However, it did not convert the origin to the world coordinate.

This is problematic when the user wants to determine
the paint's position and size with the origin being the canvas.
Specifically, this matters that when the paint is belonged
to a certain scene.

Now, the bounds() method returns the coordinates
of the paint's bounding box with the corrected world space.
User can figure out the actual boundary within the painted result.

Remark that, this may break the functional behavior compatibility.
2024-09-30 15:48:18 +09:00
Hermet Park
d1664a162e renderer/picture: added a method to search for a paint object
This utility method allows access to a specific paint instance
by its unique identifier.

Experimental API:
- const Paint* Picture::paint(uint32_t id)
- const Tvg_Paint* tvg_picture_get_paint(Tvg_Paint* paint, uint32_t id)
2024-09-30 15:48:18 +09:00
Hermet Park
32c4e1d815 renderer/accessor: added the id generator.
This function computes a unique identifier value based on the provided string.
You can use this to assign a unique ID to the Paint object.

Experimental APIs:
- uint32_t Accessorr::id(const char* name)
- uint32_t tvg_accessor_id(const char* name)
2024-09-30 15:48:18 +09:00
Hermet Park
6456252b43 API: introduce a Paint ID member as a reserved field
The "id" is a reserved field to specify a paint instance in a scene.
in this change, it assigns the layer id to the lottie scene as well.
2024-09-30 15:48:18 +09:00
Hermet Park
21d3cc4eb9 renderer/accessor: revise set() api for animation support
before:
unique_ptr<Picture> Accessor::set(unique_ptr<Picture> picture, function<bool(const Paint* paint)> func)

after:
Result Accessor::set(const Picture* picture, std::function<bool(const Paint* paint, void* data)> func, void* data)
2024-09-30 15:48:18 +09:00
Hermet Park
abf3e2d6ae renderer: newly support the Lighten/Darken Masking options
Lighten is applied, where multiple masks intersect,
the highest transparency value is used.

Darken is applied, where multiple masks intersect,
the lowest transparency value is used.

Experimental API:
- CompositeMethod::LightenMask
- CompositeMethod::DarkenMask

issue: https://github.com/thorvg/thorvg/issues/2608
2024-09-30 15:48:18 +09:00
Mira Grudzinska
1fdfe8a3b8 sw_engine: handle grad edge cases
For a linear gradient defined by identical start and end
points, and for a radial gradient with a radius of 0,
the rendered shape should have the color of the last
specified color stop.
The documentation has been updated accordingly.

@Issue: https://github.com/thorvg/thorvg/issues/2582
2024-09-30 15:48:18 +09:00
Mira Grudzinska
d29a3d754b common: move&fix trimming wrapping logic
The logic of interpretation of trimming start and
end values has been moved to the sw_engine,
so the values provided by the user are not modified.
No logical changes in the interpretation alg.

For pairs of trim's start/end values where the distance
between begin and end is >= 1, the entire stroke should
be drawn, but instead, nothing or only part is drawn. Fixed.

Stroke trim docs fixed.
2024-09-30 15:48:18 +09:00
Hermet Park
656fb6f498 renderer/animation: rectified the segment value exception
A zero-range segment can be useful for a stopped motion.
There is no need to prohibit these values.
2024-09-30 15:38:10 +09:00
Mira Grudzinska
0944f3253d common: version api introduced
@Issue: https://github.com/thorvg/thorvg/issues/2543
2024-09-30 15:35:34 +09:00
Hermet Park
78ece5befd renderer: Rectified the paint transforms.
This corrects the return value to Result::InsufficientCondition
when a custom transform is applied.

Additionally, unnecessary x and y member fields have been removed.
2024-09-30 12:57:14 +09:00
Hermet Park
4345d6b8a5 API: revise the APIs.
deprecate the `identifier()` APIs by replacing them with `type()`.

ThorVG is going to introduce an instance `id()`,
and this could be confused with the `identifier()` methods.

with this new type() method can reduce the memory size
by removing unncessary type data.

New Experimental C APIs:
- enum Tvg_Type
- Tvg_Result tvg_paint_get_type(const Tvg_Paint* paint, Tvg_Type* type)
- Tvg_Result tvg_gradient_get_type(const Tvg_Gradient* grad, Tvg_Type* type)

New Experimental C++ APIs:
- Type Paint::type() const
- Type Fill::type() const
- Type LinearGradient::type() const
- Type RadialGradient::type() const
- Type Shape::type() const
- Type Scene::type() const
- Type Picture::type() const
- Type Text::type() const

Deprecated C APIs:
- enum Tvg_Identifier
- Tvg_Result tvg_paint_get_identifier(const Tvg_Paint* paint, Tvg_Identifier* identifier)
- Tvg_Result tvg_gradient_get_identifier(const Tvg_Gradient* grad, Tvg_Identifier* identifier)

Deprecated C++ APIs:
- enum class Type
- uint32_t Paint::identifier() const
- uint32_t Fill::identifier() const
- static uint32_t Picture::identifier()
- static uint32_t Scene::identifier()
- static uint32_t Shape::identifier()
- static uint32_t LinearGradient:identifier()
- static uint32_T RadialGradient::identfier()

Removed Experimental APIs:
- static uint32_t Text::identifier()

issue: https://github.com/thorvg/thorvg/issues/1372
2024-09-30 12:55:16 +09:00
Hermet Park
7b79f37dd2 api: ++description
issue: https://github.com/thorvg/thorvg/issues/2494
2024-09-30 12:45:29 +09:00
Josh Soref
e3c66db301 common: fix 178+ spelling errors 2024-09-30 12:41:38 +09:00
Hermet Park
0ecd09e7ff doc: polishing++ 2024-09-30 12:36:43 +09:00
Hermet Park
b6597fc1ef apis: promotes to official apis.
C++
- GlCanvas::gen()

CAPI
- TVG_COMPOSITE_METHOD_INVERSE_LUMA_MASK
2024-06-27 14:42:27 +09:00
Hermet Park
8259bb9d4e doc: removed useless information for easier maintainence.
That basic information is addressed in the Results section.
We can only add information that pertains to a specific scenario.
2024-06-27 14:42:27 +09:00
Mira Grudzinska
01b99f1cf5 docs: add missing args description 2024-06-27 14:42:27 +09:00
Hermet Park
4b01c0ef52 renderer/canvas: ++exceptional handling.
do not allow change the target if the condition is not satisfied.
2024-06-27 14:42:27 +09:00
Mira Grudzinska
33640eae83 common: fix returned value
In the case of requesting to unload a font that
has not been previously loaded, InsufficientCondition
should be returned, not InvalidArgument.
2024-06-24 14:52:27 +09:00
Hermet Park
41ffcf2bdf doc: updated the WgCanvas api doc 2024-06-24 14:50:34 +09:00
Sergii Liebodkin
47b9866f8b wg_engine: cross-platform support
it provide changes public API for webgpu canvas interface to provide nessessary handles to native window for different platforms:

API Change:
- Result target(void *instance, void *surface, uint32_t w, uint32_t h) noexcept;
2024-06-24 14:50:28 +09:00
Mira Grudzinska
ec77d8bd89 ttf_loader: support loading from memory
New text API for loading fonts from memory
is introduced. This is necessary to enable
embedded fonts support.
2024-06-24 14:50:13 +09:00
Mira Grudzinska
733f0996d8 docs: resolve doxygen warnings 2024-06-24 14:43:48 +09:00
Hermet Park
d5f41c85d3 api: corrected return type.
NonSupport indicates unsupported options due to disabled features
or lack of system support. InvalidArgument indicates the case
such as incorrect parameter values.
2024-06-24 14:42:46 +09:00
Mira Grudzinska
61de65e10b common: clarification of returned types
The functions setting stroke's features always
returned a true. Returnig a boolen was a remnant
from a previous implementation. Since now they
never return false, they can be void functions.
The APIs description has been corrected.
2024-06-24 14:42:12 +09:00
Mira Grudzinska
e6f4b5a2a8 common: strokeTrim api introduced
New api sets/gets the trim of the stroke
along the defined path segment, allowing
control over which part of the stroke is
visible.

@issue: https://github.com/thorvg/thorvg/issues/2190
2024-06-24 14:37:53 +09:00
Hermet Park
a93c348207 renderer/canvas: tweak the viewport behavior.
reset the viewport context when target buffer is reset.
2024-06-24 14:29:42 +09:00
Hermet Park
090ebfba86 xrenderer/engines: support the canvas viewport function.
The viewport function defines the rectangular area of the canvas
that will be used for drawing operations.

It is used to clip the rendering output to the boundaries of the rectangle.
Apps can use this function to set the drawing region within the canvas.

When the ThorVG canvas is partially inside the screen area such as during scrolling
it could help enhance rendering performance.

New Experimental API:
- Result Canvas::viewport(int32_t x, int32_t y, int32_t w, int32_t h) noexcept;

Issue: https://github.com/thorvg/thorvg/issues/2274
2024-06-24 14:20:46 +09:00
Hermet Park
827a00b076 animation/lottie: improved the precision of frame values.
Refined the logic for updating frame numbers
to ensure greater accuracy in value precision.

issue: https://github.com/thorvg/thorvg/issues/2266
2024-06-24 14:12:00 +09:00
Hermet Park
b615348df1 doc: adds the api version history 2024-06-24 12:29:36 +09:00
Lucas Niu
194bd8f01d lottie: Support the Animation Segment(Marker)
A single animation might have a desinated markers with naming: 0 ~ 0.5 (sector A), 0.5 ~ 1.0  (sector B). Selecting one of them using a marker name(sector A) and could play only that part with animation controllers.

usage:
- `animation->segment("sectionA") // Named segment(Marker)`
- `auto cnt = animation->markerCnt()`
- `auto name = animation->markers(index)`
- `animation->segment(0, 0.5) // Segment`
- `animation->segment(&begin, &end)`

Co-authored-by: Jinny You <jinny@lottiefiles.com>
2024-06-24 12:00:25 +09:00
Hermet Park
ca7aec5fff lottie: rectify the frame updates.
Currently, tvg ignores the frame value if the difference
is less than 0.001. In most cases, updating the frames
when the change is less than 1ms is just an unnecessary
burden on the system.

Instead, this ensures that the perfect last frame is reached.

issue: https://github.com/thorvg/thorvg/issues/2147
2024-06-24 11:58:48 +09:00
Hermet Park
4746b2cf7b gl_engine: hotfix for the main surface drawing issue.
GL might need to generate a default target FBO
when the given target ID indicates the main surface.

However, users may want to draw visuals directly onto the main surface.

This policy must be reviewed thoroughly.
2024-04-07 15:15:59 +09:00
Hermet Park
04b5525db4 api: Promote experimental Animation APIs to official status.
These APIs have been thoroughly tested and verified.

New API:
- Result Animation::frame(float no)
- Picture* Animation::picture() const
- float Animation::curFrame() const
- float Animation::totalFrame() const
- float Animation::duration() const
- static Animation::std::unique_ptr<Animation> gen()

New CAPI:
- Tvg_Animation* tvg_animation_new()
- Tvg_Result tvg_animation_set_frame(Tvg_Animation* animation, float no)
- Tvg_Paint* tvg_animation_get_picture(Tvg_Animation* animation)
- Tvg_Result tvg_animation_get_frame(Tvg_Animation* animation, float* no)
- Tvg_Result tvg_animation_get_total_frame(Tvg_Animation* animation, float* cnt)
- Tvg_Result tvg_animation_get_duration(Tvg_Animation* animation, float* duration)
- Tvg_Result tvg_animation_del(Tvg_Animation* animation)

issue: https://github.com/thorvg/thorvg/issues/2067
2024-04-06 12:08:23 +09:00
Hermet Park
5d10e514d7 renderer/gl_engine: Refine GlCanvas Interface
Refactor the GlCanvas::target() interface to allow
passing the drawing target ID from the user side.

Previously, it performed the drawing on the currently set FBO target.

Beta API change:

Result GlCanvas::target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h)
-> Result GlCanvas::target(int32_t id, uint32_t w, uint32_t h)
2024-04-06 12:08:21 +09:00
Hermet Park
fa393f1c52 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-04-06 12:08:21 +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