diff --git a/dom/src/dom/animation/cubic_bezier_animation.cc b/dom/src/dom/animation/cubic_bezier_animation.cc index df33f510f2b..89b1c61f511 100644 --- a/dom/src/dom/animation/cubic_bezier_animation.cc +++ b/dom/src/dom/animation/cubic_bezier_animation.cc @@ -51,22 +51,32 @@ CubicBezier CubicBezierAnimation::ParseCubicBezierStr(const std::string& str) { double CubicBezierAnimation::CalculateColor(double start_color, double to_color, double scale) { auto start_value = static_cast(start_color); - auto start_red = static_cast(((start_value >> 24) & 0xff)); - auto start_green = static_cast(((start_value >> 16) & 0xff)); - auto start_blue = static_cast(((start_value >> 8) & 0xff)); - auto start_alpha = static_cast((start_value & 0xff)); - + if (start_color < 0) { + auto start_int_value = static_cast(start_color); + start_value = static_cast(start_int_value); + } + + auto start_alpha = ((start_value >> 24) & 0xff); + auto start_red = ((start_value >> 16) & 0xff); + auto start_green = ((start_value >> 8) & 0xff); + auto start_blue = (start_value & 0xff); + auto to_value = static_cast(to_color); - auto to_red = static_cast(((to_value >> 24) & 0xff)); - auto to_green = static_cast(((to_value >> 16) & 0xff)); - auto to_blue = static_cast(((to_value >> 8) & 0xff)); - auto to_alpha = static_cast((to_value & 0xff)); - - auto red = static_cast(start_red + (to_red - start_red) * scale); - auto green = static_cast(start_green + (to_green - start_green) * scale); - auto blue = static_cast(start_blue + (to_blue - start_blue) * scale); - auto alpha = static_cast(start_alpha + (to_alpha - start_alpha) * scale); - auto ret = (static_cast(red) << 24) + (static_cast(green) << 16) + (static_cast(blue) << 8) + alpha; + if (to_color < 0) { + auto to_int_value = static_cast(to_color); + to_value = static_cast(to_int_value); + } + + auto to_alpha = ((to_value >> 24) & 0xff); + auto to_red = ((to_value >> 16) & 0xff); + auto to_green = ((to_value >> 8) & 0xff); + auto to_blue = (to_value & 0xff); + + auto red = static_cast(start_red + static_cast(to_red - start_red) * scale); + auto green = static_cast(start_green + static_cast(to_green - start_green) * scale); + auto blue = static_cast(start_blue + static_cast(to_blue - start_blue) * scale); + auto alpha = static_cast(start_alpha + static_cast(to_alpha - start_alpha) * scale); + auto ret = (static_cast(alpha) << 24) + (static_cast(red) << 16) + (static_cast(green) << 8) + static_cast(blue); return static_cast(ret); } diff --git a/framework/ohos/src/main/cpp/impl/renderer/native/include/renderer/utils/hr_value_utils.h b/framework/ohos/src/main/cpp/impl/renderer/native/include/renderer/utils/hr_value_utils.h index 5d6501750eb..2cf5cc0093d 100644 --- a/framework/ohos/src/main/cpp/impl/renderer/native/include/renderer/utils/hr_value_utils.h +++ b/framework/ohos/src/main/cpp/impl/renderer/native/include/renderer/utils/hr_value_utils.h @@ -47,7 +47,12 @@ class HRValueUtils { } else if (value.IsDouble()) { double doubleValue = 0; value.ToDouble(doubleValue); - return static_cast(doubleValue); + if (doubleValue < 0) { + int32_t intValue = static_cast(doubleValue); + return static_cast(intValue); + } else { + return static_cast(doubleValue); + } } return 0; }