1#define FASTLED_INTERNAL
2#define __PROG_TYPES_COMPAT__
14FASTLED_NAMESPACE_BEGIN
19 const struct CRGB& color)
21 for(
int i = 0; i < numToFill; ++i) {
22 targetArray[i] = color;
27 const struct CHSV& color)
29 for(
int i = 0; i < numToFill; ++i) {
30 targetArray[i] = color;
49 for(
int i = 0; i < numToFill; ++i) {
63 for(
int i = 0; i < numToFill; ++i) {
72 if (numToFill == 0)
return;
79 const uint16_t hueChange = 65535 / (uint16_t)numToFill;
80 uint16_t hueOffset = 0;
82 for (
int i = 0; i < numToFill; ++i) {
84 if (reversed) hueOffset -= hueChange;
85 else hueOffset += hueChange;
86 hsv.
hue = initialhue + (uint8_t)(hueOffset >> 8);
92 if (numToFill == 0)
return;
99 const uint16_t hueChange = 65535 / (uint16_t) numToFill;
100 uint16_t hueOffset = 0;
102 for (
int i = 0; i < numToFill; ++i) {
103 targetArray[i] = hsv;
104 if (reversed) hueOffset -= hueChange;
105 else hueOffset += hueChange;
106 hsv.
hue = initialhue + (uint8_t)(hueOffset >> 8);
112 uint16_t startpos,
CRGB startcolor,
113 uint16_t endpos,
CRGB endcolor )
116 if( endpos < startpos ) {
119 endcolor = startcolor;
129 rdistance87 = (endcolor.
r - startcolor.
r) << 7;
130 gdistance87 = (endcolor.
g - startcolor.
g) << 7;
131 bdistance87 = (endcolor.
b - startcolor.
b) << 7;
133 uint16_t pixeldistance = endpos - startpos;
134 int16_t divisor = pixeldistance ? pixeldistance : 1;
136 saccum87 rdelta87 = rdistance87 / divisor;
137 saccum87 gdelta87 = gdistance87 / divisor;
138 saccum87 bdelta87 = bdistance87 / divisor;
147 for( uint16_t i = startpos; i <= endpos; ++i) {
148 leds[i] =
CRGB( r88 >> 8, g88 >> 8, b88 >> 8);
192 uint16_t last = numLeds - 1;
199 uint16_t half = (numLeds / 2);
200 uint16_t last = numLeds - 1;
207 uint16_t onethird = (numLeds / 3);
208 uint16_t twothirds = ((numLeds * 2) / 3);
209 uint16_t last = numLeds - 1;
220 for( uint16_t i = 0; i < num_leds; ++i) {
238 nscale8( leds, num_leds, 255 - fadeBy);
243 nscale8( leds, num_leds, 255 - fadeBy);
250 nscale8( leds, num_leds, scale);
255 for( uint16_t i = 0; i < num_leds; ++i) {
267 for( uint16_t i = 0; i < numLeds; ++i) {
270 leds[i].
b =
scale8 ( leds[i].b, fb);
277 if( amountOfOverlay == 0) {
281 if( amountOfOverlay == 255) {
288 fract8 amountOfKeep = 255 - amountOfOverlay;
312 for( uint16_t i = count; i; --i) {
313 nblend( *existing, *overlay, amountOfOverlay);
322 nblend( nu, p2, amountOfP2);
328 for( uint16_t i = 0; i < count; ++i) {
329 dest[i] =
blend(src1[i], src2[i], amountOfsrc2);
338 if( amountOfOverlay == 0) {
342 if( amountOfOverlay == 255) {
347 fract8 amountOfKeep = 255 - amountOfOverlay;
349 uint8_t huedelta8 = overlay.
hue - existing.
hue;
353 if( huedelta8 > 127) {
360 if( huedelta8 < 128) {
366 existing.
hue = existing.
hue +
scale8( huedelta8, amountOfOverlay);
370 huedelta8 = -huedelta8;
371 existing.
hue = existing.
hue -
scale8( huedelta8, amountOfOverlay);
388 if(existing == overlay)
return;
389 for( uint16_t i = count; i; --i) {
390 nblend( *existing, *overlay, amountOfOverlay, directionCode);
399 nblend( nu, p2, amountOfP2, directionCode);
405 for( uint16_t i = 0; i < count; ++i) {
406 dest[i] =
blend(src1[i], src2[i], amountOfsrc2, directionCode);
428 uint8_t keep = 255 - blur_amount;
429 uint8_t seep = blur_amount >> 1;
431 for( uint16_t i = 0; i < numLeds; ++i) {
437 if( i) leds[i-1] += part;
445 blurRows(leds, width, height, blur_amount, xymap);
446 blurColumns(leds, width, height, blur_amount, xymap);
458 uint8_t keep = 255 - blur_amount;
459 uint8_t seep = blur_amount >> 1;
460 for( uint8_t row = 0; row < height; row++) {
462 for( uint8_t i = 0; i < width; i++) {
463 CRGB cur = leds[xyMap.mapToIndex(i,row)];
468 if( i) leds[xyMap.mapToIndex(i-1,row)] += part;
469 leds[xyMap.mapToIndex(i,row)] = cur;
479 uint8_t keep = 255 - blur_amount;
480 uint8_t seep = blur_amount >> 1;
481 for( uint8_t col = 0; col < width; ++col) {
483 for( uint8_t i = 0; i < height; ++i) {
484 CRGB cur = leds[xyMap.mapToIndex(col,i)];
489 if( i) leds[xyMap.mapToIndex(col,i-1)] += part;
490 leds[xyMap.mapToIndex(col,i)] = cur;
520 uint8_t heatramp = t192 & 0x3F;
528 heatcolor.
b = heatramp;
530 }
else if( t192 & 0x40 ) {
533 heatcolor.
g = heatramp;
538 heatcolor.
r = heatramp;
551inline uint8_t
lsrX4( uint8_t dividend) __attribute__((always_inline));
552inline uint8_t
lsrX4( uint8_t dividend)
567 uint8_t index_5bit = (index >> 11);
569 uint8_t offset = (uint8_t)(index >> 3);
571 const CRGB* entry = &(pal[0]) + index_5bit;
572 uint8_t red1 = entry->
red;
573 uint8_t green1 = entry->
green;
574 uint8_t blue1 = entry->
blue;
578 if (index_5bit == 31) {
585 uint8_t f1 = 255 - offset;
591 uint8_t red2 = entry->
red;
592 uint8_t green2 = entry->
green;
593 uint8_t blue2 = entry->
blue;
604 if (brightness != 255) {
607 return CRGB(red1, green1, blue1);
613 index =
map8(index, 0, 239);
617 uint8_t hi4 =
lsrX4(index);
618 uint8_t lo4 = index & 0x0F;
624 uint8_t hi4XsizeofCRGB = hi4 *
sizeof(
CRGB);
626 const CRGB* entry = (
CRGB*)( (uint8_t*)(&(pal[0])) + hi4XsizeofCRGB);
630 uint8_t red1 = entry->
red;
631 uint8_t green1 = entry->green;
632 uint8_t blue1 = entry->blue;
643 uint8_t f2 = lo4 << 4;
644 uint8_t f1 = 255 - f2;
647 uint8_t red2 = entry->red;
652 uint8_t green2 = entry->green;
657 uint8_t blue2 = entry->blue;
665 if( brightness != 255) {
672#if !(FASTLED_SCALE8_FIXED==1)
678#if !(FASTLED_SCALE8_FIXED==1)
684#if !(FASTLED_SCALE8_FIXED==1)
696 return CRGB( red1, green1, blue1);
701 uint8_t index_4bit = index >> 12;
703 uint8_t offset = (uint8_t)(index >> 4);
705 const CRGB* entry = &(pal[0]) + index_4bit;
706 uint8_t red1 = entry->
red;
707 uint8_t green1 = entry->
green;
708 uint8_t blue1 = entry->
blue;
712 if (index_4bit == 15) {
719 uint8_t f1 = 255 - offset;
725 uint8_t red2 = entry->
red;
726 uint8_t green2 = entry->
green;
727 uint8_t blue2 = entry->
blue;
738 if (brightness != 255) {
740 nscale8x3(red1, green1, blue1, brightness);
742 return CRGB(red1, green1, blue1);
748 index =
map8(index, 0, 239);
752 uint8_t hi4 =
lsrX4(index);
753 uint8_t lo4 = index & 0x0F;
758 uint8_t red1 = entry.
red;
759 uint8_t green1 = entry.
green;
760 uint8_t blue1 = entry.
blue;
772 uint8_t f2 = lo4 << 4;
773 uint8_t f1 = 255 - f2;
775 uint8_t red2 = entry.
red;
780 uint8_t green2 = entry.
green;
785 uint8_t blue2 = entry.
blue;
793 if( brightness != 255) {
800#if !(FASTLED_SCALE8_FIXED==1)
806#if !(FASTLED_SCALE8_FIXED==1)
812#if !(FASTLED_SCALE8_FIXED==1)
824 return CRGB( red1, green1, blue1);
831 index =
map8(index, 0, 247);
842 uint8_t lo3 = index & 0x07;
848 uint8_t hi5XsizeofCRGB = hi5 *
sizeof(
CRGB);
850 const CRGB* entry = (
CRGB*)( (uint8_t*)(&(pal[0])) + hi5XsizeofCRGB);
852 uint8_t red1 = entry->
red;
853 uint8_t green1 = entry->green;
854 uint8_t blue1 = entry->blue;
866 uint8_t f2 = lo3 << 5;
867 uint8_t f1 = 255 - f2;
869 uint8_t red2 = entry->
red;
874 uint8_t green2 = entry->green;
879 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 index =
map8(index, 0, 247);
937 uint8_t lo3 = index & 0x07;
941 uint8_t red1 = entry.
red;
942 uint8_t green1 = entry.
green;
943 uint8_t blue1 = entry.
blue;
955 uint8_t f2 = lo3 << 5;
956 uint8_t f1 = 255 - f2;
958 uint8_t red2 = entry.
red;
963 uint8_t green2 = entry.
green;
968 uint8_t blue2 = entry.
blue;
976 if( brightness != 255) {
983#if !(FASTLED_SCALE8_FIXED==1)
989#if !(FASTLED_SCALE8_FIXED==1)
995#if !(FASTLED_SCALE8_FIXED==1)
1007 return CRGB( red1, green1, blue1);
1014 const CRGB* entry = &(pal[0]) + index;
1016 uint8_t red = entry->
red;
1017 uint8_t green = entry->
green;
1018 uint8_t blue = entry->
blue;
1020 if( brightness != 255) {
1028 return CRGB( red, green, blue);
1033 uint8_t index_8bit = index >> 8;
1035 uint8_t offset = index & 0xff;
1037 const CRGB* entry = &(pal[0]) + index_8bit;
1038 uint8_t red1 = entry->
red;
1039 uint8_t green1 = entry->
green;
1040 uint8_t blue1 = entry->
blue;
1044 if (index_8bit == 255) {
1051 uint8_t f1 = 255 - offset;
1057 uint8_t red2 = entry->
red;
1058 uint8_t green2 = entry->
green;
1059 uint8_t blue2 = entry->
blue;
1070 if (brightness != 255) {
1072 nscale8x3(red1, green1, blue1, brightness);
1074 return CRGB(red1, green1, blue1);
1082 index =
map8(index, 0, 239);
1086 uint8_t hi4 =
lsrX4(index);
1087 uint8_t lo4 = index & 0x0F;
1090 const CHSV* entry = &(pal[0]) + hi4;
1092 uint8_t hue1 = entry->
hue;
1093 uint8_t sat1 = entry->
sat;
1094 uint8_t val1 = entry->
val;
1106 uint8_t f2 = lo4 << 4;
1107 uint8_t f1 = 255 - f2;
1109 uint8_t hue2 = entry->
hue;
1110 uint8_t sat2 = entry->
sat;
1111 uint8_t val2 = entry->
val;
1124 if( sat1 == 0 || val1 == 0) {
1130 if( sat2 == 0 || val2 == 0) {
1147 uint8_t deltaHue = (uint8_t)(hue2 - hue1);
1148 if( deltaHue & 0x80 ) {
1150 hue1 -=
scale8( 256 - deltaHue, f2);
1153 hue1 +=
scale8( deltaHue, f2);
1159 if( brightness != 255) {
1163 return CHSV( hue1, sat1, val1);
1170 index =
map8(index, 0, 247);
1173 uint8_t hi5 = index;
1181 uint8_t lo3 = index & 0x07;
1183 uint8_t hi5XsizeofCHSV = hi5 *
sizeof(
CHSV);
1184 const CHSV* entry = (
CHSV*)( (uint8_t*)(&(pal[0])) + hi5XsizeofCHSV);
1186 uint8_t hue1 = entry->hue;
1187 uint8_t sat1 = entry->sat;
1188 uint8_t val1 = entry->val;
1200 uint8_t f2 = lo3 << 5;
1201 uint8_t f1 = 255 - f2;
1203 uint8_t hue2 = entry->hue;
1204 uint8_t sat2 = entry->sat;
1205 uint8_t val2 = entry->val;
1218 if( sat1 == 0 || val1 == 0) {
1224 if( sat2 == 0 || val2 == 0) {
1241 uint8_t deltaHue = (uint8_t)(hue2 - hue1);
1242 if( deltaHue & 0x80 ) {
1244 hue1 -=
scale8( 256 - deltaHue, f2);
1247 hue1 +=
scale8( deltaHue, f2);
1253 if( brightness != 255) {
1257 return CHSV( hue1, sat1, val1);
1262 CHSV hsv = *( &(pal[0]) + index );
1264 if( brightness != 255) {
1274 for(
int i = 0; i < 256; ++i) {
1281 for(
int i = 0; i < 256; ++i) {
1289 for( uint8_t i = 0; i < 16; ++i) {
1291 destpal32[j+0] = srcpal16[i];
1292 destpal32[j+1] = srcpal16[i];
1298 for( uint8_t i = 0; i < 16; ++i) {
1300 destpal32[j+0] = srcpal16[i];
1301 destpal32[j+1] = srcpal16[i];
1307 for(
int i = 0; i < 256; ++i) {
1314 for(
int i = 0; i < 256; ++i) {
1335 uint8_t changes = 0;
1337 p1 = (uint8_t*)current.
entries;
1338 p2 = (uint8_t*)target.
entries;
1341 for( uint8_t i = 0; i < totalChannels; ++i) {
1343 if( p1[i] == p2[i] ) {
continue; }
1346 if( p1[i] < p2[i] ) { ++p1[i]; ++changes; }
1350 if( p1[i] > p2[i] ) {
1352 if( p1[i] > p2[i] ) { --p1[i]; }
1356 if( changes >= maxChanges) {
break; }
1365 orig = (float)(brightness) / (255.0);
1366 adj = pow( orig, gamma) * (255.0);
1367 uint8_t result = (uint8_t)(adj);
1368 if( (brightness > 0) && (result == 0)) {
1406 for( uint16_t i = 0; i < count; ++i) {
1413 for( uint16_t i = 0; i < count; ++i) {
1419FASTLED_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.
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.
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 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.
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.
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 ...
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)