Get a color from a palette.
These are the main functions for getting and using palette colors. Regardless of the number of entries in the base palette, this function will interpolate between entries to turn the discrete colors into a smooth gradient.
863{
865 index =
map8(index, 0, 247);
866 }
867
868 uint8_t hi5 = index;
869#if defined(__AVR__)
870 hi5 /= 2;
871 hi5 /= 2;
872 hi5 /= 2;
873#else
874 hi5 >>= 3;
875#endif
876 uint8_t lo3 = index & 0x07;
877
878
879
880
881
882 uint8_t hi5XsizeofCRGB = hi5 *
sizeof(
CRGB);
883
884 const CRGB* entry = (
CRGB*)( (uint8_t*)(&(pal[0])) + hi5XsizeofCRGB);
885
886 uint8_t red1 = entry->red;
887 uint8_t green1 = entry->green;
888 uint8_t blue1 = entry->blue;
889
891
893
894 if( hi5 == 31 ) {
895 entry = &(pal[0]);
896 } else {
897 ++entry;
898 }
899
900 uint8_t f2 = lo3 << 5;
901 uint8_t f1 = 255 - f2;
902
903 uint8_t red2 = entry->red;
906 red1 += red2;
907
908 uint8_t green2 = entry->green;
911 green1 += green2;
912
913 uint8_t blue2 = entry->blue;
916 blue1 += blue2;
917
919
920 }
921
925
926
927 if( red1 ) {
929#if !(FASTLED_SCALE8_FIXED==1)
930 ++red1;
931#endif
932 }
933 if( green1 ) {
935#if !(FASTLED_SCALE8_FIXED==1)
936 ++green1;
937#endif
938 }
939 if( blue1 ) {
941#if !(FASTLED_SCALE8_FIXED==1)
942 ++blue1;
943#endif
944 }
946 } else {
947 red1 = 0;
948 green1 = 0;
949 blue1 = 0;
950 }
951 }
952
953 return CRGB( red1, green1, blue1);
954}
UISlider brightness("Brightness", 255, 0, 255, 1)
CRGB blend(const CRGB &p1, const CRGB &p2, fract8 amountOfP2)
Computes a new color blended some fraction of the way between two other colors.
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.
@ NOBLEND
No interpolation between palette entries.
@ LINEARBLEND_NOWRAP
Linear interpolation between palette entries, but no wrap-around.
LIB8STATIC_ALWAYS_INLINE void cleanup_R1()
Clean up the r1 register after a series of *LEAVING_R1_DIRTY calls.
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.
Representation of an RGB pixel (Red, Green, Blue)