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
This commit is contained in:
Patrik Tomas Chamelo 2020-07-27 23:38:37 -07:00 коммит произвёл Facebook GitHub Bot
Родитель 7ccb67a49c
Коммит 1b362f9f76
1 изменённых файлов: 3 добавлений и 3 удалений

Просмотреть файл

@ -26,7 +26,7 @@ inline void fromRawValue(const RawValue &value, SharedColor &result) {
if (value.hasType<int>()) {
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<std::string>(round(components.red * ratio)) +
", " + folly::to<std::string>(round(components.green * ratio)) + ", " +
folly::to<std::string>(round(components.blue * ratio)) + ", " +