From bf5cea982c117769ca8f7f34c0987ad4767f439d Mon Sep 17 00:00:00 2001 From: Jinny You Date: Thu, 27 Feb 2025 13:01:45 +0800 Subject: [PATCH] common: Support .lot extension Add support for the .lot extension to recognize Lottie animation files, as this introduces an additional extension for Lottie. issue: #3248 --- examples/Lottie.cpp | 2 +- examples/LottieExpressions.cpp | 2 +- inc/thorvg.h | 6 +++--- src/bindings/capi/thorvg_capi.h | 4 ++-- src/bindings/wasm/tvgWasmLottieAnimation.cpp | 4 ++-- src/loaders/lottie/tvgLottieLoader.cpp | 2 +- src/renderer/tvgCommon.h | 2 +- src/renderer/tvgLoader.cpp | 14 +++++++------- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/examples/Lottie.cpp b/examples/Lottie.cpp index 20a21dac..95848d20 100644 --- a/examples/Lottie.cpp +++ b/examples/Lottie.cpp @@ -43,7 +43,7 @@ struct UserExample : tvgexam::Example //ignore if not lottie. const char *ext = path + strlen(path) - 4; - if (strcmp(ext, "json")) return; + if (strcmp(ext, "json") && strcmp(ext, "lot")) return; //Animation Controller auto animation = tvg::Animation::gen(); diff --git a/examples/LottieExpressions.cpp b/examples/LottieExpressions.cpp index 65388e67..06727d85 100644 --- a/examples/LottieExpressions.cpp +++ b/examples/LottieExpressions.cpp @@ -43,7 +43,7 @@ struct UserExample : tvgexam::Example //ignore if not lottie. const char *ext = path + strlen(path) - 4; - if (strcmp(ext, "json")) return; + if (strcmp(ext, "json") && strcmp(ext, "lot")) return; //Animation Controller auto animation = tvg::Animation::gen(); diff --git a/inc/thorvg.h b/inc/thorvg.h index a1618b81..18cf3372 100644 --- a/inc/thorvg.h +++ b/inc/thorvg.h @@ -1278,7 +1278,7 @@ public: /** * @class Picture * - * @brief A class representing an image read in one of the supported formats: raw, svg, png, jpg, lottie(json) and etc. + * @brief A class representing an image read in one of the supported formats: raw, svg, png, jpg, lot and etc. * Besides the methods inherited from the Paint, it provides methods to load & draw images on the canvas. * * @note Supported formats are depended on the available TVG loaders. @@ -1313,7 +1313,7 @@ public: * * @param[in] data A pointer to a memory location where the content of the picture file is stored. A null-terminated string is expected for non-binary data if @p copy is @c false. * @param[in] size The size in bytes of the memory occupied by the @p data. - * @param[in] mimeType Mimetype or extension of data such as "jpg", "jpeg", "lottie", "svg", "svg+xml", "png", etc. In case an empty string or an unknown type is provided, the loaders will be tried one by one. + * @param[in] mimeType Mimetype or extension of data such as "jpg", "jpeg", "lot", "lottie+json", "svg", "svg+xml", "png", etc. In case an empty string or an unknown type is provided, the loaders will be tried one by one. * @param[in] rpath A resource directory path, if the @p data needs to access any external resources. * @param[in] copy If @c true the data are copied into the engine local buffer, otherwise they are not. * @@ -1883,7 +1883,7 @@ public: /** * @brief Retrieves a picture instance associated with this animation instance. * - * This function provides access to the picture instance that can be used to load animation formats, such as Lottie(json). + * This function provides access to the picture instance that can be used to load animation formats, such as lot. * After setting up the picture, it can be pushed to the designated canvas, enabling control over animation frames * with this Animation instance. * diff --git a/src/bindings/capi/thorvg_capi.h b/src/bindings/capi/thorvg_capi.h index 17633b67..43e23af6 100644 --- a/src/bindings/capi/thorvg_capi.h +++ b/src/bindings/capi/thorvg_capi.h @@ -1847,7 +1847,7 @@ TVG_API Tvg_Result tvg_picture_load_raw(Tvg_Paint* paint, uint32_t *data, uint32 * @param[in] paint A Tvg_Paint pointer to the picture object. * @param[in] data A pointer to a memory location where the content of the picture file is stored. A null-terminated string is expected for non-binary data if @p copy is @c false * @param[in] size The size in bytes of the memory occupied by the @p data. -* @param[in] mimetype Mimetype or extension of data such as "jpg", "jpeg", "svg", "svg+xml", "lottie", "png", etc. In case an empty string or an unknown type is provided, the loaders will be tried one by one. +* @param[in] mimetype Mimetype or extension of data such as "jpg", "jpeg", "svg", "svg+xml", "lot", "lottie+json", "png", etc. In case an empty string or an unknown type is provided, the loaders will be tried one by one. * @param[in] rpath A resource directory path, if the @p data needs to access any external resources. * @param[in] copy If @c true the data are copied into the engine local buffer, otherwise they are not. * @@ -2273,7 +2273,7 @@ TVG_API Tvg_Result tvg_animation_set_frame(Tvg_Animation* animation, float no); /*! * @brief Retrieves a picture instance associated with this animation instance. * -* This function provides access to the picture instance that can be used to load animation formats, such as Lottie(json). +* This function provides access to the picture instance that can be used to load animation formats, such as lot. * After setting up the picture, it can be pushed to the designated canvas, enabling control over animation frames * with this Animation instance. * diff --git a/src/bindings/wasm/tvgWasmLottieAnimation.cpp b/src/bindings/wasm/tvgWasmLottieAnimation.cpp index b07a0f5e..66982c90 100644 --- a/src/bindings/wasm/tvgWasmLottieAnimation.cpp +++ b/src/bindings/wasm/tvgWasmLottieAnimation.cpp @@ -326,7 +326,7 @@ public: string filetype = mimetype; if (filetype == "json") { - filetype = "lottie"; + filetype = "lottie+json"; } if (animation->picture()->load(data.c_str(), data.size(), filetype.c_str(), rpath.c_str(), false) != Result::Success) { @@ -464,7 +464,7 @@ public: return false; } - if (animation->picture()->load(data.c_str(), data.size(), "lottie", nullptr, false) != Result::Success) { + if (animation->picture()->load(data.c_str(), data.size(), "lot", nullptr, false) != Result::Success) { errorMsg = "load() fail"; return false; } diff --git a/src/loaders/lottie/tvgLottieLoader.cpp b/src/loaders/lottie/tvgLottieLoader.cpp index 01a878b5..bba5bbb3 100644 --- a/src/loaders/lottie/tvgLottieLoader.cpp +++ b/src/loaders/lottie/tvgLottieLoader.cpp @@ -68,7 +68,7 @@ void LottieLoader::release() /* External Class Implementation */ /************************************************************************/ -LottieLoader::LottieLoader() : FrameModule(FileType::Lottie), builder(new LottieBuilder) +LottieLoader::LottieLoader() : FrameModule(FileType::Lot), builder(new LottieBuilder) { } diff --git a/src/renderer/tvgCommon.h b/src/renderer/tvgCommon.h index 09f12393..ea857133 100644 --- a/src/renderer/tvgCommon.h +++ b/src/renderer/tvgCommon.h @@ -70,7 +70,7 @@ void operator delete(void* ptr) noexcept; namespace tvg { - enum class FileType { Png = 0, Jpg, Webp, Svg, Lottie, Ttf, Raw, Gif, Unknown }; + enum class FileType { Png = 0, Jpg, Webp, Svg, Lot, Ttf, Raw, Gif, Unknown }; using Size = Point; diff --git a/src/renderer/tvgLoader.cpp b/src/renderer/tvgLoader.cpp index 9bc00c1b..90f82748 100644 --- a/src/renderer/tvgLoader.cpp +++ b/src/renderer/tvgLoader.cpp @@ -102,7 +102,7 @@ static LoadModule* _find(FileType type) #endif break; } - case FileType::Lottie: { + case FileType::Lot: { #ifdef THORVG_LOTTIE_LOADER_SUPPORT return new LottieLoader; #endif @@ -128,8 +128,8 @@ static LoadModule* _find(FileType type) format = "TTF"; break; } - case FileType::Lottie: { - format = "lottie(json)"; + case FileType::Lot: { + format = "LOT"; break; } case FileType::Raw: { @@ -166,7 +166,7 @@ static LoadModule* _findByPath(const char* filename) if (!ext) return nullptr; if (!strcmp(ext, "svg")) return _find(FileType::Svg); - if (!strcmp(ext, "json")) return _find(FileType::Lottie); + if (!strcmp(ext, "lot") || !strcmp(ext, "json")) return _find(FileType::Lot); if (!strcmp(ext, "png")) return _find(FileType::Png); if (!strcmp(ext, "jpg")) return _find(FileType::Jpg); if (!strcmp(ext, "webp")) return _find(FileType::Webp); @@ -185,7 +185,7 @@ static FileType _convert(const char* mimeType) if (!strcmp(mimeType, "svg") || !strcmp(mimeType, "svg+xml")) type = FileType::Svg; else if (!strcmp(mimeType, "ttf") || !strcmp(mimeType, "otf")) type = FileType::Ttf; - else if (!strcmp(mimeType, "lottie")) type = FileType::Lottie; + else if (!strcmp(mimeType, "lot") || !strcmp(mimeType, "lottie+json")) type = FileType::Lot; else if (!strcmp(mimeType, "raw")) type = FileType::Raw; else if (!strcmp(mimeType, "png")) type = FileType::Png; else if (!strcmp(mimeType, "jpg") || !strcmp(mimeType, "jpeg")) type = FileType::Jpg; @@ -280,7 +280,7 @@ LoadModule* LoaderMgr::loader(const char* filename, bool* invalid) //TODO: svg & lottie is not sharable. auto allowCache = true; auto ext = strExtension(filename); - if (ext && (!strcmp(ext, "svg") || !strcmp(ext, "json"))) allowCache = false; + if (ext && (!strcmp(ext, "svg") || !strcmp(ext, "json") || !strcmp(ext, "lot"))) allowCache = false; if (allowCache) { if (auto loader = _findFromCache(filename)) return loader; @@ -362,7 +362,7 @@ LoadModule* LoaderMgr::loader(const char* data, uint32_t size, const char* mimeT //TODO: lottie is not sharable. if (allowCache) { auto type = _convert(mimeType); - if (type == FileType::Lottie) allowCache = false; + if (type == FileType::Lot) allowCache = false; } if (allowCache) {