FastLED 3.10.6
Loading...
Searching...
No Matches

◆ ColorFromPaletteExtended() [2/5]

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

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

1018 {
1019 // Extract the eight most significant bits of the index as a palette index.
1020 fl::u8 index_8bit = index >> 8;
1021 // Calculate the 8-bit offset from the palette index.
1022 fl::u8 offset = index & 0xff;
1023 // Get the palette entry from the 8-bit index
1024 const CRGB *entry = &(pal[0]) + index_8bit;
1025 fl::u8 red1 = entry->red;
1026 fl::u8 green1 = entry->green;
1027 fl::u8 blue1 = entry->blue;
1028
1029 fl::u8 blend = offset && (blendType != NOBLEND);
1030 if (blend) {
1031 if (index_8bit == 255) {
1032 entry = &(pal[0]);
1033 } else {
1034 entry++;
1035 }
1036
1037 // Calculate the scaling factor and scaled values for the lower palette
1038 // value.
1039 fl::u8 f1 = 255 - offset;
1040 red1 = scale8_LEAVING_R1_DIRTY(red1, f1);
1041 green1 = scale8_LEAVING_R1_DIRTY(green1, f1);
1042 blue1 = scale8_LEAVING_R1_DIRTY(blue1, f1);
1043
1044 // Calculate the scaled values for the neighbouring palette value.
1045 fl::u8 red2 = entry->red;
1046 fl::u8 green2 = entry->green;
1047 fl::u8 blue2 = entry->blue;
1048 red2 = scale8_LEAVING_R1_DIRTY(red2, offset);
1049 green2 = scale8_LEAVING_R1_DIRTY(green2, offset);
1050 blue2 = scale8_LEAVING_R1_DIRTY(blue2, offset);
1051 cleanup_R1();
1052
1053 // These sums can't overflow, so no qadd8 needed.
1054 red1 += red2;
1055 green1 += green2;
1056 blue1 += blue2;
1057 }
1058 if (brightness != 255) {
1059 // nscale8x3_video(red1, green1, blue1, brightness);
1060 nscale8x3(red1, green1, blue1, brightness);
1061 }
1062 return CRGB(red1, green1, blue1);
1063}
fl::UISlider brightness("Brightness", BRIGHTNESS, 0, 255)
fl::UISlider offset("Offset", 0.0f, 0.0f, 1.0f, 0.01f)
unsigned char u8
Definition stdint.h:131
fl::CRGB CRGB
Definition video.h:18
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: