FastLED 3.10.8
Loading...
Searching...
No Matches

◆ ColorFromPaletteExtended() [5/5]

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

Definition at line 677 of file colorutils.cpp.hpp.

678 {
679 // Extract the five most significant bits of the index as a palette index.
680 fl::u8 index_5bit = (index >> 11);
681 // Calculate the 8-bit offset from the palette index.
682 fl::u8 offset = (fl::u8)(index >> 3);
683 // Get the palette entry from the 5-bit index
684 CRGB entry(FL_PGM_READ_DWORD_NEAR(&(pal[0]) + index_5bit));
685 fl::u8 red1 = entry.red;
686 fl::u8 green1 = entry.green;
687 fl::u8 blue1 = entry.blue;
688
689 fl::u8 blend = offset && (blendType != NOBLEND);
690 if (blend) {
691 if (index_5bit == 31) {
692 entry = FL_PGM_READ_DWORD_NEAR(&(pal[0]));
693 } else {
694 entry = FL_PGM_READ_DWORD_NEAR(&(pal[1]) + index_5bit);
695 }
696
697 // Calculate the scaling factor and scaled values for the lower palette
698 // value.
699 fl::u8 f1 = 255 - offset;
700 red1 = scale8_LEAVING_R1_DIRTY(red1, f1);
701 green1 = scale8_LEAVING_R1_DIRTY(green1, f1);
702 blue1 = scale8_LEAVING_R1_DIRTY(blue1, f1);
703
704 // Calculate the scaled values for the neighbouring palette value.
705 fl::u8 red2 = entry.red;
706 fl::u8 green2 = entry.green;
707 fl::u8 blue2 = entry.blue;
708 red2 = scale8_LEAVING_R1_DIRTY(red2, offset);
709 green2 = scale8_LEAVING_R1_DIRTY(green2, offset);
710 blue2 = scale8_LEAVING_R1_DIRTY(blue2, offset);
711 cleanup_R1();
712
713 // These sums can't overflow, so no qadd8 needed.
714 red1 += red2;
715 green1 += green2;
716 blue1 += blue2;
717 }
718 if (brightness != 255) {
719 // nscale8x3_video(red1, green1, blue1, brightness);
720 nscale8x3(red1, green1, blue1, brightness);
721 }
722 return CRGB(red1, green1, blue1);
723}
fl::UISlider brightness("Brightness", BRIGHTNESS, 0, 255)
fl::UISlider offset("Offset", 0.0f, 0.0f, 1.0f, 0.01f)
#define FL_PGM_READ_DWORD_NEAR(x)
Read a double word (32-bit) from PROGMEM memory.
unsigned char u8
Definition stdint.h:131
fl::CRGB CRGB
Definition video.h:18
CRGB blend(const CRGB &p1, const CRGB &p2, fract8 amountOfP2) FL_NO_EXCEPT
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38

References blend(), brightness, FL_NO_EXCEPT, FL_PGM_READ_DWORD_NEAR, and offset().

+ Here is the call graph for this function: