mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
lottie: add support for image size
The width and height of the image must be specified in the Lottie file and must be taken into account during rendering.
This commit is contained in:
parent
329ab9ef4a
commit
423e37d4d5
4 changed files with 12 additions and 3 deletions
|
@ -1042,6 +1042,7 @@ static void _updateImage(LottieGroup* layer)
|
|||
TaskScheduler::async(true);
|
||||
|
||||
PP(image->picture)->ref();
|
||||
image->picture->size(image->width, image->height);
|
||||
}
|
||||
|
||||
if (image->refCnt == 1) layer->scene->push(tvg::cast(image->picture));
|
||||
|
|
|
@ -458,6 +458,8 @@ struct LottieImage : LottieObject
|
|||
char* mimeType = nullptr;
|
||||
uint32_t size = 0;
|
||||
uint16_t refCnt = 0; //refernce count
|
||||
float width = 0.0f;
|
||||
float height = 0.0f;
|
||||
|
||||
~LottieImage();
|
||||
|
||||
|
|
|
@ -899,7 +899,7 @@ void LottieParser::parseObject(Array<LottieObject*>& parent)
|
|||
}
|
||||
|
||||
|
||||
LottieImage* LottieParser::parseImage(const char* data, const char* subPath, bool embedded)
|
||||
LottieImage* LottieParser::parseImage(const char* data, const char* subPath, bool embedded, float width, float height)
|
||||
{
|
||||
//Used for Image Asset
|
||||
auto image = new LottieImage;
|
||||
|
@ -922,6 +922,8 @@ LottieImage* LottieParser::parseImage(const char* data, const char* subPath, boo
|
|||
snprintf(image->path, len, "%s/%s%s", dirName, subPath, data);
|
||||
}
|
||||
|
||||
image->width = width;
|
||||
image->height = height;
|
||||
image->prepare();
|
||||
|
||||
return image;
|
||||
|
@ -938,6 +940,8 @@ LottieObject* LottieParser::parseAsset()
|
|||
//Used for Image Asset
|
||||
const char* data = nullptr;
|
||||
const char* subPath = nullptr;
|
||||
float width = 0.0f;
|
||||
float height = 0.0f;
|
||||
auto embedded = false;
|
||||
|
||||
while (auto key = nextObjectKey()) {
|
||||
|
@ -952,10 +956,12 @@ LottieObject* LottieParser::parseAsset()
|
|||
else if (KEY_AS("layers")) obj = parseLayers();
|
||||
else if (KEY_AS("u")) subPath = getString();
|
||||
else if (KEY_AS("p")) data = getString();
|
||||
else if (KEY_AS("w")) width = getFloat();
|
||||
else if (KEY_AS("h")) height = getFloat();
|
||||
else if (KEY_AS("e")) embedded = getInt();
|
||||
else skip(key);
|
||||
}
|
||||
if (data) obj = parseImage(data, subPath, embedded);
|
||||
if (data) obj = parseImage(data, subPath, embedded, width, height);
|
||||
if (obj) obj->id = id;
|
||||
return obj;
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ private:
|
|||
|
||||
LottieObject* parseObject();
|
||||
LottieObject* parseAsset();
|
||||
LottieImage* parseImage(const char* data, const char* subPath, bool embedded);
|
||||
LottieImage* parseImage(const char* data, const char* subPath, bool embedded, float width, float height);
|
||||
LottieLayer* parseLayer();
|
||||
LottieObject* parseGroup();
|
||||
LottieRect* parseRect();
|
||||
|
|
Loading…
Add table
Reference in a new issue