mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
lottie: support Tritone LayerEffect
issue: https://github.com/thorvg/thorvg/issues/2718
This commit is contained in:
parent
8ec2eee6e3
commit
17fd454459
4 changed files with 64 additions and 22 deletions
|
@ -1327,6 +1327,14 @@ void LottieBuilder::updateEffect(LottieLayer* layer, float frameNo)
|
||||||
layer->scene->push(SceneEffect::Fill, color.rgb[0], color.rgb[1], color.rgb[2], (int)(255.0f *effect->opacity(frameNo)));
|
layer->scene->push(SceneEffect::Fill, color.rgb[0], color.rgb[1], color.rgb[2], (int)(255.0f *effect->opacity(frameNo)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case LottieEffect::Tritone: {
|
||||||
|
auto effect = static_cast<LottieFxTritone*>(*ef);
|
||||||
|
auto dark = effect->dark(frameNo);
|
||||||
|
auto midtone = effect->midtone(frameNo);
|
||||||
|
auto bright = effect->bright(frameNo);
|
||||||
|
layer->scene->push(SceneEffect::Tritone, dark.rgb[0], dark.rgb[1], dark.rgb[2], midtone.rgb[0], midtone.rgb[1], midtone.rgb[2], bright.rgb[0], bright.rgb[1], bright.rgb[2]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case LottieEffect::DropShadow: {
|
case LottieEffect::DropShadow: {
|
||||||
auto effect = static_cast<LottieFxDropShadow*>(*ef);
|
auto effect = static_cast<LottieFxDropShadow*>(*ef);
|
||||||
auto color = effect->color(frameNo);
|
auto color = effect->color(frameNo);
|
||||||
|
|
|
@ -79,34 +79,26 @@ struct LottieStroke
|
||||||
|
|
||||||
struct LottieEffect
|
struct LottieEffect
|
||||||
{
|
{
|
||||||
enum Type : uint8_t
|
enum Type : uint8_t {Tint = 20, Fill, Tritone = 23, DropShadow = 25, GaussianBlur = 29};
|
||||||
{
|
|
||||||
DropShadow = 0,
|
|
||||||
GaussianBlur,
|
|
||||||
Fill,
|
|
||||||
Tint
|
|
||||||
};
|
|
||||||
|
|
||||||
virtual ~LottieEffect() {}
|
virtual ~LottieEffect() {}
|
||||||
|
|
||||||
Type type;
|
Type type;
|
||||||
bool enable = false;
|
bool enable = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct LottieFxFill : LottieEffect
|
struct LottieFxFill : LottieEffect
|
||||||
{
|
{
|
||||||
//LottieFloat fillMask?
|
//int16_t mask layer
|
||||||
//LottieDropDown allMask?
|
//LottieDropDown allMask?
|
||||||
LottieColor color;
|
LottieColor color;
|
||||||
//LottieDropDown inverted
|
//LottieDropDown inverted
|
||||||
//LottieSlider horizontalFeather
|
//LottieSlider horizontalFeather
|
||||||
//LottieSlider verticalFeather
|
//LottieSlider verticalFeather
|
||||||
LottieSlider opacity = 0;
|
LottieSlider opacity;
|
||||||
|
|
||||||
LottieFxFill()
|
LottieFxFill()
|
||||||
{
|
{
|
||||||
type = Fill;
|
type = LottieEffect::Fill;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -118,7 +110,19 @@ struct LottieFxTint : LottieEffect
|
||||||
|
|
||||||
LottieFxTint()
|
LottieFxTint()
|
||||||
{
|
{
|
||||||
type = Tint;
|
type = LottieEffect::Tint;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct LottieFxTritone : LottieEffect
|
||||||
|
{
|
||||||
|
LottieColor bright;
|
||||||
|
LottieColor midtone;
|
||||||
|
LottieColor dark;
|
||||||
|
|
||||||
|
LottieFxTritone()
|
||||||
|
{
|
||||||
|
type = LottieEffect::Tritone;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -132,11 +136,10 @@ struct LottieFxDropShadow : LottieEffect
|
||||||
|
|
||||||
LottieFxDropShadow()
|
LottieFxDropShadow()
|
||||||
{
|
{
|
||||||
type = DropShadow;
|
type = LottieEffect::DropShadow;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct LottieFxGaussianBlur : LottieEffect
|
struct LottieFxGaussianBlur : LottieEffect
|
||||||
{
|
{
|
||||||
LottieSlider blurness = 0.0f;
|
LottieSlider blurness = 0.0f;
|
||||||
|
@ -145,7 +148,7 @@ struct LottieFxGaussianBlur : LottieEffect
|
||||||
|
|
||||||
LottieFxGaussianBlur()
|
LottieFxGaussianBlur()
|
||||||
{
|
{
|
||||||
type = GaussianBlur;
|
type = LottieEffect::GaussianBlur;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -60,10 +60,11 @@ 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 LottieEffect::Tint: return new LottieFxTint;
|
||||||
case 21: return new LottieFxFill;
|
case LottieEffect::Fill: return new LottieFxFill;
|
||||||
case 25: return new LottieFxDropShadow;
|
case LottieEffect::Tritone: return new LottieFxTritone;
|
||||||
case 29: return new LottieFxGaussianBlur;
|
case LottieEffect::DropShadow: return new LottieFxDropShadow;
|
||||||
|
case LottieEffect::GaussianBlur: return new LottieFxGaussianBlur;
|
||||||
default: return nullptr;
|
default: return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1294,6 +1295,31 @@ void LottieParser::parseTint(LottieFxTint* effect)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LottieParser::parseTritone(LottieFxTritone* effect)
|
||||||
|
{
|
||||||
|
int idx = 0; //bright, midtone, dark
|
||||||
|
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->bright);
|
||||||
|
else if (idx == 1) parsePropertyInternal(effect->midtone);
|
||||||
|
else if (idx == 2) parsePropertyInternal(effect->dark);
|
||||||
|
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
|
||||||
|
@ -1378,14 +1404,18 @@ void LottieParser::parseEffect(LottieEffect* effect)
|
||||||
parseFill(static_cast<LottieFxFill*>(effect));
|
parseFill(static_cast<LottieFxFill*>(effect));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LottieEffect::GaussianBlur: {
|
case LottieEffect::Tritone: {
|
||||||
parseGaussianBlur(static_cast<LottieFxGaussianBlur*>(effect));
|
parseTritone(static_cast<LottieFxTritone*>(effect));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LottieEffect::DropShadow: {
|
case LottieEffect::DropShadow: {
|
||||||
parseDropShadow(static_cast<LottieFxDropShadow*>(effect));
|
parseDropShadow(static_cast<LottieFxDropShadow*>(effect));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case LottieEffect::GaussianBlur: {
|
||||||
|
parseGaussianBlur(static_cast<LottieFxGaussianBlur*>(effect));
|
||||||
|
break;
|
||||||
|
}
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,6 +98,7 @@ private:
|
||||||
LottieFont* parseFont();
|
LottieFont* parseFont();
|
||||||
LottieMarker* parseMarker();
|
LottieMarker* parseMarker();
|
||||||
|
|
||||||
|
void parseTritone(LottieFxTritone* effect);
|
||||||
void parseTint(LottieFxTint* effect);
|
void parseTint(LottieFxTint* effect);
|
||||||
void parseFill(LottieFxFill* effect);
|
void parseFill(LottieFxFill* effect);
|
||||||
void parseGaussianBlur(LottieFxGaussianBlur* effect);
|
void parseGaussianBlur(LottieFxGaussianBlur* effect);
|
||||||
|
|
Loading…
Add table
Reference in a new issue