23
23
// define a clamp macro to substitute the std::clamp macro which is available from C++17 onwards
24
24
#define clamp (a , min , max ) ((a) < (min) ? (min) : ((a) > (max) ? (max) : (a)))
25
25
26
- RgbColor_t HsvToRgb (HsvColor_t hsv) {
27
- RgbColor_t rgb;
26
+ const espHsvColor_t HSV_BLACK = {0 , 0 , 0 };
27
+ const espHsvColor_t HSV_WHITE = {0 , 0 , 254 };
28
+ const espHsvColor_t HSV_RED = {0 , 254 , 254 };
29
+ const espHsvColor_t HSV_YELLOW = {42 , 254 , 254 };
30
+ const espHsvColor_t HSV_GREEN = {84 , 254 , 254 };
31
+ const espHsvColor_t HSV_CYAN = {127 , 254 , 254 };
32
+ const espHsvColor_t HSV_BLUE = {169 , 254 , 254 };
33
+ const espHsvColor_t HSV_MAGENTA = {211 , 254 , 254 };
34
+
35
+ const espRgbColor_t RGB_BLACK = {0 , 0 , 0 };
36
+ const espRgbColor_t RGB_WHITE = {255 , 255 , 255 };
37
+ const espRgbColor_t RGB_RED = {255 , 0 , 0 };
38
+ const espRgbColor_t RGB_YELLOW = {255 , 255 , 0 };
39
+ const espRgbColor_t RGB_GREEN = {0 , 255 , 0 };
40
+ const espRgbColor_t RGB_CYAN = {0 , 255 , 255 };
41
+ const espRgbColor_t RGB_BLUE = {0 , 0 , 255 };
42
+ const espRgbColor_t RGB_MAGENTA = {255 , 0 , 255 };
43
+
44
+ // main color temperature values
45
+ const espCtColor_t COOL_WHITE_COLOR_TEMPERATURE = { 142 };
46
+ const espCtColor_t DAYLIGHT_WHITE_COLOR_TEMPERATURE = { 181 };
47
+ const espCtColor_t WHITE_COLOR_TEMPERATURE = { 250 };
48
+ const espCtColor_t SOFT_WHITE_COLOR_TEMPERATURE = { 370 };
49
+ const espCtColor_t WARM_WHITE_COLOR_TEMPERATURE = { 454 };
50
+
51
+ espRgbColor_t espHsvToRgbColor (uint16_t h , uint8_t s , uint8_t v ) {
52
+ espHsvColor_t hsv = {h , s , v };
53
+ return espHsvColorToRgbColor (hsv );
54
+ }
55
+
56
+ espRgbColor_t espHsvColorToRgbColor (espHsvColor_t hsv ) {
57
+ espRgbColor_t rgb ;
28
58
29
59
uint8_t region , p , q , t ;
30
60
uint32_t h , s , v , remainder ;
@@ -66,8 +96,13 @@ RgbColor_t HsvToRgb(HsvColor_t hsv) {
66
96
return rgb ;
67
97
}
68
98
69
- HsvColor_t RgbToHsv (RgbColor_t rgb) {
70
- HsvColor_t hsv;
99
+ espHsvColor_t espRgbToHsvColor (uint8_t r , uint8_t g , uint8_t b ) {
100
+ espRgbColor_t rgb = {r , g , b };
101
+ return espRgbColorToHsvColor (rgb );
102
+ }
103
+
104
+ espHsvColor_t espRgbColorToHsvColor (espRgbColor_t rgb ) {
105
+ espHsvColor_t hsv ;
71
106
uint8_t rgbMin , rgbMax ;
72
107
73
108
rgbMin = rgb .r < rgb .g ? (rgb .r < rgb .b ? rgb .r : rgb .b ) : (rgb .g < rgb .b ? rgb .g : rgb .b );
@@ -95,7 +130,11 @@ HsvColor_t RgbToHsv(RgbColor_t rgb) {
95
130
return hsv ;
96
131
}
97
132
98
- RgbColor_t XYToRgb (uint8_t Level, uint16_t current_X, uint16_t current_Y) {
133
+ espRgbColor_t espXYColorToRgbColor (uint8_t Level , espXyColor_t xy ) {
134
+ return espXYToRgbColor (Level , xy .x , xy .y );
135
+ }
136
+
137
+ espRgbColor_t espXYToRgbColor (uint8_t Level , uint16_t current_X , uint16_t current_Y ) {
99
138
// convert xyY color space to RGB
100
139
101
140
// https://www.easyrgb.com/en/math.php
@@ -108,7 +147,7 @@ RgbColor_t XYToRgb(uint8_t Level, uint16_t current_X, uint16_t current_Y) {
108
147
// y = current_Y/65536
109
148
// z = 1-x-y
110
149
111
- RgbColor_t rgb;
150
+ espRgbColor_t rgb ;
112
151
113
152
float x , y , z ;
114
153
float X , Y , Z ;
@@ -155,14 +194,19 @@ RgbColor_t XYToRgb(uint8_t Level, uint16_t current_X, uint16_t current_Y) {
155
194
return rgb ;
156
195
}
157
196
158
- XyColor_t RgbToXY (RgbColor_t rgb) {
197
+ espXyColor_t espRgbToXYColor (uint8_t r , uint8_t g , uint8_t b ){
198
+ espRgbColor_t rgb = {r , g , b };
199
+ return espRgbColorToXYColor (rgb );
200
+ }
201
+
202
+ espXyColor_t espRgbColorToXYColor (espRgbColor_t rgb ) {
159
203
// convert RGB to xy color space
160
204
161
205
// https://www.easyrgb.com/en/math.php
162
206
// https://en.wikipedia.org/wiki/SRGB
163
207
// refer https://en.wikipedia.org/wiki/CIE_1931_color_space#CIE_xy_chromaticity_diagram_and_the_CIE_xyY_color_space
164
208
165
- XyColor_t xy;
209
+ espXyColor_t xy ;
166
210
167
211
float r , g , b ;
168
212
float X , Y , Z ;
@@ -198,9 +242,13 @@ XyColor_t RgbToXY(RgbColor_t rgb) {
198
242
return xy ;
199
243
}
200
244
245
+ espRgbColor_t espCTToRgbColor (uint16_t ct ){
246
+ espCtColor_t ctColor = {ct };
247
+ return espCTColorToRgbColor (ctColor );
248
+ }
201
249
202
- RgbColor_t CTToRgb (CtColor_t ct) {
203
- RgbColor_t rgb = {0 , 0 , 0 };
250
+ espRgbColor_t espCTColorToRgbColor ( espCtColor_t ct ) {
251
+ espRgbColor_t rgb = {0 , 0 , 0 };
204
252
float r , g , b ;
205
253
206
254
if (ct .ctMireds == 0 ) {
0 commit comments