diff --git a/src/loaders/lottie/tvgLottieBuilder.cpp b/src/loaders/lottie/tvgLottieBuilder.cpp index 63f5b6fd..3ef06934 100644 --- a/src/loaders/lottie/tvgLottieBuilder.cpp +++ b/src/loaders/lottie/tvgLottieBuilder.cpp @@ -1297,14 +1297,23 @@ bool LottieBuilder::updateMatte(LottieComposition* comp, float frameNo, Scene* s void LottieBuilder::updateEffect(LottieLayer* layer, float frameNo) { + constexpr int QUALITY = 25; + constexpr float BLUR_TO_SIGMA = 0.3f; + if (layer->effects.count == 0) return; for (auto ef = layer->effects.begin(); ef < layer->effects.end(); ++ef) { if (!(*ef)->enable) continue; switch ((*ef)->type) { + case LottieEffect::DropShadow: { + auto effect = static_cast(*ef); + auto color = effect->color(frameNo); + layer->scene->push(SceneEffect::DropShadow, color.rgb[0], color.rgb[1], color.rgb[2], effect->opacity(frameNo), effect->angle(frameNo), effect->distance(frameNo), effect->blurness(frameNo), QUALITY); + break; + } case LottieEffect::GaussianBlur: { auto effect = static_cast(*ef); - layer->scene->push(SceneEffect::GaussianBlur, sqrt(effect->blurness(frameNo)), effect->direction(frameNo) - 1, effect->wrap(frameNo), 25); + layer->scene->push(SceneEffect::GaussianBlur, effect->blurness(frameNo) * BLUR_TO_SIGMA, effect->direction(frameNo) - 1, effect->wrap(frameNo), QUALITY); break; } default: break; diff --git a/src/loaders/lottie/tvgLottieModel.h b/src/loaders/lottie/tvgLottieModel.h index e2df452c..739f3303 100644 --- a/src/loaders/lottie/tvgLottieModel.h +++ b/src/loaders/lottie/tvgLottieModel.h @@ -81,7 +81,8 @@ struct LottieEffect { enum Type : uint8_t { - GaussianBlur = 0, + DropShadow = 0, + GaussianBlur = 1, }; virtual ~LottieEffect() {} @@ -91,6 +92,21 @@ struct LottieEffect }; +struct LottieDropShadow : LottieEffect +{ + LottieColor color; + LottieOpacity opacity = 0; + LottieAngle angle = 0.0f; + LottieSlider distance = 0.0f; + LottieSlider blurness = 0.0f; + + LottieDropShadow() + { + type = DropShadow; + } +}; + + struct LottieGaussianBlur : LottieEffect { LottieSlider blurness = 0.0f; diff --git a/src/loaders/lottie/tvgLottieParser.cpp b/src/loaders/lottie/tvgLottieParser.cpp index 2a4c00b5..6ba82aba 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 25: return new LottieDropShadow; case 29: return new LottieGaussianBlur; default: return nullptr; } @@ -1296,6 +1297,32 @@ void LottieParser::parseGaussianBlur(LottieGaussianBlur* effect) } +void LottieParser::parseDropShadow(LottieDropShadow* effect) +{ + int idx = 0; //color -> opacity -> angle -> distance -> blur + 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->color); + else if (idx == 1) parsePropertyInternal(effect->opacity); + else if (idx == 2) parsePropertyInternal(effect->angle); + else if (idx == 3) parsePropertyInternal(effect->distance); + else if (idx == 4) parsePropertyInternal(effect->blurness); + else skip(key); + ++idx; + } else skip(key); + } + } else skip(key); + } + } +} + + void LottieParser::parseEffect(LottieEffect* effect) { switch (effect->type) { @@ -1303,6 +1330,10 @@ void LottieParser::parseEffect(LottieEffect* effect) parseGaussianBlur(static_cast(effect)); break; } + case LottieEffect::DropShadow: { + parseDropShadow(static_cast(effect)); + break; + } default: break; } } diff --git a/src/loaders/lottie/tvgLottieParser.h b/src/loaders/lottie/tvgLottieParser.h index 9bdbae51..ff6a12fb 100644 --- a/src/loaders/lottie/tvgLottieParser.h +++ b/src/loaders/lottie/tvgLottieParser.h @@ -99,6 +99,7 @@ private: LottieMarker* parseMarker(); void parseGaussianBlur(LottieGaussianBlur* effect); + void parseDropShadow(LottieDropShadow* effect); bool parseDirection(LottieShape* shape, const char* key); bool parseCommon(LottieObject* obj, const char* key); diff --git a/src/loaders/lottie/tvgLottieProperty.h b/src/loaders/lottie/tvgLottieProperty.h index 1ba62ac4..dca034f6 100644 --- a/src/loaders/lottie/tvgLottieProperty.h +++ b/src/loaders/lottie/tvgLottieProperty.h @@ -905,6 +905,7 @@ using LottieFloat = LottieGenericProperty; using LottieOpacity = LottieGenericProperty; using LottieColor = LottieGenericProperty; using LottieSlider = LottieFloat; +using LottieAngle = LottieFloat; using LottieCheckbox = LottieGenericProperty; #endif //_TVG_LOTTIE_PROPERTY_H_