mirror of
https://github.com/thorvg/thorvg.git
synced 2025-07-23 06:38:43 +00:00
lottie: expressions compactness++
expressions is an optional feature, do not prepare expressions if the engine doesn't support it.
This commit is contained in:
parent
44075aa0f0
commit
868a085262
4 changed files with 25 additions and 15 deletions
|
@ -98,6 +98,11 @@ struct LottieBuilder
|
|||
LottieExpressions::retrieve(exps);
|
||||
}
|
||||
|
||||
bool expressions()
|
||||
{
|
||||
return exps ? true : false;
|
||||
}
|
||||
|
||||
bool update(LottieComposition* comp, float progress);
|
||||
void build(LottieComposition* comp);
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ void LottieLoader::run(unsigned tid)
|
|||
builder->update(comp, frameNo);
|
||||
//initial loading
|
||||
} else {
|
||||
LottieParser parser(content, dirName);
|
||||
LottieParser parser(content, dirName, builder->expressions());
|
||||
if (!parser.parse()) return;
|
||||
{
|
||||
ScopedLock lock(key);
|
||||
|
@ -300,7 +300,7 @@ bool LottieLoader::override(const char* slots, bool byDefault)
|
|||
auto temp = byDefault ? slots : strdup(slots);
|
||||
|
||||
//parsing slot json
|
||||
LottieParser parser(temp, dirName);
|
||||
LottieParser parser(temp, dirName, builder->expressions());
|
||||
parser.comp = comp;
|
||||
|
||||
auto idx = 0;
|
||||
|
|
|
@ -34,8 +34,18 @@
|
|||
#define KEY_AS(name) !strcmp(key, name)
|
||||
|
||||
|
||||
static LottieExpression* _expression(char* code, LottieComposition* comp, LottieLayer* layer, LottieObject* object, LottieProperty* property)
|
||||
static unsigned long _int2str(int num)
|
||||
{
|
||||
char str[20];
|
||||
snprintf(str, 20, "%d", num);
|
||||
return djb2Encode(str);
|
||||
}
|
||||
|
||||
|
||||
LottieExpression* LottieParser::getExpression(char* code, LottieComposition* comp, LottieLayer* layer, LottieObject* object, LottieProperty* property)
|
||||
{
|
||||
if (!expressions) return nullptr;
|
||||
|
||||
if (!comp->expressions) comp->expressions = true;
|
||||
|
||||
auto inst = new LottieExpression;
|
||||
|
@ -49,14 +59,6 @@ static LottieExpression* _expression(char* code, LottieComposition* comp, Lottie
|
|||
}
|
||||
|
||||
|
||||
static unsigned long _int2str(int num)
|
||||
{
|
||||
char str[20];
|
||||
snprintf(str, 20, "%d", num);
|
||||
return djb2Encode(str);
|
||||
}
|
||||
|
||||
|
||||
LottieEffect* LottieParser::getEffect(int type)
|
||||
{
|
||||
switch (type) {
|
||||
|
@ -477,7 +479,7 @@ void LottieParser::parseProperty(T& prop, LottieObject* obj)
|
|||
while (auto key = nextObjectKey()) {
|
||||
if (KEY_AS("k")) parsePropertyInternal(prop);
|
||||
else if (obj && KEY_AS("sid")) registerSlot<type>(obj, getString());
|
||||
else if (KEY_AS("x")) prop.exp = _expression(getStringCopy(), comp, context.layer, context.parent, &prop);
|
||||
else if (KEY_AS("x")) prop.exp = getExpression(getStringCopy(), comp, context.layer, context.parent, &prop);
|
||||
else if (KEY_AS("ix")) prop.ix = getInt();
|
||||
else skip();
|
||||
}
|
||||
|
@ -566,7 +568,7 @@ LottieTransform* LottieParser::parseTransform(bool ddd)
|
|||
//check separateCoord to figure out whether "x(expression)" / "x(coord)"
|
||||
else if (transform->coords && KEY_AS("x")) parseProperty<LottieProperty::Type::Float>(transform->coords->x);
|
||||
else if (transform->coords && KEY_AS("y")) parseProperty<LottieProperty::Type::Float>(transform->coords->y);
|
||||
else if (KEY_AS("x")) transform->position.exp = _expression(getStringCopy(), comp, context.layer, context.parent, &transform->position);
|
||||
else if (KEY_AS("x")) transform->position.exp = getExpression(getStringCopy(), comp, context.layer, context.parent, &transform->position);
|
||||
else if (KEY_AS("sid")) registerSlot<LottieProperty::Type::Position>(transform, getString());
|
||||
else skip();
|
||||
}
|
||||
|
@ -659,7 +661,7 @@ void LottieParser::getPathSet(LottiePathSet& path)
|
|||
getValue(path.value);
|
||||
}
|
||||
} else if (KEY_AS("x")) {
|
||||
path.exp = _expression(getStringCopy(), comp, context.layer, context.parent, &path);
|
||||
path.exp = getExpression(getStringCopy(), comp, context.layer, context.parent, &path);
|
||||
} else skip();
|
||||
}
|
||||
path.type = LottieProperty::Type::PathSet;
|
||||
|
|
|
@ -30,9 +30,10 @@
|
|||
struct LottieParser : LookaheadParserHandler
|
||||
{
|
||||
public:
|
||||
LottieParser(const char *str, const char* dirName) : LookaheadParserHandler(str)
|
||||
LottieParser(const char *str, const char* dirName, bool expressions) : LookaheadParserHandler(str)
|
||||
{
|
||||
this->dirName = dirName;
|
||||
this->expressions = expressions;
|
||||
}
|
||||
|
||||
bool parse();
|
||||
|
@ -44,6 +45,7 @@ public:
|
|||
LottieComposition* comp = nullptr;
|
||||
const char* dirName = nullptr; //base resource directory
|
||||
char* slots = nullptr;
|
||||
bool expressions = false; //support expressions?
|
||||
|
||||
private:
|
||||
RGB24 getColor(const char *str);
|
||||
|
@ -51,6 +53,7 @@ private:
|
|||
MaskMethod getMaskMethod(bool inversed);
|
||||
LottieInterpolator* getInterpolator(const char* key, Point& in, Point& out);
|
||||
LottieEffect* getEffect(int type);
|
||||
LottieExpression* getExpression(char* code, LottieComposition* comp, LottieLayer* layer, LottieObject* object, LottieProperty* property);
|
||||
|
||||
void getInterpolatorPoint(Point& pt);
|
||||
void getPathSet(LottiePathSet& path);
|
||||
|
|
Loading…
Add table
Reference in a new issue