From 1eff126b40d483c9440a45f29f466ceea1b55b4d Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Mon, 16 Dec 2024 15:08:51 +0900 Subject: [PATCH] lottie: support Tint LayerEffect issue: https://github.com/thorvg/thorvg/issues/2718 --- src/loaders/lottie/tvgLottieBuilder.cpp | 7 ++++++ src/loaders/lottie/tvgLottieModel.h | 16 ++++++++++++-- src/loaders/lottie/tvgLottieParser.cpp | 29 +++++++++++++++++++++++++ src/loaders/lottie/tvgLottieParser.h | 1 + 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/loaders/lottie/tvgLottieBuilder.cpp b/src/loaders/lottie/tvgLottieBuilder.cpp index 1f108a79..3e8e622e 100644 --- a/src/loaders/lottie/tvgLottieBuilder.cpp +++ b/src/loaders/lottie/tvgLottieBuilder.cpp @@ -1314,6 +1314,13 @@ void LottieBuilder::updateEffect(LottieLayer* layer, float frameNo) for (auto ef = layer->effects.begin(); ef < layer->effects.end(); ++ef) { if (!(*ef)->enable) continue; switch ((*ef)->type) { + case LottieEffect::Tint: { + auto effect = static_cast(*ef); + auto black = effect->black(frameNo); + auto white = effect->white(frameNo); + layer->scene->push(SceneEffect::Tint, black.rgb[0], black.rgb[1], black.rgb[2], white.rgb[0], white.rgb[1], white.rgb[2], effect->intensity(frameNo)); + break; + } case LottieEffect::Fill: { auto effect = static_cast(*ef); auto color = effect->color(frameNo); diff --git a/src/loaders/lottie/tvgLottieModel.h b/src/loaders/lottie/tvgLottieModel.h index ceab9ff9..8b3efdcb 100644 --- a/src/loaders/lottie/tvgLottieModel.h +++ b/src/loaders/lottie/tvgLottieModel.h @@ -82,8 +82,9 @@ struct LottieEffect enum Type : uint8_t { DropShadow = 0, - GaussianBlur = 1, - Fill = 2, + GaussianBlur, + Fill, + Tint }; virtual ~LottieEffect() {} @@ -109,6 +110,17 @@ struct LottieFxFill : LottieEffect } }; +struct LottieFxTint : LottieEffect +{ + LottieColor black; + LottieColor white; + LottieSlider intensity; + + LottieFxTint() + { + type = Tint; + } +}; struct LottieFxDropShadow : LottieEffect { diff --git a/src/loaders/lottie/tvgLottieParser.cpp b/src/loaders/lottie/tvgLottieParser.cpp index 3687fe56..199bdbc4 100644 --- a/src/loaders/lottie/tvgLottieParser.cpp +++ b/src/loaders/lottie/tvgLottieParser.cpp @@ -60,6 +60,7 @@ static unsigned long _int2str(int num) LottieEffect* LottieParser::getEffect(int type) { switch (type) { + case 20: return new LottieFxTint; case 21: return new LottieFxFill; case 25: return new LottieFxDropShadow; case 29: return new LottieFxGaussianBlur; @@ -1269,6 +1270,30 @@ void LottieParser::parseMasks(LottieLayer* layer) } +void LottieParser::parseTint(LottieFxTint* effect) +{ + int idx = 0; //black -> white -> intenstiy + enterArray(); + while (nextArrayValue()) { + enterObject(); + while (auto key = nextObjectKey()) { + if (KEY_AS("v")) { + enterObject(); + while (auto key = nextObjectKey()) { + if (KEY_AS("k")) { + if (idx == 0) parsePropertyInternal(effect->black); + else if (idx == 1) parsePropertyInternal(effect->white); + else if (idx == 2) parsePropertyInternal(effect->intensity); + else skip(); + } else skip(); + } + ++idx; + } else skip(); + } + } +} + + void LottieParser::parseFill(LottieFxFill* effect) { int idx = 0; //fill mask -> all mask -> color -> invert -> h feather -> v feather -> opacity @@ -1345,6 +1370,10 @@ void LottieParser::parseDropShadow(LottieFxDropShadow* effect) void LottieParser::parseEffect(LottieEffect* effect) { switch (effect->type) { + case LottieEffect::Tint: { + parseTint(static_cast(effect)); + break; + } case LottieEffect::Fill: { parseFill(static_cast(effect)); break; diff --git a/src/loaders/lottie/tvgLottieParser.h b/src/loaders/lottie/tvgLottieParser.h index d6550afb..a765cd1d 100644 --- a/src/loaders/lottie/tvgLottieParser.h +++ b/src/loaders/lottie/tvgLottieParser.h @@ -98,6 +98,7 @@ private: LottieFont* parseFont(); LottieMarker* parseMarker(); + void parseTint(LottieFxTint* effect); void parseFill(LottieFxFill* effect); void parseGaussianBlur(LottieFxGaussianBlur* effect); void parseDropShadow(LottieFxDropShadow* effect);