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

◆ ColorFromPaletteExtended() [1/5]

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

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

486 {
487 // Extract the four most significant bits of the index as a palette index.
488 fl::u8 index_4bit = index >> 12;
489 // Calculate the 8-bit offset from the palette index.
490 fl::u8 offset = (fl::u8)(index >> 4);
491 // Get the palette entry from the 4-bit index
492 const CRGB *entry = &(pal[0]) + index_4bit;
493 fl::u8 red1 = entry->red;
494 fl::u8 green1 = entry->green;
495 fl::u8 blue1 = entry->blue;
496
497 fl::u8 blend = offset && (blendType != NOBLEND);
498 if (blend) {
499 if (index_4bit == 15) {
500 entry = &(pal[0]);
501 } else {
502 entry++;
503 }
504
505 // Calculate the scaling factor and scaled values for the lower palette
506 // value.
507 fl::u8 f1 = 255 - offset;
508 red1 = scale8_LEAVING_R1_DIRTY(red1, f1);
509 green1 = scale8_LEAVING_R1_DIRTY(green1, f1);
510 blue1 = scale8_LEAVING_R1_DIRTY(blue1, f1);
511
512 // Calculate the scaled values for the neighbouring palette value.
513 fl::u8 red2 = entry->red;
514 fl::u8 green2 = entry->green;
515 fl::u8 blue2 = entry->blue;
516 red2 = scale8_LEAVING_R1_DIRTY(red2, offset);
517 green2 = scale8_LEAVING_R1_DIRTY(green2, offset);
518 blue2 = scale8_LEAVING_R1_DIRTY(blue2, offset);
519 cleanup_R1();
520
521 // These sums can't overflow, so no qadd8 needed.
522 red1 += red2;
523 green1 += green2;
524 blue1 += blue2;
525 }
526 if (brightness != 255) {
527 // nscale8x3_video(red1, green1, blue1, brightness);
528 nscale8x3(red1, green1, blue1, brightness);
529 }
530 return CRGB(red1, green1, blue1);
531}
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: