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

◆ ColorFromPaletteExtended() [2/3]

CRGB fl::ColorFromPaletteExtended ( const CRGBPalette256 & pal,
fl::u16 index,
fl::u8 brightness,
TBlendType blendType )

Definition at line 724 of file colorutils.cpp.

725 {
726 // Extract the eight most significant bits of the index as a palette index.
727 fl::u8 index_8bit = index >> 8;
728 // Calculate the 8-bit offset from the palette index.
729 fl::u8 offset = index & 0xff;
730 // Get the palette entry from the 8-bit index
731 const CRGB *entry = &(pal[0]) + index_8bit;
732 fl::u8 red1 = entry->red;
733 fl::u8 green1 = entry->green;
734 fl::u8 blue1 = entry->blue;
735
736 fl::u8 blend = offset && (blendType != NOBLEND);
737 if (blend) {
738 if (index_8bit == 255) {
739 entry = &(pal[0]);
740 } else {
741 entry++;
742 }
743
744 // Calculate the scaling factor and scaled values for the lower palette
745 // value.
746 fl::u8 f1 = 255 - offset;
747 red1 = scale8_LEAVING_R1_DIRTY(red1, f1);
748 green1 = scale8_LEAVING_R1_DIRTY(green1, f1);
749 blue1 = scale8_LEAVING_R1_DIRTY(blue1, f1);
750
751 // Calculate the scaled values for the neighbouring palette value.
752 fl::u8 red2 = entry->red;
753 fl::u8 green2 = entry->green;
754 fl::u8 blue2 = entry->blue;
755 red2 = scale8_LEAVING_R1_DIRTY(red2, offset);
756 green2 = scale8_LEAVING_R1_DIRTY(green2, offset);
757 blue2 = scale8_LEAVING_R1_DIRTY(blue2, offset);
758 cleanup_R1();
759
760 // These sums can't overflow, so no qadd8 needed.
761 red1 += red2;
762 green1 += green2;
763 blue1 += blue2;
764 }
765 if (brightness != 255) {
766 // nscale8x3_video(red1, green1, blue1, brightness);
767 nscale8x3(red1, green1, blue1, brightness);
768 }
769 return CRGB(red1, green1, blue1);
770}
UISlider brightness("Brightness", 128, 0, 255, 1)
UISlider offset("Offset", 0.0f, 0.0f, 1.0f, 0.01f)
LIB8STATIC_ALWAYS_INLINE void cleanup_R1()
Clean up the r1 register after a series of *LEAVING_R1_DIRTY calls.
Definition scale8.h:343
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:180
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:367
unsigned char u8
Definition int.h:17
CRGB blend(const CRGB &p1, const CRGB &p2, fract8 amountOfP2)
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:86

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

+ Here is the call graph for this function: