lottie: support Tint LayerEffect

issue: https://github.com/thorvg/thorvg/issues/2718
This commit is contained in:
Hermet Park 2024-12-16 15:08:51 +09:00 committed by Mira Grudzinska
parent 4050d86f2e
commit a69bad43fe
4 changed files with 51 additions and 2 deletions

View file

@ -1319,6 +1319,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<LottieFxTint*>(*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<LottieFxFill*>(*ef);
auto color = effect->color(frameNo);

View file

@ -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
{

View file

@ -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(key);
} else skip(key);
}
++idx;
} else skip(key);
}
}
}
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<LottieFxTint*>(effect));
break;
}
case LottieEffect::Fill: {
parseFill(static_cast<LottieFxFill*>(effect));
break;

View file

@ -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);