diff --git a/inc/rlottie_capi.h b/inc/rlottie_capi.h index 653c86d..d402c23 100644 --- a/inc/rlottie_capi.h +++ b/inc/rlottie_capi.h @@ -72,6 +72,22 @@ LOT_EXPORT Lottie_Animation *lottie_animation_from_file(const char *path); */ LOT_EXPORT Lottie_Animation *lottie_animation_from_data(const char *data, const char *key, const char *resource_path); +/** + * @brief Constructs an animation object from JSON string data and recolors it to correct skin color. + * + * @param[in] data The JSON string data. + * @param[in] key the string that will be used to cache the JSON string data. + * @param[in] resource_path the path that will be used to load external resource needed by the JSON data. + * @param[in] fitzpatrick_type emoji modifier fitzpatrick type; 0-6; 0 if none + * + * @return Animation object that can build the contents of the + * Lottie resource represented by JSON string data. + * + * @ingroup Lottie_Animation + * @internal + */ +LOT_EXPORT Lottie_Animation *lottie_animation_from_data_recolored(const char *data, const char *key, const char *resource_path, const int32_t fitzpatrick_type); + /** * @brief Free given Animation object resource. * diff --git a/src/binding/c/lottieanimation_capi.cpp b/src/binding/c/lottieanimation_capi.cpp index 7793607..4bb63ba 100644 --- a/src/binding/c/lottieanimation_capi.cpp +++ b/src/binding/c/lottieanimation_capi.cpp @@ -55,6 +55,16 @@ LOT_EXPORT Lottie_Animation_S *lottie_animation_from_data(const char *data, cons } } +LOT_EXPORT Lottie_Animation* lottie_animation_from_data_recolored(const char* data, const char* key, const char* resourcePath, const int32_t fitzpatrickType) { + if (auto animation = Animation::loadFromData(data, key, resourcePath, true, {}, rlottie::FitzModifier(fitzpatrickType))) { + Lottie_Animation_S* handle = new Lottie_Animation_S(); + handle->mAnimation = std::move(animation); + return handle; + } else { + return nullptr; + } +} + LOT_EXPORT void lottie_animation_destroy(Lottie_Animation_S *animation) { if (animation) { diff --git a/src/lottie/lottiemodel.cpp b/src/lottie/lottiemodel.cpp index bf0e357..e0fe123 100644 --- a/src/lottie/lottiemodel.cpp +++ b/src/lottie/lottiemodel.cpp @@ -188,11 +188,11 @@ void LOTGradient::populate(VGradientStops &stops, int frameNo) return; } int colorPoints = mColorPoints; - if (colorPoints < 0 || colorPoints > size / 4) { // for legacy bodymovin (ref: lottie-android) + if (colorPoints < 0 || size_t(colorPoints) > size / 4) { // for legacy bodymovin (ref: lottie-android) colorPoints = int(size / 4); } auto opacityArraySize = size - colorPoints * 4; - if ((opacityArraySize % 2 != 0) || (colorPoints > opacityArraySize / 2 && opacityArraySize < 4)) { + if ((opacityArraySize % 2 != 0) || (size_t(colorPoints) > opacityArraySize / 2 && opacityArraySize < 4)) { opacityArraySize = 0; } float *opacityPtr = ptr + (colorPoints * 4);