Commit graph

677 commits

Author SHA1 Message Date
Mira Grudzinska
3ed357e17a renderer: fix trimmed stroke blinking
Bug introduced as part of a7e7bbc.
After recalculating begin and end to the 0-1 range, an extra
check was added to handle cases when begin is very close to end.
However, this was a bad approach since, even for very close values,
their relationship remains important. What should have been
done in the mentioned commit is properly handling  the case
begin == end, which was incorrectly treated as trimming from begin
to end. Instead, it should be handled as trimming from begin to
1.0 and from 0.0 to end.

@Issue: https://github.com/thorvg/thorvg/issues/3204
2025-02-12 11:36:57 +09:00
Hermet Park
cc4c18d6c6 renderer: revise the Shape rect/circle features
The path direction of shapes is now functional for path trimming.
Replace the main logic with Lottie's by default
to align the spec, migrate the original logic to svg loader side.

This revision helps to reduce the binary size by 2–3 KB for lottie loader.

API Modifications:

- Result Shape::appendRect(float x, float y, float w, float h, float rx = 0, float ry = 0)
 -> Result Shape::appendRect(float x, float y, float w, float h, float rx = 0, float ry = 0, bool cw = true)
- Result Shape::appendCircle(float cx, float cy, float rx, float ry)
 -> Result Shape::appendCircle(float cx, float cy, float rx, float ry, bool cw = true)
- TVG_API Tvg_Result tvg_shape_append_circle(Tvg_Paint* paint, float cx, float cy, float rx, float ry)
 -> TVG_API Tvg_Result tvg_shape_append_circle(Tvg_Paint* paint, float cx, float cy, float rx, float ry, bool cw)
- Tvg_Result tvg_shape_append_rect(Tvg_Paint* paint, float x, float y, float w, float h, float rx, float ry)
 -> Tvg_Result tvg_shape_append_rect(Tvg_Paint* paint, float x, float y, float w, float h, float rx, float ry, bool cw)

issue: https://github.com/thorvg/thorvg/issues/3179
2025-02-12 01:41:02 +09:00
Mira Grudzinska
5c950b783c renderer: handle edge cases for trimming with dashing
- In cases where the begin and end values of trimming did not
result in trimming (end - begin > 1), trimming was ignored.
However, when the stroke is also dashed, this case affects
the shift of the point where the first dash becomes visible.

- Trimming that passes through the curve's start point (like -0.1:0.1)
requires passing through the curve twice. The points obtained from
both passes must be joined - visible when dashing
Cases for simultaneous = true have been handled.

@Issue: https://github.com/thorvg/thorvg/issues/3192
2025-02-11 19:46:13 +09:00
Hermet Park
3c25623ee9 sw/gl/wg: ++threads safety
Considered global engine initialization and termination.
Engines could be used among multiple worker threads.
2025-02-11 19:03:50 +09:00
Hermet Park
ab950b6321 sw_engine: fixed a broken dropshadow
corrected a mismatched stride value of the
direct drawing target buffer.

issue: https://github.com/thorvg/thorvg/issues/3146
2025-02-07 23:46:40 +09:00
Mira Grudzinska
d5125bd839 common: add missing condition while trimming
The idea of introducing epsilon during trimming was to
eliminate the occurrence of short segments whose length
would be zero when higher computational accuracy was used.
By mistake, during the refactor of 8ed4c2f302,
one of the conditions was lost. Fixed.

@Issue: https://github.com/thorvg/thorvg/issues/3053
2025-02-07 12:43:38 +09:00
Mira Grudzinska
3a0e1eadae gl_engine: apply common trimming logic
The trim-related implementation has been removed
and replaced with the one available in common.
The trimPath get() fun changed to be internal.

@Issue: https://github.com/thorvg/thorvg/issues/2854
@Issue: https://github.com/thorvg/thorvg/issues/3053
2025-02-06 22:39:11 +09:00
Mira Grudzinska
cb8cadfbba wg_engine: apply common trimming logic
The trim-related implementation has been removed
and replaced with the one available in common.

@Issue: https://github.com/thorvg/thorvg/issues/2854
2025-02-06 22:39:11 +09:00
Mira Grudzinska
8ed4c2f302 sw_engine: move trimming logic to TrimPath
The trim handling from sw_engine has been removed.
Instead the common logic from the TrimPath structure
is used.
On the sw_engine side, the dashed outline is now
used for both: dashed and/or trimmed strokes.

@Issue: https://github.com/thorvg/thorvg/issues/2854
2025-02-06 22:39:11 +09:00
Mira Grudzinska
669d6dc580 common: introduce TrimPath struct
The first step towards unifying trimming across engines.

@Issue: https://github.com/thorvg/thorvg/issues/2854
2025-02-06 22:39:11 +09:00
Hermet Park
0dd0a3b45c common: neat code++
introduced common BBox structure
2025-02-06 15:40:32 +09:00
Sergii Liebodkin
857f1404e1 wg_engine: gaussian blur basic implementation
Introduce blur effect for webgpu renderer
Issue: https://github.com/thorvg/thorvg/issues/3054
2025-02-06 14:44:08 +09:00
Hermet Park
f4a2c922be lottie: minor optimization
use a reusable buffer for intermediate path generation.
2025-02-06 12:21:16 +09:00
Hermet Park
4edaf311c6 lottie: ++compact & neat code
introduced RenderPath to minimize the path parameters.
2025-02-05 19:55:12 +09:00
Mira Grudzinska
580019b64b gl_engine: fix color burn/dodge edge cases
Aligned with sw_engine implementation.
2025-02-03 15:06:39 +09:00
Mira Grudzinska
e7e168a28b wg_engine: fix color burn/dodge edge cases
Aligned with sw_engine implementation.
2025-02-03 15:06:39 +09:00
Mira Grudzinska
41f10b9702 sw_engine: fix color burn/dodge edge cases
Dodge d / (1 - s):
- handle d = 0 first to avoid 0/0 when s = 1
- for d != 0 and s = 1, the formula results in d/0 (infinity),
  which maps to 1 in the 0-1 range (or 255 in the 0-255 range)

Burn 1 - (1 - d) / s:
- handle d = 1 first to avoid 0/0 when s = 0
- for d != 1 and s = 0, the formula results in  1 - 0/0 -> 1 - inf = -inf
  Negative infinity in the 0-1 range corresponds to the minimum possible
  value, which is 0 (255 if we operate in 0-255 range).
2025-02-03 15:06:39 +09:00
Mira Grudzinska
9c864f3e99 common: more accurate clipped viewport rounding
Replaced ceil and direct casts with nearbyint to improve
viewport size calculation. This ensures consistent
approach with the fastTrack case in sw_engine.

@Issue: https://github.com/thorvg/thorvg/issues/3148
2025-02-03 14:54:03 +09:00
Hermet Park
746ca7f58b renderer: hotfix a nullptr memory copy 2025-01-30 23:18:28 +09:00
Sergii Liebodkin
0ecd2c0fd4 engine: introduce scene effect dispose render method
to correctly remove RenderDate from effects it must be removed in the renderer
a new method has been added to the RenderMethod interface
2025-01-26 10:13:28 +09:00
Sergii Liebodkin
83eb89c5c9 wg_engine: fix segmentation fault on windows with SVG examples
Some SVG files fails during tesselation on windows.
Fixed
2025-01-24 20:48:08 +09:00
Hermet Park
b8f2e3815a sw_engine: ++reference info 2025-01-23 12:32:31 +09:00
Mira Grudzinska
758aa932d7 gl_engine: add support for stroke/fill ordering 2025-01-22 16:24:29 +09:00
Hermet Park
fdd760a34f api: revised the animation segment specification
Changed the unit of the segment from a normalized value to frame numbers,
ensuring alignment with other frame control interfaces.

Note that This change may break backward compatibility.

issue: https://github.com/thorvg/thorvg/issues/3116
2025-01-22 13:03:48 +09:00
Abdelrahman Ashraf
53487421b5 chore(build): exclude webgpu_native for emscripten build
- Add platform check to exclude webgpu_native in meson.build
- Avoid requiring -Dbindings=wasm_beta for Emscripten builds
2025-01-21 22:55:15 +09:00
Hermet Park
b79d12a04d gl_engine: hotfix memory leak
issue: https://github.com/thorvg/thorvg/issues/3140
2025-01-20 21:27:06 +09:00
Mira Grudzinska
5752e75ff9 wg_engine: fix bug introduced in 07e73a9
Fixed loop condition.
2025-01-20 21:25:22 +09:00
Hermet Park
44075aa0f0 sw_engine: Improved the blur performance by 12%
Applied the compromised approach for the gaussian blur
since the effect is a bit burdensome for cpu processing
as animatable effects.

- Optimized performance and quality with negligible observable differences.
- Disabled the border option until specific use cases are identified.
2025-01-20 17:46:53 +09:00
Hermet Park
ef41f3f79c sw_engine/texmap: tuning the blending logic
Compromed the translucent/opaque logic by unifying them,
for code size and maintenance.
2025-01-18 15:10:07 +09:00
Mira Grudzinska
abdb96b8a0 sw_engine: fix bug introduced in 07e73a9
The value of the variable 'i' was not modified
after the refactor, resulting in a reference to
an incorrect array element.
2025-01-17 18:33:19 +09:00
Hermet Park
df0658e2da renderer: improved engine for scalable effects
RenderMethod effects methods would have changes:
 + update()               //update the effects if any
 - prepare() -> region()  //update the effect drawing region
 - effect() -> render()   //draw the effect
2025-01-17 16:11:29 +09:00
Hermet Park
dfa05a5c43 common: neat & clean code++ 2025-01-17 00:46:03 +09:00
Jinny You
61028747c6
sw_engine: Fix buffer overflow in texture mapping rasterizer
Fix heap buffer overflow in texture mapping rasterizer by adding proper
bounds checking for texture coordinates. This prevents accessing memory
outside of the allocated image buffer during texture sampling and
interpolation.

Co-Authored-By: Hermet Park <hermet@lottiefiles.com>

issue: https://github.com/thorvg/thorvg/issues/3102
2025-01-16 14:43:17 +09:00
Jinny You
4aba0caaad wasm: fix build issue in sw/wg build only case
- resolved EMSCRIPTEN_WEBGL_CONTEXT_HANDLE declaration problem.
- currentContext() should be also called after `mContext` is initialized.
2025-01-15 21:27:00 +09:00
Hermet Park
07e73a9e6f common: code refactoring
use ARRAY_FOREACH() for neat code and
accessing the memory efficiently than normal indexing.
2025-01-15 18:03:46 +09:00
Hermet Park
8f98681ea7 renderer: minor code clean++ 2025-01-15 12:24:32 +09:00
Hermet Park
ce3f0a75e2 gl_engine: corrected ColorDodge, ColorBurn equation
issue: https://github.com/thorvg/thorvg/issues/3072
2025-01-14 12:19:18 +09:00
Hermet Park
48c8094d19 api: path api revision for v1.0
Unify the Path commands & pts getters.

C++ API modiciation:
- uint32_t Shape::pathCommands(const PathCommand** cmds) const
- uint32_t Shape::pathCoords(const PathCommand** cmds) const
 -> Result Shape::path(const PathCommand** cmds, uint32_t* cmdsCnt, const Point** pts, uint32_t* ptsCnt)

C API modification:
- Tvg_Result tvg_shape_get_path_coords(const Tvg_Paint* paint, const Tvg_Point** pts, uint32_t* cnt)
- Tvg_Result tvg_shape_get_path_commands(const Tvg_Paint* paint, const Tvg_Path_Commands** cmds, uint32_t* cnt)
 -> Tvg_Result tvg_shape_get_path(const Tvg_Paint* paint, const Tvg_Path_Command** cmds, uint32_t* cmdsCnt, const Tvg_Point** pts, uint32_t* ptsCnt)

issue: https://github.com/thorvg/thorvg/issues/3116
2025-01-14 11:47:28 +09:00
Hermet Park
f5aa347a70 api: renamed api for consistency
API modification:
- Shape::fillColor() -> Shape::fill()

issue: https://github.com/thorvg/thorvg/issues/3116
2025-01-13 16:53:14 +09:00
Hermet Park
a31eceeafa sw_engine: assign the stride omitted
This fixes a wrong compositor access
during the rasterization

issue: https://github.com/orgs/thorvg/discussions/3109
2025-01-13 15:07:57 +09:00
faxe1008
912752906c renderer: Fix loader logic for mimetype check
Fixes the logic of the mimetype check before trying to load with the
given mimetype.
2025-01-11 13:53:24 +09:00
faxe1008
0c09580cd4 common: Use explicit floating-point value types.
Co-Authored-By: Hermet Park <hermet@lottiefiles.com>
2025-01-10 12:16:13 +09:00
faxe1008
9a8173cc22 drenderer: include alloca.h for Zephyr
Changes the conditional for to also include the alloca.h header in case
it is build for the zephyr rtos.
2025-01-10 11:27:59 +09:00
Hermet Park
3d6fe5ffae sw_engine: ++portability on macOS
fixed a runtime error report of the sanitizer
at data casting.

issue: https://github.com/thorvg/thorvg/issues/3102
2025-01-09 00:43:30 +09:00
Sergii Liebodkin
222e8a25a1 wg_engine: fix context handle passimg by ref
Use reference insted of value for context passing
2025-01-08 17:21:57 +09:00
Hermet Park
d2d93792df wg_engine: corrected ColorDodge, ColorBurn equation
issue: https://github.com/thorvg/thorvg/issues/3072
2025-01-08 13:54:09 +09:00
Hermet Park
084c7ff214 sw_engine: corrected blendings
corrected wrong ColorDodge, ColorBurn, Exclusion, SoftLight blendings

issue: https://github.com/thorvg/thorvg/issues/3072
2025-01-08 13:27:58 +09:00
Hermet Park
a12accbc93 updated copyright 2025-01-03 14:32:31 +09:00
Mira Grudzinska
acc614ab2f sw_engine: prevent warning
Remove unused version of SUBPIXELS().
2025-01-03 10:24:46 +09:00
Hermet Park
2fb925a2d7 sw_engine: corrected the rle cell building
Properly build the cell cover value
when a new cell value is just overlapped.

This fixes certain weird visual artifacts at a corner case.

issue: https://github.com/thorvg/thorvg/issues/2929
2025-01-02 17:49:28 +09:00