Commit graph

2525 commits

Author SHA1 Message Date
Jinny You
38e248bbe4 lottie: Support the slot reverting feature
Implemented the ability to revert Lottie slots by calling override with nullptr.
This functionality allows for the complete reversal of applied slots.

usage:
- `animation->override(nullptr)`

Co-Authored-By: Hermet Park <hermet@lottiefiles.com>
2024-03-21 17:06:36 +09:00
Hermet Park
b4f2944175 lottie/property: code refactoring
introduce the release() method for memory freeing.
This method can be used for any demands.
2024-03-21 17:06:24 +09:00
JunsuChoi
41619c8d75 loader/lottie: Prevent leak memory when image load fails
When image data fails to load or image parsing fails,
the id is leaked without being assigned to the name.
To prevent that, free id value when obj is nullptr.

related issue: https://github.com/thorvg/thorvg/issues/2072
BrokenLottie.7z/test3_IDX_130_RAND_18289244608080059871.json
BrokenLottie.7z/test3_IDX_131_RAND_7772102071213376276.json
BrokenLottie.7z/test3_IDX_132_RAND_3072617087893397532.json
BrokenLottie.7z/test3_IDX_134_RAND_17738488813555566674.json
BrokenLottie.7z/test3_IDX_137_RAND_13903188963759129023.json
BrokenLottie.7z/test3_IDX_138_RAND_1645404078965858130.json
2024-03-21 17:06:18 +09:00
Jinny You
900637f41a lottie: Added gradient population preventing logic
`LottieGradient.populate` function checks whether the value has already been calculated and populated via the flag `populated`.
2024-03-21 17:06:11 +09:00
JunsuChoi
b71ce3a8d6 loader/svg: Remove duplicate if-check in pathAppendArcTo
The if-check to skip-rule when drawing an arc path is already checked in line 476.
In addition, since the float type equal check is performed in the range of 1/256,
unintentional skiped may occur. Therefore, remove duplicate code.
https://www.w3.org/TR/SVG2/paths.html#ArcOutOfRangeParameters

test file: SVG_FILE_147893.svg
related issue: https://github.com/thorvg/thorvg/issues/1255
2024-03-21 17:05:55 +09:00
JunsuChoi
6e2275116e lottie: Prevent memory leak when file is invalid
When json file is invalid in the parser,
the LottieComposition object is not released and the parse() returns false.
To prevent memory leaks, free the memory before returning false.

related issue : https://github.com/thorvg/thorvg/issues/2070
2024-03-21 17:05:45 +09:00
Hermet Park
75d08aec07 renderer: ensure paints retain composition context
This commit addresses an issue where paints lost their
composition context when drawings occurred without any updates.

Now, paints will consistently retain the composition context,
ensuring accurate rendering.

Issue: https://github.com/thorvg/thorvg/issues/2058
2024-03-21 17:05:37 +09:00
Hermet Park
d47838a7a9 ttf: enhance UWP portability with alternative file loading
Enhances the portability of the TTF loader on UWP platforms
by implementing an alternative file loading mechanism.

This is designed to support environments where the file mapping
feature is not available, ensuring wider compatibility and reliability
in file handling.

Issue: https://github.com/thorvg/thorvg/issues/1912
2024-03-21 17:05:25 +09:00
Jinny You
4a0ba170e4 lottie: Renamed function names with prefix
Fixed naming conflict in short names.

issue: #2062
2024-03-21 17:05:14 +09:00
Hermet Park
8545cf5ab8 bump up version 0.12.8 2024-03-15 11:29:31 +09:00
Hermet Park
37fbe9dad1 lottie: fixed a compiler warning:
error: storing the address of local variable 'context' in '*this.LottieParser::context' [-Werror=dangling-pointer=]
 1255 |     this->context = &context;

issue: https://github.com/thorvg/thorvg/issues/2051
2024-03-15 11:28:06 +09:00
JunsuChoi
78dd7a41e6 loader/webp: Remove WEBP_FORCE_ALIGNED and use memcpy() instead
The google's libwebp source uses aligned memory access.
This patch is that applies the two commits below to our static lib code.

refer to:
[Remove WEBP_FORCE_ALIGNED and use memcpy() instead]
3884972e3f
[bit_reader.c: s/VP8L_USE_UNALIGNED_LOAD/VP8L_USE_FAST_LOAD/]
ac49e4e4dc
source :
https://chromium.googlesource.com/webm/libwebp/+/refs/heads/main/src/utils/bit_reader_inl_utils.h#80

related issue: https://github.com/thorvg/thorvg/issues/2006
2024-03-15 11:27:57 +09:00
Hermet Park
f88d9a6d5f capi: Add two additional ColorSpace options to align with C++ APIs.
APIs:
- Tvg_Colorspace::TVG_COLORSPACE_ABGR8888S
- Tvg_Colorspace::TVG_COLORSPACE_ARGB8888S

Issue: https://github.com/thorvg/thorvg/issues/2053
2024-03-15 11:27:51 +09:00
Jinny You
3182a8af2c lottie/slot: Support overriding plural sids
Previously, slot overriding only works in single sid, the others are ignored.

This patch enables slot overriding for all sids within a single slot.
2024-03-15 11:27:41 +09:00
Hermet Park
cddae9966c bump up version 0.12.7 2024-03-08 15:47:35 +09:00
Hermet Park
a25496fb36 png: corrected a wrong premultiplied option.
this is a regresion bug by 886b6b365b
2024-03-08 15:47:35 +09:00
Lorcán Mc Donagh
2854cbbcf9 sw_engine: fix radial gradient when focal point is outside circle on ARM/Apple Silicon
sw_engine: radial gradient
[issues 2014: radial gradient](#2014)

Radial gradient results in a corrupted image when the focal point is outside the circle on Apple Silicon.
This happens because some compilers use FMA to optimize the a = dr² - dx² - dy² calculation,
which cause loss of precision.

We rely on temporary variables to prevent FMA.
We could also use compiler specific float contraction control pragmas to avoid this if this doesn't work in the future
2024-03-08 14:23:51 +09:00
Hermet Park
d46ddf43cd lottie/slot: ++reliability 2024-03-08 14:22:47 +09:00
Hermet Park
663d0abda4 lottie: fix potential memory leaks.
memory could be leaked during the slot property overriding.
2024-03-08 14:22:38 +09:00
Jinny You
881e1d08fe lottie/api: specify clear result for override API
In case the given JSON is invalid, it's more closed to `Result::InvalidArguments`.
2024-03-08 14:22:25 +09:00
Hermet Park
16215c16dc renderer/loader: revamping the caching mechanism.
The previous loader cache mechanism encountered a problem
when the user changed the content of the cached data.

In such cases, a new request would not be processed
because the renderer would use the previously cached content.

So far, the TVG cache mechanism utilizes a pointer hash key
for the fastest hashing mechanism available.
One limitation is that it assumes the address is unique for the data.

To resolve this, we modified the caching policy.
Now, the renderer will not cache copied data;
it will only cache the given data when it is deemed shareable.

issue: https://github.com/thorvg/thorvg/issues/2020
2024-03-08 14:21:58 +09:00
Jinny You
ecf030d650 capi: added missing lottie header
Currently, the Lottie Animation API is not working due to the missing header.
2024-03-08 14:20:04 +09:00
Mira Grudzinska
4c8ceb3e0f sw_engine: fix a regression bug
After introducing the length measurement
of approximate and exact Bezier curves in
a8c0030d80
the calculation of the outline length still
used the approximate functions, while further
calculations took the exact value into account.
This discrepancy led to the creation of artifacts.

@Issue: https://github.com/thorvg/thorvg/issues/2021
2024-03-08 14:19:52 +09:00
Hermet Park
e29ee085e9 sw_engine: fix a regression bug.
stroke line drawing has been broken at a certain case,
this reverts a part of change from the old optimization:

d81f5d29fb

note that this change wouldn't affect any performance.

issue: https://github.com/thorvg/thorvg/issues/2015
2024-03-08 14:19:41 +09:00
Hermet Park
f606903470 lottie: code refactoring.
Maintains compact lines of code and functions without altering logic,
consistently prioritizing simplicity in software complexity metrics.
2024-03-08 14:19:34 +09:00
Hermet Park
3b6b538a19 lottie: copy the data only necessarily. 2024-03-08 14:19:27 +09:00
Hermet Park
5abe777118 saver: ++robustness
do not delete the given picture if the reference counting is
more than 0.
2024-03-08 14:19:21 +09:00
Mira Grudzinska
b476cc712d common: Changing the rounded rect starting point
According to the SVG standard, drawing a rectangle
starts at (x+rx, y) point. Till now it was (x+w, y+ry).
The difference was visible only for dashed strokes.
2024-03-08 14:19:14 +09:00
Mira Grudzinska
d25c56eae8 common: Changing the circle/ellipse starting point
According to the SVG standard, drawing a circle/ellipse
should start at the '3 o'clock' position and proceed
in a clock-wise direction. Until now, this point was
set at '12 o'clock'.
The differences in the outcome were visible for dashed
strokes.

issue: https://github.com/thorvg/thorvg/issues/1686
2024-03-08 14:19:07 +09:00
Mira Grudzinska
fb721037b2 lottie: use internal append rect/ellipse func
The lottie format defines the starting point for
drawing rectangles and ellipses differently than
the API available in the TVG. In the case of using
dashes or trim paths, this leads to discrepancies.
Therefore, when using the lottie builder, internal
functions for appending rectangles and circles are
utilized.

@issue: https://github.com/thorvg/thorvg/issues/1997
2024-03-08 14:18:59 +09:00
Hermet Park
a9fe9082c9 binding/capi: support lottie extensions
these experimental apis are allowed to use
when the lottie loader is enabled.

APIs:
- Tvg_Animation* tvg_lottie_animation_new()
- Tvg_Result tvg_lottie_animation_override(Tvg_Animation* animation, const char* slot)
2024-03-08 14:18:50 +09:00
Hermet Park
db434a5632 lottie: clean up code and minor bugs by mistake. 2024-03-08 14:18:38 +09:00
Jinny You
ff8f280b43 examples: Added lottie advanced features example 2024-03-08 14:18:25 +09:00
Jinny You
ded1a08d02 lottie: Introduce the LottieAnimation class
This class extends the Animation and serves advanced Lottie features.
It's designed to separately have Lottie Animation's unique specs.

For now, this will have Slot overriding feature,
you can include <thorvg_lottie.h> for its extensive features.

@APIs:
- Result LottieAnimation::override(const char* slotJson) noexcept;
- static std::unique_ptr<LottieAnimation> LottieAnimation::gen() noexcept;

@Issue: https://github.com/thorvg/thorvg/issues/1808
2024-03-08 14:17:16 +09:00
Jinny You
59eecf5574 lottie: Support the slot overriding feature
Internal model and parser modifications have been made
to parse "sid" and retrieve their data into the LottieComposition.
This will enable dynamic changes to the following Lottie objects:

The slot feature will encompass these properties:

- LottieSolidStroke
- LottieSolidFill
- LottieGradientStroke
- LottieGradientFill
- LottieTextDoc"

Issue: https://github.com/thorvg/thorvg/issues/1808

Co-authored-by: Hermet Park <hermet@lottiefiles.com>
2024-03-08 14:16:42 +09:00
Jinny You
e398dfd34d lottie: Revise the solid model
To ensure consistent properties, `LottieSolid` has been defined.

Both `LottieSolidStroke` and `LottieSolidFill` can be typecasted to the `LottieSolid`.
2024-03-08 14:14:03 +09:00
Jinny You
abf9cebe06 lottie: Revise the gradient model
Currently, the `LottieGradient` does not incorporate the `LottieObject` functionality.

It now inherits from the `LottieObject`.
2024-03-08 14:13:59 +09:00
Hermet Park
f63ce3ba3d lottie: introduced LottieProperty base class
this is useful for slot & expression type casting.
2024-03-08 14:13:52 +09:00
Hermet Park
cc57ffb974 common/array: code refactoring
Make the array interface pair begin()/end() for consistency.
2024-03-08 14:13:48 +09:00
Hermet Park
adbc929ced bump up version 0.12.6 2024-02-23 12:26:46 +09:00
Hermet Park
d9120b9dee examples: ++threading stability.
Ensure synchronous calls are made after updating the canvases.
2024-02-23 12:26:46 +09:00
Vincent Torri
c1ea9d4585 Lottie loader: fix compilation on windows
strlen() was used in tvgLottieModel.h without the inclusion of
cstring. This patch fixes this
2024-02-23 11:45:11 +09:00
JunsuChoi
a92633e1d8 svg: Improve valid check for url(#id)
Improve parenthesis checking and space checking.
 - There must be only one pair of parentheses.
 - There cannot be spaces(and ') between id strings.

Issue: https://github.com/thorvg/thorvg/issues/1983

Co-authored-by: Hermet Park <hermet@lottiefiles.com>
2024-02-23 11:45:05 +09:00
Mira Grudzinska
f14d4168e9 sw_engine: Increasing accuracy for dashed curves
Dashed curves require greater precision in calculating
their lengths and while splitting Bezier curves.
Otherwise, it results in visual discrepancies compared
to the expected outcomes.
Approximate functions 'bezLengthApprox' and 'bezAtApprox'
used for calculations in the lottie loader.

issue: https://github.com/thorvg/thorvg/issues/1686
2024-02-23 11:44:29 +09:00
Mira Grudzinska
cdc7fca9b5 sw_engine: fixing stroke outline
In the case of non-uniform scaling for
thick strokes, artifacts were visible.
The calculations took into account the angle
resulting from the already transformed points,
whereas the untransformed points should have
been considered - the transformation is taken
into account in the next step.

@issue: https://github.com/thorvg/thorvg/issues/1915
2024-02-23 11:44:22 +09:00
Hermet Park
5c130c6848 lottie/parser: clean up the exception handling mechanisms.
Since the parser has become stable enough,
remove the exceptions and instead rely on parser error handling.
2024-02-23 11:44:09 +09:00
Hermet Park
9e4331fe5c loader/webp: do not expose webp apis.
this reduces the bin size around -1.5kb
2024-02-23 11:40:33 +09:00
Hermet Park
1c4a25cb4a lottie: remove the duplicated binary search logic. 2024-02-23 11:40:24 +09:00
JunsuChoi
92200449e8 loader/svg: Fix empty id to null
empty id is invalid. Therefore, set it to null and make it is not used.

issue: https://github.com/thorvg/thorvg/issues/1977
2024-02-23 11:40:16 +09:00
Martin Capitanio
a5cc5a3894 Portability: Fix compiler shadowing warning 2024-02-23 11:39:47 +09:00