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

◆ ColorFromPaletteExtended() [2/5]

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

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

937 {
938 // Extract the eight most significant bits of the index as a palette index.
939 fl::u8 index_8bit = index >> 8;
940 // Calculate the 8-bit offset from the palette index.
941 fl::u8 offset = index & 0xff;
942 // Get the palette entry from the 8-bit index
943 const CRGB *entry = &(pal[0]) + index_8bit;
944 fl::u8 red1 = entry->red;
945 fl::u8 green1 = entry->green;
946 fl::u8 blue1 = entry->blue;
947
948 fl::u8 blend = offset && (blendType != NOBLEND);
949 if (blend) {
950 if (index_8bit == 255) {
951 entry = &(pal[0]);
952 } else {
953 entry++;
954 }
955
956 // Calculate the scaling factor and scaled values for the lower palette
957 // value.
958 fl::u8 f1 = 255 - offset;
959 red1 = scale8_LEAVING_R1_DIRTY(red1, f1);
960 green1 = scale8_LEAVING_R1_DIRTY(green1, f1);
961 blue1 = scale8_LEAVING_R1_DIRTY(blue1, f1);
962
963 // Calculate the scaled values for the neighbouring palette value.
964 fl::u8 red2 = entry->red;
965 fl::u8 green2 = entry->green;
966 fl::u8 blue2 = entry->blue;
967 red2 = scale8_LEAVING_R1_DIRTY(red2, offset);
968 green2 = scale8_LEAVING_R1_DIRTY(green2, offset);
969 blue2 = scale8_LEAVING_R1_DIRTY(blue2, offset);
970 cleanup_R1();
971
972 // These sums can't overflow, so no qadd8 needed.
973 red1 += red2;
974 green1 += green2;
975 blue1 += blue2;
976 }
977 if (brightness != 255) {
978 // nscale8x3_video(red1, green1, blue1, brightness);
979 nscale8x3(red1, green1, blue1, brightness);
980 }
981 return CRGB(red1, green1, blue1);
982}
fl::UISlider brightness("Brightness", BRIGHTNESS, 0, 255)
fl::UISlider offset("Offset", 0.0f, 0.0f, 1.0f, 0.01f)
unsigned char u8
Definition s16x16x4.h:132
fl::CRGB CRGB
Definition video.h:15
CRGB blend(const CRGB &p1, const CRGB &p2, fract8 amountOfP2)
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38

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

+ Here is the call graph for this function: