From 251388216e996571bd50c534ef1a494fb0cf1440 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Mon, 21 Jul 2025 17:46:46 +0900 Subject: [PATCH] lottie: code cleanup++ just renamed internal variable. --- src/loaders/lottie/tvgLottieBuilder.cpp | 28 ++++++++++----------- src/loaders/lottie/tvgLottieData.h | 20 +++++++-------- src/loaders/lottie/tvgLottieExpressions.cpp | 18 ++++++------- src/loaders/lottie/tvgLottieExpressions.h | 6 ++--- src/loaders/lottie/tvgLottieModel.cpp | 4 +-- src/loaders/lottie/tvgLottieModel.h | 22 ++++++++-------- src/loaders/lottie/tvgLottieParser.cpp | 20 +++++++-------- src/loaders/lottie/tvgLottieParser.h | 4 +-- src/loaders/lottie/tvgLottieProperty.h | 2 +- 9 files changed, 61 insertions(+), 63 deletions(-) diff --git a/src/loaders/lottie/tvgLottieBuilder.cpp b/src/loaders/lottie/tvgLottieBuilder.cpp index e9b775e2..a108b429 100644 --- a/src/loaders/lottie/tvgLottieBuilder.cpp +++ b/src/loaders/lottie/tvgLottieBuilder.cpp @@ -260,7 +260,7 @@ bool LottieBuilder::updateSolidStroke(LottieGroup* parent, LottieObject** child, ctx->merging = nullptr; auto color = stroke->color(frameNo, tween, exps); - ctx->propagator->strokeFill(color.rgb[0], color.rgb[1], color.rgb[2], opacity); + ctx->propagator->strokeFill(color.r, color.g, color.b, opacity); _updateStroke(static_cast(stroke), frameNo, ctx, tween, exps); return false; @@ -296,7 +296,7 @@ bool LottieBuilder::updateSolidFill(LottieGroup* parent, LottieObject** child, f ctx->merging = nullptr; auto color = fill->color(frameNo, tween, exps); - ctx->propagator->fill(color.rgb[0], color.rgb[1], color.rgb[2], opacity); + ctx->propagator->fill(color.r, color.g, color.b, opacity); ctx->propagator->fillRule(fill->rule); if (ctx->propagator->strokeWidth() > 0) ctx->propagator->order(true); @@ -916,7 +916,7 @@ static void _fontText(TextDocument& doc, Scene* scene) } txt->text(token); - txt->fill(doc.color.rgb[0], doc.color.rgb[1], doc.color.rgb[2]); + txt->fill(doc.color.r, doc.color.g, doc.color.b); float width; txt->bounds(nullptr, nullptr, &width, nullptr); @@ -1044,14 +1044,14 @@ void LottieBuilder::updateText(LottieLayer* layer, float frameNo) } } } - shape->fill(doc.color.rgb[0], doc.color.rgb[1], doc.color.rgb[2]); + shape->fill(doc.color.r, doc.color.g, doc.color.b); shape->translate(cursor.x - textGroupMatrix.e13, cursor.y - textGroupMatrix.e23); shape->opacity(255); if (doc.stroke.width > 0.0f) { shape->strokeJoin(StrokeJoin::Round); shape->strokeWidth(doc.stroke.width / scale); - shape->strokeFill(doc.stroke.color.rgb[0], doc.stroke.color.rgb[1], doc.stroke.color.rgb[2]); + shape->strokeFill(doc.stroke.color.r, doc.stroke.color.g, doc.stroke.color.b); shape->order(doc.stroke.below); } @@ -1088,12 +1088,12 @@ void LottieBuilder::updateText(LottieLayer* layer, float frameNo) range->color(frameNo, color, strokeColor, f, tween, exps); fillOpacity = (uint8_t)(fillOpacity - f * (fillOpacity - range->style.fillOpacity(frameNo, tween, exps))); - shape->fill(color.rgb[0], color.rgb[1], color.rgb[2], fillOpacity); + shape->fill(color.r, color.g, color.b, fillOpacity); if (range->style.flags.strokeWidth) shape->strokeWidth(f * range->style.strokeWidth(frameNo, tween, exps) / scale); if (shape->strokeWidth() > 0.0f) { strokeOpacity = (uint8_t)(strokeOpacity - f * (strokeOpacity - range->style.strokeOpacity(frameNo, tween, exps))); - shape->strokeFill(strokeColor.rgb[0], strokeColor.rgb[1], strokeColor.rgb[2], strokeOpacity); + shape->strokeFill(strokeColor.r, strokeColor.g, strokeColor.b, strokeOpacity); shape->order(doc.stroke.below); } cursor.x += f * range->style.letterSpacing(frameNo, tween, exps); @@ -1287,7 +1287,7 @@ void LottieBuilder::updateStrokeEffect(LottieLayer* layer, LottieFxStroke* effec //fill the color to the layer shapes if any auto color = effect->color(frameNo); - if (color.rgb[0] != 255 || color.rgb[1] != 255 || color.rgb[2] != 255) { + if (color.r != 255 || color.g != 255 || color.b != 255) { auto accessor = tvg::Accessor::gen(); auto stroke = (layer->type == LottieLayer::Type::Shape) ? true : false; auto f = [color, size, stroke](const tvg::Paint* paint, void* data) -> bool { @@ -1296,9 +1296,9 @@ void LottieBuilder::updateStrokeEffect(LottieLayer* layer, LottieFxStroke* effec //expand shape to fill the stroke region if (stroke) { shape->strokeWidth(size); - shape->strokeFill(color.rgb[0], color.rgb[1], color.rgb[2], 255); + shape->strokeFill(color.r, color.g, color.b, 255); } - shape->fill(color.rgb[0], color.rgb[1], color.rgb[2], 255); + shape->fill(color.r, color.g, color.b, 255); } return true; }; @@ -1324,13 +1324,13 @@ void LottieBuilder::updateEffect(LottieLayer* layer, float frameNo) auto effect = static_cast(*p); auto black = effect->black(frameNo); auto white = effect->white(frameNo); - layer->scene->push(SceneEffect::Tint, black.rgb[0], black.rgb[1], black.rgb[2], white.rgb[0], white.rgb[1], white.rgb[2], (double)effect->intensity(frameNo)); + layer->scene->push(SceneEffect::Tint, black.r, black.g, black.b, white.r, white.g, white.b, (double)effect->intensity(frameNo)); break; } case LottieEffect::Fill: { auto effect = static_cast(*p); auto color = effect->color(frameNo); - layer->scene->push(SceneEffect::Fill, color.rgb[0], color.rgb[1], color.rgb[2], (int)(255.0f * effect->opacity(frameNo))); + layer->scene->push(SceneEffect::Fill, color.r, color.g, color.b, (int)(255.0f * effect->opacity(frameNo))); break; } case LottieEffect::Stroke: { @@ -1343,14 +1343,14 @@ void LottieBuilder::updateEffect(LottieLayer* layer, float frameNo) auto dark = effect->dark(frameNo); auto midtone = effect->midtone(frameNo); auto bright = effect->bright(frameNo); - layer->scene->push(SceneEffect::Tritone, dark.rgb[0], dark.rgb[1], dark.rgb[2], midtone.rgb[0], midtone.rgb[1], midtone.rgb[2], bright.rgb[0], bright.rgb[1], bright.rgb[2], (int)effect->blend(frameNo)); + layer->scene->push(SceneEffect::Tritone, dark.r, dark.g, dark.b, midtone.r, midtone.g, midtone.b, bright.r, bright.g, bright.b, (int)effect->blend(frameNo)); break; } case LottieEffect::DropShadow: { auto effect = static_cast(*p); auto color = effect->color(frameNo); //seems the opacity range in dropshadow is 0 ~ 256 - layer->scene->push(SceneEffect::DropShadow, color.rgb[0], color.rgb[1], color.rgb[2], std::min(255, (int)effect->opacity(frameNo)), (double)effect->angle(frameNo), double(effect->distance(frameNo) * 0.5f), (double)(effect->blurness(frameNo) * BLUR_TO_SIGMA), QUALITY); + layer->scene->push(SceneEffect::DropShadow, color.r, color.g, color.b, std::min(255, (int)effect->opacity(frameNo)), (double)effect->angle(frameNo), double(effect->distance(frameNo) * 0.5f), (double)(effect->blurness(frameNo) * BLUR_TO_SIGMA), QUALITY); break; } case LottieEffect::GaussianBlur: { diff --git a/src/loaders/lottie/tvgLottieData.h b/src/loaders/lottie/tvgLottieData.h index c9438a9b..cfe4b331 100644 --- a/src/loaders/lottie/tvgLottieData.h +++ b/src/loaders/lottie/tvgLottieData.h @@ -36,9 +36,9 @@ struct PathSet }; -struct RGB24 +struct RGB32 { - int32_t rgb[3]; + int32_t r, g, b; }; @@ -54,13 +54,13 @@ struct TextDocument char* text = nullptr; float height; float shift; - RGB24 color; + RGB32 color; struct { Point pos; Point size; } bbox; struct { - RGB24 color; + RGB32 color; float width; bool below = false; } stroke; @@ -86,21 +86,21 @@ static inline int32_t REMAP255(float val) } -static inline RGB24 operator-(const RGB24& lhs, const RGB24& rhs) +static inline RGB32 operator-(const RGB32& lhs, const RGB32& rhs) { - return {lhs.rgb[0] - rhs.rgb[0], lhs.rgb[1] - rhs.rgb[1], lhs.rgb[2] - rhs.rgb[2]}; + return {lhs.r - rhs.r, lhs.g - rhs.g, lhs.b - rhs.b}; } -static inline RGB24 operator+(const RGB24& lhs, const RGB24& rhs) +static inline RGB32 operator+(const RGB32& lhs, const RGB32& rhs) { - return {lhs.rgb[0] + rhs.rgb[0], lhs.rgb[1] + rhs.rgb[1], lhs.rgb[2] + rhs.rgb[2]}; + return {lhs.r + rhs.r, lhs.g + rhs.g, lhs.b + rhs.b}; } -static inline RGB24 operator*(const RGB24& lhs, float rhs) +static inline RGB32 operator*(const RGB32& lhs, float rhs) { - return {(int32_t)nearbyintf(lhs.rgb[0] * rhs), (int32_t)nearbyintf(lhs.rgb[1] * rhs), (int32_t)nearbyintf(lhs.rgb[2] * rhs)}; + return {(int32_t)nearbyintf(lhs.r * rhs), (int32_t)nearbyintf(lhs.g * rhs), (int32_t)nearbyintf(lhs.b * rhs)}; } diff --git a/src/loaders/lottie/tvgLottieExpressions.cpp b/src/loaders/lottie/tvgLottieExpressions.cpp index 9f907da2..9fdb96e1 100644 --- a/src/loaders/lottie/tvgLottieExpressions.cpp +++ b/src/loaders/lottie/tvgLottieExpressions.cpp @@ -99,12 +99,12 @@ static jerry_value_t _point2d(const Point& pt) } -static jerry_value_t _color(RGB24 rgb) +static jerry_value_t _color(RGB32 rgb) { auto value = jerry_object(); - auto r = jerry_number((float)rgb.rgb[0]); - auto g = jerry_number((float)rgb.rgb[1]); - auto b = jerry_number((float)rgb.rgb[2]); + auto r = jerry_number((float)rgb.r); + auto g = jerry_number((float)rgb.g); + auto b = jerry_number((float)rgb.b); jerry_object_set_index(value, 0, r); jerry_object_set_index(value, 1, g); jerry_object_set_index(value, 2, b); @@ -125,15 +125,13 @@ static Point _point2d(jerry_value_t obj) return pt; } -static RGB24 _color(jerry_value_t obj) +static RGB32 _color(jerry_value_t obj) { - RGB24 out; + RGB32 out; auto r = jerry_object_get_index(obj, 0); auto g = jerry_object_get_index(obj, 1); auto b = jerry_object_get_index(obj, 2); - out.rgb[0] = jerry_value_as_int32(r); - out.rgb[1] = jerry_value_as_int32(g); - out.rgb[2] = jerry_value_as_int32(b); + out = {jerry_value_as_int32(r), jerry_value_as_int32(g), jerry_value_as_int32(b)}; jerry_value_free(r); jerry_value_free(g); jerry_value_free(b); @@ -1486,7 +1484,7 @@ Point LottieExpressions::toPoint2d(jerry_value_t obj) } -RGB24 LottieExpressions::toColor(jerry_value_t obj) +RGB32 LottieExpressions::toColor(jerry_value_t obj) { return _color(obj); } diff --git a/src/loaders/lottie/tvgLottieExpressions.h b/src/loaders/lottie/tvgLottieExpressions.h index e701ba25..828f23ac 100644 --- a/src/loaders/lottie/tvgLottieExpressions.h +++ b/src/loaders/lottie/tvgLottieExpressions.h @@ -70,7 +70,7 @@ public: } template - bool result(float frameNo, RGB24& out, LottieExpression* exp) + bool result(float frameNo, RGB32& out, LottieExpression* exp) { auto bm_rt = evaluate(frameNo, exp); if (jerry_value_is_undefined(bm_rt)) return false; @@ -144,7 +144,7 @@ private: void buildWritables(LottieExpression* exp); Point toPoint2d(jerry_value_t obj); - RGB24 toColor(jerry_value_t obj); + RGB32 toColor(jerry_value_t obj); //global object, attributes, methods jerry_value_t global; @@ -160,7 +160,7 @@ struct LottieExpressions { template bool result(TVG_UNUSED float, TVG_UNUSED NumType&, TVG_UNUSED LottieExpression*) { return false; } template bool result(TVG_UNUSED float, TVG_UNUSED Point&, LottieExpression*) { return false; } - template bool result(TVG_UNUSED float, TVG_UNUSED RGB24&, TVG_UNUSED LottieExpression*) { return false; } + template bool result(TVG_UNUSED float, TVG_UNUSED RGB32&, TVG_UNUSED LottieExpression*) { return false; } template bool result(TVG_UNUSED float, TVG_UNUSED Fill*, TVG_UNUSED LottieExpression*) { return false; } template bool result(TVG_UNUSED float, TVG_UNUSED RenderPath&, TVG_UNUSED Matrix*, TVG_UNUSED LottieModifier*, TVG_UNUSED LottieExpression*) { return false; } bool result(TVG_UNUSED float, TVG_UNUSED TextDocument& doc, TVG_UNUSED LottieExpression*) { return false; } diff --git a/src/loaders/lottie/tvgLottieModel.cpp b/src/loaders/lottie/tvgLottieModel.cpp index ea380631..045c7376 100644 --- a/src/loaders/lottie/tvgLottieModel.cpp +++ b/src/loaders/lottie/tvgLottieModel.cpp @@ -660,7 +660,7 @@ LottieProperty* LottieLayer::property(uint16_t ix) } -void LottieLayer::prepare(RGB24* color) +void LottieLayer::prepare(RGB32* color) { /* if layer is hidden, only useful data is its transform matrix. so force it to be a Null Layer and release all resource. */ @@ -681,7 +681,7 @@ void LottieLayer::prepare(RGB24* color) } else if (color && type == LottieLayer::Solid) { auto solidFill = Shape::gen(); solidFill->appendRect(0, 0, static_cast(w), static_cast(h)); - solidFill->fill(color->rgb[0], color->rgb[1], color->rgb[2]); + solidFill->fill(color->r, color->g, color->b); solidFill->ref(); statical.pooler.push(solidFill); } diff --git a/src/loaders/lottie/tvgLottieModel.h b/src/loaders/lottie/tvgLottieModel.h index 8a7b4fe4..2129b7c0 100644 --- a/src/loaders/lottie/tvgLottieModel.h +++ b/src/loaders/lottie/tvgLottieModel.h @@ -333,8 +333,8 @@ struct LottieTextRange } struct { - LottieColor fillColor = RGB24{255, 255, 255}; - LottieColor strokeColor = RGB24{255, 255, 255}; + LottieColor fillColor = RGB32{255, 255, 255}; + LottieColor strokeColor = RGB32{255, 255, 255}; LottieVector position = Point{0, 0}; LottieScalar scale = Point{100, 100}; LottieFloat letterSpacing = 0.0f; @@ -367,19 +367,19 @@ struct LottieTextRange float factor(float frameNo, float totalLen, float idx); - void color(float frameNo, RGB24& fillColor, RGB24& strokeColor, float factor, Tween& tween, LottieExpressions* exps) + void color(float frameNo, RGB32& fillColor, RGB32& strokeColor, float factor, Tween& tween, LottieExpressions* exps) { if (style.flags.fillColor) { auto color = style.fillColor(frameNo, tween, exps); - fillColor.rgb[0] = tvg::lerp(fillColor.rgb[0], color.rgb[0], factor); - fillColor.rgb[1] = tvg::lerp(fillColor.rgb[1], color.rgb[1], factor); - fillColor.rgb[2] = tvg::lerp(fillColor.rgb[2], color.rgb[2], factor); + fillColor.r = tvg::lerp(fillColor.r, color.r, factor); + fillColor.g = tvg::lerp(fillColor.g, color.g, factor); + fillColor.b = tvg::lerp(fillColor.b, color.b, factor); } if (style.flags.strokeColor) { auto color = style.strokeColor(frameNo, tween, exps); - strokeColor.rgb[0] = tvg::lerp(strokeColor.rgb[0], color.rgb[0], factor); - strokeColor.rgb[1] = tvg::lerp(strokeColor.rgb[1], color.rgb[1], factor); - strokeColor.rgb[2] = tvg::lerp(strokeColor.rgb[2], color.rgb[2], factor); + strokeColor.r = tvg::lerp(strokeColor.r, color.r, factor); + strokeColor.g = tvg::lerp(strokeColor.g, color.g, factor); + strokeColor.b = tvg::lerp(strokeColor.b, color.b, factor); } } }; @@ -726,7 +726,7 @@ struct LottieTransform : LottieObject struct LottieSolid : LottieObject { - LottieColor color = RGB24{255, 255, 255}; + LottieColor color = RGB32{255, 255, 255}; LottieOpacity opacity = 255; LottieProperty* property(uint16_t ix) override @@ -975,7 +975,7 @@ struct LottieLayer : LottieGroup ~LottieLayer(); bool mergeable() override { return false; } - void prepare(RGB24* color = nullptr); + void prepare(RGB32* color = nullptr); float remap(LottieComposition* comp, float frameNo, LottieExpressions* exp); LottieProperty* property(uint16_t ix) override; bool assign(const char* layer, uint32_t ix, const char* var, float val); diff --git a/src/loaders/lottie/tvgLottieParser.cpp b/src/loaders/lottie/tvgLottieParser.cpp index 5b3812ae..c34e0140 100644 --- a/src/loaders/lottie/tvgLottieParser.cpp +++ b/src/loaders/lottie/tvgLottieParser.cpp @@ -92,9 +92,9 @@ MaskMethod LottieParser::getMaskMethod(bool inversed) } -RGB24 LottieParser::getColor(const char *str) +RGB32 LottieParser::getColor(const char *str) { - RGB24 color = {0, 0, 0}; + RGB32 color = {0, 0, 0}; if (!str) return color; @@ -106,15 +106,15 @@ RGB24 LottieParser::getColor(const char *str) char tmp[3] = {'\0', '\0', '\0'}; tmp[0] = str[1]; tmp[1] = str[2]; - color.rgb[0] = uint8_t(strtol(tmp, nullptr, 16)); + color.r = uint8_t(strtol(tmp, nullptr, 16)); tmp[0] = str[3]; tmp[1] = str[4]; - color.rgb[1] = uint8_t(strtol(tmp, nullptr, 16)); + color.g = uint8_t(strtol(tmp, nullptr, 16)); tmp[0] = str[5]; tmp[1] = str[6]; - color.rgb[2] = uint8_t(strtol(tmp, nullptr, 16)); + color.b = uint8_t(strtol(tmp, nullptr, 16)); return color; } @@ -305,16 +305,16 @@ bool LottieParser::getValue(Point& pt) } -bool LottieParser::getValue(RGB24& color) +bool LottieParser::getValue(RGB32& color) { if (peekType() == kArrayType) { enterArray(); if (!nextArrayValue()) return false; } - color.rgb[0] = REMAP255(getFloat()); - color.rgb[1] = REMAP255(getFloat()); - color.rgb[2] = REMAP255(getFloat()); + color.r = REMAP255(getFloat()); + color.g = REMAP255(getFloat()); + color.b = REMAP255(getFloat()); while (nextArrayValue()) getFloat(); //drop @@ -1442,7 +1442,7 @@ LottieLayer* LottieParser::parseLayer(LottieLayer* precomp) context.layer = layer; auto ddd = false; - RGB24 color; + RGB32 color; enterObject(); diff --git a/src/loaders/lottie/tvgLottieParser.h b/src/loaders/lottie/tvgLottieParser.h index 66a96290..f95b5fa7 100644 --- a/src/loaders/lottie/tvgLottieParser.h +++ b/src/loaders/lottie/tvgLottieParser.h @@ -48,7 +48,7 @@ public: bool expressions = false; //support expressions? private: - RGB24 getColor(const char *str); + RGB32 getColor(const char *str); FillRule getFillRule(); MaskMethod getMaskMethod(bool inversed); LottieInterpolator* getInterpolator(const char* key, Point& in, Point& out); @@ -65,7 +65,7 @@ private: bool getValue(float& val); bool getValue(uint8_t& val); bool getValue(int8_t& val); - bool getValue(RGB24& color); + bool getValue(RGB32& color); bool getValue(Point& pt); template bool parseTangent(const char *key, LottieVectorFrame& value); diff --git a/src/loaders/lottie/tvgLottieProperty.h b/src/loaders/lottie/tvgLottieProperty.h index e0778265..c5df0eda 100644 --- a/src/loaders/lottie/tvgLottieProperty.h +++ b/src/loaders/lottie/tvgLottieProperty.h @@ -1006,7 +1006,7 @@ using LottieFloat = LottieGenericProperty, float, Lotti using LottieInteger = LottieGenericProperty, int8_t, LottieProperty::Type::Integer>; using LottieScalar = LottieGenericProperty, Point, LottieProperty::Type::Scalar>; using LottieVector = LottieGenericProperty, Point, LottieProperty::Type::Vector, 0>; -using LottieColor = LottieGenericProperty, RGB24, LottieProperty::Type::Color>; +using LottieColor = LottieGenericProperty, RGB32, LottieProperty::Type::Color>; using LottieOpacity = LottieGenericProperty, uint8_t, LottieProperty::Type::Opacity>; #endif //_TVG_LOTTIE_PROPERTY_H_