From d54a23dd7fc26224e89ca347cae5d7170305e1c5 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Tue, 9 Apr 2024 17:20:57 +0900 Subject: [PATCH] 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 --- src/loaders/lottie/tvgLottieLoader.cpp | 21 ++++++--------------- src/loaders/lottie/tvgLottieModel.h | 4 ++-- src/loaders/lottie/tvgLottieParser.cpp | 12 ++++++------ src/loaders/lottie/tvgLottieParser.h | 2 +- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/src/loaders/lottie/tvgLottieLoader.cpp b/src/loaders/lottie/tvgLottieLoader.cpp index 8d327663..25e80e57 100644 --- a/src/loaders/lottie/tvgLottieLoader.cpp +++ b/src/loaders/lottie/tvgLottieLoader.cpp @@ -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(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(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; } diff --git a/src/loaders/lottie/tvgLottieModel.h b/src/loaders/lottie/tvgLottieModel.h index 71df32a8..9d657d56 100644 --- a/src/loaders/lottie/tvgLottieModel.h +++ b/src/loaders/lottie/tvgLottieModel.h @@ -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 assets; diff --git a/src/loaders/lottie/tvgLottieParser.cpp b/src/loaders/lottie/tvgLottieParser.cpp index de30d38c..996fa919 100644 --- a/src/loaders/lottie/tvgLottieParser.cpp +++ b/src/loaders/lottie/tvgLottieParser.cpp @@ -1089,14 +1089,14 @@ void LottieParser::parseText(Array& 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(); diff --git a/src/loaders/lottie/tvgLottieParser.h b/src/loaders/lottie/tvgLottieParser.h index 9e218107..9c573666 100644 --- a/src/loaders/lottie/tvgLottieParser.h +++ b/src/loaders/lottie/tvgLottieParser.h @@ -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& pts);