4#include "platforms/is_platform.h"
7#define FASTLED_INTERNAL
22#if defined(FL_IS_AVR) && !defined(FL_IS_AVR_ATTINY)
36#define APPLY_DIMMING(X) (X)
40#define HSV_SECTION_6 (0x20)
44#define HSV_SECTION_3 (0x40)
61 fl::u8 saturation = hsv.sat;
66 fl::u8 brightness_floor = (value * invsat) / 256;
71 fl::u8 color_amplitude = value - brightness_floor;
111 fl::u8 rampup_amp_adj = (rampup * color_amplitude) / (256 / 4);
112 fl::u8 rampdown_amp_adj = (rampdown * color_amplitude) / (256 / 4);
115 fl::u8 rampup_adj_with_floor = rampup_amp_adj + brightness_floor;
116 fl::u8 rampdown_adj_with_floor = rampdown_amp_adj + brightness_floor;
122 rgb.r = brightness_floor;
123 rgb.g = rampdown_adj_with_floor;
124 rgb.b = rampup_adj_with_floor;
127 rgb.r = rampup_adj_with_floor;
128 rgb.g = brightness_floor;
129 rgb.b = rampdown_adj_with_floor;
133 rgb.r = rampdown_adj_with_floor;
134 rgb.g = rampup_adj_with_floor;
135 rgb.b = brightness_floor;
141#if defined(FL_IS_AVR) && !defined(FL_IS_AVR_ATTINY)
147 saturation = hsv.sat;
151 saturation = 255 - saturation;
162 "mul %[value], %[invsat] \n"
163 "mov %[brightness_floor], r1 \n"
164 : [brightness_floor]
"=r" (brightness_floor)
165 : [value]
"r" (value),
166 [invsat]
"r" (invsat)
173 fl::u8 color_amplitude = value - brightness_floor;
186 "mul %[rampup], %[color_amplitude] \n"
187 "mov %[rampup_amp_adj], r1 \n"
189 "mul %[rampup], %[color_amplitude] \n"
190 "mov %[rampdown_amp_adj], r1 \n"
191 : [rampup_amp_adj]
"=&r" (rampup_amp_adj),
192 [rampdown_amp_adj]
"=&r" (rampdown_amp_adj),
193 [rampup]
"+r" (rampup)
194 : [color_amplitude]
"r" (color_amplitude)
200 fl::u8 rampup_adj_with_floor = rampup_amp_adj + brightness_floor;
201 fl::u8 rampdown_adj_with_floor = rampdown_amp_adj + brightness_floor;
210 asm volatile(
"" : : :
"r26",
"r27" );
215 rgb.r = rampup_adj_with_floor;
216 rgb.g = brightness_floor;
217 rgb.b = rampdown_adj_with_floor;
221 rgb.r = brightness_floor;
222 rgb.g = rampdown_adj_with_floor;
223 rgb.b = rampup_adj_with_floor;
226 rgb.r = rampdown_adj_with_floor;
227 rgb.g = rampup_adj_with_floor;
228 rgb.b = brightness_floor;
241 hsv2.hue = scale8( hsv2.hue, 191);
253#define FORCE_REFERENCE(var) asm volatile( "" : : "r" (var) )
300#if defined(FL_IS_AVR)
315 fl::u8 third = scale8( offset8, (256 / 3));
319 if( ! (
hue & 0x80) ) {
321 if( ! (
hue & 0x40) ) {
324 if( ! (
hue & 0x20) ) {
343 fl::u8 twothirds = scale8( offset8, ((256 * 2) / 3));
352 if( ! (
hue & 0x20) ) {
357 fl::u8 twothirds = scale8( offset8, ((256 * 2) / 3));
358 r = K171 - twothirds;
381 if( ! (
hue & 0x40) ) {
383 if( ! (
hue & 0x20) ) {
389 fl::u8 twothirds = scale8( offset8, ((256 * 2) / 3));
390 g = K171 - twothirds;
403 if( ! (
hue & 0x20) ) {
432 if( Gscale ) g = scale8_video( g, Gscale);
438 r = 255; b = 255; g = 255;
441 desat = scale8_video( desat, desat);
443 fl::u8 satscale = 255 - desat;
447#if (FASTLED_SCALE8_FIXED==1)
448 r = scale8_LEAVING_R1_DIRTY( r, satscale);
450 g = scale8_LEAVING_R1_DIRTY( g, satscale);
452 b = scale8_LEAVING_R1_DIRTY( b, satscale);
456 if( r ) r = scale8( r, satscale) + 1;
457 if( g ) g = scale8( g, satscale) + 1;
458 if( b ) b = scale8( b, satscale) + 1;
460 fl::u8 brightness_floor = desat;
461 r += brightness_floor;
462 g += brightness_floor;
463 b += brightness_floor;
472 val = scale8_video( val, val);
477#if (FASTLED_SCALE8_FIXED==1)
478 r = scale8_LEAVING_R1_DIRTY( r, val);
480 g = scale8_LEAVING_R1_DIRTY( g, val);
482 b = scale8_LEAVING_R1_DIRTY( b, val);
486 if( r ) r = scale8( r, val) + 1;
487 if( g ) g = scale8( g, val) + 1;
488 if( b ) b = scale8( b, val) + 1;
505 const auto f = [](
const int n,
const fl::u8 h) -> fl::u32 {
506 constexpr int kZero = 0 << 8;
507 constexpr int kOne = 1 << 8;
508 constexpr int kFour = 4 << 8;
509 constexpr int kSix = 6 << 8;
511 const int k = ((n << 8) + 6*h) % kSix;
512 const int k2 = kFour - k;
516 const fl::u32 chroma = hsv.v * hsv.s / 255;
517 rgb.r = hsv.v - ((chroma * f(5, hsv.h)) >> 8);
518 rgb.g = hsv.v - ((chroma * f(3, hsv.h)) >> 8);
519 rgb.b = hsv.v - ((chroma * f(1, hsv.h)) >> 8);
531 for(
int i = 0; i < numLeds; ++i) {
537 for(
int i = 0; i < numLeds; ++i) {
543 for(
int i = 0; i < numLeds; ++i) {
549 for (
int i = 0; i < numLeds; ++i) {
555#define FIXFRAC8(N,D) (((N)*256)/(D))
571 if( r < desat) desat = r;
572 if( g < desat) desat = g;
573 if( b < desat) desat = b;
591 s = 255 - fl::sqrt16( (255-s) * 256);
601 if( (r + g + b) == 0) {
603 return CHSV( 0, 0, 255 - s);
609 fl::u32 scaleup = 65535 / (s);
610 r = ((fl::u32)(r) * scaleup) / 256;
611 g = ((fl::u32)(g) * scaleup) / 256;
612 b = ((fl::u32)(b) * scaleup) / 256;
618 fl::u16 total = r + g + b;
626 if( total == 0) total = 1;
627 fl::u32 scaleup = 65535 / (total);
628 r = ((fl::u32)(r) * scaleup) / 256;
629 g = ((fl::u32)(g) * scaleup) / 256;
630 b = ((fl::u32)(b) * scaleup) / 256;
639 v = qadd8(desat,total);
641 if( v != 255) v = fl::sqrt16( v * 256);
679 if( g > highest) highest = g;
680 if( b > highest) highest = b;
688 h += scale8( qsub8(r, 128),
FIXFRAC8(48,128));
689 }
else if ( (r - g) > g) {
710 h += scale8( qsub8((g - 85) + (255 - r), 4),
FIXFRAC8(32,170));
713 }
else if ( highest == g) {
721 fl::u8 radj = scale8( qsub8(171,r), 47);
722 fl::u8 gadj = scale8( qsub8(g,171), 96);
723 fl::u8 rgadj = radj + gadj;
724 fl::u8 hueadv = rgadj / 2;
735 h += scale8( qsub8(b, 85),
FIXFRAC8(8,42));
745 h += scale8( qsub8(b, 128),
FIXFRAC8(24,128));
746 }
else if ( (b-r) > r) {
753 h += scale8( qsub8(r, 85),
FIXFRAC8(32,85));
758 return CHSV( h, s, v);
@ HUE_PURPLE
Purple (270°)
fl::UISlider offset("Offset", 0.0f, 0.0f, 1.0f, 0.01f)
Internal FastLED header for implementation files.
void hsv2rgb_fullspectrum(const CHSV &hsv, CRGB &rgb) FL_NO_EXCEPT
Converts an HSV value to RGB using the algorithm from here: https://en.wikipedia.org/wiki/HSL_and_HSV...
void hsv2rgb_raw(const CHSV &hsv, CRGB &rgb) FL_NO_EXCEPT
Convert an HSV value to RGB using a mathematically straight spectrum.
CHSV rgb2hsv_approximate(const CRGB &rgb) FL_NO_EXCEPT
Recover approximate HSV values from RGB.
CRGB hsv2rgb_rainbow(const CHSV &hsv) FL_NO_EXCEPT
CRGB hsv2rgb_spectrum(const CHSV &hsv) FL_NO_EXCEPT
Inline version of hsv2rgb_spectrum which returns a CRGB object.
#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 CHSV &hsv, CRGB &rgb) FL_NO_EXCEPT
HSV to RGB implementation in raw C, for the AVR platform only.
void hsv2rgb_raw_C(const CHSV &hsv, CRGB &rgb) FL_NO_EXCEPT
HSV to RGB implementation in raw C, platform independent.
#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.
constexpr common_type_t< T, U > max(T a, U b) FL_NO_EXCEPT
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NO_EXCEPT