mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
lottie: support Tint LayerEffect
issue: https://github.com/thorvg/thorvg/issues/2718
This commit is contained in:
parent
8e8611b608
commit
1eff126b40
4 changed files with 51 additions and 2 deletions
|
@ -1314,6 +1314,13 @@ void LottieBuilder::updateEffect(LottieLayer* layer, float frameNo)
|
||||||
for (auto ef = layer->effects.begin(); ef < layer->effects.end(); ++ef) {
|
for (auto ef = layer->effects.begin(); ef < layer->effects.end(); ++ef) {
|
||||||
if (!(*ef)->enable) continue;
|
if (!(*ef)->enable) continue;
|
||||||
switch ((*ef)->type) {
|
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: {
|
case LottieEffect::Fill: {
|
||||||
auto effect = static_cast<LottieFxFill*>(*ef);
|
auto effect = static_cast<LottieFxFill*>(*ef);
|
||||||
auto color = effect->color(frameNo);
|
auto color = effect->color(frameNo);
|
||||||
|
|
|
@ -82,8 +82,9 @@ struct LottieEffect
|
||||||
enum Type : uint8_t
|
enum Type : uint8_t
|
||||||
{
|
{
|
||||||
DropShadow = 0,
|
DropShadow = 0,
|
||||||
GaussianBlur = 1,
|
GaussianBlur,
|
||||||
Fill = 2,
|
Fill,
|
||||||
|
Tint
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual ~LottieEffect() {}
|
virtual ~LottieEffect() {}
|
||||||
|
@ -109,6 +110,17 @@ struct LottieFxFill : LottieEffect
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct LottieFxTint : LottieEffect
|
||||||
|
{
|
||||||
|
LottieColor black;
|
||||||
|
LottieColor white;
|
||||||
|
LottieSlider intensity;
|
||||||
|
|
||||||
|
LottieFxTint()
|
||||||
|
{
|
||||||
|
type = Tint;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
struct LottieFxDropShadow : LottieEffect
|
struct LottieFxDropShadow : LottieEffect
|
||||||
{
|
{
|
||||||
|
|
|
@ -60,6 +60,7 @@ static unsigned long _int2str(int num)
|
||||||
LottieEffect* LottieParser::getEffect(int type)
|
LottieEffect* LottieParser::getEffect(int type)
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
case 20: return new LottieFxTint;
|
||||||
case 21: return new LottieFxFill;
|
case 21: return new LottieFxFill;
|
||||||
case 25: return new LottieFxDropShadow;
|
case 25: return new LottieFxDropShadow;
|
||||||
case 29: return new LottieFxGaussianBlur;
|
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)
|
void LottieParser::parseFill(LottieFxFill* effect)
|
||||||
{
|
{
|
||||||
int idx = 0; //fill mask -> all mask -> color -> invert -> h feather -> v feather -> opacity
|
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)
|
void LottieParser::parseEffect(LottieEffect* effect)
|
||||||
{
|
{
|
||||||
switch (effect->type) {
|
switch (effect->type) {
|
||||||
|
case LottieEffect::Tint: {
|
||||||
|
parseTint(static_cast<LottieFxTint*>(effect));
|
||||||
|
break;
|
||||||
|
}
|
||||||
case LottieEffect::Fill: {
|
case LottieEffect::Fill: {
|
||||||
parseFill(static_cast<LottieFxFill*>(effect));
|
parseFill(static_cast<LottieFxFill*>(effect));
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -98,6 +98,7 @@ private:
|
||||||
LottieFont* parseFont();
|
LottieFont* parseFont();
|
||||||
LottieMarker* parseMarker();
|
LottieMarker* parseMarker();
|
||||||
|
|
||||||
|
void parseTint(LottieFxTint* effect);
|
||||||
void parseFill(LottieFxFill* effect);
|
void parseFill(LottieFxFill* effect);
|
||||||
void parseGaussianBlur(LottieFxGaussianBlur* effect);
|
void parseGaussianBlur(LottieFxGaussianBlur* effect);
|
||||||
void parseDropShadow(LottieFxDropShadow* effect);
|
void parseDropShadow(LottieFxDropShadow* effect);
|
||||||
|
|
Loading…
Add table
Reference in a new issue