You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ColorFromPalette loops back to first color with index > 240 #380
When calling ColorFromPalette with a CRGBPalette16 and a heat index > 240, I expect the function to return a color that is interpolated between the second to last color and the last color in the palette. Instead it seems to interpolate between the second to last color and the first color in the palette. In the code below I would expect the LED to fade from cyan to blue to red but instead it fades from cyan to blue to white.
It looks like the issue is related to how the function:
CRGB ColorFromPalette( const CRGBPalette16& pal, uint8_t index, uint8_t brightness, TBlendType blendType)
deals with hi5 indexing the last chunk:
if( hi4 == 15 ) {
entry = &(pal[0]);
Is this the intended behavior? I realize I can work around it by just ignoring the last palette entry and never indexing above 240 but it would be preferable to use the whole range.
Yep. In order to support smooth blending for "circular" palettes, each color blends with "the next"-- and in the case of the last color, "the next" is the first color again since it wraps around.
If you want to avoid wrapping, just do this:
CRGB c = ColorFromPalette( myPal, scale8( i , 240 ) );
This is what I do. It lets me program with 0-255 for i, and since scale8 is extremely small and fast the code overhead is basically unnoticeable.
The "circular wraparound" of palette colors is by design, and since there's an easy way for programmers to avoid if if they wish, I think we're likely to leave it as is.
Thanks for the feedback, and always happy to see people using palettes (and FastLED)!
Activity
marmilicious commentedon Dec 9, 2016
@clinder, I did see this in the docs:
"Recommend that you use values 0-240 rather than the usual 0-255, as the last 15 colors will be 'wrapping around' from the hot end to the cold end, which looks wrong."
from here:
http://fastled.io/docs/3.1/group___colorpalletes.html
kriegsman commentedon Dec 9, 2016
Yep. In order to support smooth blending for "circular" palettes, each color blends with "the next"-- and in the case of the last color, "the next" is the first color again since it wraps around.
If you want to avoid wrapping, just do this:
CRGB c = ColorFromPalette( myPal, scale8( i , 240 ) );
This is what I do. It lets me program with 0-255 for i, and since scale8 is extremely small and fast the code overhead is basically unnoticeable.
The "circular wraparound" of palette colors is by design, and since there's an easy way for programmers to avoid if if they wish, I think we're likely to leave it as is.
Thanks for the feedback, and always happy to see people using palettes (and FastLED)!