FastLED 3.9.15
Loading...
Searching...
No Matches

◆ HSV16toRGB()

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

Definition at line 121 of file hsv16.cpp.

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

References fl::HSV16::h, map16_to_8(), map32_to_16(), fl::HSV16::s, fl::HSV16::v, and x.

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

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