FastLED 3.10.8
Loading...
Searching...
No Matches

◆ HSV16toRGB()

static CRGB fl::HSV16toRGB ( const HSV16 & hsv)
static

Definition at line 122 of file hsv16.cpp.hpp.

122 {
123 // Convert 16-bit values to working range
124 u32 h = hsv.h;
125 u32 s = hsv.s;
126 u32 v = hsv.v;
127
128 if (s == 0) {
129 // Grayscale case - use precise mapping
130 u8 gray = map16_to_8(v);
131 return CRGB{gray, gray, gray};
132 }
133
134 // Determine which sector of the color wheel (0-5)
135 u32 sector = (h * 6) / 65536;
136 u32 sector_pos = (h * 6) % 65536; // Position within sector (0-65535)
137
138 // Calculate intermediate values using precise mapping
139 // c = v * s / 65536, with proper rounding
140 u32 c = map32_to_16(v * s);
141
142 // Calculate x = c * (1 - |2*(sector_pos/65536) - 1|)
143 u32 x;
144 if (sector & 1) {
145 // For odd sectors (1, 3, 5), we want decreasing values
146 // x = c * (65535 - sector_pos) / 65535
147 x = map32_to_16(c * (65535 - sector_pos));
148 } else {
149 // For even sectors (0, 2, 4), we want increasing values
150 // x = c * sector_pos / 65535
151 x = map32_to_16(c * sector_pos);
152 }
153
154 u32 m = v - c;
155
156 u32 r1, g1, b1;
157 switch (sector) {
158 case 0: r1 = c; g1 = x; b1 = 0; break;
159 case 1: r1 = x; g1 = c; b1 = 0; break;
160 case 2: r1 = 0; g1 = c; b1 = x; break;
161 case 3: r1 = 0; g1 = x; b1 = c; break;
162 case 4: r1 = x; g1 = 0; b1 = c; break;
163 default: r1 = c; g1 = 0; b1 = x; break;
164 }
165
166 // Add baseline and scale to 8-bit using accurate mapping
167 u8 R = map16_to_8(u16(r1 + m));
168 u8 G = map16_to_8(u16(g1 + m));
169 u8 B = map16_to_8(u16(b1 + m));
170
171 return CRGB{R, G, B};
172}
u16 map32_to_16(u32 x) FL_NO_EXCEPT
Definition intmap.h:72
u8 map16_to_8(u16 x) FL_NO_EXCEPT
Definition intmap.h:66
unsigned char u8
Definition stdint.h:131
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38
u16 v
Definition hsv16.h:12
u16 h
Definition hsv16.h:10
u16 s
Definition hsv16.h:11

References B, FL_NO_EXCEPT, map16_to_8(), map32_to_16(), and x.

Referenced by fl::HSV16::ToRGB().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: