lottie/parser: tiny binary size reduction

This commit is contained in:
Hermet Park 2024-07-12 14:37:19 +09:00
parent 8340c1e1d7
commit cfc8f13584
2 changed files with 17 additions and 12 deletions

View file

@ -532,6 +532,18 @@ bool LottieParser::parseCommon(LottieObject* obj, const char* key)
} }
bool LottieParser::parseDirection(LottieShape* shape, const char* key)
{
if (KEY_AS("d")) {
if (getInt() == 3) {
shape->clockwise = false; //default is true
}
return true;
}
return false;
}
LottieRect* LottieParser::parseRect() LottieRect* LottieParser::parseRect()
{ {
auto rect = new LottieRect; auto rect = new LottieRect;
@ -543,7 +555,7 @@ LottieRect* LottieParser::parseRect()
else if (KEY_AS("s")) parseProperty<LottieProperty::Type::Point>(rect->size); else if (KEY_AS("s")) parseProperty<LottieProperty::Type::Point>(rect->size);
else if (KEY_AS("p")) parseProperty<LottieProperty::Type::Position>(rect->position); else if (KEY_AS("p")) parseProperty<LottieProperty::Type::Position>(rect->position);
else if (KEY_AS("r")) parseProperty<LottieProperty::Type::Float>(rect->radius); else if (KEY_AS("r")) parseProperty<LottieProperty::Type::Float>(rect->radius);
else if (KEY_AS("d")) rect->clockwise = getDirection(); else if (parseDirection(rect, key)) continue;
else skip(key); else skip(key);
} }
rect->prepare(); rect->prepare();
@ -561,7 +573,7 @@ LottieEllipse* LottieParser::parseEllipse()
if (parseCommon(ellipse, key)) continue; if (parseCommon(ellipse, key)) continue;
else if (KEY_AS("p")) parseProperty<LottieProperty::Type::Position>(ellipse->position); else if (KEY_AS("p")) parseProperty<LottieProperty::Type::Position>(ellipse->position);
else if (KEY_AS("s")) parseProperty<LottieProperty::Type::Point>(ellipse->size); else if (KEY_AS("s")) parseProperty<LottieProperty::Type::Point>(ellipse->size);
else if (KEY_AS("d")) ellipse->clockwise = getDirection(); else if (parseDirection(ellipse, key)) continue;
else skip(key); else skip(key);
} }
ellipse->prepare(); ellipse->prepare();
@ -698,7 +710,7 @@ LottiePath* LottieParser::parsePath()
while (auto key = nextObjectKey()) { while (auto key = nextObjectKey()) {
if (parseCommon(path, key)) continue; if (parseCommon(path, key)) continue;
else if (KEY_AS("ks")) getPathSet(path->pathset); else if (KEY_AS("ks")) getPathSet(path->pathset);
else if (KEY_AS("d")) path->clockwise = getDirection(); else if (parseDirection(path, key)) continue;
else skip(key); else skip(key);
} }
path->prepare(); path->prepare();
@ -722,7 +734,7 @@ LottiePolyStar* LottieParser::parsePolyStar()
else if (KEY_AS("os")) parseProperty<LottieProperty::Type::Float>(star->outerRoundness); else if (KEY_AS("os")) parseProperty<LottieProperty::Type::Float>(star->outerRoundness);
else if (KEY_AS("r")) parseProperty<LottieProperty::Type::Float>(star->rotation); else if (KEY_AS("r")) parseProperty<LottieProperty::Type::Float>(star->rotation);
else if (KEY_AS("sy")) star->type = (LottiePolyStar::Type) getInt(); else if (KEY_AS("sy")) star->type = (LottiePolyStar::Type) getInt();
else if (KEY_AS("d")) star->clockwise = getDirection(); else if (parseDirection(star, key)) continue;
else skip(key); else skip(key);
} }
star->prepare(); star->prepare();
@ -1086,13 +1098,6 @@ void LottieParser::parseTimeRemap(LottieLayer* layer)
} }
uint8_t LottieParser::getDirection()
{
if (getInt() == 3) return false;
return true;
}
void LottieParser::parseShapes(Array<LottieObject*>& parent) void LottieParser::parseShapes(Array<LottieObject*>& parent)
{ {
enterArray(); enterArray();

View file

@ -51,7 +51,6 @@ private:
StrokeJoin getStrokeJoin(); StrokeJoin getStrokeJoin();
CompositeMethod getMaskMethod(bool inversed); CompositeMethod getMaskMethod(bool inversed);
LottieInterpolator* getInterpolator(const char* key, Point& in, Point& out); LottieInterpolator* getInterpolator(const char* key, Point& in, Point& out);
uint8_t getDirection();
void getInterpolatorPoint(Point& pt); void getInterpolatorPoint(Point& pt);
void getPathSet(LottiePathSet& path); void getPathSet(LottiePathSet& path);
@ -94,6 +93,7 @@ private:
LottieFont* parseFont(); LottieFont* parseFont();
LottieMarker* parseMarker(); LottieMarker* parseMarker();
bool parseDirection(LottieShape* shape, const char* key);
bool parseCommon(LottieObject* obj, const char* key); bool parseCommon(LottieObject* obj, const char* key);
void parseObject(Array<LottieObject*>& parent); void parseObject(Array<LottieObject*>& parent);
void parseShapes(Array<LottieObject*>& parent); void parseShapes(Array<LottieObject*>& parent);