5#define FASTLED_INTERNAL
20#if defined(__AVR__) && !defined( LIB8_ATTINY )
34#define APPLY_DIMMING(X) (X)
38#define HSV_SECTION_6 (0x20)
42#define HSV_SECTION_3 (0x40)
59 uint8_t saturation = hsv.sat;
64 uint8_t brightness_floor = (value * invsat) / 256;
69 uint8_t color_amplitude = value - brightness_floor;
109 uint8_t rampup_amp_adj = (rampup * color_amplitude) / (256 / 4);
110 uint8_t rampdown_amp_adj = (rampdown * color_amplitude) / (256 / 4);
113 uint8_t rampup_adj_with_floor = rampup_amp_adj + brightness_floor;
114 uint8_t rampdown_adj_with_floor = rampdown_amp_adj + brightness_floor;
120 rgb.r = brightness_floor;
121 rgb.g = rampdown_adj_with_floor;
122 rgb.b = rampup_adj_with_floor;
125 rgb.r = rampup_adj_with_floor;
126 rgb.g = brightness_floor;
127 rgb.b = rampdown_adj_with_floor;
131 rgb.r = rampdown_adj_with_floor;
132 rgb.g = rampup_adj_with_floor;
133 rgb.b = brightness_floor;
139#if defined(__AVR__) && !defined( LIB8_ATTINY )
142 uint8_t
hue, saturation, value;
145 saturation = hsv.sat;
149 saturation = 255 - saturation;
157 uint8_t brightness_floor;
160 "mul %[value], %[invsat] \n"
161 "mov %[brightness_floor], r1 \n"
162 : [brightness_floor]
"=r" (brightness_floor)
163 : [value]
"r" (value),
164 [invsat]
"r" (invsat)
171 uint8_t color_amplitude = value - brightness_floor;
176 uint8_t rampup =
offset * 4;
180 uint8_t rampup_amp_adj;
181 uint8_t rampdown_amp_adj;
184 "mul %[rampup], %[color_amplitude] \n"
185 "mov %[rampup_amp_adj], r1 \n"
187 "mul %[rampup], %[color_amplitude] \n"
188 "mov %[rampdown_amp_adj], r1 \n"
189 : [rampup_amp_adj]
"=&r" (rampup_amp_adj),
190 [rampdown_amp_adj]
"=&r" (rampdown_amp_adj),
191 [rampup]
"+r" (rampup)
192 : [color_amplitude]
"r" (color_amplitude)
198 uint8_t rampup_adj_with_floor = rampup_amp_adj + brightness_floor;
199 uint8_t rampdown_adj_with_floor = rampdown_amp_adj + brightness_floor;
208 asm volatile(
"" : : :
"r26",
"r27" );
213 rgb.r = rampup_adj_with_floor;
214 rgb.g = brightness_floor;
215 rgb.b = rampdown_adj_with_floor;
219 rgb.r = brightness_floor;
220 rgb.g = rampdown_adj_with_floor;
221 rgb.b = rampup_adj_with_floor;
224 rgb.r = rampdown_adj_with_floor;
225 rgb.g = rampup_adj_with_floor;
226 rgb.b = brightness_floor;
239 hsv2.hue =
scale8( hsv2.hue, 191);
251#define FORCE_REFERENCE(var) asm volatile( "" : : "r" (var) )
277 const uint8_t Y1 = 1;
278 const uint8_t Y2 = 0;
282 const uint8_t G2 = 0;
286 const uint8_t Gscale = 0;
289 uint8_t
hue = hsv.hue;
290 uint8_t sat = hsv.sat;
291 uint8_t val = hsv.val;
313 uint8_t third =
scale8( offset8, (256 / 3));
317 if( ! (
hue & 0x80) ) {
319 if( ! (
hue & 0x40) ) {
322 if( ! (
hue & 0x20) ) {
341 uint8_t twothirds =
scale8( offset8, ((256 * 2) / 3));
350 if( ! (
hue & 0x20) ) {
355 uint8_t twothirds =
scale8( offset8, ((256 * 2) / 3));
356 r = K171 - twothirds;
379 if( ! (
hue & 0x40) ) {
381 if( ! (
hue & 0x20) ) {
387 uint8_t twothirds =
scale8( offset8, ((256 * 2) / 3));
388 g = K171 - twothirds;
401 if( ! (
hue & 0x20) ) {
430 r = 255; b = 255; g = 255;
432 uint8_t desat = 255 - sat;
435 uint8_t satscale = 255 - desat;
439#if (FASTLED_SCALE8_FIXED==1)
448 if( r ) r =
scale8( r, satscale) + 1;
449 if( g ) g =
scale8( g, satscale) + 1;
450 if( b ) b =
scale8( b, satscale) + 1;
452 uint8_t brightness_floor = desat;
453 r += brightness_floor;
454 g += brightness_floor;
455 b += brightness_floor;
467#if (FASTLED_SCALE8_FIXED==1)
476 if( r ) r =
scale8( r, val) + 1;
477 if( g ) g =
scale8( g, val) + 1;
478 if( b ) b =
scale8( b, val) + 1;
495 const auto f = [](
const int n,
const uint8_t h) ->
unsigned int {
496 constexpr int kZero = 0 << 8;
497 constexpr int kOne = 1 << 8;
498 constexpr int kFour = 4 << 8;
499 constexpr int kSix = 6 << 8;
501 const int k = ((n << 8) + 6*h) % kSix;
502 const int k2 = kFour - k;
506 const unsigned int chroma = hsv.v * hsv.s / 255;
507 rgb.r = hsv.v - ((chroma * f(5, hsv.h)) >> 8);
508 rgb.g = hsv.v - ((chroma * f(3, hsv.h)) >> 8);
509 rgb.b = hsv.v - ((chroma * f(1, hsv.h)) >> 8);
521 for(
int i = 0; i < numLeds; ++i) {
527 for(
int i = 0; i < numLeds; ++i) {
533 for(
int i = 0; i < numLeds; ++i) {
539 for (
int i = 0; i < numLeds; ++i) {
545#define FIXFRAC8(N,D) (((N)*256)/(D))
559 if( r < desat) desat = r;
560 if( g < desat) desat = g;
561 if( b < desat) desat = b;
579 s = 255 -
sqrt16( (255-s) * 256);
589 if( (r + g + b) == 0) {
591 return CHSV( 0, 0, 255 - s);
597 uint32_t scaleup = 65535 / (s);
598 r = ((uint32_t)(r) * scaleup) / 256;
599 g = ((uint32_t)(g) * scaleup) / 256;
600 b = ((uint32_t)(b) * scaleup) / 256;
606 uint16_t total = r + g + b;
612 if( total == 0) total = 1;
613 uint32_t scaleup = 65535 / (total);
614 r = ((uint32_t)(r) * scaleup) / 256;
615 g = ((uint32_t)(g) * scaleup) / 256;
616 b = ((uint32_t)(b) * scaleup) / 256;
625 v =
qadd8(desat,total);
627 if( v != 255) v =
sqrt16( v * 256);
665 if( g > highest) highest = g;
666 if( b > highest) highest = b;
675 }
else if ( (r - g) > g) {
685 }
else if ( highest == g) {
695 uint8_t rgadj = radj + gadj;
696 uint8_t hueadv = rgadj / 2;
718 }
else if ( (b-r) > r) {
730 return CHSV( h, s, v);
central include file for FastLED, defines the CFastLED class/object
@ HUE_PURPLE
Purple (270°)
UISlider offset("Offset", 0.0f, 0.0f, 1.0f, 0.01f)
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.
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.
CRGB hsv2rgb_rainbow(const struct CHSV &hsv)
#define FORCE_REFERENCE(var)
Force a variable reference to avoid compiler over-optimization.
void hsv2rgb_raw(const struct CHSV &hsv, struct CRGB &rgb)
void hsv2rgb_raw_avr(const struct CHSV &hsv, struct CRGB &rgb)
HSV to RGB implementation in raw C, for the AVR platform only.
CRGB hsv2rgb_spectrum(const struct CHSV &hsv)
Inline version of hsv2rgb_spectrum which returns a CRGB object.
FASTLED_NAMESPACE_BEGIN void hsv2rgb_raw_C(const struct CHSV &hsv, struct CRGB &rgb)
HSV to RGB implementation in raw C, platform independent.
void hsv2rgb_fullspectrum(const struct CHSV &hsv, CRGB &rgb)
#define HSV_SECTION_3
Divide the color wheel into four sections, 64 elements each.
Functions to convert from the HSV colorspace to the RGB colorspace.
#define FASTLED_NAMESPACE_END
#define FASTLED_NAMESPACE_BEGIN
FL_DISABLE_WARNING_PUSH U common_type_t< T, U > fl_min(T a, U b)
common_type_t< T, U > fl_max(T a, U b)
Representation of an RGB pixel (Red, Green, Blue)
Representation of an HSV pixel (hue, saturation, value (aka brightness)).