Color.h revision efb4b06493fe7b1604c762a448b13c7af2845a8d
1/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef COLOR_H
17#define COLOR_H
18
19#include <math.h>
20
21#include <SkColor.h>
22
23namespace android {
24namespace uirenderer {
25    namespace Color {
26        enum Color {
27            Red_500 = 0xFFF44336,
28            Pink_500 = 0xFFE91E63,
29            Purple_500 = 0xFF9C27B0,
30            DeepPurple_500 = 0xFF673AB7,
31            Indigo_500 = 0xFF3F51B5,
32            Blue_500 = 0xFF2196F3,
33            LightBlue_300 = 0xFF4FC3F7,
34            LightBlue_500 = 0xFF03A9F4,
35            Cyan_500 = 0xFF00BCD4,
36            Teal_500 = 0xFF009688,
37            Teal_700 = 0xFF00796B,
38            Green_500 = 0xFF4CAF50,
39            Green_700 = 0xFF388E3C,
40            LightGreen_500 = 0xFF8BC34A,
41            LightGreen_700 = 0xFF689F38,
42            Lime_500 = 0xFFCDDC39,
43            Yellow_500 = 0xFFFFEB3B,
44            Amber_500 = 0xFFFFC107,
45            Orange_500 = 0xFFFF9800,
46            DeepOrange_500 = 0xFFFF5722,
47            Brown_500 = 0xFF795548,
48            Grey_200 = 0xFFEEEEEE,
49            Grey_500 = 0xFF9E9E9E,
50            Grey_700 = 0xFF616161,
51            BlueGrey_500 = 0xFF607D8B,
52            Transparent = 0x00000000,
53            Black = 0xFF000000,
54            White = 0xFFFFFFFF,
55        };
56    }
57
58    static_assert(Color::White == SK_ColorWHITE, "color format has changed");
59    static_assert(Color::Black == SK_ColorBLACK, "color format has changed");
60
61    // Array of bright (500 intensity) colors for synthetic content
62    static const Color::Color BrightColors[] = {
63        Color::Red_500,
64        Color::Pink_500,
65        Color::Purple_500,
66        Color::DeepPurple_500,
67        Color::Indigo_500,
68        Color::Blue_500,
69        Color::LightBlue_500,
70        Color::Cyan_500,
71        Color::Teal_500,
72        Color::Green_500,
73        Color::LightGreen_500,
74        Color::Lime_500,
75        Color::Yellow_500,
76        Color::Amber_500,
77        Color::Orange_500,
78        Color::DeepOrange_500,
79        Color::Brown_500,
80        Color::Grey_500,
81        Color::BlueGrey_500,
82    };
83    static constexpr int BrightColorsCount = sizeof(BrightColors) / sizeof(Color::Color);
84
85    // Opto-electronic conversion function for the sRGB color space
86    // Takes a linear sRGB value and converts it to a gamma-encoded sRGB value
87    static constexpr float OECF_sRGB(float linear) {
88        // IEC 61966-2-1:1999
89        return linear <= 0.0031308f ?
90                linear * 12.92f : (powf(linear, 1.0f / 2.4f) * 1.055f) - 0.055f;
91    }
92
93    // Opto-electronic conversion function for the sRGB color space
94    // Takes a linear sRGB value and converts it to a gamma-encoded sRGB value
95    // This function returns the input unmodified if linear blending is not enabled
96    static constexpr float OECF(float linear) {
97#ifdef ANDROID_ENABLE_LINEAR_BLENDING
98        return OECF_sRGB(linear);
99#else
100        return linear;
101#endif
102    }
103
104    // Electro-optical conversion function for the sRGB color space
105    // Takes a gamma-encoded sRGB value and converts it to a linear sRGB value
106    static constexpr float EOCF_sRGB(float srgb) {
107        // IEC 61966-2-1:1999
108        return srgb <= 0.04045f ? srgb / 12.92f : powf((srgb + 0.055f) / 1.055f, 2.4f);
109    }
110
111    // Electro-optical conversion function for the sRGB color space
112    // Takes a gamma-encoded sRGB value and converts it to a linear sRGB value
113    // This function returns the input unmodified if linear blending is not enabled
114    static constexpr float EOCF(float srgb) {
115#ifdef ANDROID_ENABLE_LINEAR_BLENDING
116        return EOCF_sRGB(srgb);
117#else
118        return srgb;
119#endif
120    }
121} /* namespace uirenderer */
122} /* namespace android */
123
124#endif /* COLOR_H */
125