| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#ifndef COLOR_H |
| 17 |
#define COLOR_H |
| 18 |
|
| 19 |
#include <SkColor.h> |
| 20 |
#include <SkColorSpace.h> |
| 21 |
#include <SkImageInfo.h> |
| 22 |
#include <cutils/compiler.h> |
| 23 |
#include <math.h> |
| 24 |
#include <system/graphics.h> |
| 25 |
|
| 26 |
#include <optional> |
| 27 |
|
| 28 |
struct ANativeWindow_Buffer; |
| 29 |
struct AHardwareBuffer_Desc; |
| 30 |
|
| 31 |
namespace android { |
| 32 |
namespace uirenderer { |
| 33 |
namespace Color { |
| 34 |
enum Color { |
| 35 |
Red_500 = 0xFFF44336, |
| 36 |
Pink_500 = 0xFFE91E63, |
| 37 |
Purple_500 = 0xFF9C27B0, |
| 38 |
DeepPurple_500 = 0xFF673AB7, |
| 39 |
Indigo_500 = 0xFF3F51B5, |
| 40 |
Blue_500 = 0xFF2196F3, |
| 41 |
LightBlue_300 = 0xFF4FC3F7, |
| 42 |
LightBlue_500 = 0xFF03A9F4, |
| 43 |
Cyan_500 = 0xFF00BCD4, |
| 44 |
Teal_500 = 0xFF008577, |
| 45 |
Teal_700 = 0xFF00796B, |
| 46 |
Green_500 = 0xFF4CAF50, |
| 47 |
Green_700 = 0xFF388E3C, |
| 48 |
LightGreen_500 = 0xFF8BC34A, |
| 49 |
LightGreen_700 = 0xFF689F38, |
| 50 |
Lime_500 = 0xFFCDDC39, |
| 51 |
Yellow_500 = 0xFFFFEB3B, |
| 52 |
Amber_500 = 0xFFFFC107, |
| 53 |
Orange_500 = 0xFFFF9800, |
| 54 |
DeepOrange_500 = 0xFFFF5722, |
| 55 |
Brown_500 = 0xFF795548, |
| 56 |
Grey_200 = 0xFFEEEEEE, |
| 57 |
Grey_500 = 0xFF9E9E9E, |
| 58 |
Grey_700 = 0xFF616161, |
| 59 |
BlueGrey_500 = 0xFF607D8B, |
| 60 |
Transparent = 0x00000000, |
| 61 |
Black = 0xFF000000, |
| 62 |
White = 0xFFFFFFFF, |
| 63 |
}; |
| 64 |
} |
| 65 |
|
| 66 |
static_assert(Color::White == SK_ColorWHITE, "color format has changed"); |
| 67 |
static_assert(Color::Black == SK_ColorBLACK, "color format has changed"); |
| 68 |
|
| 69 |
|
| 70 |
static const Color::Color BrightColors[] = { |
| 71 |
Color::Red_500, Color::Pink_500, Color::Purple_500, Color::DeepPurple_500, |
| 72 |
Color::Indigo_500, Color::Blue_500, Color::LightBlue_500, Color::Cyan_500, |
| 73 |
Color::Teal_500, Color::Green_500, Color::LightGreen_500, Color::Lime_500, |
| 74 |
Color::Yellow_500, Color::Amber_500, Color::Orange_500, Color::DeepOrange_500, |
| 75 |
Color::Brown_500, Color::Grey_500, Color::BlueGrey_500, |
| 76 |
}; |
| 77 |
static constexpr int BrightColorsCount = sizeof(BrightColors) / sizeof(Color::Color); |
| 78 |
|
| 79 |
enum class TransferFunctionType : int8_t { None = 0, Full, Limited, Gamma }; |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
static constexpr float OECF_sRGB(float linear) { |
| 84 |
|
| 85 |
return linear <= 0.0031308f ? linear * 12.92f : (powf(linear, 1.0f / 2.4f) * 1.055f) - 0.055f; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
static constexpr float EOCF_sRGB(float srgb) { |
| 91 |
|
| 92 |
return srgb <= 0.04045f ? srgb / 12.92f : powf((srgb + 0.055f) / 1.055f, 2.4f); |
| 93 |
} |
| 94 |
|
| 95 |
#ifdef __ANDROID__ |
| 96 |
SkImageInfo ANativeWindowToImageInfo(const ANativeWindow_Buffer& buffer, |
| 97 |
sk_sp<SkColorSpace> colorSpace); |
| 98 |
|
| 99 |
SkImageInfo BufferDescriptionToImageInfo(const AHardwareBuffer_Desc& bufferDesc, |
| 100 |
sk_sp<SkColorSpace> colorSpace); |
| 101 |
|
| 102 |
uint32_t ColorTypeToBufferFormat(SkColorType colorType); |
| 103 |
#endif |
| 104 |
|
| 105 |
ANDROID_API sk_sp<SkColorSpace> DataSpaceToColorSpace(android_dataspace dataspace); |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
ANDROID_API android_dataspace ColorSpaceToADataSpace(SkColorSpace*, SkColorType); |
| 122 |
|
| 123 |
struct Lab { |
| 124 |
float L; |
| 125 |
float a; |
| 126 |
float b; |
| 127 |
}; |
| 128 |
|
| 129 |
Lab sRGBToLab(SkColor color); |
| 130 |
SkColor LabToSRGB(const Lab& lab, SkAlpha alpha); |
| 131 |
skcms_TransferFunction GetPQSkTransferFunction(float sdr_white_level = 0.f); |
| 132 |
std::optional<skcms_TransferFunction> GetHLGScaleTransferFunction(); |
| 133 |
|
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
#endif |