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

◆ ColorFromPaletteExtended() [4/5]

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

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

623 {
624 // Extract the four most significant bits of the index as a palette index.
625 fl::u8 index_4bit = index >> 12;
626 // Calculate the 8-bit offset from the palette index.
627 fl::u8 offset = (fl::u8)(index >> 4);
628 // Get the palette entry from the 4-bit index
629 CRGB entry(FL_PGM_READ_DWORD_NEAR(&(pal[0]) + index_4bit));
630 fl::u8 red1 = entry.red;
631 fl::u8 green1 = entry.green;
632 fl::u8 blue1 = entry.blue;
633
634 fl::u8 blend = offset && (blendType != NOBLEND);
635 if (blend) {
636 if (index_4bit == 15) {
637 entry = FL_PGM_READ_DWORD_NEAR(&(pal[0]));
638 } else {
639 entry = FL_PGM_READ_DWORD_NEAR(&(pal[1]) + index_4bit);
640 }
641
642 // Calculate the scaling factor and scaled values for the lower palette
643 // value.
644 fl::u8 f1 = 255 - offset;
645 red1 = scale8_LEAVING_R1_DIRTY(red1, f1);
646 green1 = scale8_LEAVING_R1_DIRTY(green1, f1);
647 blue1 = scale8_LEAVING_R1_DIRTY(blue1, f1);
648
649 // Calculate the scaled values for the neighbouring palette value.
650 fl::u8 red2 = entry.red;
651 fl::u8 green2 = entry.green;
652 fl::u8 blue2 = entry.blue;
653 red2 = scale8_LEAVING_R1_DIRTY(red2, offset);
654 green2 = scale8_LEAVING_R1_DIRTY(green2, offset);
655 blue2 = scale8_LEAVING_R1_DIRTY(blue2, offset);
656 cleanup_R1();
657
658 // These sums can't overflow, so no qadd8 needed.
659 red1 += red2;
660 green1 += green2;
661 blue1 += blue2;
662 }
663 if (brightness != 255) {
664 // nscale8x3_video(red1, green1, blue1, brightness);
665 nscale8x3(red1, green1, blue1, brightness);
666 }
667 return CRGB(red1, green1, blue1);
668}
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: