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:
David Vacca 2018-08-15 17:50:02 -07:00 committed by Facebook Github Bot
parent b8a50c7614
commit 8a8ee33f48
1 changed files with 10 additions and 8 deletions

View File

@ -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
}; };
} }