Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions inc/rlottie_capi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
10 changes: 10 additions & 0 deletions src/binding/c/lottieanimation_capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/lottie/lottiemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down