FastLED 3.10.8
Loading...
Searching...
No Matches

◆ ColorFromPaletteExtended() [2/5]

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

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

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

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

+ Here is the call graph for this function: