1#define FASTLED_INTERNAL
2#define __PROG_TYPES_COMPAT__
15#if __has_include(<assert.h>)
18#define assert(x) ((void)0)
24uint16_t XY(uint8_t x, uint8_t y) __attribute__((weak));
26uint16_t XY(uint8_t x, uint8_t y) {
43 uint16_t xy_legacy_wrapper(uint16_t x, uint16_t y,
44 uint16_t width, uint16_t height) {
45 FASTLED_UNUSED(width);
46 FASTLED_UNUSED(height);
53 const struct CRGB& color)
55 for(
int i = 0; i < numToFill; ++i) {
56 targetArray[i] = color;
61 const struct CHSV& color)
63 for(
int i = 0; i < numToFill; ++i) {
64 targetArray[i] = color;
83 for(
int i = 0; i < numToFill; ++i) {
97 for(
int i = 0; i < numToFill; ++i) {
106 if (numToFill == 0)
return;
109 hsv.
hue = initialhue;
113 const uint16_t hueChange = 65535 / (uint16_t)numToFill;
114 uint16_t hueOffset = 0;
116 for (
int i = 0; i < numToFill; ++i) {
117 targetArray[i] = hsv;
118 if (reversed) hueOffset -= hueChange;
119 else hueOffset += hueChange;
120 hsv.
hue = initialhue + (uint8_t)(hueOffset >> 8);
126 if (numToFill == 0)
return;
129 hsv.
hue = initialhue;
133 const uint16_t hueChange = 65535 / (uint16_t) numToFill;
134 uint16_t hueOffset = 0;
136 for (
int i = 0; i < numToFill; ++i) {
137 targetArray[i] = hsv;
138 if (reversed) hueOffset -= hueChange;
139 else hueOffset += hueChange;
140 hsv.
hue = initialhue + (uint8_t)(hueOffset >> 8);
146 uint16_t startpos,
CRGB startcolor,
147 uint16_t endpos,
CRGB endcolor )
150 if( endpos < startpos ) {
153 endcolor = startcolor;
163 rdistance87 = (endcolor.
r - startcolor.
r) << 7;
164 gdistance87 = (endcolor.
g - startcolor.
g) << 7;
165 bdistance87 = (endcolor.
b - startcolor.
b) << 7;
167 uint16_t pixeldistance = endpos - startpos;
168 int16_t divisor = pixeldistance ? pixeldistance : 1;
170 saccum87 rdelta87 = rdistance87 / divisor;
171 saccum87 gdelta87 = gdistance87 / divisor;
172 saccum87 bdelta87 = bdistance87 / divisor;
181 for( uint16_t i = startpos; i <= endpos; ++i) {
182 leds[i] =
CRGB( r88 >> 8, g88 >> 8, b88 >> 8);
226 uint16_t last = numLeds - 1;
233 uint16_t half = (numLeds / 2);
234 uint16_t last = numLeds - 1;
241 uint16_t onethird = (numLeds / 3);
242 uint16_t twothirds = ((numLeds * 2) / 3);
243 uint16_t last = numLeds - 1;
254 for( uint16_t i = 0; i < num_leds; ++i) {
272 nscale8( leds, num_leds, 255 - fadeBy);
277 nscale8( leds, num_leds, 255 - fadeBy);
283 for( uint16_t i = 0; i < num_leds; ++i) {
295 for( uint16_t i = 0; i < numLeds; ++i) {
298 leds[i].
b =
scale8 ( leds[i].b, fb);
305 if( amountOfOverlay == 0) {
309 if( amountOfOverlay == 255) {
316 fract8 amountOfKeep = 255 - amountOfOverlay;
340 for( uint16_t i = count; i; --i) {
341 nblend( *existing, *overlay, amountOfOverlay);
350 nblend( nu, p2, amountOfP2);
356 for( uint16_t i = 0; i < count; ++i) {
357 dest[i] =
blend(src1[i], src2[i], amountOfsrc2);
366 if( amountOfOverlay == 0) {
370 if( amountOfOverlay == 255) {
375 fract8 amountOfKeep = 255 - amountOfOverlay;
377 uint8_t huedelta8 = overlay.
hue - existing.
hue;
381 if( huedelta8 > 127) {
388 if( huedelta8 < 128) {
394 existing.
hue = existing.
hue +
scale8( huedelta8, amountOfOverlay);
398 huedelta8 = -huedelta8;
399 existing.
hue = existing.
hue -
scale8( huedelta8, amountOfOverlay);
416 if(existing == overlay)
return;
417 for( uint16_t i = count; i; --i) {
418 nblend( *existing, *overlay, amountOfOverlay, directionCode);
427 nblend( nu, p2, amountOfP2, directionCode);
433 for( uint16_t i = 0; i < count; ++i) {
434 dest[i] =
blend(src1[i], src2[i], amountOfsrc2, directionCode);
456 uint8_t keep = 255 - blur_amount;
457 uint8_t seep = blur_amount >> 1;
459 for( uint16_t i = 0; i < numLeds; ++i) {
465 if( i) leds[i-1] += part;
473 blurRows(leds, width, height, blur_amount, xymap);
474 blurColumns(leds, width, height, blur_amount, xymap);
479 XYMap xy = XYMap::constructWithUserFunction(width, height, xy_legacy_wrapper);
480 blur2d(leds, width, height, blur_amount, xy);
492 uint8_t keep = 255 - blur_amount;
493 uint8_t seep = blur_amount >> 1;
494 for( uint8_t row = 0; row < height; row++) {
496 for( uint8_t i = 0; i < width; i++) {
497 CRGB cur = leds[xyMap.mapToIndex(i,row)];
502 if( i) leds[xyMap.mapToIndex(i-1,row)] += part;
503 leds[xyMap.mapToIndex(i,row)] = cur;
513 uint8_t keep = 255 - blur_amount;
514 uint8_t seep = blur_amount >> 1;
515 for( uint8_t col = 0; col < width; ++col) {
517 for( uint8_t i = 0; i < height; ++i) {
518 CRGB cur = leds[xyMap.mapToIndex(col,i)];
523 if( i) leds[xyMap.mapToIndex(col,i-1)] += part;
524 leds[xyMap.mapToIndex(col,i)] = cur;
554 uint8_t heatramp = t192 & 0x3F;
562 heatcolor.
b = heatramp;
564 }
else if( t192 & 0x40 ) {
567 heatcolor.
g = heatramp;
572 heatcolor.
r = heatramp;
585inline uint8_t
lsrX4( uint8_t dividend) __attribute__((always_inline));
586inline uint8_t
lsrX4( uint8_t dividend)
601 uint8_t index_5bit = (index >> 11);
603 uint8_t offset = (uint8_t)(index >> 3);
605 const CRGB* entry = &(pal[0]) + index_5bit;
606 uint8_t red1 = entry->
red;
607 uint8_t green1 = entry->
green;
608 uint8_t blue1 = entry->
blue;
612 if (index_5bit == 31) {
619 uint8_t f1 = 255 - offset;
625 uint8_t red2 = entry->
red;
626 uint8_t green2 = entry->
green;
627 uint8_t blue2 = entry->
blue;
638 if (brightness != 255) {
641 return CRGB(red1, green1, blue1);
647 index =
map8(index, 0, 239);
651 uint8_t hi4 =
lsrX4(index);
652 uint8_t lo4 = index & 0x0F;
658 uint8_t hi4XsizeofCRGB = hi4 *
sizeof(
CRGB);
660 const CRGB* entry = (
CRGB*)( (uint8_t*)(&(pal[0])) + hi4XsizeofCRGB);
664 uint8_t red1 = entry->
red;
665 uint8_t green1 = entry->green;
666 uint8_t blue1 = entry->blue;
677 uint8_t f2 = lo4 << 4;
678 uint8_t f1 = 255 - f2;
681 uint8_t red2 = entry->red;
686 uint8_t green2 = entry->green;
691 uint8_t blue2 = entry->blue;
699 if( brightness != 255) {
706#if !(FASTLED_SCALE8_FIXED==1)
712#if !(FASTLED_SCALE8_FIXED==1)
718#if !(FASTLED_SCALE8_FIXED==1)
730 return CRGB( red1, green1, blue1);
735 uint8_t index_4bit = index >> 12;
737 uint8_t offset = (uint8_t)(index >> 4);
739 const CRGB* entry = &(pal[0]) + index_4bit;
740 uint8_t red1 = entry->
red;
741 uint8_t green1 = entry->
green;
742 uint8_t blue1 = entry->
blue;
746 if (index_4bit == 15) {
753 uint8_t f1 = 255 - offset;
759 uint8_t red2 = entry->
red;
760 uint8_t green2 = entry->
green;
761 uint8_t blue2 = entry->
blue;
772 if (brightness != 255) {
774 nscale8x3(red1, green1, blue1, brightness);
776 return CRGB(red1, green1, blue1);
782 index =
map8(index, 0, 239);
786 uint8_t hi4 =
lsrX4(index);
787 uint8_t lo4 = index & 0x0F;
792 uint8_t red1 = entry.
red;
793 uint8_t green1 = entry.
green;
794 uint8_t blue1 = entry.
blue;
806 uint8_t f2 = lo4 << 4;
807 uint8_t f1 = 255 - f2;
809 uint8_t red2 = entry.
red;
814 uint8_t green2 = entry.
green;
819 uint8_t blue2 = entry.
blue;
827 if( brightness != 255) {
834#if !(FASTLED_SCALE8_FIXED==1)
840#if !(FASTLED_SCALE8_FIXED==1)
846#if !(FASTLED_SCALE8_FIXED==1)
858 return CRGB( red1, green1, blue1);
865 index =
map8(index, 0, 247);
876 uint8_t lo3 = index & 0x07;
882 uint8_t hi5XsizeofCRGB = hi5 *
sizeof(
CRGB);
884 const CRGB* entry = (
CRGB*)( (uint8_t*)(&(pal[0])) + hi5XsizeofCRGB);
886 uint8_t red1 = entry->
red;
887 uint8_t green1 = entry->green;
888 uint8_t blue1 = entry->blue;
900 uint8_t f2 = lo3 << 5;
901 uint8_t f1 = 255 - f2;
903 uint8_t red2 = entry->
red;
908 uint8_t green2 = entry->green;
913 uint8_t blue2 = entry->blue;
922 if( brightness != 255) {
929#if !(FASTLED_SCALE8_FIXED==1)
935#if !(FASTLED_SCALE8_FIXED==1)
941#if !(FASTLED_SCALE8_FIXED==1)
953 return CRGB( red1, green1, blue1);
960 index =
map8(index, 0, 247);
971 uint8_t lo3 = index & 0x07;
975 uint8_t red1 = entry.
red;
976 uint8_t green1 = entry.
green;
977 uint8_t blue1 = entry.
blue;
989 uint8_t f2 = lo3 << 5;
990 uint8_t f1 = 255 - f2;
992 uint8_t red2 = entry.
red;
997 uint8_t green2 = entry.
green;
1002 uint8_t blue2 = entry.
blue;
1010 if( brightness != 255) {
1017#if !(FASTLED_SCALE8_FIXED==1)
1023#if !(FASTLED_SCALE8_FIXED==1)
1029#if !(FASTLED_SCALE8_FIXED==1)
1041 return CRGB( red1, green1, blue1);
1048 const CRGB* entry = &(pal[0]) + index;
1050 uint8_t red = entry->
red;
1051 uint8_t green = entry->
green;
1052 uint8_t blue = entry->
blue;
1054 if( brightness != 255) {
1062 return CRGB( red, green, blue);
1067 uint8_t index_8bit = index >> 8;
1069 uint8_t offset = index & 0xff;
1071 const CRGB* entry = &(pal[0]) + index_8bit;
1072 uint8_t red1 = entry->
red;
1073 uint8_t green1 = entry->
green;
1074 uint8_t blue1 = entry->
blue;
1078 if (index_8bit == 255) {
1085 uint8_t f1 = 255 - offset;
1091 uint8_t red2 = entry->
red;
1092 uint8_t green2 = entry->
green;
1093 uint8_t blue2 = entry->
blue;
1104 if (brightness != 255) {
1106 nscale8x3(red1, green1, blue1, brightness);
1108 return CRGB(red1, green1, blue1);
1116 index =
map8(index, 0, 239);
1120 uint8_t hi4 =
lsrX4(index);
1121 uint8_t lo4 = index & 0x0F;
1124 const CHSV* entry = &(pal[0]) + hi4;
1126 uint8_t hue1 = entry->
hue;
1127 uint8_t sat1 = entry->
sat;
1128 uint8_t val1 = entry->
val;
1140 uint8_t f2 = lo4 << 4;
1141 uint8_t f1 = 255 - f2;
1143 uint8_t hue2 = entry->
hue;
1144 uint8_t sat2 = entry->
sat;
1145 uint8_t val2 = entry->
val;
1158 if( sat1 == 0 || val1 == 0) {
1164 if( sat2 == 0 || val2 == 0) {
1181 uint8_t deltaHue = (uint8_t)(hue2 - hue1);
1182 if( deltaHue & 0x80 ) {
1184 hue1 -=
scale8( 256 - deltaHue, f2);
1187 hue1 +=
scale8( deltaHue, f2);
1193 if( brightness != 255) {
1197 return CHSV( hue1, sat1, val1);
1204 index =
map8(index, 0, 247);
1207 uint8_t hi5 = index;
1215 uint8_t lo3 = index & 0x07;
1217 uint8_t hi5XsizeofCHSV = hi5 *
sizeof(
CHSV);
1218 const CHSV* entry = (
CHSV*)( (uint8_t*)(&(pal[0])) + hi5XsizeofCHSV);
1220 uint8_t hue1 = entry->hue;
1221 uint8_t sat1 = entry->sat;
1222 uint8_t val1 = entry->val;
1234 uint8_t f2 = lo3 << 5;
1235 uint8_t f1 = 255 - f2;
1237 uint8_t hue2 = entry->hue;
1238 uint8_t sat2 = entry->sat;
1239 uint8_t val2 = entry->val;
1252 if( sat1 == 0 || val1 == 0) {
1258 if( sat2 == 0 || val2 == 0) {
1275 uint8_t deltaHue = (uint8_t)(hue2 - hue1);
1276 if( deltaHue & 0x80 ) {
1278 hue1 -=
scale8( 256 - deltaHue, f2);
1281 hue1 +=
scale8( deltaHue, f2);
1287 if( brightness != 255) {
1291 return CHSV( hue1, sat1, val1);
1296 CHSV hsv = *( &(pal[0]) + index );
1298 if( brightness != 255) {
1308 for(
int i = 0; i < 256; ++i) {
1315 for(
int i = 0; i < 256; ++i) {
1323 for( uint8_t i = 0; i < 16; ++i) {
1325 destpal32[j+0] = srcpal16[i];
1326 destpal32[j+1] = srcpal16[i];
1332 for( uint8_t i = 0; i < 16; ++i) {
1334 destpal32[j+0] = srcpal16[i];
1335 destpal32[j+1] = srcpal16[i];
1341 for(
int i = 0; i < 256; ++i) {
1348 for(
int i = 0; i < 256; ++i) {
1369 uint8_t changes = 0;
1371 p1 = (uint8_t*)current.
entries;
1372 p2 = (uint8_t*)target.
entries;
1375 for( uint8_t i = 0; i < totalChannels; ++i) {
1377 if( p1[i] == p2[i] ) {
continue; }
1380 if( p1[i] < p2[i] ) { ++p1[i]; ++changes; }
1384 if( p1[i] > p2[i] ) {
1386 if( p1[i] > p2[i] ) { --p1[i]; }
1390 if( changes >= maxChanges) {
break; }
1399 orig = (float)(brightness) / (255.0);
1400 adj = pow( orig, gamma) * (255.0);
1401 uint8_t result = (uint8_t)(adj);
1402 if( (brightness > 0) && (result == 0)) {
1440 for( uint16_t i = 0; i < count; ++i) {
1447 for( uint16_t i = 0; i < count; ++i) {
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.
uint8_t lsrX4(uint8_t dividend)
Helper function to divide a number by 16, aka four logical shift right (LSR)'s.
uint32_t TProgmemRGBPalette32[32]
CRGBPalette32 entries stored in PROGMEM memory.
uint32_t TProgmemRGBPalette16[16]
CRGBPalette16 entries stored in PROGMEM memory.
#define FL_PGM_READ_DWORD_NEAR(x)
Read a double word (32-bit) from PROGMEM memory.
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, const XYMap &xyMap)
Perform a blur1d() on every row of a rectangular matrix.
void blurColumns(CRGB *leds, uint8_t width, uint8_t height, fract8 blur_amount, const XYMap &xyMap)
Perform a blur1d() on every column of a rectangular matrix.
void blur1d(CRGB *leds, uint16_t numLeds, fract8 blur_amount)
One-dimensional blur filter.
void blur2d(CRGB *leds, uint8_t width, uint8_t height, fract8 blur_amount, const XYMap &xymap)
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.
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 ColorFromPaletteExtended(const CRGBPalette32 &pal, uint16_t index, uint8_t brightness, TBlendType blendType)
Same as ColorFromPalette, but higher precision.
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 class CRGBPalette16 &srcpal16, class 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 void nscale8x3(uint8_t &r, uint8_t &g, uint8_t &b, fract8 scale)
Scale three one-byte values by a fourth one, which is treated as the numerator of a fraction whose de...
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 void nscale8x3_video(uint8_t &r, uint8_t &g, uint8_t &b, fract8 scale)
Scale three one-byte values by a fourth one, which is treated as the numerator of a fraction whose de...
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 FASTLED_NAMESPACE_END
End of the FastLED namespace.
#define FASTLED_NAMESPACE_BEGIN
Start of the FastLED namespace.
Implements a simple red square effect for 2D LED grids.
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)
FASTLED_FORCE_INLINE 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.