|
12 | 12 |
|
13 | 13 | namespace facebook::react {
|
14 | 14 |
|
15 |
| -using Color = int32_t; |
| 15 | +using Color = int64_t; |
16 | 16 |
|
17 | 17 | namespace HostPlatformColor {
|
18 | 18 | static const facebook::react::Color UndefinedColor =
|
19 | 19 | std::numeric_limits<facebook::react::Color>::max();
|
20 | 20 | }
|
21 | 21 |
|
22 | 22 | inline Color hostPlatformColorFromComponents(ColorComponents components) {
|
23 |
| - float ratio = 255; |
24 |
| - return ((int)round(components.alpha * ratio) & 0xff) << 24 | |
25 |
| - ((int)round(components.red * ratio) & 0xff) << 16 | |
26 |
| - ((int)round(components.green * ratio) & 0xff) << 8 | |
27 |
| - ((int)round(components.blue * ratio) & 0xff); |
| 23 | + if (components.colorSpace == ColorSpace::DisplayP3) { |
| 24 | + int ratio = 15360; |
| 25 | + int red = static_cast<int>(round(components.red * ratio)) & 0xffff; |
| 26 | + int green = static_cast<int>(round(components.green * ratio)) & 0xffff; |
| 27 | + int blue = static_cast<int>(round(components.blue * ratio)) & 0xffff; |
| 28 | + int alpha = static_cast<int>(round(components.alpha * 0x3ff)) & 0x3ff; |
| 29 | + int colorSpace = 7; |
| 30 | + int64_t androidColor = (static_cast<int64_t>(red) << 48) | |
| 31 | + (static_cast<int64_t>(green) << 32) | |
| 32 | + (static_cast<int64_t>(blue) << 16) | |
| 33 | + (static_cast<int64_t>(alpha) << 6) | |
| 34 | + static_cast<int64_t>(colorSpace); |
| 35 | + return androidColor; |
| 36 | + } else { |
| 37 | + int ratio = 255; |
| 38 | + int alpha = static_cast<int>(round(components.alpha * ratio)) & 0xff; |
| 39 | + int red = static_cast<int>(round(components.red * ratio)) & 0xff; |
| 40 | + int green = static_cast<int>(round(components.green * ratio)) & 0xff; |
| 41 | + int blue = static_cast<int>(round(components.blue * ratio)) & 0xff; |
| 42 | + int64_t androidColor = (static_cast<int64_t>(alpha) << 56) | |
| 43 | + (static_cast<int64_t>(red) << 48) | |
| 44 | + (static_cast<int64_t>(green) << 40) | |
| 45 | + (static_cast<int64_t>(blue) << 32); |
| 46 | + return androidColor; |
| 47 | + } |
28 | 48 | }
|
29 | 49 |
|
30 | 50 | inline ColorComponents colorComponentsFromHostPlatformColor(Color color) {
|
31 |
| - float ratio = 255; |
32 |
| - return ColorComponents{ |
33 |
| - (float)((color >> 16) & 0xff) / ratio, |
34 |
| - (float)((color >> 8) & 0xff) / ratio, |
35 |
| - (float)((color >> 0) & 0xff) / ratio, |
36 |
| - (float)((color >> 24) & 0xff) / ratio}; |
| 51 | + if ((color & 0x3f) == 7) { |
| 52 | + int ratio = 15360; |
| 53 | + return ColorComponents{ |
| 54 | + (float)((color >> 48) & 0xffff) / ratio, |
| 55 | + (float)((color >> 32) & 0xffff) / ratio, |
| 56 | + (float)((color >> 16) & 0xffff) / ratio, |
| 57 | + (float)((color >> 6) & 0x3ff) / ratio, |
| 58 | + ColorSpace::DisplayP3}; |
| 59 | + } else { |
| 60 | + int ratio = 255; |
| 61 | + return ColorComponents{ |
| 62 | + (float)((color >> 48) & 0xff) / ratio, |
| 63 | + (float)((color >> 40) & 0xff) / ratio, |
| 64 | + (float)((color >> 32) & 0xff) / ratio, |
| 65 | + (float)((color >> 56) & 0xff) / ratio, |
| 66 | + ColorSpace::sRGB}; |
| 67 | + } |
37 | 68 | }
|
38 | 69 |
|
39 | 70 | } // namespace facebook::react
|
0 commit comments