5#define FASTLED_INTERNAL
10FASTLED_NAMESPACE_BEGIN
17#if defined(__AVR__) && !defined( LIB8_ATTINY )
31#define APPLY_DIMMING(X) (X)
35#define HSV_SECTION_6 (0x20)
39#define HSV_SECTION_3 (0x40)
49 uint8_t saturation = hsv.
sat;
54 uint8_t brightness_floor = (value * invsat) / 256;
59 uint8_t color_amplitude = value - brightness_floor;
66 uint8_t rampup = offset;
99 uint8_t rampup_amp_adj = (rampup * color_amplitude) / (256 / 4);
100 uint8_t rampdown_amp_adj = (rampdown * color_amplitude) / (256 / 4);
103 uint8_t rampup_adj_with_floor = rampup_amp_adj + brightness_floor;
104 uint8_t rampdown_adj_with_floor = rampdown_amp_adj + brightness_floor;
110 rgb.
r = brightness_floor;
111 rgb.
g = rampdown_adj_with_floor;
112 rgb.
b = rampup_adj_with_floor;
115 rgb.
r = rampup_adj_with_floor;
116 rgb.
g = brightness_floor;
117 rgb.
b = rampdown_adj_with_floor;
121 rgb.
r = rampdown_adj_with_floor;
122 rgb.
g = rampup_adj_with_floor;
123 rgb.
b = brightness_floor;
129#if defined(__AVR__) && !defined( LIB8_ATTINY )
132 uint8_t hue, saturation, value;
135 saturation = hsv.
sat;
139 saturation = 255 - saturation;
147 uint8_t brightness_floor;
150 "mul %[value], %[invsat] \n"
151 "mov %[brightness_floor], r1 \n"
152 : [brightness_floor]
"=r" (brightness_floor)
153 : [value]
"r" (value),
154 [invsat]
"r" (invsat)
161 uint8_t color_amplitude = value - brightness_floor;
166 uint8_t rampup = offset * 4;
170 uint8_t rampup_amp_adj;
171 uint8_t rampdown_amp_adj;
174 "mul %[rampup], %[color_amplitude] \n"
175 "mov %[rampup_amp_adj], r1 \n"
177 "mul %[rampup], %[color_amplitude] \n"
178 "mov %[rampdown_amp_adj], r1 \n"
179 : [rampup_amp_adj]
"=&r" (rampup_amp_adj),
180 [rampdown_amp_adj]
"=&r" (rampdown_amp_adj),
181 [rampup]
"+r" (rampup)
182 : [color_amplitude]
"r" (color_amplitude)
188 uint8_t rampup_adj_with_floor = rampup_amp_adj + brightness_floor;
189 uint8_t rampdown_adj_with_floor = rampdown_amp_adj + brightness_floor;
198 asm volatile(
"" : : :
"r26",
"r27" );
203 rgb.
r = rampup_adj_with_floor;
204 rgb.
g = brightness_floor;
205 rgb.
b = rampdown_adj_with_floor;
209 rgb.
r = brightness_floor;
210 rgb.
g = rampdown_adj_with_floor;
211 rgb.
b = rampup_adj_with_floor;
214 rgb.
r = rampdown_adj_with_floor;
215 rgb.
g = rampup_adj_with_floor;
216 rgb.
b = brightness_floor;
241#define FORCE_REFERENCE(var) asm volatile( "" : : "r" (var) )
261 const uint8_t Y1 = 1;
262 const uint8_t Y2 = 0;
266 const uint8_t G2 = 0;
270 const uint8_t Gscale = 0;
273 uint8_t hue = hsv.
hue;
274 uint8_t sat = hsv.
sat;
275 uint8_t val = hsv.
val;
277 uint8_t offset = hue & 0x1F;
280 uint8_t offset8 = offset;
297 uint8_t third =
scale8( offset8, (256 / 3));
301 if( ! (hue & 0x80) ) {
303 if( ! (hue & 0x40) ) {
306 if( ! (hue & 0x20) ) {
325 uint8_t twothirds =
scale8( offset8, ((256 * 2) / 3));
334 if( ! (hue & 0x20) ) {
339 uint8_t twothirds =
scale8( offset8, ((256 * 2) / 3));
340 r = K171 - twothirds;
363 if( ! (hue & 0x40) ) {
365 if( ! ( hue & 0x20) ) {
371 uint8_t twothirds =
scale8( offset8, ((256 * 2) / 3));
372 g = K171 - twothirds;
385 if( ! (hue & 0x20) ) {
414 r = 255; b = 255; g = 255;
416 uint8_t desat = 255 - sat;
419 uint8_t satscale = 255 - desat;
423#if (FASTLED_SCALE8_FIXED==1)
429 if( r ) r =
scale8( r, satscale) + 1;
430 if( g ) g =
scale8( g, satscale) + 1;
431 if( b ) b =
scale8( b, satscale) + 1;
433 uint8_t brightness_floor = desat;
434 r += brightness_floor;
435 g += brightness_floor;
436 b += brightness_floor;
448#if (FASTLED_SCALE8_FIXED==1)
454 if( r ) r =
scale8( r, val) + 1;
455 if( g ) g =
scale8( g, val) + 1;
456 if( b ) b =
scale8( b, val) + 1;
474 for(
int i = 0; i < numLeds; ++i) {
480 for(
int i = 0; i < numLeds; ++i) {
486 for(
int i = 0; i < numLeds; ++i) {
493#define FIXFRAC8(N,D) (((N)*256)/(D))
507 if( r < desat) desat = r;
508 if( g < desat) desat = g;
509 if( b < desat) desat = b;
527 s = 255 -
sqrt16( (255-s) * 256);
537 if( (r + g + b) == 0) {
539 return CHSV( 0, 0, 255 - s);
545 uint32_t scaleup = 65535 / (s);
546 r = ((uint32_t)(r) * scaleup) / 256;
547 g = ((uint32_t)(g) * scaleup) / 256;
548 b = ((uint32_t)(b) * scaleup) / 256;
554 uint16_t total = r + g + b;
560 if( total == 0) total = 1;
561 uint32_t scaleup = 65535 / (total);
562 r = ((uint32_t)(r) * scaleup) / 256;
563 g = ((uint32_t)(g) * scaleup) / 256;
564 b = ((uint32_t)(b) * scaleup) / 256;
573 v =
qadd8(desat,total);
575 if( v != 255) v =
sqrt16( v * 256);
613 if( g > highest) highest = g;
614 if( b > highest) highest = b;
621 h = (HUE_PURPLE + HUE_PINK) / 2;
623 }
else if ( (r - g) > g) {
633 }
else if ( highest == g) {
643 uint8_t rgadj = radj + gadj;
644 uint8_t hueadv = rgadj / 2;
664 h = HUE_AQUA + ((HUE_BLUE - HUE_AQUA) / 4);
666 }
else if ( (b-r) > r) {
678 return CHSV( h, s, v);
central include file for FastLED, defines the CFastLED class/object
void hsv2rgb_raw(const struct CHSV &hsv, struct CRGB &rgb)
Convert an HSV value to RGB using a mathematically straight spectrum.
void hsv2rgb_spectrum(const struct CHSV &hsv, CRGB &rgb)
Convert an HSV value to RGB using a mathematically straight spectrum.
CHSV rgb2hsv_approximate(const CRGB &rgb)
Recover approximate HSV values from RGB.
LIB8STATIC_ALWAYS_INLINE uint8_t qadd8(uint8_t i, uint8_t j)
Add one byte to another, saturating at 0xFF.
LIB8STATIC uint8_t sqrt16(uint16_t x)
Square root for 16-bit integers.
LIB8STATIC_ALWAYS_INLINE uint8_t qsub8(uint8_t i, uint8_t j)
Subtract one byte from another, saturating at 0x00.
void hsv2rgb_rainbow(const CHSV &hsv, CRGB &rgb)
Forward declaration of hsv2rgb_rainbow here, to avoid circular dependencies.
uint8_t r
Red channel value.
uint8_t g
Green channel value.
uint8_t b
Blue channel value.
LIB8STATIC_ALWAYS_INLINE void cleanup_R1()
Clean up the r1 register after a series of *LEAVING_R1_DIRTY calls.
LIB8STATIC_ALWAYS_INLINE uint8_t scale8_LEAVING_R1_DIRTY(uint8_t i, fract8 scale)
This version of scale8() does not clean up the R1 register on AVR.
LIB8STATIC_ALWAYS_INLINE uint8_t scale8_video_LEAVING_R1_DIRTY(uint8_t i, fract8 scale)
This version of scale8_video() does not clean up the R1 register on AVR.
LIB8STATIC_ALWAYS_INLINE uint8_t scale8_video(uint8_t i, fract8 scale)
The "video" version of scale8() guarantees that the output will be only be zero if one or both of the...
LIB8STATIC_ALWAYS_INLINE uint8_t scale8(uint8_t i, fract8 scale)
Scale one byte by a second one, which is treated as the numerator of a fraction whose denominator is ...
#define APPLY_DIMMING(X)
Apply dimming compensation to values.
#define FIXFRAC8(N, D)
Convert a fractional input into a constant.
#define FORCE_REFERENCE(var)
Force a variable reference to avoid compiler over-optimization.
void hsv2rgb_raw_avr(const struct CHSV &hsv, struct CRGB &rgb)
HSV to RGB implementation in raw C, for the AVR platform only.
void hsv2rgb_raw_C(const struct CHSV &hsv, struct CRGB &rgb)
HSV to RGB implementation in raw C, platform independent.
#define HSV_SECTION_3
Divide the color wheel into four sections, 64 elements each.
Representation of an HSV pixel (hue, saturation, value (aka brightness)).
uint8_t sat
Color saturation.
uint8_t val
Color value (brightness).
Representation of an RGB pixel (Red, Green, Blue)