2323// define a clamp macro to substitute the std::clamp macro which is available from C++17 onwards
2424#define clamp (a , min , max ) ((a) < (min) ? (min) : ((a) > (max) ? (max) : (a)))
2525
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 ;
2858
2959 uint8_t region , p , q , t ;
3060 uint32_t h , s , v , remainder ;
@@ -66,8 +96,13 @@ RgbColor_t HsvToRgb(HsvColor_t hsv) {
6696 return rgb ;
6797}
6898
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 ;
71106 uint8_t rgbMin , rgbMax ;
72107
73108 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) {
95130 return hsv ;
96131}
97132
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 ) {
99138 // convert xyY color space to RGB
100139
101140 // 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) {
108147 // y = current_Y/65536
109148 // z = 1-x-y
110149
111- RgbColor_t rgb;
150+ espRgbColor_t rgb ;
112151
113152 float x , y , z ;
114153 float X , Y , Z ;
@@ -155,14 +194,19 @@ RgbColor_t XYToRgb(uint8_t Level, uint16_t current_X, uint16_t current_Y) {
155194 return rgb ;
156195}
157196
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 ) {
159203 // convert RGB to xy color space
160204
161205 // https://www.easyrgb.com/en/math.php
162206 // https://en.wikipedia.org/wiki/SRGB
163207 // refer https://en.wikipedia.org/wiki/CIE_1931_color_space#CIE_xy_chromaticity_diagram_and_the_CIE_xyY_color_space
164208
165- XyColor_t xy;
209+ espXyColor_t xy ;
166210
167211 float r , g , b ;
168212 float X , Y , Z ;
@@ -198,9 +242,13 @@ XyColor_t RgbToXY(RgbColor_t rgb) {
198242 return xy ;
199243}
200244
245+ espRgbColor_t espCTToRgbColor (uint16_t ct ){
246+ espCtColor_t ctColor = {ct };
247+ return espCTColorToRgbColor (ctColor );
248+ }
201249
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 };
204252 float r , g , b ;
205253
206254 if (ct .ctMireds == 0 ) {
0 commit comments