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:
Родитель
7ccb67a49c
Коммит
1b362f9f76
|
@ -26,7 +26,7 @@ inline void fromRawValue(const RawValue &value, SharedColor &result) {
|
||||||
|
|
||||||
if (value.hasType<int>()) {
|
if (value.hasType<int>()) {
|
||||||
auto argb = (int64_t)value;
|
auto argb = (int64_t)value;
|
||||||
auto ratio = 256.f;
|
auto ratio = 255.f;
|
||||||
alpha = ((argb >> 24) & 0xFF) / ratio;
|
alpha = ((argb >> 24) & 0xFF) / ratio;
|
||||||
red = ((argb >> 16) & 0xFF) / ratio;
|
red = ((argb >> 16) & 0xFF) / ratio;
|
||||||
green = ((argb >> 8) & 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) {
|
inline folly::dynamic toDynamic(const SharedColor &color) {
|
||||||
ColorComponents components = colorComponentsFromColor(color);
|
ColorComponents components = colorComponentsFromColor(color);
|
||||||
auto ratio = 256.f;
|
auto ratio = 255.f;
|
||||||
return (
|
return (
|
||||||
((int)(components.alpha * ratio) & 0xff) << 24 |
|
((int)(components.alpha * ratio) & 0xff) << 24 |
|
||||||
((int)(components.red * ratio) & 0xff) << 16 |
|
((int)(components.red * ratio) & 0xff) << 16 |
|
||||||
|
@ -61,7 +61,7 @@ inline folly::dynamic toDynamic(const SharedColor &color) {
|
||||||
|
|
||||||
inline std::string toString(const SharedColor &value) {
|
inline std::string toString(const SharedColor &value) {
|
||||||
ColorComponents components = colorComponentsFromColor(value);
|
ColorComponents components = colorComponentsFromColor(value);
|
||||||
auto ratio = 256.f;
|
auto ratio = 255.f;
|
||||||
return "rgba(" + folly::to<std::string>(round(components.red * ratio)) +
|
return "rgba(" + folly::to<std::string>(round(components.red * ratio)) +
|
||||||
", " + folly::to<std::string>(round(components.green * ratio)) + ", " +
|
", " + folly::to<std::string>(round(components.green * ratio)) + ", " +
|
||||||
folly::to<std::string>(round(components.blue * ratio)) + ", " +
|
folly::to<std::string>(round(components.blue * ratio)) + ", " +
|
||||||
|
|
Загрузка…
Ссылка в новой задаче