Fix color conversions for android
Summary: This diff fixes the color conversions for Android Reviewed By: shergin Differential Revision: D9093561 fbshipit-source-id: a17e61c58be511bd463dc0b21b632dc24066b8b6
This commit is contained in:
parent
b8a50c7614
commit
8a8ee33f48
|
@ -11,21 +11,23 @@ namespace facebook {
|
||||||
namespace react {
|
namespace react {
|
||||||
|
|
||||||
SharedColor colorFromComponents(ColorComponents components) {
|
SharedColor colorFromComponents(ColorComponents components) {
|
||||||
|
float ratio = 255.9999;
|
||||||
return SharedColor(
|
return SharedColor(
|
||||||
((int)components.alpha & 0xff) << 24 |
|
((int)(components.alpha * ratio) & 0xff) << 24 |
|
||||||
((int)components.red & 0xff) << 16 |
|
((int)(components.red * ratio) & 0xff) << 16 |
|
||||||
((int)components.green & 0xff) << 8 |
|
((int)(components.green * ratio) & 0xff) << 8 |
|
||||||
((int)components.blue & 0xff)
|
((int)(components.blue * ratio) & 0xff)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
ColorComponents colorComponentsFromColor(SharedColor sharedColor) {
|
ColorComponents colorComponentsFromColor(SharedColor sharedColor) {
|
||||||
|
float ratio = 256;
|
||||||
Color color = *sharedColor;
|
Color color = *sharedColor;
|
||||||
return ColorComponents {
|
return ColorComponents {
|
||||||
(float)((color >> 16) & 0xff),
|
(float)((color >> 16) & 0xff) / ratio,
|
||||||
(float)((color >> 8) & 0xff),
|
(float)((color >> 8) & 0xff) / ratio,
|
||||||
(float)((color ) & 0xff),
|
(float)((color ) & 0xff) / ratio,
|
||||||
(float)((color >> 24) & 0xff)
|
(float)((color >> 24) & 0xff) / ratio
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue