Commit graph

332 commits

Author SHA1 Message Date
Hermet Park
22d94ea629 renderer: introduced paint reference counting
The reference count of the Paint object allows
easy & safe shared ownership and control over its lifetime
among users and the engine.

New APIs:
- uint8_t Paint::ref()
- uint8_t Paint::unref(bool free = true)
- uint8_t Paint::refCnt() const

issue: https://github.com/thorvg/thorvg/issues/1372 https://github.com/thorvg/thorvg/issues/2598
2024-11-20 01:53:25 +09:00
Hermet Park
ed01ef717e api: revise the spec
Remove the requirement for unique_ptr in the function prototypes.
This change will simplify the API usage, making it more streamlined
and user-friendly. However, memory management will now be the
responsibility of the user.

C++ API Modification:
- Result Paint::mask(std::unique_ptr<Paint> target, MaskMethod method) -> Result Paint::mask(Paint* target, MaskMethod method)
- Result Paint::clip(std::unique_ptr<Paint> clipper) -> Result Paint::clip(Paint* clipper)
- virtual Result Canvas::push(std::unique_ptr<Paint> paint) -> virtual Result Canvas::push(Paint* paint)
- std::unique_ptr<LinearGradient> LinearGradient::gen() -> LinearGradient* LinearGradient::gen()
- std::unique_ptr<RadialGradient> RadialGradient::gen() -> RadialGradient* RadialGradient::gen()
- Result Shape::strokeFill(std::unique_ptr<Fill> f) -> Result Shape::strokeFill(Fill* f)
- Result Shape::fill(std::unique_ptr<Fill> f) -> Result Shape::fill(Fill* f)
- std::unique_ptr<Shape> Shape::gen() -> Shape* Shape::gen()
- std::unique_ptr<Picture> Picture::gen() -> Result Picture::push(Paint* paint)
- std::unique_ptr<Scene> Scene::gen() -> Scene* Scene::gen()
- Result Text::fill(std::unique_ptr<Fill> f) -> Result Text::fill(Fill* f)
- std::unique_ptr<Text> Text::gen() -> Text* Text::gen()
- std::unique_ptr<SwCanvas> SwCanvas::gen() -> SwCanvas* SwCanvas::gen()
- std::unique_ptr<GlCanvas> GlCanvas::gen() -> GlCanvas* GlCanvas::gen()
- std::unique_ptr<Animation> Animation::gen() -> Animation* Animation::gen()
- Result Saver::background(std::unique_ptr<Paint> paint) -> Result Saver::background(Paint* paint)
- Result Saver::save(std::unique_ptr<Paint> paint, const char* filename, uint32_t quality = 100) -> Result Saver::save(Paint* paint, const char* filename, uint32_t quality = 100)
- std::unique_ptr<Saver> Saver::gen() -> Saver* Saver::gen()
- std::unique_ptr<Accessor> Accessor::gen() -> Accessor* Accessor::gen()

C++ API removal:
- template<typename T = tvg::Paint> std::unique_ptr<T> cast(Paint* paint)
- template<typename T = tvg::Paint> std::unique_ptr<T> cast(Paint* paint)

issue: https://github.com/thorvg/thorvg/issues
2024-11-09 12:29:15 +09:00
Hermet Park
4aaa0dafc4 common: code refactoring
replaced internal string usage with char*
2024-11-08 15:26:04 +09:00
Hermet Park
9a134fcb90 api: revise the apis for v1.0
replaced std::string with char* in API parameters.

API Modification:
- Result Picture::load(const std::string& path) -> Result Picture::load(const char* filename)
- Result Picture::load(const char* data, uint32_t size, const std::string& mimeType, const std::string& rpath = "", bool copy = false) -> Result Picture::load(const char* data, uint32_t size, const char* mimeType, const char* rpath = "", bool copy = false)
- Result Text::load(const std::string& path) -> Result Text::load(const char* filename)
- Result Text::load(const char* name, const char* data, uint32_t size, const std::string& mimeType = "ttf", bool copy = false) -> Result Text::load(const char* name, const char* data, uint32_t size, const char* mimeType = "ttf", bool copy = false)
- Result Text::unload(const std::string& path) -> Result Text::unload(const char* filename)
- Result Saver::save(std::unique_ptr<Paint> paint, const std::string& path, uint32_t quality = 100) -> Result Saver::save(std::unique_ptr<Paint> paint, const char* filename, uint32_t quality = 100)
- Result Saver::save(std::unique_ptr<Animation> animation, const std::string& path, uint32_t quality = 100, uint32_t fps = 0) -> Result Saver::save(std::unique_ptr<Animation> animation, const char* filename, uint32_t quality = 100, uint32_t fps = 0)

issue: https://github.com/thorvg/thorvg/issues/1372
2024-11-06 21:32:45 +09:00
Hermet Park
e0365142a7 renderer: support SceneEffect DropShadow
Apply a drop shadow effect with a Gaussian Blur filter.

API Addition:
 - enum class SceneEffect::DropShadow

Parameters:
 - color_R(int)[0 - 255]
 - color_G(int)[0 - 255]
 - color_B(int)[0 - 255]
 - opacity(int)[0 - 255]
 - angle(float)[0 - 360]
 - distance(float)
 - blur_sigma(float)[> 0]
 - quality(int)[0 - 100]

issue: https://github.com/thorvg/thorvg/issues/2718
2024-11-06 00:56:11 +09:00
Mira Grudzinska
422674b4c9 api: add focal parameters to the radial apis
API modification:
- Result RadialGradient::radial(float cx, float cy, float radius)
- Result RadialGradient::radial(float cx, float cy, float r, float fx, float fy, float fr)
- Result RadialGradient::radial(float* cx, float* cy, float* radius)
- Result RadialGradient::radial(float* cx, float* cy, float* r, float* fx = nullptr, float* fy = nullptr, float* fr = nullptr)

@Issue: https://github.com/thorvg/thorvg/issues/2860
2024-10-23 11:10:14 +09:00
Hermet Park
0a16152d75 api: renamed the composite with mask.
Since we've separated ClipPath and Masking,
Masking now has a distinct and independent purpose.

API Modification:
 - enum class CompositeMethod -> enum class MaskMethod
 - Result Paint::composite(std::unique_ptr<Paint> target, CompositeMethod method) -> Result Paint::mask(std::unique_ptr<Paint> target, MaskMethod method)
 - CompositeMethod Paint::mask(const Paint** target) const -> MaskMethod Paint::mask(const Paint** target) const

issue: https://github.com/thorvg/thorvg/issues/1372
2024-10-16 14:41:26 +09:00
Hermet Park
630cbc48ae api: revise the api for v1.0
- refactored the Fill matrix to hold internal data statically.
- refactored for clean & neat the raster engine / svg loader logic.

API Modification:
 - Matrix Fill::transform() const -> Matrix& Fill::transform() const

issue: https://github.com/thorvg/thorvg/issues/1372
2024-10-14 23:32:55 +09:00
Hermet Park
6a45e6e494 api: revise the api for v1.0
API Modification:
- Matrix Paint::transform() -> Matrix& Paint::transform()

issue: https://github.com/thorvg/thorvg/issues/1372
2024-10-14 17:22:20 +09:00
Hermet Park
8ee5f5c544 api: path data size reduction (to 1 byte)
API Modification:
- enum class PathCommand -> enum class PathCommand : uint8_t
- enum class Result::Unknown (6) -> enum class Result::Unknown = 255

- typedef enum Tvg_Path_Command -> typedef uint8_t Tvg_Path_Command
- TVG_RESULT_UNKNOWN (6) -> TVG_RESULT_UNKNOWN = 255
2024-10-14 14:46:40 +09:00
Hermet Park
65916857e2 api: polish the thorvg API usages
Use ColorSpace to support various types of raw bitmaps.

API Modifications:
- Result Picture::load(uint32_t* data, uint32_t w, uint32_t h, bool premultiplied, bool copy = false) -> Result Picture::load(uint32_t* data, uint32_t w, uint32_t h, ColorSpace cs, bool copy = false)
- Tvg_Result tvg_picture_load_raw(Tvg_Paint* paint, uint32_t *data, uint32_t w, uint32_t h, bool premultiplied, bool copy) -> Tvg_Result tvg_picture_load_raw(Tvg_Paint* paint, uint32_t *data, uint32_t w, uint32_t h, Tvg_Colorspace cs, bool copy)

issue: https://github.com/thorvg/thorvg/issues/1372
2024-10-13 11:15:57 +09:00
Hermet Park
367ac5f331 api: removed redundant CompisiteMethod::ClipPath
issue: https://github.com/thorvg/thorvg/issues/1372
2024-10-12 16:02:38 +09:00
Hermet Park
9bc900206b api: polish the thorvg API usages.
API Modification:
- SwCanvas::Colorspace -> ColorSpace

API Addition:
- ColorSpace::Unknown

issue: https://github.com/thorvg/thorvg/issues/1372
2024-10-12 15:38:03 +09:00
Hermet Park
01559a45c0 api: remove deprecations
issue: https://github.com/thorvg/thorvg/issues/1372
2024-10-07 20:43:37 +09:00
Hermet Park
2558e5dc10 renderer: introduced SceneEffect feature
Scene effects are typically applied to modify
the final appearance of a rendered scene,
such as adding a blur effect.

Each effect would have a different number of parameters
to control its visual properties. The Scene::push() interface
 uses variadic arguments to accommodate various cases.

Users should refer to the SceneEffect API documentation
and pass the parameters exactly as required for the specific
effect type. For instance, GaussianBlur expects 3 parameters
which are:

- sigma(float)[greater than 0]
- direction(int)[both: 0 / horizontal: 1 / vertical: 2]
- border(int)[extend: 0 / wrap: 1]
- quality(int)[0 ~ 100]

and, scene->push(SceneEffect::GaussianBlur, 5.0f, 0, 0, 100);

New Experimental APIs:
- SceneEffect::ClearAll
- SceneEffect::GaussianBlur
- Result Scene::push(SceneEffect effect, ...);

Example:
- examples/SceneEffect

issue: https://github.com/thorvg/thorvg/issues/374
2024-09-29 15:04:22 +09:00
Hermet Park
76fb3f3cd9 api: clean up
promoted offical c++ apis (v0.15)
 - enum class BlendMethod
 - enum class CanvasEngine::Wg
 - virtual Result Canvas::viewport(int32_t x, int32_t y, int32_t w, int32_t h);
 - class Text
 - Result Text::fill(uint8_t r, uint8_t g, uint8_t b)
 - Result Text::fill(std::unique_ptr<Fill> f)
 - static Result Text::unload(const std::string& path)
 - static Result Text::load(const std::string& path)
 - static Result Text::load(const char* name, const char* data, uint32_t size, const std::string& mimeType = "ttf", bool copy = false)
 - static std::unique_ptr<Text> Text::gen()
 - class WgCanvas
 - static std::unique_ptr<WgCanvas> WgCanvas::gen()
 - static const char* Initializer::version(uint32_t* major, uint32_t* minor, uint32_t* micro)
 - class LottieAnimation

promoted official c apis (v0.15)
 - Tvg_Blend_Method
 - Tvg_Result tvg_engine_version(uint32_t* major, uint32_t* minor, uint32_t* micro, const char** version)
 - Tvg_Result tvg_canvas_set_viewport(Tvg_Canvas* canvas, int32_t x, int32_t y, int32_t w, int32_t h)
 - Tvg_Result tvg_paint_set_blend_method(Tvg_Paint* paint, Tvg_Blend_Method method)
 - Tvg_Paint* tvg_text_new(void)
 - Tvg_Result tvg_text_set_fill_color(Tvg_Paint* paint, uint8_t r, uint8_t g, uint8_t b)
 - Tvg_Result tvg_text_set_gradient(Tvg_Paint* paint, Tvg_Gradient* gradient)
 - Tvg_Result tvg_font_load(const char* path)
 - Tvg_Result tvg_font_load_data(const char* name, const char* data, uint32_t size, const char *mimetype, bool copy)
 - Tvg_Result tvg_font_unload(const char* path)
 - Tvg_Animation* tvg_lottie_animation_new(void)

removed experimental apis
 - BlendMethod paint::blend() const
 - bool Shape::strokeTrim(float* begin, float* end) const
 - Tvg_Result tvg_paint_get_blend_method(const Tvg_Paint* paint, Tvg_Blend_Method* method)
 - Tvg_Result tvg_shape_get_stroke_trim(Tvg_Paint* paint, float* begin, float* end, bool* simultaneous)
 - tvg_text_set_linear_gradient(Paint* paint, Tvg_Gradient* gradient)
 - tvg_text_set_radial_gradient(Paint* paint, Tvg_Gradient* gradient)

issue: https://github.com/thorvg/thorvg/issues/1372
2024-09-23 21:53:50 +09:00
Hermet Park
b0683a26ec api: Introduced Paint::clip() API
Separate clip function from the Composite()
clipping and composition can be used together.

This helps avoid the introduction of nested scenes
when composition and clipping overlap.

Deprecated:
- enum class CompositeMethod::ClipPath
- enum Tvg_Composite_Method::TVG_COMPOSITE_METHOD_CLIP_PATH

Experimental API:
- Result Paint::clip(std::unique_ptr<Paint> clipper)
- Tvg_Result tvg_paint_set_clip(Tvg_Paint* paint, Tvg_Paint* clipper)

Issue: https://github.com/thorvg/thorvg/issues/1496
2024-09-19 14:46:05 +09:00
Hermet Park
a746e1fcd6 renderer: blending refactoring++
- reordered the blending types to align with lottie spec.
- removed source over.
2024-09-09 21:18:13 +09:00
Hermet Park
dd6ad0fc6e api: clean form++ 2024-09-06 14:32:02 +09:00
Sergii Liebodkin
e2e4fc6964
wg_engine: external device handles (web integration)
move instance, adapter and device creation from renderer to application
its necessary for web integration, because browser have its own mechanics to create hardware handles
this changes makes webgpu canvas more universal to use in case of system and web applications

issue: https://github.com/thorvg/thorvg/issues/2410
2024-09-06 13:08:58 +09:00
Hermet Park
71d3fce1dd renderer: text refactoring
- assign the shape instance as mandatory.
- assign the text instance internally.
2024-08-21 14:51:53 +09:00
Hermet Park
c75311d239 api: corrected wrong const specifier
Setter obvisouly modifies the instance.
2024-08-21 14:50:40 +09:00
Mira Grudzinska
5448b1b9cd docs: description++ 2024-08-20 18:44:39 +09:00
Hermet Park
8598348ec0 doc: ++enhancement in Picture::load()
addressed supported raw data format.

issue: https://github.com/thorvg/thorvg/issues/2648
2024-08-20 11:53:40 +09:00
Hermet Park
5332876fe8 common: spec out TexMap
Spec out this incomplete experimental feature,
this is a still promising one, we will reintroduce
this officially after 1.0 release

size: -2kb

issue: https://github.com/thorvg/thorvg/issues/1372
2024-08-20 11:14:54 +09:00
Elliott Sales de Andrade
966aeb5ee3 build: Override dependency for use as subproject
A pkgconfig file is already provided, which enables using `thorvg` once
it is installed. However, this file is not, and cannot be, available at
setup time if using `thorvg` as a subproject.

In such cases, Meson provides the `override_dependency` mechanism for a
subproject to tell its parent how to use it.
2024-08-19 17:42:06 +09:00
Mira Grudzinska
f79558eb62 API: deprecate the appendArc() api
@Issue: https://github.com/thorvg/thorvg/issues/2632
2024-08-16 13:30:58 +09:00
Hermet Park
407fc84796 common: spec out Scene Clipper
Scene Clipper is an unusual feature
that is too unstable and ambiguous in ThorVG.

Users can achieve the same functionality
with multiple composed shapes instead of scene clipping.

size: -2.5kb

issues:
- https://github.com/thorvg/thorvg/issues/1548
- https://github.com/thorvg/thorvg/issues/1549
- https://github.com/thorvg/thorvg/issues/1573
2024-08-13 10:21:54 +09:00
Hermet Park
43c87b4eb5 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-08-07 12:02:22 +09:00
Hermet Park
ee3293401b 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-08-07 12:02:22 +09:00
Hermet Park
ed9eee897a 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-08-07 12:02:22 +09:00
Hermet Park
45352c9a1f 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-08-07 12:02:22 +09:00
Hermet Park
d62b913455 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-08-07 12:02:22 +09:00
Hermet Park
49f3395631 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-08-07 11:04:38 +09:00
Mira Grudzinska
58797ffafd 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-08-01 14:25:29 +09:00
Mira Grudzinska
7c87d8e632 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-07-31 14:32:04 +02:00
Hermet Park
b388bf06d5 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-07-25 20:12:32 +09:00
Mira Grudzinska
17e0bcd332 common: version api introduced
@Issue: https://github.com/thorvg/thorvg/issues/2543
2024-07-18 12:47:58 +09:00
Hermet Park
eb86ac539c 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-07-07 21:43:30 +09:00
Hermet Park
889d1d1fa2 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-07-05 21:25:58 +09:00
Hermet Park
e4c4a95495 api: ++description
issue: https://github.com/thorvg/thorvg/issues/2494
2024-07-02 18:21:11 +09:00
Josh Soref
e061fa6628
common: fix 178+ spelling errors 2024-07-01 21:58:46 +09:00
Hermet Park
d6e64c0619 doc: polishing++ 2024-06-28 16:14:57 +09:00
Hermet Park
1ad00f987c apis: promotes to official apis.
C++
- GlCanvas::gen()

CAPI
- TVG_COMPOSITE_METHOD_INVERSE_LUMA_MASK
2024-06-26 15:16:26 +09:00
Hermet Park
a7c7539674 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-25 11:11:33 +09:00
Mira Grudzinska
f202137acd docs: add missing args description 2024-06-24 21:41:12 +09:00
Hermet Park
9fb8a49d52 renderer/canvas: ++exceptional handling.
do not allow change the target if the condition is not satisfied.
2024-06-24 01:29:57 +09:00
Mira Grudzinska
e8b5062657 docs: descriptions++ 2024-06-20 23:12:34 +09:00
Mira Grudzinska
6544747e70 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-17 11:45:25 +09:00
Hermet Park
45bf996a19 doc: updated the WgCanvas api doc 2024-06-12 12:45:47 +09:00