Commit graph

277 commits

Author SHA1 Message Date
Mira Grudzinska
33f5ea34c0 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-05 11:55:36 +09:00
Hermet Park
c784ed7362 renderer/canvas: tweak the viewport behavior.
reset the viewport context when target buffer is reset.
2024-05-20 14:44:15 +09:00
Hermet Park
42409987e2 renderer/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-05-18 18:10:50 +09:00
Hermet Park
38bd34b01f 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-05-14 15:28:48 +09:00
Hermet Park
7a9ba52d0c doc: adds the api version history 2024-04-30 14:32:07 +02:00
Lucas Niu
3af9faf116 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-04-14 23:54:26 +09:00
Hermet Park
50707482ba 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-04-11 10:54:02 +09:00
Hermet Park
1efb72ce94 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-05 01:11:14 +09:00
Hermet Park
d6504ed35d doc: List the parameters in their respective order. 2024-03-28 14:01:17 +09:00
Hermet Park
e4775727eb 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-03-27 16:18:42 +09:00
Hermet Park
754a4aeaea 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-03-13 10:13:02 +02:00
Hermet Park
1e4bf308da 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-06 14:34:58 +09:00
Hermet Park
1d9ea58be3 api: promote to official APIs.
New API:
- CanvasEngine::All
- SwCanvas::Colorspace::ABGR8888S
- SwCanvas::ColorSpace::ARGB8888S
2023-12-27 16:42:26 +09:00
Hermet Park
84e8e38f0a doc: remove unnecessary doxy guide. 2023-12-27 11:05:58 +09:00
Hermet Park
0f69eef8ed 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
2023-12-25 12:40:12 +09:00
Hermet Park
cd2e343192 doc: polish up the doxygen.
- applied @retval for those const values.
- applied @return for return value description.
2023-12-18 23:39:46 +09:00
Hermet Park
f2c29063d2 api: updated the recent changed api again.
Reordered by the data packing size.
Also removed a wrong capi default parameter value.

Result Picture::load(const char* data, uint32_t size, const std::string& mimeType, bool copy = false, const std::string& rpath = "")
-> Result load(const char* data, uint32_t size, const std::string& mimeType, const std::string& rpath = "", bool copy = false)

Tvg_Result tvg_picture_load_data(Tvg_Paint* paint, const char *data, uint32_t size, const char *mimetype, bool copy, const char* resourcePath)
-> Tvg_Result tvg_picture_load_data(Tvg_Paint* paint, const char *data, uint32_t size, const char *mimetype, const char* resourcePath, bool copy);
2023-11-23 11:59:38 +09:00
Jinny You
132be91de4 lottie/loader: support external image from memeory lottie
I've added new parameter, const string& resourcePath, to load external image on lottie.

Result load(const char* data, uint32_t size, const string& mimeType, bool copy, const string& resourcePath)

Note: tvgLoadModule will have new overrided method `open`, not to effect to other changes except animation.

Issue: #1793
2023-11-22 18:04:35 +09:00
Sergii Liebodkin
548962f5f8 apis/engines: Revise the clear() buffer behavior.
ThorVG has offered an option to clear the buffer since version 1.0.
This is essential when users utilize the canvas target buffer
with the main render target. They share the buffer
and need to draw contents onto the existing contents.

API:
Result Canvas::clear(bool free = true)
-> Result Canvas::clear(bool paints = true, bool buffer = true)

Tvg_Result tvg_canvas_clear(Tvg_Canvas* canvas, bool free);
-> Tvg_Result tvg_canvas_clear(Tvg_Canvas* canvas, bool paints, bool buffer);

Issue: https://github.com/thorvg/thorvg/issues/1779

Co-Authored-By: Hermet Park <hermet@lottiefiles.com>
2023-11-20 18:23:00 +09:00
Hermet Park
561a6d8935 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-11-14 10:47:52 +09:00
Hermet Park
2082343463 doc: make it up missing parameter information. 2023-11-09 14:46:14 +09:00
Sergii
4da90b2847 picture: added ability to support premultiplied for picture raw loader
[issues 1479: picture raw loader to support premultiplied](https://github.com/thorvg/thorvg/issues/1764)

api changes:
    Result Picture::load(uint32_t* data, uint32_t w, uint32_t h, bool copy);
    Result Picture::load(uint32_t* data, uint32_t w, uint32_t h, bool premultiplied, bool copy);

capi changes
    TVG_API Tvg_Result tvg_picture_load_raw(Tvg_Paint* paint, uint32_t *data, uint32_t w, uint32_t h, bool copy);
    TVG_API Tvg_Result tvg_picture_load_raw(Tvg_Paint* paint, uint32_t *data, uint32_t w, uint32_t h, bool premultiplied, bool copy);
2023-11-08 10:46:23 +09:00
Hermet Park
0687b09c72 doc: keep the style clean & neat 2023-11-03 23:54:58 +09:00
Jinny You
a60c881b60 docs: Remove all warnings from doxygen 2023-11-03 12:05:21 +09:00
JunsuChoi
d03bf7a089 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-11-02 17:50:27 +09:00
Hermet Park
d879e56856 saver: Revised the API for the 1.0 release
replaced the 'compress' option with 'quality'

API changes:
Result Saver::save(std::unique_ptr<Paint> paint, const std::string& path, bool compress) ->
Result Saver::save(std::unique_ptr<Paint> paint, const std::string& path, uint32_t quality = 100)

TVG_API Tvg_Result tvg_saver_save(Tvg_Saver* saver, Tvg_Paint* paint, const char* path, bool compress) ->
Tvg_Result tvg_saver_save(Tvg_Saver* saver, Tvg_Paint* paint, const char* path, uint32_t quality)

Issue: #1372
2023-11-02 11:58:23 +09:00
Hermet Park
2d2928652b 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-10-31 12:03:32 +09:00
Hermet Park
d6fffd13c2 api: revise the engine initializer for the 1.0 release.
This change introduces the CanvasEngine::All type to automatically
initialize the engines available on the current system.

These revisions improve the usability of these APIs.

Addtions:
- enum class CanvasEngine::All

Modifications:
- Result Initializer::init(CanvasEngine engine, uint32_t threads) ->
Result Initializer::init(uint32_t threads, CanvasEngine engine = tvg::CanvasEngine::All)
2023-10-30 11:48:02 +09:00
Mira Grudzinska
25a1321243 common: stroke dash offset support with new apis.
This change just allows users to use the offset of the stroke dash.
Actually feature enhacement has been introduced by
478e45f9f3.

@APIs:
uint32_t Shape::strokeDash(const float** dashPattern) ->
uint32_t Shape::strokeDash(const float** dashPattern, float* offset = nullptr)

Result Shape::strokeDash(const float* dashPattern, uint32_t cnt) ->
Result Shape::strokeDash(const float* dashPattern, uint32_t cnt, float offset = 0.0f)

Tvg_Result tvg_shape_set_stroke_dash(Tvg_Paint* paint, const float* dashPattern, uint32_t cnt) ->
Tvg_Result tvg_shape_set_stroke_dash(Tvg_Paint* paint, const float* dashPattern, uint32_t cnt, float offset)

Tvg_Result tvg_shape_get_stroke_dash(const Tvg_Paint* paint, const float** dashPattern, uint32_t* cnt) ->
Tvg_Result tvg_shape_get_stroke_dash(const Tvg_Paint* paint, const float** dashPattern, uint32_t* cnt, float* offset)

@Issue: https://github.com/thorvg/thorvg/issues/1372
2023-10-30 11:47:51 +09:00
Hermet Park
db55481e97 renamed stroke apis family.
float Shape::stroke(float width) -> float Shape::strokeWidth(float width)
Result Shape::stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) -> Result Shape::strokeFill(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255)
Result Shape::stroke(std::unique_ptr<Fill> f) -> Result Shape::strokeFill(std::unique_ptr<Fill> f)
Result Shape::stroke(const float* dashPattern, uint32_t cnt, float offset = 0.0f) ->  Result Shape::strokeDash(const float* dashPattern, uint32_t cnt, float offset = 0.0f)
Result Shape::stroke(StrokeCap cap) -> Result Shape::strokeCap(StrokeCap cap)
Result Shape::stroke(StrokeJoin join) -> Result Shape::strokeJoin(StrokeJoin join)
Result Shape::strokeColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a = nullptr) const -> Result Shape::strokeFill(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a = nullptr) const

@Issue: https://github.com/thorvg/thorvg/issues/1372
2023-10-27 11:46:51 +09:00
Hermet Park
978f85c3ea apis: optimize for compact data size.
Still it needs to size down of the PathCommand.

@Issue: https://github.com/thorvg/thorvg/issues/1372
2023-10-26 15:11:31 +09:00
Hermet Park
21911fa1c8 apis: remove deprecated
- Result Picture::bounds(float* x, float* y, float* w, float* h) const
- Result Picture::load(const char* data, uint32_t size, bool copy = false)
- Result Canvas::reserve(uint32_t size)
- Result Scene::reserve(uint32_t size)

@Issue: https://github.com/thorvg/thorvg/issues/1372
2023-10-26 15:03:13 +09:00
Hermet Park
e570064eba 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-10-24 11:49:57 +09:00
Hermet Park
a6d7a19047 api: enhance the API usage.
Allow users to omit the default type casting for added convenience.
2023-10-18 14:35:57 +09:00
SergeyLebedkin
8d5c728119
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-10-13 22:59:32 +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