Commit graph

467 commits

Author SHA1 Message Date
Hermet Park
4ea95d8707 loader: fixed potential memory leaks in font handling
Simply loading a font doesn't mean it is in use.
Fixed the loader's reference count to prevent incorrect increments.
2025-03-12 20:26:38 +01:00
pharuxtan
07da6c5870 sw_engine: fix internal types of rasterXYFlip
Before the C++ compiler couldn't decide the template of std::min (that happen if `int` type is not an `int32_t`), so explicitly changing all types to int32_t fixes this.
2025-03-12 20:26:38 +01:00
Mira Grudzinska
41b340bbdb gl_engine: add offset support in dashed strokes
Offset is correctly applied to dashed strokes,
properly shifting the dash pattern.

@Issue: https://github.com/thorvg/thorvg/issues/3217
@Issue: https://github.com/thorvg/thorvg/issues/3223
@Issue: https://github.com/thorvg/thorvg/issues/3191
2025-03-12 20:26:32 +01:00
Mira Grudzinska
5b15db0c8e gl_engine: fix dashing
Incorrect condition for drawing segments in cubics;
missing checks.

@Issue: https://github.com/thorvg/thorvg/issues/2729
@Issue: https://github.com/thorvg/thorvg/issues/3222
2025-03-12 02:10:32 +01:00
Mira Grudzinska
0e633bd009 sw_engine: fix update issue
In cases where the fill was changed while the stroke existed
but remained unchanged, the stroke would disappear because it
was being reset during the shape preparing (shapeReset).
Fixed by disabling the reset of stroke rle from shape reseting.

Also the shape should be prepared not only when the RenderUpdateFlag
is set to Color, but also when it is set to Gradient.

@Issue: https://github.com/thorvg/thorvg/issues/3237
2025-03-12 02:10:32 +01:00
Hermet Park
7968b9668e 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-03-12 02:10:32 +01:00
Mira Grudzinska
0a76a4f0a3 gl_engine: fix color burn/dodge edge cases
Aligned with sw_engine implementation.
2025-03-12 02:10:32 +01:00
Mira Grudzinska
6a00eb8db0 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-03-12 02:10:32 +01:00
Hermet Park
782f067b22 renderer: hotfix a null memory copy 2025-01-30 21:09:27 +09:00
Mira Grudzinska
8f7103e109 gl_engine: add support for stroke/fill ordering 2025-01-30 20:32:45 +09:00
Hermet Park
89e98b6fcb 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-30 20:24:20 +09:00
Hermet Park
819b93a9a4 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-30 20:23:39 +09:00
Jinny You
c64624c8c8 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 18:50:32 +01:00
Hermet Park
c460591b39 gl_engine: corrected ColorDodge, ColorBurn equation
issue: https://github.com/thorvg/thorvg/issues/3072
2025-01-16 18:44:41 +01:00
Hermet Park
e815fd25e4 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-16 18:41:19 +01:00
faxe1008
6489e65064 common: Use explicit floating-point value types.
Co-Authored-By: Hermet Park <hermet@lottiefiles.com>
2025-01-16 18:34:12 +01:00
faxe1008
14ea212535 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-16 18:30:36 +01:00
Hermet Park
949c918af9 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-16 18:29:31 +01:00
Hermet Park
3831a90a7d sw_engine: corrected blendings
corrected wrong ColorDodge, ColorBurn, Exclusion, SoftLight blendings

issue: https://github.com/thorvg/thorvg/issues/3072
2025-01-16 18:22:17 +01:00
Hermet Park
cb0691fee0 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 15:08:43 +01:00
Marcin Baszczewski
978464d87c gl_engine: Fix for rendering short paths
Ensure they do not terminate prematurely for paths
with a step of 0 or exceptionally small values
when a valid stroke-width is present.

In my opinion, the optimal approach was to separate vertex generation
into dedicated methods: strokeRoundPoint and strokeSquarePoint.

My update supports two different stroke-cap styles.
I have also tested it with various files (JSON, SVG)
as well as a small example application similar
to the one included in the previous pull request (#3066).

issue: https://github.com/thorvg/thorvg/issues/3065
2025-01-02 15:04:41 +01:00
Hermet Park
b59c7a0bee API: enable users to use an accessor to traverse Scene
remove the restriction of targeting only Picture.
now, any kind of paints can be adaptable here.
2025-01-02 14:48:30 +01:00
Marcin Baszczewski
a5f67ee92c Fix for Rendering Short Paths. 2025-01-02 13:11:21 +01:00
Hermet Park
bed521a08c common: refactored the scene effect tint
Pre-convert the data type from float to uint8_t
2025-01-02 13:10:31 +01:00
Mira Grudzinska
9b8ff114eb renderer: fix dash offset
The dash offset value was not copied while
'=' opetator was applied.

@Issue: https://github.com/thorvg/thorvg/issues/1643
2024-12-20 00:38:19 +01:00
Hermet Park
5131a8ba92 renderer: support Trintone SceneEffect
The Tritone effect maps the scene's shadows, midtones, and highlights
to three specific colors, allowing for more complex and artistic color grading.

Applied Tritone Formula:
if (L < 0.5) Result = (1 - 2L) * Shadow + 2L * Midtone
else Result = (1 - 2(L - 0.5)) * Midtone + (2(L - 0.5)) * Highlight
Where the L is Luminance.

issue: https://github.com/thorvg/thorvg/issues/2718
2024-12-20 00:38:15 +01:00
Hermet Park
4050d86f2e common: support Tint SceneEffect
The Tint effect in ThorVG is used to modify the overall color tone of a scene.
It works by blending a specified tint color with the existing colors of the scene.
This effect is useful for color grading, mood changes, or applying thematic filters
to vector graphics and animations.

Applied the equation is:
Result = (1 - L) * Black + L * White, where the L is Luminance.

issue: https://github.com/thorvg/thorvg/issues/2718
2024-12-20 00:35:40 +01:00
Hermet Park
8585b27abf sw_engine: fixed a rendering bug when the invalid clipper is applied.
Shapes with boundaries outside the rendering area are ignored as non-visible.
The issue arises when such a shape serves as a clipper.
The expected behavior is for the entire clipee to be cut out,
but previously, the clipee remained fully visible as if no clip was applied.

The fix identifies these clippers and skips rendering clipees.

Please note that we can skip rendering at the Paint update stage
if the clipper's viewport is outside the canvas.
This optimization can improve performance, but only for this specific case.
The downside of the approach is that it disrupts multi-processing for clipper updates.
As a result, that approach was discarded.

issue: https://github.com/thorvg/thorvg/issues/3003
issue: https://github.com/thorvg/thorvg/issues/2684

Co-Authored-By: Mira Grudzinska <mira@lottiefiles.com>
2024-12-19 16:29:21 +01:00
RuiwenTang
7031d7fc50 gl_engine: Fix gradient color not correct when shape has opacity
When rendering gradient color, needs to take opacity value into
consider.
2024-12-19 16:27:18 +01:00
Mira Grudzinska
9e4037b4db sw_engine: fix grad calculations
Added a term that was omitted during one of the refactorings.
2024-12-19 16:19:53 +01:00
Hermet Park
adf32b5628 sw_engine: --compiler warnings on MSYS2
comparison of integer expressions of different signedness: 'uint32_t' {aka 'unsigned int'} and 'long int' [-Wsign-compare]
2024-12-19 16:18:49 +01:00
Hermet Park
5c129472ff renderer: add a new scene effect type - Fill
Fill is used for overriding the scene content color
with a given fill information. It's yet an Experimental API.

issue: https://github.com/thorvg/thorvg/issues/2718
2024-12-19 16:12:28 +01:00
RuiwenTang
be538bacf7 gl_engine: Fix calculation error in path triming
Basically rewrite the PathTrim code, correct the Line and Bezier split
function calling.
Also the trim situation where start is greater than end can be handled correctly.
2024-12-19 13:27:23 +01:00
Hermet Park
36e5f68222 common: improve the rendering pipeline
enhanced the rendering composition target to better support features such as
alpha blending, blending, masking, post effects, and more.
This allows rasterizers to prepare the composition context with more precise control.

Additionally, resolved a crash in the software engine's post-effect process
caused by a buffer size mismatch during XY buffer flipping.

issue: https://github.com/thorvg/thorvg/issues/3009
issue: https://github.com/thorvg/thorvg/issues/2984
2024-12-05 13:13:42 +01:00
Dragoș Tiselice
c5a7d76109 sw_engine: replaced longjmp with returns
Since longjmp is not yet fully supported on Wasm (emscripten uses
JS to make the jumps and requires slow jumps), but also because
longjmp is hard to reason about, this patch replaces it with
return values. The logic stays exactly the same.
2024-12-05 12:20:12 +01:00
Hermet Park
52cf31a79d renderer: make the file io configurable
certain systems, may not support file I/O operations.
ThorVG should provide users with an option to configure
builds according to their requirements.

This ensures that file I/O calls are avoided,
preventing potential crashes.

Please use the meson '-Dfile=true/false' option for this.

Please note that "THORVG_FILE_IO_SUPPORT" might be expected
for your thorvg manual build.

issue: https://github.com/thorvg/thorvg/issues/3008
2024-12-02 12:03:15 +09:00
RuiwenTang
c0aab8c738 gl_engine: Fix the wrong bounds cause composition not correct
The bounds should allow negative origins, only zero width or height bounds needs discard.
2024-12-02 11:56:00 +09:00
RuiwenTang
14d66198d1 gl_engine: correct the stroke alpha calculation
The wrong matrix scale factor value caused the stroke alpha to be zero
when the matrix contains rotation.
2024-11-27 19:17:23 +09:00
Hermet Park
c6632d9ec0 portability: fixed a compile error on msys2 2024-11-27 19:17:23 +09:00
Hermet Park
f05ee1ca63 renderer/sw_engine: fix omitted alpha multiplication in the dropshadow effect
When a scene has a valid opacity, it must be multiplied with the
direct dropshadow image to ensure correct rendering.
2024-11-26 01:19:28 +09:00
Hermet Park
f0d4e7a7c7 sw_engine: hotfix range broken
hotfix for release. need to review the logic again
2024-11-26 01:17:36 +09:00
Hermet Park
e95f80c18f lottie: corrected drop-shadow handling
opacity value type should be float with range 0 ~ 256
2024-11-26 01:17:28 +09:00
Hermet Park
2324f6e75d 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-26 01:16:37 +09:00
lpogic
8daf0b7b94 renderer: Fix paint transformation on scene change
issue: https://github.com/thorvg/thorvg/issues/2958
2024-11-26 01:15:01 +09:00
Hermet Park
fcf080cc4e sw_engine: ++exceptional handling
issue: https://github.com/thorvg/thorvg/pull/2955
2024-11-18 23:39:38 +09:00
RuiwenTang
552d4bcee1 gl_engine: Fix repeated clip drawing causes performance degradation
The clips need to be cleared every time when shape update.
Otherwise, the increasing number of clips will hurt the performance.
2024-11-18 23:35:47 +09:00
RuiwenTang
e82830147c gl_engine: Support new radial gradient data struct and calculation
Change the shader and uniform struct to support new radial gradient.
The mathematical calculation comes from https://skia.org/docs/dev/design/conical/
2024-11-18 23:22:56 +09:00
RuiwenTang
159bf6949e gl_engine: Fix memory leak in the IndexBuffer object
The CPU buffer cache in the IndexBuffer object needs to be cleared, otherwise it will cause memory leaks and reduce performance per frame
2024-11-18 23:07:42 +09:00
RuiwenTang
8b37ec5d9c gl_engine: seperate the index buffer from vertex buffer
WebGL has a strict rule that does not allow the same GLBuffer
to be bound to both ARRAY_BUFFER and ELEMENT_ARRAY_BUFFER at the same time.
(https://registry.khronos.org/webgl/specs/latest/1.0/#5.14.5)

To support WebGL in the future, a separate GLBuffer is used to store index data.
2024-11-18 23:07:29 +09:00
Mira Grudzinska
ed90581a1f sw_engine: fix render fill region
Shape's bbox represents only fill's render region.
Render region of fill and stroke is stored in SwTask.
This was visible while rendering shapes with a stroke -
fill was to big.

@Issue: https://github.com/thorvg/thorvg/issues/2908

Co-Authored-By: Hermet Park <hermet@lottiefiles.com>
2024-11-01 17:38:09 +09:00