From 1b362f9f7697e764acb1e8ec953fe0563742f2bd Mon Sep 17 00:00:00 2001 From: Patrik Tomas Chamelo Date: Mon, 27 Jul 2020 23:38:37 -0700 Subject: [PATCH] Fix ratio for color conversion Summary: As part of our usage color detection that relies on precise values of colors, it appears that the ration used was 256, but RBGA scale is 0-255 Reviewed By: shergin Differential Revision: D22785378 fbshipit-source-id: 87a6f9b4611ceaadbbbb75a4566f4cf9b8285b68 --- ReactCommon/fabric/graphics/conversions.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ReactCommon/fabric/graphics/conversions.h b/ReactCommon/fabric/graphics/conversions.h index 4806feec89..2cf7968279 100644 --- a/ReactCommon/fabric/graphics/conversions.h +++ b/ReactCommon/fabric/graphics/conversions.h @@ -26,7 +26,7 @@ inline void fromRawValue(const RawValue &value, SharedColor &result) { if (value.hasType()) { auto argb = (int64_t)value; - auto ratio = 256.f; + auto ratio = 255.f; alpha = ((argb >> 24) & 0xFF) / ratio; red = ((argb >> 16) & 0xFF) / ratio; green = ((argb >> 8) & 0xFF) / ratio; @@ -49,7 +49,7 @@ inline void fromRawValue(const RawValue &value, SharedColor &result) { inline folly::dynamic toDynamic(const SharedColor &color) { ColorComponents components = colorComponentsFromColor(color); - auto ratio = 256.f; + auto ratio = 255.f; return ( ((int)(components.alpha * ratio) & 0xff) << 24 | ((int)(components.red * ratio) & 0xff) << 16 | @@ -61,7 +61,7 @@ inline folly::dynamic toDynamic(const SharedColor &color) { inline std::string toString(const SharedColor &value) { ColorComponents components = colorComponentsFromColor(value); - auto ratio = 256.f; + auto ratio = 255.f; return "rgba(" + folly::to(round(components.red * ratio)) + ", " + folly::to(round(components.green * ratio)) + ", " + folly::to(round(components.blue * ratio)) + ", " +