lottie: corrected the comp/layer size data type.

Actually, the these size is expected to be a floating-point value.
This correction addresses a parsing error.

issue: https://github.com/thorvg/thorvg/issues/2153
This commit is contained in:
Hermet Park 2024-04-09 17:20:57 +09:00
parent 1498ef83d0
commit d54a23dd7f
4 changed files with 15 additions and 24 deletions

View file

@ -30,15 +30,6 @@
/* Internal Class Implementation */
/************************************************************************/
static float _str2float(const char* str, int len)
{
auto tmp = strDuplicate(str, len);
auto ret = strToFloat(tmp, nullptr);
free(tmp);
return ret;
}
void LottieLoader::run(unsigned tid)
{
//update frame
@ -127,7 +118,7 @@ bool LottieLoader::header()
p += 5;
auto e = strstr(p, ",");
if (!e) e = strstr(p, "}");
frameRate = _str2float(p, e - p);
frameRate = strToFloat(p, nullptr);
p = e;
continue;
}
@ -137,7 +128,7 @@ bool LottieLoader::header()
p += 5;
auto e = strstr(p, ",");
if (!e) e = strstr(p, "}");
startFrame = _str2float(p, e - p);
startFrame = strToFloat(p, nullptr);
p = e;
continue;
}
@ -147,7 +138,7 @@ bool LottieLoader::header()
p += 5;
auto e = strstr(p, ",");
if (!e) e = strstr(p, "}");
endFrame = _str2float(p, e - p);
endFrame = strToFloat(p, nullptr);
p = e;
continue;
}
@ -157,7 +148,7 @@ bool LottieLoader::header()
p += 4;
auto e = strstr(p, ",");
if (!e) e = strstr(p, "}");
w = static_cast<float>(str2int(p, e - p));
w = strToFloat(p, nullptr);
p = e;
continue;
}
@ -166,7 +157,7 @@ bool LottieLoader::header()
p += 4;
auto e = strstr(p, ",");
if (!e) e = strstr(p, "}");
h = static_cast<float>(str2int(p, e - p));
h = strToFloat(p, nullptr);
p = e;
continue;
}
@ -181,7 +172,7 @@ bool LottieLoader::header()
frameCnt = (endFrame - startFrame);
frameDuration = frameCnt / frameRate;
TVGLOG("LOTTIE", "info: frame rate = %f, duration = %f size = %d x %d", frameRate, frameDuration, (int)w, (int)h);
TVGLOG("LOTTIE", "info: frame rate = %f, duration = %f size = %f x %f", frameRate, frameDuration, w, h);
return true;
}

View file

@ -617,7 +617,7 @@ struct LottieLayer : LottieGroup
RGB24 color; //used by Solid layer
float timeStretch = 1.0f;
uint32_t w = 0, h = 0;
float w = 0.0f, h = 0.0f;
float inFrame = 0.0f;
float outFrame = 0.0f;
float startFrame = 0.0f;
@ -758,7 +758,7 @@ struct LottieComposition
LottieLayer* root = nullptr;
char* version = nullptr;
char* name = nullptr;
uint32_t w, h;
float w, h;
float startFrame, endFrame;
float frameRate;
Array<LottieObject*> assets;

View file

@ -1089,14 +1089,14 @@ void LottieParser::parseText(Array<LottieObject*>& parent)
}
void LottieParser::getLayerSize(uint32_t& val)
void LottieParser::getLayerSize(float& val)
{
if (val == 0) {
val = getInt();
if (val == 0.0f) {
val = getFloat();
} else {
//layer might have both w(width) & sw(solid color width)
//override one if the a new size is smaller.
uint32_t w = getInt();
auto w = getFloat();
if (w < val) val = w;
}
}
@ -1307,8 +1307,8 @@ bool LottieParser::parse()
else if (!strcmp(key, "fr")) comp->frameRate = getFloat();
else if (!strcmp(key, "ip")) comp->startFrame = getFloat();
else if (!strcmp(key, "op")) comp->endFrame = getFloat();
else if (!strcmp(key, "w")) comp->w = getInt();
else if (!strcmp(key, "h")) comp->h = getInt();
else if (!strcmp(key, "w")) comp->w = getFloat();
else if (!strcmp(key, "h")) comp->h = getFloat();
else if (!strcmp(key, "nm")) comp->name = getStringCopy();
else if (!strcmp(key, "assets")) parseAssets();
else if (!strcmp(key, "layers")) comp->root = parseLayers();

View file

@ -55,7 +55,7 @@ private:
void getInperpolatorPoint(Point& pt);
void getPathSet(LottiePathSet& path);
void getLayerSize(uint32_t& val);
void getLayerSize(float& val);
void getValue(TextDocument& doc);
void getValue(PathSet& path);
void getValue(Array<Point>& pts);