1#define FASTLED_INTERNAL
2#define __PROG_TYPES_COMPAT__
21 const struct CRGB& color)
23 for(
int i = 0; i < numToFill; ++i) {
24 targetArray[i] = color;
29 const struct CHSV& color)
31 for(
int i = 0; i < numToFill; ++i) {
32 targetArray[i] = color;
51 for(
int i = 0; i < numToFill; ++i) {
65 for(
int i = 0; i < numToFill; ++i) {
74 if (numToFill == 0)
return;
81 const uint16_t hueChange = 65535 / (uint16_t)numToFill;
82 uint16_t hueOffset = 0;
84 for (
int i = 0; i < numToFill; ++i) {
86 if (reversed) hueOffset -= hueChange;
87 else hueOffset += hueChange;
88 hsv.
hue = initialhue + (uint8_t)(hueOffset >> 8);
94 if (numToFill == 0)
return;
101 const uint16_t hueChange = 65535 / (uint16_t) numToFill;
102 uint16_t hueOffset = 0;
104 for (
int i = 0; i < numToFill; ++i) {
105 targetArray[i] = hsv;
106 if (reversed) hueOffset -= hueChange;
107 else hueOffset += hueChange;
108 hsv.
hue = initialhue + (uint8_t)(hueOffset >> 8);
114 uint16_t startpos,
CRGB startcolor,
115 uint16_t endpos,
CRGB endcolor )
118 if( endpos < startpos ) {
121 endcolor = startcolor;
131 rdistance87 = (endcolor.
r - startcolor.
r) << 7;
132 gdistance87 = (endcolor.
g - startcolor.
g) << 7;
133 bdistance87 = (endcolor.
b - startcolor.
b) << 7;
135 uint16_t pixeldistance = endpos - startpos;
136 int16_t divisor = pixeldistance ? pixeldistance : 1;
138 saccum87 rdelta87 = rdistance87 / divisor;
139 saccum87 gdelta87 = gdistance87 / divisor;
140 saccum87 bdelta87 = bdistance87 / divisor;
149 for( uint16_t i = startpos; i <= endpos; ++i) {
150 leds[i] =
CRGB( r88 >> 8, g88 >> 8, b88 >> 8);
194 uint16_t last = numLeds - 1;
201 uint16_t half = (numLeds / 2);
202 uint16_t last = numLeds - 1;
209 uint16_t onethird = (numLeds / 3);
210 uint16_t twothirds = ((numLeds * 2) / 3);
211 uint16_t last = numLeds - 1;
222 for( uint16_t i = 0; i < num_leds; ++i) {
240 nscale8( leds, num_leds, 255 - fadeBy);
245 nscale8( leds, num_leds, 255 - fadeBy);
251 for( uint16_t i = 0; i < num_leds; ++i) {
263 for( uint16_t i = 0; i < numLeds; ++i) {
266 leds[i].
b =
scale8 ( leds[i].b, fb);
273 if( amountOfOverlay == 0) {
277 if( amountOfOverlay == 255) {
284 fract8 amountOfKeep = 255 - amountOfOverlay;
308 for( uint16_t i = count; i; --i) {
309 nblend( *existing, *overlay, amountOfOverlay);
318 nblend( nu, p2, amountOfP2);
324 for( uint16_t i = 0; i < count; ++i) {
325 dest[i] =
blend(src1[i], src2[i], amountOfsrc2);
334 if( amountOfOverlay == 0) {
338 if( amountOfOverlay == 255) {
343 fract8 amountOfKeep = 255 - amountOfOverlay;
345 uint8_t huedelta8 = overlay.
hue - existing.
hue;
349 if( huedelta8 > 127) {
356 if( huedelta8 < 128) {
362 existing.
hue = existing.
hue +
scale8( huedelta8, amountOfOverlay);
366 huedelta8 = -huedelta8;
367 existing.
hue = existing.
hue -
scale8( huedelta8, amountOfOverlay);
384 if(existing == overlay)
return;
385 for( uint16_t i = count; i; --i) {
386 nblend( *existing, *overlay, amountOfOverlay, directionCode);
395 nblend( nu, p2, amountOfP2, directionCode);
401 for( uint16_t i = 0; i < count; ++i) {
402 dest[i] =
blend(src1[i], src2[i], amountOfsrc2, directionCode);
424 uint8_t keep = 255 - blur_amount;
425 uint8_t seep = blur_amount >> 1;
427 for( uint16_t i = 0; i < numLeds; ++i) {
433 if( i) leds[i-1] += part;
441 blurRows(leds, width, height, blur_amount, xymap);
442 blurColumns(leds, width, height, blur_amount, xymap);
454 uint8_t keep = 255 - blur_amount;
455 uint8_t seep = blur_amount >> 1;
456 for( uint8_t row = 0; row < height; row++) {
458 for( uint8_t i = 0; i < width; i++) {
459 CRGB cur = leds[xyMap.mapToIndex(i,row)];
464 if( i) leds[xyMap.mapToIndex(i-1,row)] += part;
465 leds[xyMap.mapToIndex(i,row)] = cur;
475 uint8_t keep = 255 - blur_amount;
476 uint8_t seep = blur_amount >> 1;
477 for( uint8_t col = 0; col < width; ++col) {
479 for( uint8_t i = 0; i < height; ++i) {
480 CRGB cur = leds[xyMap.mapToIndex(col,i)];
485 if( i) leds[xyMap.mapToIndex(col,i-1)] += part;
486 leds[xyMap.mapToIndex(col,i)] = cur;
516 uint8_t heatramp = t192 & 0x3F;
524 heatcolor.
b = heatramp;
526 }
else if( t192 & 0x40 ) {
529 heatcolor.
g = heatramp;
534 heatcolor.
r = heatramp;
547inline uint8_t
lsrX4( uint8_t dividend) __attribute__((always_inline));
548inline uint8_t
lsrX4( uint8_t dividend)
563 uint8_t index_5bit = (index >> 11);
565 uint8_t offset = (uint8_t)(index >> 3);
567 const CRGB* entry = &(pal[0]) + index_5bit;
568 uint8_t red1 = entry->
red;
569 uint8_t green1 = entry->
green;
570 uint8_t blue1 = entry->
blue;
574 if (index_5bit == 31) {
581 uint8_t f1 = 255 - offset;
587 uint8_t red2 = entry->
red;
588 uint8_t green2 = entry->
green;
589 uint8_t blue2 = entry->
blue;
600 if (brightness != 255) {
603 return CRGB(red1, green1, blue1);
609 index =
map8(index, 0, 239);
613 uint8_t hi4 =
lsrX4(index);
614 uint8_t lo4 = index & 0x0F;
620 uint8_t hi4XsizeofCRGB = hi4 *
sizeof(
CRGB);
622 const CRGB* entry = (
CRGB*)( (uint8_t*)(&(pal[0])) + hi4XsizeofCRGB);
626 uint8_t red1 = entry->
red;
627 uint8_t green1 = entry->green;
628 uint8_t blue1 = entry->blue;
639 uint8_t f2 = lo4 << 4;
640 uint8_t f1 = 255 - f2;
643 uint8_t red2 = entry->red;
648 uint8_t green2 = entry->green;
653 uint8_t blue2 = entry->blue;
661 if( brightness != 255) {
668#if !(FASTLED_SCALE8_FIXED==1)
674#if !(FASTLED_SCALE8_FIXED==1)
680#if !(FASTLED_SCALE8_FIXED==1)
692 return CRGB( red1, green1, blue1);
697 uint8_t index_4bit = index >> 12;
699 uint8_t offset = (uint8_t)(index >> 4);
701 const CRGB* entry = &(pal[0]) + index_4bit;
702 uint8_t red1 = entry->
red;
703 uint8_t green1 = entry->
green;
704 uint8_t blue1 = entry->
blue;
708 if (index_4bit == 15) {
715 uint8_t f1 = 255 - offset;
721 uint8_t red2 = entry->
red;
722 uint8_t green2 = entry->
green;
723 uint8_t blue2 = entry->
blue;
734 if (brightness != 255) {
736 nscale8x3(red1, green1, blue1, brightness);
738 return CRGB(red1, green1, blue1);
744 index =
map8(index, 0, 239);
748 uint8_t hi4 =
lsrX4(index);
749 uint8_t lo4 = index & 0x0F;
754 uint8_t red1 = entry.
red;
755 uint8_t green1 = entry.
green;
756 uint8_t blue1 = entry.
blue;
768 uint8_t f2 = lo4 << 4;
769 uint8_t f1 = 255 - f2;
771 uint8_t red2 = entry.
red;
776 uint8_t green2 = entry.
green;
781 uint8_t blue2 = entry.
blue;
789 if( brightness != 255) {
796#if !(FASTLED_SCALE8_FIXED==1)
802#if !(FASTLED_SCALE8_FIXED==1)
808#if !(FASTLED_SCALE8_FIXED==1)
820 return CRGB( red1, green1, blue1);
827 index =
map8(index, 0, 247);
838 uint8_t lo3 = index & 0x07;
844 uint8_t hi5XsizeofCRGB = hi5 *
sizeof(
CRGB);
846 const CRGB* entry = (
CRGB*)( (uint8_t*)(&(pal[0])) + hi5XsizeofCRGB);
848 uint8_t red1 = entry->
red;
849 uint8_t green1 = entry->green;
850 uint8_t blue1 = entry->blue;
862 uint8_t f2 = lo3 << 5;
863 uint8_t f1 = 255 - f2;
865 uint8_t red2 = entry->
red;
870 uint8_t green2 = entry->green;
875 uint8_t blue2 = entry->blue;
884 if( brightness != 255) {
891#if !(FASTLED_SCALE8_FIXED==1)
897#if !(FASTLED_SCALE8_FIXED==1)
903#if !(FASTLED_SCALE8_FIXED==1)
915 return CRGB( red1, green1, blue1);
922 index =
map8(index, 0, 247);
933 uint8_t lo3 = index & 0x07;
937 uint8_t red1 = entry.
red;
938 uint8_t green1 = entry.
green;
939 uint8_t blue1 = entry.
blue;
951 uint8_t f2 = lo3 << 5;
952 uint8_t f1 = 255 - f2;
954 uint8_t red2 = entry.
red;
959 uint8_t green2 = entry.
green;
964 uint8_t blue2 = entry.
blue;
972 if( brightness != 255) {
979#if !(FASTLED_SCALE8_FIXED==1)
985#if !(FASTLED_SCALE8_FIXED==1)
991#if !(FASTLED_SCALE8_FIXED==1)
1003 return CRGB( red1, green1, blue1);
1010 const CRGB* entry = &(pal[0]) + index;
1012 uint8_t red = entry->
red;
1013 uint8_t green = entry->
green;
1014 uint8_t blue = entry->
blue;
1016 if( brightness != 255) {
1024 return CRGB( red, green, blue);
1029 uint8_t index_8bit = index >> 8;
1031 uint8_t offset = index & 0xff;
1033 const CRGB* entry = &(pal[0]) + index_8bit;
1034 uint8_t red1 = entry->
red;
1035 uint8_t green1 = entry->
green;
1036 uint8_t blue1 = entry->
blue;
1040 if (index_8bit == 255) {
1047 uint8_t f1 = 255 - offset;
1053 uint8_t red2 = entry->
red;
1054 uint8_t green2 = entry->
green;
1055 uint8_t blue2 = entry->
blue;
1066 if (brightness != 255) {
1068 nscale8x3(red1, green1, blue1, brightness);
1070 return CRGB(red1, green1, blue1);
1078 index =
map8(index, 0, 239);
1082 uint8_t hi4 =
lsrX4(index);
1083 uint8_t lo4 = index & 0x0F;
1086 const CHSV* entry = &(pal[0]) + hi4;
1088 uint8_t hue1 = entry->
hue;
1089 uint8_t sat1 = entry->
sat;
1090 uint8_t val1 = entry->
val;
1102 uint8_t f2 = lo4 << 4;
1103 uint8_t f1 = 255 - f2;
1105 uint8_t hue2 = entry->
hue;
1106 uint8_t sat2 = entry->
sat;
1107 uint8_t val2 = entry->
val;
1120 if( sat1 == 0 || val1 == 0) {
1126 if( sat2 == 0 || val2 == 0) {
1143 uint8_t deltaHue = (uint8_t)(hue2 - hue1);
1144 if( deltaHue & 0x80 ) {
1146 hue1 -=
scale8( 256 - deltaHue, f2);
1149 hue1 +=
scale8( deltaHue, f2);
1155 if( brightness != 255) {
1159 return CHSV( hue1, sat1, val1);
1166 index =
map8(index, 0, 247);
1169 uint8_t hi5 = index;
1177 uint8_t lo3 = index & 0x07;
1179 uint8_t hi5XsizeofCHSV = hi5 *
sizeof(
CHSV);
1180 const CHSV* entry = (
CHSV*)( (uint8_t*)(&(pal[0])) + hi5XsizeofCHSV);
1182 uint8_t hue1 = entry->hue;
1183 uint8_t sat1 = entry->sat;
1184 uint8_t val1 = entry->val;
1196 uint8_t f2 = lo3 << 5;
1197 uint8_t f1 = 255 - f2;
1199 uint8_t hue2 = entry->hue;
1200 uint8_t sat2 = entry->sat;
1201 uint8_t val2 = entry->val;
1214 if( sat1 == 0 || val1 == 0) {
1220 if( sat2 == 0 || val2 == 0) {
1237 uint8_t deltaHue = (uint8_t)(hue2 - hue1);
1238 if( deltaHue & 0x80 ) {
1240 hue1 -=
scale8( 256 - deltaHue, f2);
1243 hue1 +=
scale8( deltaHue, f2);
1249 if( brightness != 255) {
1253 return CHSV( hue1, sat1, val1);
1258 CHSV hsv = *( &(pal[0]) + index );
1260 if( brightness != 255) {
1270 for(
int i = 0; i < 256; ++i) {
1277 for(
int i = 0; i < 256; ++i) {
1285 for( uint8_t i = 0; i < 16; ++i) {
1287 destpal32[j+0] = srcpal16[i];
1288 destpal32[j+1] = srcpal16[i];
1294 for( uint8_t i = 0; i < 16; ++i) {
1296 destpal32[j+0] = srcpal16[i];
1297 destpal32[j+1] = srcpal16[i];
1303 for(
int i = 0; i < 256; ++i) {
1310 for(
int i = 0; i < 256; ++i) {
1331 uint8_t changes = 0;
1333 p1 = (uint8_t*)current.
entries;
1334 p2 = (uint8_t*)target.
entries;
1337 for( uint8_t i = 0; i < totalChannels; ++i) {
1339 if( p1[i] == p2[i] ) {
continue; }
1342 if( p1[i] < p2[i] ) { ++p1[i]; ++changes; }
1346 if( p1[i] > p2[i] ) {
1348 if( p1[i] > p2[i] ) { --p1[i]; }
1352 if( changes >= maxChanges) {
break; }
1361 orig = (float)(brightness) / (255.0);
1362 adj = pow( orig, gamma) * (255.0);
1363 uint8_t result = (uint8_t)(adj);
1364 if( (brightness > 0) && (result == 0)) {
1402 for( uint16_t i = 0; i < count; ++i) {
1409 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.
FASTLED_FORCE_INLINE 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.