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

◆ ColorFromPaletteExtended() [1/5]

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

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

567 {
568 // Extract the four most significant bits of the index as a palette index.
569 fl::u8 index_4bit = index >> 12;
570 // Calculate the 8-bit offset from the palette index.
571 fl::u8 offset = (fl::u8)(index >> 4);
572 // Get the palette entry from the 4-bit index
573 const CRGB *entry = &(pal[0]) + index_4bit;
574 fl::u8 red1 = entry->red;
575 fl::u8 green1 = entry->green;
576 fl::u8 blue1 = entry->blue;
577
578 fl::u8 blend = offset && (blendType != NOBLEND);
579 if (blend) {
580 if (index_4bit == 15) {
581 entry = &(pal[0]);
582 } else {
583 entry++;
584 }
585
586 // Calculate the scaling factor and scaled values for the lower palette
587 // value.
588 fl::u8 f1 = 255 - offset;
589 red1 = scale8_LEAVING_R1_DIRTY(red1, f1);
590 green1 = scale8_LEAVING_R1_DIRTY(green1, f1);
591 blue1 = scale8_LEAVING_R1_DIRTY(blue1, f1);
592
593 // Calculate the scaled values for the neighbouring palette value.
594 fl::u8 red2 = entry->red;
595 fl::u8 green2 = entry->green;
596 fl::u8 blue2 = entry->blue;
597 red2 = scale8_LEAVING_R1_DIRTY(red2, offset);
598 green2 = scale8_LEAVING_R1_DIRTY(green2, offset);
599 blue2 = scale8_LEAVING_R1_DIRTY(blue2, offset);
600 cleanup_R1();
601
602 // These sums can't overflow, so no qadd8 needed.
603 red1 += red2;
604 green1 += green2;
605 blue1 += blue2;
606 }
607 if (brightness != 255) {
608 // nscale8x3_video(red1, green1, blue1, brightness);
609 nscale8x3(red1, green1, blue1, brightness);
610 }
611 return CRGB(red1, green1, blue1);
612}
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: