4#include "platforms/is_platform.h"
7#define FASTLED_INTERNAL
21#if defined(FL_IS_AVR) && !defined(FL_IS_AVR_ATTINY)
35#define APPLY_DIMMING(X) (X)
39#define HSV_SECTION_6 (0x20)
43#define HSV_SECTION_3 (0x40)
60 fl::u8 saturation = hsv.sat;
65 fl::u8 brightness_floor = (value * invsat) / 256;
70 fl::u8 color_amplitude = value - brightness_floor;
110 fl::u8 rampup_amp_adj = (rampup * color_amplitude) / (256 / 4);
111 fl::u8 rampdown_amp_adj = (rampdown * color_amplitude) / (256 / 4);
114 fl::u8 rampup_adj_with_floor = rampup_amp_adj + brightness_floor;
115 fl::u8 rampdown_adj_with_floor = rampdown_amp_adj + brightness_floor;
121 rgb.r = brightness_floor;
122 rgb.g = rampdown_adj_with_floor;
123 rgb.b = rampup_adj_with_floor;
126 rgb.r = rampup_adj_with_floor;
127 rgb.g = brightness_floor;
128 rgb.b = rampdown_adj_with_floor;
132 rgb.r = rampdown_adj_with_floor;
133 rgb.g = rampup_adj_with_floor;
134 rgb.b = brightness_floor;
140#if defined(FL_IS_AVR) && !defined(FL_IS_AVR_ATTINY)
146 saturation = hsv.sat;
150 saturation = 255 - saturation;
161 "mul %[value], %[invsat] \n"
162 "mov %[brightness_floor], r1 \n"
163 : [brightness_floor]
"=r" (brightness_floor)
164 : [value]
"r" (value),
165 [invsat]
"r" (invsat)
172 fl::u8 color_amplitude = value - brightness_floor;
185 "mul %[rampup], %[color_amplitude] \n"
186 "mov %[rampup_amp_adj], r1 \n"
188 "mul %[rampup], %[color_amplitude] \n"
189 "mov %[rampdown_amp_adj], r1 \n"
190 : [rampup_amp_adj]
"=&r" (rampup_amp_adj),
191 [rampdown_amp_adj]
"=&r" (rampdown_amp_adj),
192 [rampup]
"+r" (rampup)
193 : [color_amplitude]
"r" (color_amplitude)
199 fl::u8 rampup_adj_with_floor = rampup_amp_adj + brightness_floor;
200 fl::u8 rampdown_adj_with_floor = rampdown_amp_adj + brightness_floor;
209 asm volatile(
"" : : :
"r26",
"r27" );
214 rgb.r = rampup_adj_with_floor;
215 rgb.g = brightness_floor;
216 rgb.b = rampdown_adj_with_floor;
220 rgb.r = brightness_floor;
221 rgb.g = rampdown_adj_with_floor;
222 rgb.b = rampup_adj_with_floor;
225 rgb.r = rampdown_adj_with_floor;
226 rgb.g = rampup_adj_with_floor;
227 rgb.b = brightness_floor;
240 hsv2.hue = scale8( hsv2.hue, 191);
252#define FORCE_REFERENCE(var) asm volatile( "" : : "r" (var) )
299#if defined(FL_IS_AVR)
314 fl::u8 third = scale8( offset8, (256 / 3));
318 if( ! (
hue & 0x80) ) {
320 if( ! (
hue & 0x40) ) {
323 if( ! (
hue & 0x20) ) {
342 fl::u8 twothirds = scale8( offset8, ((256 * 2) / 3));
351 if( ! (
hue & 0x20) ) {
356 fl::u8 twothirds = scale8( offset8, ((256 * 2) / 3));
357 r = K171 - twothirds;
380 if( ! (
hue & 0x40) ) {
382 if( ! (
hue & 0x20) ) {
388 fl::u8 twothirds = scale8( offset8, ((256 * 2) / 3));
389 g = K171 - twothirds;
402 if( ! (
hue & 0x20) ) {
425 if( Gscale ) g = scale8_video_LEAVING_R1_DIRTY( g, Gscale);
431 r = 255; b = 255; g = 255;
434 desat = scale8_video( desat, desat);
436 fl::u8 satscale = 255 - desat;
440#if (FASTLED_SCALE8_FIXED==1)
441 r = scale8_LEAVING_R1_DIRTY( r, satscale);
443 g = scale8_LEAVING_R1_DIRTY( g, satscale);
445 b = scale8_LEAVING_R1_DIRTY( b, satscale);
449 if( r ) r = scale8( r, satscale) + 1;
450 if( g ) g = scale8( g, satscale) + 1;
451 if( b ) b = scale8( b, satscale) + 1;
453 fl::u8 brightness_floor = desat;
454 r += brightness_floor;
455 g += brightness_floor;
456 b += brightness_floor;
463 val = scale8_video_LEAVING_R1_DIRTY( val, val);
468#if (FASTLED_SCALE8_FIXED==1)
469 r = scale8_LEAVING_R1_DIRTY( r, val);
471 g = scale8_LEAVING_R1_DIRTY( g, val);
473 b = scale8_LEAVING_R1_DIRTY( b, val);
477 if( r ) r = scale8( r, val) + 1;
478 if( g ) g = scale8( g, val) + 1;
479 if( b ) b = scale8( b, val) + 1;
496 const auto f = [](
const int n,
const fl::u8 h) -> fl::u32 {
497 constexpr int kZero = 0 << 8;
498 constexpr int kOne = 1 << 8;
499 constexpr int kFour = 4 << 8;
500 constexpr int kSix = 6 << 8;
502 const int k = ((n << 8) + 6*h) % kSix;
503 const int k2 = kFour - k;
507 const fl::u32 chroma = hsv.v * hsv.s / 255;
508 rgb.r = hsv.v - ((chroma * f(5, hsv.h)) >> 8);
509 rgb.g = hsv.v - ((chroma * f(3, hsv.h)) >> 8);
510 rgb.b = hsv.v - ((chroma * f(1, hsv.h)) >> 8);
522 for(
int i = 0; i < numLeds; ++i) {
528 for(
int i = 0; i < numLeds; ++i) {
534 for(
int i = 0; i < numLeds; ++i) {
540 for (
int i = 0; i < numLeds; ++i) {
546#define FIXFRAC8(N,D) (((N)*256)/(D))
560 if( r < desat) desat = r;
561 if( g < desat) desat = g;
562 if( b < desat) desat = b;
580 s = 255 - fl::sqrt16( (255-s) * 256);
590 if( (r + g + b) == 0) {
592 return CHSV( 0, 0, 255 - s);
598 fl::u32 scaleup = 65535 / (s);
599 r = ((fl::u32)(r) * scaleup) / 256;
600 g = ((fl::u32)(g) * scaleup) / 256;
601 b = ((fl::u32)(b) * scaleup) / 256;
607 fl::u16 total = r + g + b;
613 if( total == 0) total = 1;
614 fl::u32 scaleup = 65535 / (total);
615 r = ((fl::u32)(r) * scaleup) / 256;
616 g = ((fl::u32)(g) * scaleup) / 256;
617 b = ((fl::u32)(b) * scaleup) / 256;
626 v = qadd8(desat,total);
628 if( v != 255) v = fl::sqrt16( v * 256);
666 if( g > highest) highest = g;
667 if( b > highest) highest = b;
675 h += scale8( qsub8(r, 128),
FIXFRAC8(48,128));
676 }
else if ( (r - g) > g) {
683 h += scale8( qsub8((g - 85) + (171 - r), 4),
FIXFRAC8(32,85));
686 }
else if ( highest == g) {
694 fl::u8 radj = scale8( qsub8(171,r), 47);
695 fl::u8 gadj = scale8( qsub8(g,171), 96);
696 fl::u8 rgadj = radj + gadj;
697 fl::u8 hueadv = rgadj / 2;
708 h += scale8( qsub8(b, 85),
FIXFRAC8(8,42));
718 h += scale8( qsub8(b, 128),
FIXFRAC8(24,128));
719 }
else if ( (b-r) > r) {
726 h += scale8( qsub8(r, 85),
FIXFRAC8(32,85));
731 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.
CRGB hsv2rgb_spectrum(const CHSV &hsv)
Inline version of hsv2rgb_spectrum which returns a CRGB object.
CHSV rgb2hsv_approximate(const CRGB &rgb)
Recover approximate HSV values from RGB.
CRGB hsv2rgb_rainbow(const CHSV &hsv)
void hsv2rgb_raw(const CHSV &hsv, CRGB &rgb)
Convert an HSV value to RGB using a mathematically straight spectrum.
void hsv2rgb_fullspectrum(const CHSV &hsv, CRGB &rgb)
Converts an HSV value to RGB using the algorithm from here: https://en.wikipedia.org/wiki/HSL_and_HSV...
void hsv2rgb_raw_C(const CHSV &hsv, CRGB &rgb)
HSV to RGB implementation in raw C, platform independent.
#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.
#define HSV_SECTION_3
Divide the color wheel into four sections, 64 elements each.
void hsv2rgb_raw_avr(const CHSV &hsv, CRGB &rgb)
HSV to RGB implementation in raw C, for the AVR platform only.
Functions to convert from the HSV colorspace to the RGB colorspace.
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NOEXCEPT
constexpr common_type_t< T, U > max(T a, U b) FL_NOEXCEPT