Commit graph

178 commits

Author SHA1 Message Date
Mira Grudzinska
031dd647bc sw_engine: fix too small memory alloc for spans
In some clipping cases, the memory allocated for storing spans
was too small. As a result, the entire clipped area might not
have been rendered.
This has been resolved by adding an experimental factor to increase
the size of allocated memory.

@issue: https://github.com/thorvg/thorvg/issues/3461
2025-05-24 01:37:24 +09:00
Hermet Park
bb6458b50a sw_engine: fixed a a regression bug during main dev
borker by 14130e7e72afaecff2dd091e5e272169c79515b9
2025-05-24 01:37:24 +09:00
Hermet Park
1b37743b2c renderer: fixed a clippging update isssue
ThorVG did not consider updates to the clipping path
when a paint object was modified after being added to the scene.

This fix ensures that any updates to clipping are correctly
reflected during rendering.

issue: https://github.com/thorvg/thorvg/issues/3403
2025-05-24 01:37:24 +09:00
Hermet Park
ba00675559 renderer: safety++
introduced a threshold for the minimum dash size
to prevent excessive fragmentation.

issue: https://github.com/thorvg/thorvg/issues/3332
2025-04-03 21:17:54 +02:00
Hermet Park
aa697d9311 sw_engine: hotfix a out of bound image access.
this simply revert logic from the previous change:
https://github.com/thorvg/thorvg/pull/2552

issue: https://github.com/thorvg/thorvg/issues/3327
2025-04-03 21:13:46 +02:00
Hermet Park
c554205238 sw_engine: fix a incorrect rle cell position.
All cells that are on the left of the clipping region
go to the - 1 horizontal position.

issue: https://github.com/thorvg/thorvg/issues/2657
2025-03-12 21:02:51 +01:00
Mira Grudzinska
c6960502eb sw_engine: hanndle empty clips
Generating the outline may return false, e.g., if the shape
is completely trimmed. If such a shape was used as a clip,
an attempt to generate 'rle' will still be made. In such a case,
a crash will occur because the outline is nullptr.
2025-03-12 20:26:39 +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
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
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
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
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
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
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
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
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
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
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
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
Hermet Park
fcf080cc4e sw_engine: ++exceptional handling
issue: https://github.com/thorvg/thorvg/pull/2955
2024-11-18 23:39:38 +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
Hermet Park
4d8c0e9a64 sw_engine: corrected the blur feathering region.
issue: https://github.com/thorvg/thorvg/issues/2892
2024-11-01 17:30:42 +09:00
Hermet Park
ec62ca869f sw_engine: fixed linear gradient filling masking.
properly filtering alpha channel of the 8bits linear gradient
masking drawing.

issue: https://github.com/thorvg/thorvg/issues/2204
2024-10-22 00:41:31 +09:00
Mira Grudzinska
fa49f14412 sw_engine: fix _rasterDirectImage
Since the source buffer is 32 bits, not 8 bits,
both alpha and inverse alpha need to be calculated.
2024-10-22 00:41:07 +09:00
Hermet Park
719fbc9d64 sw_engine: rectify the blending method of grayscale fill
issue: https://github.com/thorvg/thorvg/issues/2842
issue: https://github.com/thorvg/thorvg/issues/2841
2024-10-22 00:40:15 +09:00
Mira Grudzinska
cb2a15528d sw_engine: split long lines to avoid overflow
@Issue: https://github.com/thorvg/thorvg/issues/2651
2024-10-22 00:39:14 +09:00
Hermet Park
43cdd4c7ec lottie: Fine-tune for post-processing effect.
reduce quality for the post-processing effect to
improve general performance, while fine-tuning the quality
for lower resolutions.
2024-10-22 00:39:06 +09:00
Hermet Park
75ae8bcc7b sw_engine: properly update the render region
shape render region should be aligned with the
current shape bbox. this could bring the compact size
of the rendering region even shapes are not drawable.
2024-10-22 00:38:58 +09:00
Mira Grudzinska
52def8dc27 sw_engine: ++exception handling
Prevent the infinite loop in the worst case

@Issue: https://github.com/thorvg/thorvg/issues/2651
2024-10-04 00:34:16 +09:00
Mira Grudzinska
03bbfd3183 sw_engine: ignore small cubics
During the stroke's outline calculation, the function
handling small cubics set all angles to zero. When
the cubic was small but not zero, this resulted in
incorrect outlines. Now such curves are ignored.

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

Issue: https://github.com/thorvg/thorvg/issues/2776
Issue: https://github.com/thorvg/thorvg/issues/2712
2024-10-03 21:42:14 +09:00
Hermet Park
aece166cb7 sw_engine: ++stability
cut the Bezier curve based on the number of points
and transform it into a straight line when it's very small.

issue: https://github.com/thorvg/thorvg/issues/2759
2024-10-03 19:02:26 +09:00
Hermet Park
bceedf081f sw_engine: fixed an uninitialized data access 2024-10-03 19:02:14 +09:00
Hermet Park
2972a631bd sw_engine: applied OpenMP to improve post-processing performance.
- OpenMp threads will be allocated alongside the TaskSculeduler::threads()
- Performance improved by 2x in a specific animation.
- Disable the thread feature in the Android build test due to system issues with OpenMP compilation.
2024-09-30 16:44:22 +09:00
Hermet Park
ad7c65d2ea 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-30 16:44:22 +09:00
Mira Grudzinska
59ffd90758 sw_engine: add support for 8bits gradient rectangles
Rastering for 32bits dst buffer was implemented,
but 8bits dst were not supported.

@Issue: https://github.com/thorvg/thorvg/issues/2765
2024-09-30 16:44:22 +09:00
Mira Grudzinska
99153ef26e sw_engine: fix translucent grad rastering
8bit translucent gradient rle were missing AA. Fixed.
2024-09-30 16:44:22 +09:00
Hermet Park
319b3843a5 common: code refactoring
Properly renamed internal interfaces.
No logical changes.

- Compositor -> RenderCompositor
- Surface -> RenderSurface
2024-09-30 16:44:22 +09:00