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

◆ ColorFromPalette() [8/8]

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

Definition at line 616 of file colorutils.cpp.

617 {
618 if (blendType == LINEARBLEND_NOWRAP) {
619 index = map8(index, 0, 247); // Blend range is affected by lo3 blend of
620 // values, remap to avoid wrapping
621 }
622
623 fl::u8 hi5 = index;
624#if defined(__AVR__)
625 hi5 /= 2;
626 hi5 /= 2;
627 hi5 /= 2;
628#else
629 hi5 >>= 3;
630#endif
631 fl::u8 lo3 = index & 0x07;
632
633 CRGB entry(FL_PGM_READ_DWORD_NEAR(&(pal[0]) + hi5));
634
635 fl::u8 red1 = entry.red;
636 fl::u8 green1 = entry.green;
637 fl::u8 blue1 = entry.blue;
638
639 fl::u8 blend = lo3 && (blendType != NOBLEND);
640
641 if (blend) {
642
643 if (hi5 == 31) {
644 entry = FL_PGM_READ_DWORD_NEAR(&(pal[0]));
645 } else {
646 entry = FL_PGM_READ_DWORD_NEAR(&(pal[1]) + hi5);
647 }
648
649 fl::u8 f2 = lo3 << 5;
650 fl::u8 f1 = 255 - f2;
651
652 fl::u8 red2 = entry.red;
653 red1 = scale8_LEAVING_R1_DIRTY(red1, f1);
654 red2 = scale8_LEAVING_R1_DIRTY(red2, f2);
655 red1 += red2;
656
657 fl::u8 green2 = entry.green;
658 green1 = scale8_LEAVING_R1_DIRTY(green1, f1);
659 green2 = scale8_LEAVING_R1_DIRTY(green2, f2);
660 green1 += green2;
661
662 fl::u8 blue2 = entry.blue;
663 blue1 = scale8_LEAVING_R1_DIRTY(blue1, f1);
664 blue2 = scale8_LEAVING_R1_DIRTY(blue2, f2);
665 blue1 += blue2;
666
667 cleanup_R1();
668 }
669
670 if (brightness != 255) {
671 if (brightness) {
672 ++brightness; // adjust for rounding
673 // Now, since brightness is nonzero, we don't need the full
674 // scale8_video logic; we can just to scale8 and then add one
675 // (unless scale8 fixed) to all nonzero inputs.
676 if (red1) {
678#if !(FASTLED_SCALE8_FIXED == 1)
679 ++red1;
680#endif
681 }
682 if (green1) {
683 green1 = scale8_LEAVING_R1_DIRTY(green1, brightness);
684#if !(FASTLED_SCALE8_FIXED == 1)
685 ++green1;
686#endif
687 }
688 if (blue1) {
689 blue1 = scale8_LEAVING_R1_DIRTY(blue1, brightness);
690#if !(FASTLED_SCALE8_FIXED == 1)
691 ++blue1;
692#endif
693 }
694 cleanup_R1();
695 } else {
696 red1 = 0;
697 green1 = 0;
698 blue1 = 0;
699 }
700 }
701
702 return CRGB(red1, green1, blue1);
703}
UISlider brightness("Brightness", 128, 0, 255, 1)
CRGB blend(const CRGB &p1, const CRGB &p2, fract8 amountOfP2)
#define FL_PGM_READ_DWORD_NEAR(x)
Read a double word (32-bit) from PROGMEM memory.
LIB8STATIC uint8_t map8(uint8_t in, uint8_t rangeStart, uint8_t rangeEnd)
Map from one full-range 8-bit value into a narrower range of 8-bit values, possibly a range of hues.
Definition lib8tion.h:397
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
unsigned char u8
Definition int.h:17
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:86

References blend(), brightness(), cleanup_R1(), FL_PGM_READ_DWORD_NEAR, map8(), and scale8_LEAVING_R1_DIRTY().

+ Here is the call graph for this function: