Commit graph

259 commits

Author SHA1 Message Date
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
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