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
This commit is contained in:
Jinny You 2025-02-27 13:01:45 +08:00 committed by Hermet Park
parent ce96024e99
commit bf5cea982c
8 changed files with 18 additions and 18 deletions

View file

@ -43,7 +43,7 @@ struct UserExample : tvgexam::Example
//ignore if not lottie. //ignore if not lottie.
const char *ext = path + strlen(path) - 4; const char *ext = path + strlen(path) - 4;
if (strcmp(ext, "json")) return; if (strcmp(ext, "json") && strcmp(ext, "lot")) return;
//Animation Controller //Animation Controller
auto animation = tvg::Animation::gen(); auto animation = tvg::Animation::gen();

View file

@ -43,7 +43,7 @@ struct UserExample : tvgexam::Example
//ignore if not lottie. //ignore if not lottie.
const char *ext = path + strlen(path) - 4; const char *ext = path + strlen(path) - 4;
if (strcmp(ext, "json")) return; if (strcmp(ext, "json") && strcmp(ext, "lot")) return;
//Animation Controller //Animation Controller
auto animation = tvg::Animation::gen(); auto animation = tvg::Animation::gen();

View file

@ -1278,7 +1278,7 @@ public:
/** /**
* @class Picture * @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. * 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. * @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] 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] 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] 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. * @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. * @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 * After setting up the picture, it can be pushed to the designated canvas, enabling control over animation frames
* with this Animation instance. * with this Animation instance.
* *

View file

@ -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] 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] 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] 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] 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. * @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. * @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 * After setting up the picture, it can be pushed to the designated canvas, enabling control over animation frames
* with this Animation instance. * with this Animation instance.
* *

View file

@ -326,7 +326,7 @@ public:
string filetype = mimetype; string filetype = mimetype;
if (filetype == "json") { 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) { 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; 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"; errorMsg = "load() fail";
return false; return false;
} }

View file

@ -68,7 +68,7 @@ void LottieLoader::release()
/* External Class Implementation */ /* External Class Implementation */
/************************************************************************/ /************************************************************************/
LottieLoader::LottieLoader() : FrameModule(FileType::Lottie), builder(new LottieBuilder) LottieLoader::LottieLoader() : FrameModule(FileType::Lot), builder(new LottieBuilder)
{ {
} }

View file

@ -70,7 +70,7 @@ void operator delete(void* ptr) noexcept;
namespace tvg { 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; using Size = Point;

View file

@ -102,7 +102,7 @@ static LoadModule* _find(FileType type)
#endif #endif
break; break;
} }
case FileType::Lottie: { case FileType::Lot: {
#ifdef THORVG_LOTTIE_LOADER_SUPPORT #ifdef THORVG_LOTTIE_LOADER_SUPPORT
return new LottieLoader; return new LottieLoader;
#endif #endif
@ -128,8 +128,8 @@ static LoadModule* _find(FileType type)
format = "TTF"; format = "TTF";
break; break;
} }
case FileType::Lottie: { case FileType::Lot: {
format = "lottie(json)"; format = "LOT";
break; break;
} }
case FileType::Raw: { case FileType::Raw: {
@ -166,7 +166,7 @@ static LoadModule* _findByPath(const char* filename)
if (!ext) return nullptr; if (!ext) return nullptr;
if (!strcmp(ext, "svg")) return _find(FileType::Svg); 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, "png")) return _find(FileType::Png);
if (!strcmp(ext, "jpg")) return _find(FileType::Jpg); if (!strcmp(ext, "jpg")) return _find(FileType::Jpg);
if (!strcmp(ext, "webp")) return _find(FileType::Webp); 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; 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, "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, "raw")) type = FileType::Raw;
else if (!strcmp(mimeType, "png")) type = FileType::Png; else if (!strcmp(mimeType, "png")) type = FileType::Png;
else if (!strcmp(mimeType, "jpg") || !strcmp(mimeType, "jpeg")) type = FileType::Jpg; 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. //TODO: svg & lottie is not sharable.
auto allowCache = true; auto allowCache = true;
auto ext = strExtension(filename); 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 (allowCache) {
if (auto loader = _findFromCache(filename)) return loader; 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. //TODO: lottie is not sharable.
if (allowCache) { if (allowCache) {
auto type = _convert(mimeType); auto type = _convert(mimeType);
if (type == FileType::Lottie) allowCache = false; if (type == FileType::Lot) allowCache = false;
} }
if (allowCache) { if (allowCache) {