Commit graph

839 commits

Author SHA1 Message Date
JunsuChoi
43b5d0e462 loader/svg: Skip to invalid polygon
If a Polygon's points array is odd, it is not a valid shape.
2024-06-24 11:59:32 +09:00
Hermet Park
f108fc9363 lottie: corrected the comp/layer size data type.
Actually, the these size is expected to be a floating-point value.
This correction addresses a parsing error.

issue: https://github.com/thorvg/thorvg/issues/2153
2024-06-24 11:59:16 +09:00
Hermet Park
ca7aec5fff lottie: rectify the frame updates.
Currently, tvg ignores the frame value if the difference
is less than 0.001. In most cases, updating the frames
when the change is less than 1ms is just an unnecessary
burden on the system.

Instead, this ensures that the perfect last frame is reached.

issue: https://github.com/thorvg/thorvg/issues/2147
2024-06-24 11:58:48 +09:00
Hermet Park
37b431c02f svg: code refactoring
-- compiler warnings on msvc
2024-04-07 15:15:59 +09:00
JunsuChoi
b3b2bc6bd5 loader/svg: Fix invalid syntax check
If the key is not parsed and the '=' keyword is located next,
modify it to parse the following syntax.

related issue:
https://github.com/thorvg/thorvg/issues/2116
2024-04-06 12:48:30 +09:00
Hermet Park
1632ad9ee5 lottie: removed unused code.
Currently, thorvg has no plan to support dotlottie format.
2024-04-06 12:48:30 +09:00
Hermet Park
ef03e5b006 lottie: hotfix memory corruption.
revise the fix that occured a side effect by:
287e6d33d2
2024-04-06 12:48:30 +09:00
Jinny You
f54f22ae78 lottie: Fix heap-buffer-overflow in gradient populate 2024-04-06 12:48:30 +09:00
JunsuChoi
349fd266b9 loader/svg: Check invalid color
Checks whether the string that can be specified in Color is valid.

example)
```
     style="stroke:asdasd"
```

related issue: https://github.com/thorvg/thorvg/issues/1255
2024-04-06 12:48:30 +09:00
Hermet Park
ecee01ebd6 lottie: Properly handle the TrimPath mode.
This correction addresses the drawing order of
objects when a group contains a TrimPath and
is merging shapes.

Additionally, the TrimPath method is can applied
to the engine to control the drawing behavior by
7f3dc541d6b7abcdc03facd884489f37c327fd98

issue: https://github.com/thorvg/thorvg/issues/2047
2024-04-06 12:48:30 +09:00
Hermet Park
6688f03396 sw_engine: revised the trimpath dash line logic
Support the TrimPath modes (individual/simultaneous)
internally in the engine to handle them efficiently.
2024-04-06 12:48:30 +09:00
JunsuChoi
0c6395cbea loader/svg: Support hsl color format
Support parsing of hsl(hue, saturation, brightness) color type
and conversion to rgb color.
2024-04-06 12:48:30 +09:00
Hermet Park
f7bfc57f23 portability: removed a compiler waring
D:\Projects\thorvg\src\loaders\lottie\tvgLottieParserHandler.h(52): warning C4083: expected ')'; found identifier 'effc'
[44/46] Compiling C++ object src/thorvg-0.dll.p/loaders_lottie_tvgLottieParserHandler.cpp.obj
D:\Projects\thorvg\src\loaders\lottie\tvgLottieParserHandler.h(52): warning C4083: expected ')'; found identifier 'effc'
[45/46] Compiling C++ object src/thorvg-0.dll.p/loaders_lottie_tvgLottieParser.cpp.obj
D:\Projects\thorvg\src\loaders\lottie\tvgLottieParserHandler.h(52): warning C4083: expected ')'; found identifier 'effc'

I'm not sure this option is really necessary.
2024-04-06 12:08:23 +09:00
Hermet Park
d883cc23cf lottie: polish up a comment. 2024-04-06 12:08:23 +09:00
Hermet Park
1f04df60dd lottie: Removed redundant code.
The settings were incorrect;
'direction' and 'fillRule' do not have a relationship.
2024-04-06 12:08:23 +09:00
Hermet Park
f6170a224a lottie: optimize the rendering performance.
this optimization nicely merges shapes
when a child group has a only (transformed) pathes.

this also fixes the following compatibility issue nicely.

issue: https://github.com/thorvg/thorvg/issues/2061
2024-04-06 12:08:23 +09:00
Hermet Park
40647d5882 lottie: optimize the rendering by preventing partial rendering branches.
this optimization is to figure out if this group is a simple path drawing.
In that case, the rendering context can be sharable with the parent's.
2024-04-06 12:08:23 +09:00
JunsuChoi
f0527a2304 loader/svg: Check whether href id of use is parent or not
When finding the 'nodeFrom' referenced by `<use>`,
if it is the parent, it is not referenced.

https://www.w3.org/TR/SVG2/struct.html#UseElement
Specification:
If the referenced element is a (shadow-including) ancestor
of the ‘use’ element, then this is an invalid circular reference
and the ‘use’ element is in error.

related issue: https://github.com/thorvg/thorvg/issues/2078
SVG_FILE_65171.svg
SVG_FILE_65172.svg
2024-04-06 12:08:23 +09:00
JunsuChoi
b408178ca6 loader/svg: Do recalc after gradient inheritance
Inherit gradientUnits and recalculate each element
radial(cx, cy, r,...), linear(x1, y1, x2, y2).

related issue: https://github.com/thorvg/thorvg/issues/2078
2024-04-06 12:08:23 +09:00
Hermet Park
736a79674b lottie: code refactoring.
removed unused static condition.

static was prepared for optimization,
but not used at all.

we will revisit this later when time permits.

binary size: -6kb
2024-04-06 12:08:23 +09:00
Jinny You
7ec7a4c08c lottie: Fix crash from invalid masking method
This change is better for stability. Returns `None` if the `mode` attribute cannot be parsed.

related issue: #2072
2024-04-06 12:08:23 +09:00
Jinny You
c8ddc316db lottie: Fix crash when an invalid gradient is provided
When lottie is broken and provides invalid gradient, the program crashes in segmentation fault.

At that time, in the `populate` function, `ColorStop& color` doesn't have `input` but tries to use it.

Added checking nullptr logic. The function `populate` will not proceed and return 0 in that case.

related issue: #2072
2024-04-06 12:08:23 +09:00
Jinny You
9d040f9042 lottie/slot: Fixed potential overriding bug
Slot overriding tries to set property via the `LottieObject`. It potentially causes unexpected changes.

Revised the `override` function. The purpose of this patch is to aim atomic property to be overriden.
2024-04-06 12:08:23 +09:00
Vincent Torri
2f196b514f [common] code clean up
use fmodf() instead of fmod()
2024-04-06 12:08:23 +09:00
vtorri
3640724b99 [common] code clean up
use MATH_PI and MATH_PI2 instead of M_PI and M_PI_2
2024-04-06 12:08:23 +09:00
Hermet Park
c73370a0ae ttf: ++uwp portability
use the preprocessor directives properly.
2024-04-06 12:08:23 +09:00
Jinny You
984eb2eff9 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-04-06 12:08:23 +09:00
Hermet Park
3cb8c4311d lottie/property: code refactoring
introduce the release() method for memory freeing.
This method can be used for any demands.
2024-04-06 12:08:23 +09:00
JunsuChoi
727b699223 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-04-06 12:08:23 +09:00
Jinny You
d5af1e3b67 lottie: Added gradient population preventing logic
`LottieGradient.populate` function checks whether the value has already been calculated and populated via the flag `populated`.
2024-04-06 12:08:23 +09:00
JunsuChoi
4ec76144dc 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-04-06 12:08:22 +09:00
JunsuChoi
c4da341f4b 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-04-06 12:08:22 +09:00
Hermet Park
1008575932 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-04-06 12:08:21 +09:00
Jinny You
dee5a7294a lottie: Renamed function names with prefix
Fixed naming conflict in short names.

issue: #2062
2024-04-06 12:08:21 +09:00
Hermet Park
b1ab52f89e 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-04-06 12:08:21 +09:00
JunsuChoi
fc4f452362 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-04-06 12:08:21 +09:00
Jinny You
7f2cd1090c 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-04-06 12:08:21 +09:00
Hermet Park
946d934827 png: corrected a wrong premultiplied option.
this is a regresion bug by 886b6b365b
2024-04-06 12:08:21 +09:00
Hermet Park
851f8eaabc lottie/slot: ++reliability 2024-04-06 12:08:21 +09:00
Hermet Park
d50eea2a2c lottie: fix potential memory leaks.
memory could be leaked during the slot property overriding.
2024-04-06 12:08:21 +09:00
Jinny You
725dc0d18e lottie/api: specify clear result for override API
In case the given JSON is invalid, it's more closed to `Result::InvalidArguments`.
2024-04-06 12:08:21 +09:00
Hermet Park
3ed8309a11 lottie: code refactoring.
Maintains compact lines of code and functions without altering logic,
consistently prioritizing simplicity in software complexity metrics.
2024-04-06 12:08:21 +09:00
Hermet Park
2e7fc5ebcb lottie: copy the data only necessarily. 2024-04-06 12:08:21 +09:00
Mira Grudzinska
a7bcc7b6d8 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-04-06 12:08:21 +09:00
Hermet Park
97240a893a lottie: clean up code and minor bugs by mistake. 2024-04-06 12:08:21 +09:00
Jinny You
c8a7e5b02e 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-04-06 12:08:21 +09:00
Jinny You
5ed068cec3 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-04-06 12:08:21 +09:00
Vincent Torri
da6199a2bd Lottie loader: fix compilation on windows
strlen() was used in tvgLottieModel.h without the inclusion of
cstring. This patch fixes this
2024-04-06 12:08:21 +09:00
Jinny You
447a3d8ad5 lottie: Revise the solid model
To ensure consistent properties, `LottieSolid` has been defined.

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

It now inherits from the `LottieObject`.
2024-04-06 12:08:21 +09:00