1#define FASTLED_INTERNAL
2#define __PROG_TYPES_COMPAT__
12FASTLED_NAMESPACE_BEGIN
17 const struct CRGB& color)
19 for(
int i = 0; i < numToFill; ++i) {
20 targetArray[i] = color;
25 const struct CHSV& color)
27 for(
int i = 0; i < numToFill; ++i) {
28 targetArray[i] = color;
47 for(
int i = 0; i < numToFill; ++i) {
61 for(
int i = 0; i < numToFill; ++i) {
70 if (numToFill == 0)
return;
77 const uint16_t hueChange = 65535 / (uint16_t)numToFill;
78 uint16_t hueOffset = 0;
80 for (
int i = 0; i < numToFill; ++i) {
82 if (reversed) hueOffset -= hueChange;
83 else hueOffset += hueChange;
84 hsv.
hue = initialhue + (uint8_t)(hueOffset >> 8);
90 if (numToFill == 0)
return;
97 const uint16_t hueChange = 65535 / (uint16_t) numToFill;
98 uint16_t hueOffset = 0;
100 for (
int i = 0; i < numToFill; ++i) {
101 targetArray[i] = hsv;
102 if (reversed) hueOffset -= hueChange;
103 else hueOffset += hueChange;
104 hsv.
hue = initialhue + (uint8_t)(hueOffset >> 8);
110 uint16_t startpos,
CRGB startcolor,
111 uint16_t endpos,
CRGB endcolor )
114 if( endpos < startpos ) {
117 endcolor = startcolor;
127 rdistance87 = (endcolor.
r - startcolor.
r) << 7;
128 gdistance87 = (endcolor.
g - startcolor.
g) << 7;
129 bdistance87 = (endcolor.
b - startcolor.
b) << 7;
131 uint16_t pixeldistance = endpos - startpos;
132 int16_t divisor = pixeldistance ? pixeldistance : 1;
134 saccum87 rdelta87 = rdistance87 / divisor;
135 saccum87 gdelta87 = gdistance87 / divisor;
136 saccum87 bdelta87 = bdistance87 / divisor;
145 for( uint16_t i = startpos; i <= endpos; ++i) {
146 leds[i] =
CRGB( r88 >> 8, g88 >> 8, b88 >> 8);
190 uint16_t last = numLeds - 1;
197 uint16_t half = (numLeds / 2);
198 uint16_t last = numLeds - 1;
205 uint16_t onethird = (numLeds / 3);
206 uint16_t twothirds = ((numLeds * 2) / 3);
207 uint16_t last = numLeds - 1;
218 for( uint16_t i = 0; i < num_leds; ++i) {
236 nscale8( leds, num_leds, 255 - fadeBy);
241 nscale8( leds, num_leds, 255 - fadeBy);
248 nscale8( leds, num_leds, scale);
253 for( uint16_t i = 0; i < num_leds; ++i) {
265 for( uint16_t i = 0; i < numLeds; ++i) {
268 leds[i].
b =
scale8 ( leds[i].b, fb);
275 if( amountOfOverlay == 0) {
279 if( amountOfOverlay == 255) {
286 fract8 amountOfKeep = 255 - amountOfOverlay;
310 for( uint16_t i = count; i; --i) {
311 nblend( *existing, *overlay, amountOfOverlay);
320 nblend( nu, p2, amountOfP2);
326 for( uint16_t i = 0; i < count; ++i) {
327 dest[i] =
blend(src1[i], src2[i], amountOfsrc2);
336 if( amountOfOverlay == 0) {
340 if( amountOfOverlay == 255) {
345 fract8 amountOfKeep = 255 - amountOfOverlay;
347 uint8_t huedelta8 = overlay.
hue - existing.
hue;
351 if( huedelta8 > 127) {
358 if( huedelta8 < 128) {
364 existing.
hue = existing.
hue +
scale8( huedelta8, amountOfOverlay);
368 huedelta8 = -huedelta8;
369 existing.
hue = existing.
hue -
scale8( huedelta8, amountOfOverlay);
386 if(existing == overlay)
return;
387 for( uint16_t i = count; i; --i) {
388 nblend( *existing, *overlay, amountOfOverlay, directionCode);
397 nblend( nu, p2, amountOfP2, directionCode);
403 for( uint16_t i = 0; i < count; ++i) {
404 dest[i] =
blend(src1[i], src2[i], amountOfsrc2, directionCode);
413uint16_t
XY( uint8_t, uint8_t);
431 uint8_t keep = 255 - blur_amount;
432 uint8_t seep = blur_amount >> 1;
434 for( uint16_t i = 0; i < numLeds; ++i) {
440 if( i) leds[i-1] += part;
448 blurRows(leds, width, height, blur_amount);
460 uint8_t keep = 255 - blur_amount;
461 uint8_t seep = blur_amount >> 1;
462 for( uint8_t row = 0; row < height; row++) {
464 for( uint8_t i = 0; i < width; i++) {
465 CRGB cur = leds[
XY(i,row)];
470 if( i) leds[
XY(i-1,row)] += part;
471 leds[
XY(i,row)] = cur;
481 uint8_t keep = 255 - blur_amount;
482 uint8_t seep = blur_amount >> 1;
483 for( uint8_t col = 0; col < width; ++col) {
485 for( uint8_t i = 0; i < height; ++i) {
486 CRGB cur = leds[
XY(col,i)];
491 if( i) leds[
XY(col,i-1)] += part;
492 leds[
XY(col,i)] = cur;
522 uint8_t heatramp = t192 & 0x3F;
530 heatcolor.
b = heatramp;
532 }
else if( t192 & 0x40 ) {
535 heatcolor.
g = heatramp;
540 heatcolor.
r = heatramp;
553inline uint8_t
lsrX4( uint8_t dividend) __attribute__((always_inline));
554inline uint8_t
lsrX4( uint8_t dividend)
571 index =
map8(index, 0, 239);
575 uint8_t hi4 =
lsrX4(index);
576 uint8_t lo4 = index & 0x0F;
582 uint8_t hi4XsizeofCRGB = hi4 *
sizeof(
CRGB);
584 const CRGB* entry = (
CRGB*)( (uint8_t*)(&(pal[0])) + hi4XsizeofCRGB);
588 uint8_t red1 = entry->
red;
589 uint8_t green1 = entry->green;
590 uint8_t blue1 = entry->blue;
601 uint8_t f2 = lo4 << 4;
602 uint8_t f1 = 255 - f2;
605 uint8_t red2 = entry->red;
610 uint8_t green2 = entry->green;
615 uint8_t blue2 = entry->blue;
623 if( brightness != 255) {
630#if !(FASTLED_SCALE8_FIXED==1)
636#if !(FASTLED_SCALE8_FIXED==1)
642#if !(FASTLED_SCALE8_FIXED==1)
654 return CRGB( red1, green1, blue1);
660 index =
map8(index, 0, 239);
664 uint8_t hi4 =
lsrX4(index);
665 uint8_t lo4 = index & 0x0F;
667 CRGB entry = FL_PGM_READ_DWORD_NEAR( &(pal[0]) + hi4 );
670 uint8_t red1 = entry.
red;
671 uint8_t green1 = entry.
green;
672 uint8_t blue1 = entry.
blue;
679 entry = FL_PGM_READ_DWORD_NEAR( &(pal[0]) );
681 entry = FL_PGM_READ_DWORD_NEAR( &(pal[1]) + hi4 );
684 uint8_t f2 = lo4 << 4;
685 uint8_t f1 = 255 - f2;
687 uint8_t red2 = entry.
red;
692 uint8_t green2 = entry.
green;
697 uint8_t blue2 = entry.
blue;
705 if( brightness != 255) {
712#if !(FASTLED_SCALE8_FIXED==1)
718#if !(FASTLED_SCALE8_FIXED==1)
724#if !(FASTLED_SCALE8_FIXED==1)
736 return CRGB( red1, green1, blue1);
743 index =
map8(index, 0, 247);
754 uint8_t lo3 = index & 0x07;
760 uint8_t hi5XsizeofCRGB = hi5 *
sizeof(
CRGB);
762 const CRGB* entry = (
CRGB*)( (uint8_t*)(&(pal[0])) + hi5XsizeofCRGB);
764 uint8_t red1 = entry->
red;
765 uint8_t green1 = entry->green;
766 uint8_t blue1 = entry->blue;
778 uint8_t f2 = lo3 << 5;
779 uint8_t f1 = 255 - f2;
781 uint8_t red2 = entry->
red;
786 uint8_t green2 = entry->green;
791 uint8_t blue2 = entry->blue;
800 if( brightness != 255) {
807#if !(FASTLED_SCALE8_FIXED==1)
813#if !(FASTLED_SCALE8_FIXED==1)
819#if !(FASTLED_SCALE8_FIXED==1)
831 return CRGB( red1, green1, blue1);
838 index =
map8(index, 0, 247);
849 uint8_t lo3 = index & 0x07;
851 CRGB entry = FL_PGM_READ_DWORD_NEAR( &(pal[0]) + hi5);
853 uint8_t red1 = entry.
red;
854 uint8_t green1 = entry.
green;
855 uint8_t blue1 = entry.
blue;
862 entry = FL_PGM_READ_DWORD_NEAR( &(pal[0]) );
864 entry = FL_PGM_READ_DWORD_NEAR( &(pal[1]) + hi5 );
867 uint8_t f2 = lo3 << 5;
868 uint8_t f1 = 255 - f2;
870 uint8_t red2 = entry.
red;
875 uint8_t green2 = entry.
green;
880 uint8_t blue2 = entry.
blue;
888 if( brightness != 255) {
895#if !(FASTLED_SCALE8_FIXED==1)
901#if !(FASTLED_SCALE8_FIXED==1)
907#if !(FASTLED_SCALE8_FIXED==1)
919 return CRGB( red1, green1, blue1);
926 const CRGB* entry = &(pal[0]) + index;
928 uint8_t red = entry->
red;
929 uint8_t green = entry->
green;
930 uint8_t blue = entry->
blue;
932 if( brightness != 255) {
940 return CRGB( red, green, blue);
947 index =
map8(index, 0, 239);
951 uint8_t hi4 =
lsrX4(index);
952 uint8_t lo4 = index & 0x0F;
955 const CHSV* entry = &(pal[0]) + hi4;
957 uint8_t hue1 = entry->
hue;
958 uint8_t sat1 = entry->
sat;
959 uint8_t val1 = entry->
val;
971 uint8_t f2 = lo4 << 4;
972 uint8_t f1 = 255 - f2;
974 uint8_t hue2 = entry->
hue;
975 uint8_t sat2 = entry->
sat;
976 uint8_t val2 = entry->
val;
989 if( sat1 == 0 || val1 == 0) {
995 if( sat2 == 0 || val2 == 0) {
1012 uint8_t deltaHue = (uint8_t)(hue2 - hue1);
1013 if( deltaHue & 0x80 ) {
1015 hue1 -=
scale8( 256 - deltaHue, f2);
1018 hue1 +=
scale8( deltaHue, f2);
1024 if( brightness != 255) {
1028 return CHSV( hue1, sat1, val1);
1035 index =
map8(index, 0, 247);
1038 uint8_t hi5 = index;
1046 uint8_t lo3 = index & 0x07;
1048 uint8_t hi5XsizeofCHSV = hi5 *
sizeof(
CHSV);
1049 const CHSV* entry = (
CHSV*)( (uint8_t*)(&(pal[0])) + hi5XsizeofCHSV);
1051 uint8_t hue1 = entry->
hue;
1052 uint8_t sat1 = entry->sat;
1053 uint8_t val1 = entry->val;
1065 uint8_t f2 = lo3 << 5;
1066 uint8_t f1 = 255 - f2;
1068 uint8_t hue2 = entry->hue;
1069 uint8_t sat2 = entry->sat;
1070 uint8_t val2 = entry->val;
1083 if( sat1 == 0 || val1 == 0) {
1089 if( sat2 == 0 || val2 == 0) {
1106 uint8_t deltaHue = (uint8_t)(hue2 - hue1);
1107 if( deltaHue & 0x80 ) {
1109 hue1 -=
scale8( 256 - deltaHue, f2);
1112 hue1 +=
scale8( deltaHue, f2);
1118 if( brightness != 255) {
1122 return CHSV( hue1, sat1, val1);
1127 CHSV hsv = *( &(pal[0]) + index );
1129 if( brightness != 255) {
1139 for(
int i = 0; i < 256; ++i) {
1146 for(
int i = 0; i < 256; ++i) {
1154 for( uint8_t i = 0; i < 16; ++i) {
1156 destpal32[j+0] = srcpal16[i];
1157 destpal32[j+1] = srcpal16[i];
1163 for( uint8_t i = 0; i < 16; ++i) {
1165 destpal32[j+0] = srcpal16[i];
1166 destpal32[j+1] = srcpal16[i];
1172 for(
int i = 0; i < 256; ++i) {
1179 for(
int i = 0; i < 256; ++i) {
1200 uint8_t changes = 0;
1202 p1 = (uint8_t*)current.
entries;
1203 p2 = (uint8_t*)target.
entries;
1206 for( uint8_t i = 0; i < totalChannels; ++i) {
1208 if( p1[i] == p2[i] ) {
continue; }
1211 if( p1[i] < p2[i] ) { ++p1[i]; ++changes; }
1215 if( p1[i] > p2[i] ) {
1217 if( p1[i] > p2[i] ) { --p1[i]; }
1221 if( changes >= maxChanges) {
break; }
1230 orig = (float)(brightness) / (255.0);
1231 adj = pow( orig, gamma) * (255.0);
1232 uint8_t result = (uint8_t)(adj);
1233 if( (brightness > 0) && (result == 0)) {
1271 for( uint16_t i = 0; i < count; ++i) {
1278 for( uint16_t i = 0; i < count; ++i) {
1284FASTLED_NAMESPACE_END
CFastLED FastLED
Global LED strip management instance.
central include file for FastLED, defines the CFastLED class/object
HSV color palette with 16 discrete values.
HSV color palette with 256 discrete values.
HSV color palette with 32 discrete values.
RGB color palette with 16 discrete values.
CRGB entries[16]
the color entries that make up the palette
RGB color palette with 256 discrete values.
RGB color palette with 32 discrete values.
uint16_t XY(uint8_t, uint8_t)
Forward declaration of the function "XY" which must be provided by the application for use in two-dim...
void nscale8_raw(CRGB *leds, uint16_t num_leds, uint8_t scale)
Unused alias of nscale8(CRGB*, uint16_t, uint8_t)
uint8_t lsrX4(uint8_t dividend)
Helper function to divide a number by 16, aka four logical shift right (LSR)'s.
CRGB & nblend(CRGB &existing, const CRGB &overlay, fract8 amountOfOverlay)
Destructively modifies one color, blending in a given fraction of an overlay color.
CRGB blend(const CRGB &p1, const CRGB &p2, fract8 amountOfP2)
Computes a new color blended some fraction of the way between two other colors.
void blurRows(CRGB *leds, uint8_t width, uint8_t height, fract8 blur_amount)
Perform a blur1d() on every row of a rectangular matrix.
void blur1d(CRGB *leds, uint16_t numLeds, fract8 blur_amount)
One-dimensional blur filter.
void blurColumns(CRGB *leds, uint8_t width, uint8_t height, fract8 blur_amount)
Perform a blur1d() on every column of a rectangular matrix.
void blur2d(CRGB *leds, uint8_t width, uint8_t height, fract8 blur_amount)
Two-dimensional blur filter.
void fadeToBlackBy(CRGB *leds, uint16_t num_leds, uint8_t fadeBy)
Reduce the brightness of an array of pixels all at once.
void nscale8_video(CRGB *leds, uint16_t num_leds, uint8_t scale)
Scale the brightness of an array of pixels all at once.
void fade_raw(CRGB *leds, uint16_t num_leds, uint8_t fadeBy)
Reduce the brightness of an array of pixels all at once.
void fadeLightBy(CRGB *leds, uint16_t num_leds, uint8_t fadeBy)
Reduce the brightness of an array of pixels all at once.
void nscale8(CRGB *leds, uint16_t num_leds, uint8_t scale)
Scale the brightness of an array of pixels all at once.
void fadeUsingColor(CRGB *leds, uint16_t numLeds, const CRGB &colormask)
Reduce the brightness of an array of pixels as thought it were seen through a transparent filter with...
void fade_video(CRGB *leds, uint16_t num_leds, uint8_t fadeBy)
Reduce the brightness of an array of pixels all at once.
TGradientDirectionCode
Hue direction for calculating fill gradients.
void fill_rainbow(struct CRGB *targetArray, int numToFill, uint8_t initialhue, uint8_t deltahue)
Fill a range of LEDs with a rainbow of colors.
void fill_gradient(T *targetArray, uint16_t startpos, CHSV startcolor, uint16_t endpos, CHSV endcolor, TGradientDirectionCode directionCode=SHORTEST_HUES)
Fill a range of LEDs with a smooth HSV gradient between two HSV colors.
#define saccum87
ANSI: signed short _Accum.
void fill_gradient_RGB(CRGB *leds, uint16_t startpos, CRGB startcolor, uint16_t endpos, CRGB endcolor)
Fill a range of LEDs with a smooth RGB gradient between two RGB colors.
void fill_rainbow_circular(struct CRGB *targetArray, int numToFill, uint8_t initialhue, bool reversed)
Fill a range of LEDs with a rainbow of colors, so that the hues are continuous between the end of the...
void fill_solid(struct CRGB *targetArray, int numToFill, const struct CRGB &color)
Fill a range of LEDs with a solid color.
CRGB HeatColor(uint8_t temperature)
Approximates a "black body radiation" spectrum for a given "heat" level.
@ LONGEST_HUES
Hue goes whichever way is longest.
@ FORWARD_HUES
Hue always goes clockwise around the color wheel.
@ SHORTEST_HUES
Hue goes whichever way is shortest.
@ BACKWARD_HUES
Hue always goes counter-clockwise around the color wheel.
uint16_t accum88
ANSI: unsigned short _Accum. 8 bits int, 8 bits fraction.
uint8_t fract8
ANSI: unsigned short _Fract.
CRGB & napplyGamma_video(CRGB &rgb, float gamma)
Destructively applies a gamma adjustment to a color.
uint8_t applyGamma_video(uint8_t brightness, float gamma)
Applies a gamma adjustment to a color channel.
LIB8STATIC uint8_t map8(uint8_t in, uint8_t rangeStart, uint8_t rangeEnd)
Map from one full-range 8-bit value into a narrower range of 8-bit values, possibly a range of hues.
LIB8STATIC uint8_t blend8(uint8_t a, uint8_t b, uint8_t amountOfB)
Blend a variable proportion (0-255) of one byte to another.
uint32_t TProgmemRGBPalette32[32]
CRGBPalette32 entries stored in PROGMEM memory.
uint32_t TProgmemRGBPalette16[16]
CRGBPalette16 entries stored in PROGMEM memory.
void nblendPaletteTowardPalette(CRGBPalette16 ¤t, CRGBPalette16 &target, uint8_t maxChanges)
Alter one palette by making it slightly more like a "target palette".
TBlendType
Color interpolation options for palette.
CRGB ColorFromPalette(const CRGBPalette16 &pal, uint8_t index, uint8_t brightness, TBlendType blendType)
Get a color from a palette.
@ NOBLEND
No interpolation between palette entries.
@ LINEARBLEND_NOWRAP
Linear interpolation between palette entries, but no wrap-around.
void UpscalePalette(const struct CRGBPalette16 &srcpal16, struct CRGBPalette256 &destpal256)
Convert a 16-entry palette to a 256-entry palette.
@ HUE_PURPLE
Purple (270°)
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 ...
Representation of an HSV pixel (hue, saturation, value (aka brightness)).
uint8_t sat
Color saturation.
uint8_t value
Color value (brightness).
uint8_t val
Color value (brightness).
Representation of an RGB pixel (Red, Green, Blue)
CRGB & nscale8_video(uint8_t scaledown)
Scale down a RGB to N/256ths of it's current brightness using "video" dimming rules.
uint8_t r
Red channel value.
CRGB & nscale8(uint8_t scaledown)
Scale down a RGB to N/256ths of its current brightness, using "plain math" dimming rules.
uint8_t g
Green channel value.
uint8_t red
Red channel value.
uint8_t blue
Blue channel value.
uint8_t b
Blue channel value.
uint8_t green
Green channel value.