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

◆ ColorFromPalette()

CRGB fl::ColorFromPalette ( const CRGBPalette16 & pal,
fl::u8 index,
fl::u8 brightness,
TBlendType blendType )
Examples
ColorPalette.ino, DemoReel100.ino, Fire2012WithPalette.ino, Pacifica.ino, and TwinkleFox.ino.

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

477 {
478 if (blendType == LINEARBLEND_NOWRAP) {
479 index = map8(index, 0, 239); // Blend range is affected by lo4 blend of
480 // values, remap to avoid wrapping
481 }
482
483 // hi4 = index >> 4;
484 fl::u8 hi4 = lsrX4(index);
485 fl::u8 lo4 = index & 0x0F;
486
487 // const CRGB* entry = &(pal[0]) + hi4;
488 // since hi4 is always 0..15, hi4 * sizeof(CRGB) can be a single-byte value,
489 // instead of the two byte 'int' that avr-gcc defaults to.
490 // So, we multiply hi4 X sizeof(CRGB), giving hi4XsizeofCRGB;
491 fl::u8 hi4XsizeofCRGB = hi4 * sizeof(CRGB);
492 // We then add that to a base array pointer.
493 const CRGB *entry = (CRGB *)((fl::u8 *)(&(pal[0])) + hi4XsizeofCRGB);
494
495 fl::u8 blend = lo4 && (blendType != NOBLEND);
496
497 fl::u8 red1 = entry->red;
498 fl::u8 green1 = entry->green;
499 fl::u8 blue1 = entry->blue;
500
501 if (blend) {
502
503 if (hi4 == 15) {
504 entry = &(pal[0]);
505 } else {
506 ++entry;
507 }
508
509 fl::u8 f2 = lo4 << 4;
510 fl::u8 f1 = 255 - f2;
511
512 // rgb1.nscale8(f1);
513 fl::u8 red2 = entry->red;
514 red1 = scale8_LEAVING_R1_DIRTY(red1, f1);
515 red2 = scale8_LEAVING_R1_DIRTY(red2, f2);
516 red1 += red2;
517
518 fl::u8 green2 = entry->green;
519 green1 = scale8_LEAVING_R1_DIRTY(green1, f1);
520 green2 = scale8_LEAVING_R1_DIRTY(green2, f2);
521 green1 += green2;
522
523 fl::u8 blue2 = entry->blue;
524 blue1 = scale8_LEAVING_R1_DIRTY(blue1, f1);
525 blue2 = scale8_LEAVING_R1_DIRTY(blue2, f2);
526 blue1 += blue2;
527
528 cleanup_R1();
529 }
530
531 if (brightness != 255) {
532 if (brightness) {
533 ++brightness; // adjust for rounding
534 // Now, since brightness is nonzero, we don't need the full
535 // scale8_video logic; we can just to scale8 and then add one
536 // (unless scale8 fixed) to all nonzero inputs.
537 if (red1) {
538 red1 = scale8_LEAVING_R1_DIRTY(red1, brightness);
539#if !(FASTLED_SCALE8_FIXED == 1)
540 ++red1;
541#endif
542 }
543 if (green1) {
544 green1 = scale8_LEAVING_R1_DIRTY(green1, brightness);
545#if !(FASTLED_SCALE8_FIXED == 1)
546 ++green1;
547#endif
548 }
549 if (blue1) {
550 blue1 = scale8_LEAVING_R1_DIRTY(blue1, brightness);
551#if !(FASTLED_SCALE8_FIXED == 1)
552 ++blue1;
553#endif
554 }
555 cleanup_R1();
556 } else {
557 red1 = 0;
558 green1 = 0;
559 blue1 = 0;
560 }
561 }
562
563 return CRGB(red1, green1, blue1);
564}
fl::UISlider brightness("Brightness", BRIGHTNESS, 0, 255)
CRGB blend(const CRGB &p1, const CRGB &p2, fract8 amountOfP2)
fl::CRGB CRGB
Definition crgb.h:25
LIB8STATIC fl::u8 map8(fl::u8 in, fl::u8 rangeStart, fl::u8 rangeEnd)
Map from one full-range 8-bit value into a narrower range of 8-bit values, possibly a range of hues.
Definition lib8tion.h:467
unsigned char u8
Definition stdint.h:131
fl::u8 lsrX4(fl::u8 dividend)
Helper function to divide a number by 16, aka four logical shift right (LSR)'s.

Referenced by fl::anonymous_namespace{gradient.cpp.hpp}::Visitor::accept(), fl::anonymous_namespace{gradient.cpp.hpp}::Visitor::accept(), fl::anonymous_namespace{gradient.cpp.hpp}::VisitorFill::accept(), fl::anonymous_namespace{gradient.cpp.hpp}::VisitorFill::accept(), bpm(), computeOneTwinkle(), drawPlasmaWave(), drawRadialSpectrum(), drawSpectrumBars(), drawVUMeter(), drawWaveform(), fillFrameBufferFire(), fillFrameBufferNoise(), FillLEDsFromPaletteColors(), Fire2012WithPalette(), Fire2023(), loop(), and pacifica_one_layer().

+ Here is the caller graph for this function: