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
I always love to use FastLED with most of my arduino projects, best library ever :)
I'm wondering lately about the possibility to have a ColorFromPalette in 16bits definition (index in 16bits) in addition to the 8bit definition that is currently in place in order to have smoother transitions? Right now, if you have very slow transitions in place throughout the palette, you can see the (very small) "jumps" from one color to the other on the LEDs.
The idea is that each index in the color palette would have to be multiplied by 256 (only in the function) so that the "spread" between each color is wider thus giving more definition.
See #202 . Been a pr for some time now, who knows when it will get merged. But you could try it out by maybe making a custom local branch with that commit added if you want.
Thanks @5chmidti !
I've added this in my code directly. Super smooth now!
It was mostly working but some things where overflowing when being at plain values (R=255 or G=255 or B=255) so I've updated it a bit. See below:
CRGBsevenSegments::colorFromPaletteExtended(const CRGBPalette16 &pal, uint16_t index, uint8_t brightness, TBlendType blendType)
{
// This fucnction has the same intuitive behavior as the other ColorFromPalette// functions, except it provides 8-bit interpolation between palette entries.// Extract the four most significant bits of the index as a palette index.uint8_t index_4bit = (index >> 12);
// Calculate the 8-bit offset from the palette index.// Throws away the 4 least significant bits and uses the middle 8.uint8_t offset = (uint8_t)(index >> 4);
// Get the palette entry from the 4-bit index// CRGB rgb1 = pal[ hi4];constCRGB *entry = &(pal[0]) + index_4bit;
uint8_t red1 = entry->red;
uint8_t green1 = entry->green;
uint8_t blue1 = entry->blue;
uint8_t blend = offset && (blendType != NOBLEND);
if (blend)
{
// If palette blending is enabled, use the offset to interpolate between// the selected palette entry and the next.if (index_4bit == 15)
{
entry = &(pal[0]);
}
else
{
entry++;
}
// Calculate the scaling factor and scaled values for the lower palette value.uint8_t f1 = 256 - offset;
red1 = scale8_LEAVING_R1_DIRTY(red1, f1);
green1 = scale8_LEAVING_R1_DIRTY(green1, f1);
blue1 = scale8_LEAVING_R1_DIRTY(blue1, f1);
// Calculate the scaled values for the neighboring palette value.uint8_t red2 = entry->red;
uint8_t green2 = entry->green;
uint8_t blue2 = entry->blue;
red2 = scale8_LEAVING_R1_DIRTY(red2, offset);
green2 = scale8_LEAVING_R1_DIRTY(green2, offset);
blue2 = scale8_LEAVING_R1_DIRTY(blue2, offset);
cleanup_R1();
// This was overflowing so I've updated it using qadd8
red1 = qadd8(red1, red2);
green1 = qadd8(green1, green2);
blue1 = qadd8(blue1, blue2);
}
if (brightness != 255)
{
nscale8x3_video(red1, green1, blue1, brightness);
}
returnCRGB(red1, green1, blue1);
}
Here it is modified for CRGBPalette32. It didn't take much. Hopefully this saves someone a few minutes.
CRGB ColorFromPaletteExtended(const CRGBPalette32 &pal, uint16_t index, uint8_t brightness, TBlendType blendType)
{
// This function has the same intuitive behavior as the other ColorFromPalette
// functions, except it provides 8-bit interpolation between palette entries.
// Extract the five most significant bits of the index as a palette index.
uint8_t index_5bit = (index >> 11);
// Calculate the 8-bit offset from the palette index.
// Throws away the 3 least significant bits and uses the next 8.
uint8_t offset = (uint8_t)(index >> 3);
// Get the palette entry from the 5-bit index
const CRGB *entry = &(pal[0]) + index_5bit;
uint8_t red1 = entry->red;
uint8_t green1 = entry->green;
uint8_t blue1 = entry->blue;
uint8_t blend = offset && (blendType != NOBLEND);
if (blend)
{
// If palette blending is enabled, use the offset to interpolate between
// the selected palette entry and the next.
if (index_5bit == 31)
{
entry = &(pal[0]);
}
else
{
entry++;
}
// Calculate the scaling factor and scaled values for the lower palette value.
uint8_t f1 = 256 - offset;
red1 = scale8_LEAVING_R1_DIRTY(red1, f1);
green1 = scale8_LEAVING_R1_DIRTY(green1, f1);
blue1 = scale8_LEAVING_R1_DIRTY(blue1, f1);
// Calculate the scaled values for the neighboring palette value.
uint8_t red2 = entry->red;
uint8_t green2 = entry->green;
uint8_t blue2 = entry->blue;
red2 = scale8_LEAVING_R1_DIRTY(red2, offset);
green2 = scale8_LEAVING_R1_DIRTY(green2, offset);
blue2 = scale8_LEAVING_R1_DIRTY(blue2, offset);
cleanup_R1();
// This was overflowing so I've updated it using qadd8
red1 = qadd8(red1, red2);
green1 = qadd8(green1, green2);
blue1 = qadd8(blue1, blue2);
}
if (brightness != 255)
{
nscale8x3_video(red1, green1, blue1, brightness);
}
return CRGB(red1, green1, blue1);
}
Opened #2372 as a broader meta issue for the high-precision palette pipeline. #1014 is now covered there as the 16-bit-index part of the work, alongside CRGB16 output, high-precision brightness scaling, and noise-to-palette precision.
Resolved by #1687. Verified on current master: ColorFromPaletteExtended(const CRGBPalette16&, fl::u16, ...) provides the requested 16-bit-index palette lookup, with regression coverage retained in ests/fl/gfx/colorutils.cpp; #2373 additionally added the CRGB16 high-precision output path.
Activity
5chmidti commentedon May 8, 2020
See #202 . Been a pr for some time now, who knows when it will get merged. But you could try it out by maybe making a custom local branch with that commit added if you want.
RomRider commentedon May 9, 2020
Thanks @5chmidti !
I've added this in my code directly. Super smooth now!
It was mostly working but some things where overflowing when being at plain values (R=255 or G=255 or B=255) so I've updated it a bit. See below:
leifclaesson commentedon Dec 6, 2020
@RomRider Thanks for this!
Here it is modified for CRGBPalette32. It didn't take much. Hopefully this saves someone a few minutes.
sutaburosu commentedon Dec 31, 2020
There's that bug again.
256should be255.zackees commentedon Apr 22, 2026
Opened #2372 as a broader meta issue for the high-precision palette pipeline. #1014 is now covered there as the 16-bit-index part of the work, alongside CRGB16 output, high-precision brightness scaling, and noise-to-palette precision.
zackees commentedon Aug 20, 2026
Resolved by #1687. Verified on current master: ColorFromPaletteExtended(const CRGBPalette16&, fl::u16, ...) provides the requested 16-bit-index palette lookup, with regression coverage retained in ests/fl/gfx/colorutils.cpp; #2373 additionally added the CRGB16 high-precision output path.