Commit graph

921 commits

Author SHA1 Message Date
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
JunsuChoi
c6cf9cb2cf 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-04-06 12:08:21 +09:00
Hermet Park
fe6493351a lottie: introduced LottieProperty base class
this is useful for slot & expression type casting.
2024-04-06 12:08:21 +09:00
Hermet Park
c08c11db7d common: code refactoring
refactor common code to consolidate Bezier and line
function implementations into a single location.
2024-04-06 12:08:21 +09:00
Hermet Park
71c636e33c Revert "Revert "sw_engine: Increasing accuracy for dashed curves""
This reverts commit e49f9125b2.
2024-04-06 12:08:21 +09:00
Hermet Park
c01c8338d7 Revert "sw_engine: Increasing accuracy for dashed curves"
This reverts commit a8c0030d80.
2024-04-06 12:08:21 +09:00
Mira Grudzinska
d399ae922a 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-04-06 12:08:21 +09:00
Hermet Park
6b63c85404 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-04-06 12:08:21 +09:00
Hermet Park
b0540929e5 common/array: code refactoring
Make the array interface pair begin()/end() for consistency.
2024-04-06 12:08:21 +09:00
Hermet Park
aa07e98c7b loader/webp: do not expose webp apis.
this reduces the bin size around -1.5kb
2024-04-06 12:08:21 +09:00
Hermet Park
e559388f63 lottie: remove the duplicated binary search logic. 2024-04-06 12:08:21 +09:00
JunsuChoi
b400512fda 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-04-06 12:08:21 +09:00
Hermet Park
baf04d1cde webp: removed non-existing symbol methods. 2024-04-06 12:08:21 +09:00
Hermet Park
c64ed2ec03 loaders: enhance decoding efficiency
enhance decoding efficiency by determining the desired canvas format
during image loading. This allows loaders to preemptively decode
the image in the specified format, to not convert the format again.
2024-04-06 12:08:21 +09:00
Hermet Park
c4e6b03b84 loaders: decode the image with premultiplied alpha.
basically, the renderer requires images with premultiplied alpha.
2024-04-06 12:08:21 +09:00
Hermet Park
5d892c241c Revert "lottie: compatibility++"
This reverts commit c89f6253bf.

No more valid by 3f235d9e3f
2024-04-06 12:08:21 +09:00
Junsu Choi
e0eeaf54b0 loader/webp: Support static webp loader
Built to libwebp code in to support the static option of webp loader.
Code from :https://github.com/jacklicn/libwebp

This forking version only contains the minimal webp decoding feature.

Binary Size: +68kb

Co-authored-by: Hermet Park <hermet@lottiefiles.com>

issue: https://github.com/thorvg/thorvg/issues/1427
2024-04-06 12:08:18 +09:00
Hermet Park
6fa5a2a690 lottie/parser: shutdown a compiler warning.
corrected a data type.
2024-04-05 17:47:13 +09:00
Hermet Park
ce8c5c0038 lottie: fixed a parsing error in assets
An unused key in assets parsing corrupted the sequence.
This change now ensures they are tightly ignored.
2024-04-05 17:47:06 +09:00