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

◆ ColorFromPaletteExtended() [1/3]

CRGB ColorFromPaletteExtended ( const CRGBPalette16 & pal,
uint16_t index,
uint8_t brightness,
TBlendType blendType )

Same as ColorFromPalette, but with uint16_t index to give greater precision.

Author
https://github.com/generalelectrix
See also
https://github.com/FastLED/FastLED/pull/202
https://wokwi.com/projects/285170662915441160
https://wokwi.com/projects/407831886158110721

Definition at line 733 of file colorutils.cpp.

733 {
734 // Extract the four most significant bits of the index as a palette index.
735 uint8_t index_4bit = index >> 12;
736 // Calculate the 8-bit offset from the palette index.
737 uint8_t offset = (uint8_t)(index >> 4);
738 // Get the palette entry from the 4-bit index
739 const CRGB* entry = &(pal[0]) + index_4bit;
740 uint8_t red1 = entry->red;
741 uint8_t green1 = entry->green;
742 uint8_t blue1 = entry->blue;
743
744 uint8_t blend = offset && (blendType != NOBLEND);
745 if (blend) {
746 if (index_4bit == 15) {
747 entry = &(pal[0]);
748 } else {
749 entry++;
750 }
751
752 // Calculate the scaling factor and scaled values for the lower palette value.
753 uint8_t f1 = 255 - offset;
754 red1 = scale8_LEAVING_R1_DIRTY(red1, f1);
755 green1 = scale8_LEAVING_R1_DIRTY(green1, f1);
756 blue1 = scale8_LEAVING_R1_DIRTY(blue1, f1);
757
758 // Calculate the scaled values for the neighbouring palette value.
759 uint8_t red2 = entry->red;
760 uint8_t green2 = entry->green;
761 uint8_t blue2 = entry->blue;
762 red2 = scale8_LEAVING_R1_DIRTY(red2, offset);
763 green2 = scale8_LEAVING_R1_DIRTY(green2, offset);
764 blue2 = scale8_LEAVING_R1_DIRTY(blue2, offset);
765 cleanup_R1();
766
767 // These sums can't overflow, so no qadd8 needed.
768 red1 += red2;
769 green1 += green2;
770 blue1 += blue2;
771 }
772 if (brightness != 255) {
773 // nscale8x3_video(red1, green1, blue1, brightness);
774 nscale8x3(red1, green1, blue1, brightness);
775 }
776 return CRGB(red1, green1, blue1);
777}
UISlider brightness("Brightness", 255, 0, 255, 1)
CRGB blend(const CRGB &p1, const CRGB &p2, fract8 amountOfP2)
Computes a new color blended some fraction of the way between two other colors.
@ NOBLEND
No interpolation between palette entries.
LIB8STATIC_ALWAYS_INLINE void cleanup_R1()
Clean up the r1 register after a series of *LEAVING_R1_DIRTY calls.
Definition scale8.h:333
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.
Definition scale8.h:170
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...
Definition scale8.h:357
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:54

References blend(), brightness, cleanup_R1(), NOBLEND, nscale8x3(), and scale8_LEAVING_R1_DIRTY().

+ Here is the call graph for this function: