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

◆ operator=() [8/8]

CRGBPalette32 & CRGBPalette32::operator= ( TProgmemRGBGradientPalette_bytes progpal)
inline

Creates a palette from a gradient palette in PROGMEM.

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 1654 of file colorutils.h.

1655 {
1656 TRGBGradientPaletteEntryUnion* progent = (TRGBGradientPaletteEntryUnion*)(progpal);
1657 TRGBGradientPaletteEntryUnion u;
1658
1659 // Count entries
1660 uint16_t count = 0;
1661 do {
1662 u.dword = FL_PGM_READ_DWORD_NEAR(progent + count);
1663 ++count;
1664 } while ( u.index != 255);
1665
1666 int8_t lastSlotUsed = -1;
1667
1668 u.dword = FL_PGM_READ_DWORD_NEAR( progent);
1669 CRGB rgbstart( u.r, u.g, u.b);
1670
1671 int indexstart = 0;
1672 uint8_t istart8 = 0;
1673 uint8_t iend8 = 0;
1674 while( indexstart < 255) {
1675 ++progent;
1676 u.dword = FL_PGM_READ_DWORD_NEAR( progent);
1677 int indexend = u.index;
1678 CRGB rgbend( u.r, u.g, u.b);
1679 istart8 = indexstart / 8;
1680 iend8 = indexend / 8;
1681 if( count < 16) {
1682 if( (istart8 <= lastSlotUsed) && (lastSlotUsed < 31)) {
1683 istart8 = lastSlotUsed + 1;
1684 if( iend8 < istart8) {
1685 iend8 = istart8;
1686 }
1687 }
1688 lastSlotUsed = iend8;
1689 }
1690 fill_gradient_RGB( &(entries[0]), istart8, rgbstart, iend8, rgbend);
1691 indexstart = indexend;
1692 rgbstart = rgbend;
1693 }
1694 return *this;
1695 }
CRGB entries[32]
the color entries that make up the palette
#define FL_PGM_READ_DWORD_NEAR(x)
Read a double word (32-bit) from PROGMEM memory.
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.
uint32_t dword
values as a packed 32-bit double word
Definition colorutils.h:684

References CRGBPalette32(), TRGBGradientPaletteEntryUnion::dword, entries, fill_gradient_RGB(), and FL_PGM_READ_DWORD_NEAR.

+ Here is the call graph for this function: