FastLED 3.9.15
Loading...
Searching...
No Matches

◆ loadDynamicGradientPalette()

CRGBPalette256 & CRGBPalette256::loadDynamicGradientPalette ( TDynamicRGBGradientPalette_bytes gpal)
inline

Creates a palette from a gradient palette in dynamic (heap) memory.

Gradient palettes are loaded into CRGBPalettes in such a way that, if possible, every color represented in the gradient palette is also represented in the CRGBPalette.

For example, consider a gradient palette that is all black except for a single, one-element-wide (1/256th!) spike of red in the middle:

0, 0,0,0
124, 0,0,0
125, 255,0,0 // one 1/256th-palette-wide red stripe
126, 0,0,0
255, 0,0,0

A naive conversion of this 256-element palette to a 16-element palette might accidentally completely eliminate the red spike, rendering the palette completely black.

However, the conversions provided here would attempt to include a the red stripe in the output, more-or-less as faithfully as possible. So in this case, the resulting CRGBPalette16 palette would have a red stripe in the middle which was 1/16th of a palette wide – the narrowest possible in a CRGBPalette16.

This means that the relative width of stripes in a CRGBPalette16 will be, by definition, different from the widths in the gradient palette. This code attempts to preserve "all the colors", rather than the exact stripe widths at the expense of dropping some colors.

Definition at line 1962 of file colorutils.h.

1963 {
1964 TRGBGradientPaletteEntryUnion* ent = (TRGBGradientPaletteEntryUnion*)(gpal);
1965 TRGBGradientPaletteEntryUnion u;
1966 u = *ent;
1967 CRGB rgbstart( u.r, u.g, u.b);
1968
1969 int indexstart = 0;
1970 while( indexstart < 255) {
1971 ++ent;
1972 u = *ent;
1973 int indexend = u.index;
1974 CRGB rgbend( u.r, u.g, u.b);
1975 fill_gradient_RGB( &(entries[0]), indexstart, rgbstart, indexend, rgbend);
1976 indexstart = indexend;
1977 rgbstart = rgbend;
1978 }
1979 return *this;
1980 }
CRGB entries[256]
the color entries that make up the palette
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.

References CRGBPalette256(), entries, and fill_gradient_RGB().

+ Here is the call graph for this function: