Added color shift support to GIFAnimComponent and LottieAnimComponent.

This commit is contained in:
Leon Styhre 2023-03-04 10:28:43 +01:00
parent bc0aee4445
commit 088cf3fd34
5 changed files with 74 additions and 9 deletions

View file

@ -361,6 +361,9 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"speed", FLOAT}, {"speed", FLOAT},
{"direction", STRING}, {"direction", STRING},
{"interpolation", STRING}, {"interpolation", STRING},
{"color", COLOR},
{"colorEnd", COLOR},
{"gradientType", STRING},
{"brightness", FLOAT}, {"brightness", FLOAT},
{"opacity", FLOAT}, {"opacity", FLOAT},
{"saturation", FLOAT}, {"saturation", FLOAT},

View file

@ -43,6 +43,9 @@ GIFAnimComponent::GIFAnimComponent()
, mExternalPause {false} , mExternalPause {false}
, mAlternate {false} , mAlternate {false}
, mTargetIsMax {false} , mTargetIsMax {false}
, mColorShift {0xFFFFFFFF}
, mColorShiftEnd {0xFFFFFFFF}
, mColorGradientHorizontal {true}
{ {
// Get an empty texture for rendering the animation. // Get an empty texture for rendering the animation.
mTexture = TextureResource::get(""); mTexture = TextureResource::get("");
@ -359,6 +362,30 @@ void GIFAnimComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
} }
} }
if (properties & COLOR) {
if (elem->has("color")) {
mColorShift = elem->get<unsigned int>("color");
mColorShiftEnd = mColorShift;
}
if (elem->has("colorEnd"))
mColorShiftEnd = elem->get<unsigned int>("colorEnd");
if (elem->has("gradientType")) {
const std::string& gradientType {elem->get<std::string>("gradientType")};
if (gradientType == "horizontal") {
mColorGradientHorizontal = true;
}
else if (gradientType == "vertical") {
mColorGradientHorizontal = false;
}
else {
mColorGradientHorizontal = true;
LOG(LogWarning) << "GIFAnimComponent: Invalid theme configuration, property "
"\"gradientType\" for element \""
<< element.substr(10) << "\" defined as \"" << gradientType << "\"";
}
}
}
if (elem->has("path")) if (elem->has("path"))
setAnimation(elem->get<std::string>("path")); setAnimation(elem->get<std::string>("path"));
} }
@ -512,10 +539,10 @@ void GIFAnimComponent::render(const glm::mat4& parentTrans)
Renderer::Vertex vertices[4]; Renderer::Vertex vertices[4];
// clang-format off // clang-format off
vertices[0] = {{0.0f, 0.0f }, {0.0f, 0.0f}, 0xFFFFFFFF}; vertices[0] = {{0.0f, 0.0f }, {0.0f, 0.0f}, mColorShift};
vertices[1] = {{0.0f, mSize.y}, {0.0f, 1.0f}, 0xFFFFFFFF}; vertices[1] = {{0.0f, mSize.y}, {0.0f, 1.0f}, mColorGradientHorizontal ? mColorShift : mColorShiftEnd};
vertices[2] = {{mSize.x, 0.0f }, {1.0f, 0.0f}, 0xFFFFFFFF}; vertices[2] = {{mSize.x, 0.0f }, {1.0f, 0.0f}, mColorGradientHorizontal ? mColorShiftEnd : mColorShift};
vertices[3] = {{mSize.x, mSize.y}, {1.0f, 1.0f}, 0xFFFFFFFF}; vertices[3] = {{mSize.x, mSize.y}, {1.0f, 1.0f}, mColorShiftEnd};
// clang-format on // clang-format on
// Round vertices. // Round vertices.

View file

@ -101,6 +101,10 @@ private:
bool mExternalPause; bool mExternalPause;
bool mAlternate; bool mAlternate;
bool mTargetIsMax; bool mTargetIsMax;
unsigned int mColorShift;
unsigned int mColorShiftEnd;
bool mColorGradientHorizontal;
}; };
#endif // ES_CORE_COMPONENTS_GIF_ANIM_COMPONENT_H #endif // ES_CORE_COMPONENTS_GIF_ANIM_COMPONENT_H

View file

@ -38,6 +38,9 @@ LottieAnimComponent::LottieAnimComponent()
, mExternalPause {false} , mExternalPause {false}
, mAlternate {false} , mAlternate {false}
, mTargetIsMax {false} , mTargetIsMax {false}
, mColorShift {0xFFFFFFFF}
, mColorShiftEnd {0xFFFFFFFF}
, mColorGradientHorizontal {true}
{ {
// Get an empty texture for rendering the animation. // Get an empty texture for rendering the animation.
mTexture = TextureResource::get(""); mTexture = TextureResource::get("");
@ -313,6 +316,30 @@ void LottieAnimComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
} }
} }
if (properties & COLOR) {
if (elem->has("color")) {
mColorShift = elem->get<unsigned int>("color");
mColorShiftEnd = mColorShift;
}
if (elem->has("colorEnd"))
mColorShiftEnd = elem->get<unsigned int>("colorEnd");
if (elem->has("gradientType")) {
const std::string& gradientType {elem->get<std::string>("gradientType")};
if (gradientType == "horizontal") {
mColorGradientHorizontal = true;
}
else if (gradientType == "vertical") {
mColorGradientHorizontal = false;
}
else {
mColorGradientHorizontal = true;
LOG(LogWarning) << "LottieAnimComponent: Invalid theme configuration, property "
"\"gradientType\" for element \""
<< element.substr(10) << "\" defined as \"" << gradientType << "\"";
}
}
}
if (elem->has("path")) if (elem->has("path"))
setAnimation(elem->get<std::string>("path")); setAnimation(elem->get<std::string>("path"));
} }
@ -503,10 +530,10 @@ void LottieAnimComponent::render(const glm::mat4& parentTrans)
Renderer::Vertex vertices[4]; Renderer::Vertex vertices[4];
// clang-format off // clang-format off
vertices[0] = {{0.0f, 0.0f }, {0.0f, 0.0f}, 0xFFFFFFFF}; vertices[0] = {{0.0f, 0.0f }, {0.0f, 0.0f}, mColorShift};
vertices[1] = {{0.0f, mSize.y}, {0.0f, 1.0f}, 0xFFFFFFFF}; vertices[1] = {{0.0f, mSize.y}, {0.0f, 1.0f}, mColorGradientHorizontal ? mColorShift : mColorShiftEnd};
vertices[2] = {{mSize.x, 0.0f }, {1.0f, 0.0f}, 0xFFFFFFFF}; vertices[2] = {{mSize.x, 0.0f }, {1.0f, 0.0f}, mColorGradientHorizontal ? mColorShiftEnd : mColorShift};
vertices[3] = {{mSize.x, mSize.y}, {1.0f, 1.0f}, 0xFFFFFFFF}; vertices[3] = {{mSize.x, mSize.y}, {1.0f, 1.0f}, mColorShiftEnd};
// clang-format on // clang-format on
// Round vertices. // Round vertices.

View file

@ -58,7 +58,7 @@ private:
std::vector<uint8_t> mPictureRGBA; std::vector<uint8_t> mPictureRGBA;
std::unordered_map<size_t, std::vector<uint8_t>> mFrameCache; std::unordered_map<size_t, std::vector<uint8_t>> mFrameCache;
// Set a 1024 MiB total Lottie animation cache as default. // Set a 1024 MiB total Lottie animation cache as default.
static inline size_t mMaxTotalFrameCache = 1024 * 1024 * 1024; static inline size_t mMaxTotalFrameCache {1024 * 1024 * 1024};
static inline size_t mTotalFrameCache; static inline size_t mTotalFrameCache;
bool mCacheFrames; bool mCacheFrames;
size_t mMaxCacheSize; size_t mMaxCacheSize;
@ -87,6 +87,10 @@ private:
bool mExternalPause; bool mExternalPause;
bool mAlternate; bool mAlternate;
bool mTargetIsMax; bool mTargetIsMax;
unsigned int mColorShift;
unsigned int mColorShiftEnd;
bool mColorGradientHorizontal;
}; };
#endif // ES_CORE_COMPONENTS_LOTTIE_ANIM_COMPONENT_H #endif // ES_CORE_COMPONENTS_LOTTIE_ANIM_COMPONENT_H