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

◆ ColorFromPalette() [8/8]

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

Definition at line 615 of file colorutils.cpp.

616 {
617 if (blendType == LINEARBLEND_NOWRAP) {
618 index = map8(index, 0, 247); // Blend range is affected by lo3 blend of
619 // values, remap to avoid wrapping
620 }
621
622 uint8_t hi5 = index;
623#if defined(__AVR__)
624 hi5 /= 2;
625 hi5 /= 2;
626 hi5 /= 2;
627#else
628 hi5 >>= 3;
629#endif
630 uint8_t lo3 = index & 0x07;
631
632 CRGB entry(FL_PGM_READ_DWORD_NEAR(&(pal[0]) + hi5));
633
634 uint8_t red1 = entry.red;
635 uint8_t green1 = entry.green;
636 uint8_t blue1 = entry.blue;
637
638 uint8_t blend = lo3 && (blendType != NOBLEND);
639
640 if (blend) {
641
642 if (hi5 == 31) {
643 entry = FL_PGM_READ_DWORD_NEAR(&(pal[0]));
644 } else {
645 entry = FL_PGM_READ_DWORD_NEAR(&(pal[1]) + hi5);
646 }
647
648 uint8_t f2 = lo3 << 5;
649 uint8_t f1 = 255 - f2;
650
651 uint8_t red2 = entry.red;
652 red1 = scale8_LEAVING_R1_DIRTY(red1, f1);
653 red2 = scale8_LEAVING_R1_DIRTY(red2, f2);
654 red1 += red2;
655
656 uint8_t green2 = entry.green;
657 green1 = scale8_LEAVING_R1_DIRTY(green1, f1);
658 green2 = scale8_LEAVING_R1_DIRTY(green2, f2);
659 green1 += green2;
660
661 uint8_t blue2 = entry.blue;
662 blue1 = scale8_LEAVING_R1_DIRTY(blue1, f1);
663 blue2 = scale8_LEAVING_R1_DIRTY(blue2, f2);
664 blue1 += blue2;
665
666 cleanup_R1();
667 }
668
669 if (brightness != 255) {
670 if (brightness) {
671 ++brightness; // adjust for rounding
672 // Now, since brightness is nonzero, we don't need the full
673 // scale8_video logic; we can just to scale8 and then add one
674 // (unless scale8 fixed) to all nonzero inputs.
675 if (red1) {
677#if !(FASTLED_SCALE8_FIXED == 1)
678 ++red1;
679#endif
680 }
681 if (green1) {
682 green1 = scale8_LEAVING_R1_DIRTY(green1, brightness);
683#if !(FASTLED_SCALE8_FIXED == 1)
684 ++green1;
685#endif
686 }
687 if (blue1) {
688 blue1 = scale8_LEAVING_R1_DIRTY(blue1, brightness);
689#if !(FASTLED_SCALE8_FIXED == 1)
690 ++blue1;
691#endif
692 }
693 cleanup_R1();
694 } else {
695 red1 = 0;
696 green1 = 0;
697 blue1 = 0;
698 }
699 }
700
701 return CRGB(red1, green1, blue1);
702}
UISlider brightness("Brightness", 255, 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:541
LIB8STATIC_ALWAYS_INLINE void cleanup_R1()
Clean up the r1 register after a series of *LEAVING_R1_DIRTY calls.
Definition scale8.h:339
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:176
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:55

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

+ Here is the call graph for this function: