mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-16 13:04:48 +00:00
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:
parent
1498ef83d0
commit
d54a23dd7f
4 changed files with 15 additions and 24 deletions
|
@ -30,15 +30,6 @@
|
||||||
/* Internal Class Implementation */
|
/* 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)
|
void LottieLoader::run(unsigned tid)
|
||||||
{
|
{
|
||||||
//update frame
|
//update frame
|
||||||
|
@ -127,7 +118,7 @@ bool LottieLoader::header()
|
||||||
p += 5;
|
p += 5;
|
||||||
auto e = strstr(p, ",");
|
auto e = strstr(p, ",");
|
||||||
if (!e) e = strstr(p, "}");
|
if (!e) e = strstr(p, "}");
|
||||||
frameRate = _str2float(p, e - p);
|
frameRate = strToFloat(p, nullptr);
|
||||||
p = e;
|
p = e;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -137,7 +128,7 @@ bool LottieLoader::header()
|
||||||
p += 5;
|
p += 5;
|
||||||
auto e = strstr(p, ",");
|
auto e = strstr(p, ",");
|
||||||
if (!e) e = strstr(p, "}");
|
if (!e) e = strstr(p, "}");
|
||||||
startFrame = _str2float(p, e - p);
|
startFrame = strToFloat(p, nullptr);
|
||||||
p = e;
|
p = e;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -147,7 +138,7 @@ bool LottieLoader::header()
|
||||||
p += 5;
|
p += 5;
|
||||||
auto e = strstr(p, ",");
|
auto e = strstr(p, ",");
|
||||||
if (!e) e = strstr(p, "}");
|
if (!e) e = strstr(p, "}");
|
||||||
endFrame = _str2float(p, e - p);
|
endFrame = strToFloat(p, nullptr);
|
||||||
p = e;
|
p = e;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -157,7 +148,7 @@ bool LottieLoader::header()
|
||||||
p += 4;
|
p += 4;
|
||||||
auto e = strstr(p, ",");
|
auto e = strstr(p, ",");
|
||||||
if (!e) e = strstr(p, "}");
|
if (!e) e = strstr(p, "}");
|
||||||
w = static_cast<float>(str2int(p, e - p));
|
w = strToFloat(p, nullptr);
|
||||||
p = e;
|
p = e;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -166,7 +157,7 @@ bool LottieLoader::header()
|
||||||
p += 4;
|
p += 4;
|
||||||
auto e = strstr(p, ",");
|
auto e = strstr(p, ",");
|
||||||
if (!e) e = strstr(p, "}");
|
if (!e) e = strstr(p, "}");
|
||||||
h = static_cast<float>(str2int(p, e - p));
|
h = strToFloat(p, nullptr);
|
||||||
p = e;
|
p = e;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -181,7 +172,7 @@ bool LottieLoader::header()
|
||||||
frameCnt = (endFrame - startFrame);
|
frameCnt = (endFrame - startFrame);
|
||||||
frameDuration = frameCnt / frameRate;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -617,7 +617,7 @@ struct LottieLayer : LottieGroup
|
||||||
RGB24 color; //used by Solid layer
|
RGB24 color; //used by Solid layer
|
||||||
|
|
||||||
float timeStretch = 1.0f;
|
float timeStretch = 1.0f;
|
||||||
uint32_t w = 0, h = 0;
|
float w = 0.0f, h = 0.0f;
|
||||||
float inFrame = 0.0f;
|
float inFrame = 0.0f;
|
||||||
float outFrame = 0.0f;
|
float outFrame = 0.0f;
|
||||||
float startFrame = 0.0f;
|
float startFrame = 0.0f;
|
||||||
|
@ -758,7 +758,7 @@ struct LottieComposition
|
||||||
LottieLayer* root = nullptr;
|
LottieLayer* root = nullptr;
|
||||||
char* version = nullptr;
|
char* version = nullptr;
|
||||||
char* name = nullptr;
|
char* name = nullptr;
|
||||||
uint32_t w, h;
|
float w, h;
|
||||||
float startFrame, endFrame;
|
float startFrame, endFrame;
|
||||||
float frameRate;
|
float frameRate;
|
||||||
Array<LottieObject*> assets;
|
Array<LottieObject*> assets;
|
||||||
|
|
|
@ -1089,14 +1089,14 @@ void LottieParser::parseText(Array<LottieObject*>& parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LottieParser::getLayerSize(uint32_t& val)
|
void LottieParser::getLayerSize(float& val)
|
||||||
{
|
{
|
||||||
if (val == 0) {
|
if (val == 0.0f) {
|
||||||
val = getInt();
|
val = getFloat();
|
||||||
} else {
|
} else {
|
||||||
//layer might have both w(width) & sw(solid color width)
|
//layer might have both w(width) & sw(solid color width)
|
||||||
//override one if the a new size is smaller.
|
//override one if the a new size is smaller.
|
||||||
uint32_t w = getInt();
|
auto w = getFloat();
|
||||||
if (w < val) val = w;
|
if (w < val) val = w;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1307,8 +1307,8 @@ bool LottieParser::parse()
|
||||||
else if (!strcmp(key, "fr")) comp->frameRate = getFloat();
|
else if (!strcmp(key, "fr")) comp->frameRate = getFloat();
|
||||||
else if (!strcmp(key, "ip")) comp->startFrame = getFloat();
|
else if (!strcmp(key, "ip")) comp->startFrame = getFloat();
|
||||||
else if (!strcmp(key, "op")) comp->endFrame = getFloat();
|
else if (!strcmp(key, "op")) comp->endFrame = getFloat();
|
||||||
else if (!strcmp(key, "w")) comp->w = getInt();
|
else if (!strcmp(key, "w")) comp->w = getFloat();
|
||||||
else if (!strcmp(key, "h")) comp->h = getInt();
|
else if (!strcmp(key, "h")) comp->h = getFloat();
|
||||||
else if (!strcmp(key, "nm")) comp->name = getStringCopy();
|
else if (!strcmp(key, "nm")) comp->name = getStringCopy();
|
||||||
else if (!strcmp(key, "assets")) parseAssets();
|
else if (!strcmp(key, "assets")) parseAssets();
|
||||||
else if (!strcmp(key, "layers")) comp->root = parseLayers();
|
else if (!strcmp(key, "layers")) comp->root = parseLayers();
|
||||||
|
|
|
@ -55,7 +55,7 @@ private:
|
||||||
|
|
||||||
void getInperpolatorPoint(Point& pt);
|
void getInperpolatorPoint(Point& pt);
|
||||||
void getPathSet(LottiePathSet& path);
|
void getPathSet(LottiePathSet& path);
|
||||||
void getLayerSize(uint32_t& val);
|
void getLayerSize(float& val);
|
||||||
void getValue(TextDocument& doc);
|
void getValue(TextDocument& doc);
|
||||||
void getValue(PathSet& path);
|
void getValue(PathSet& path);
|
||||||
void getValue(Array<Point>& pts);
|
void getValue(Array<Point>& pts);
|
||||||
|
|
Loading…
Add table
Reference in a new issue