FastLED 3.10.8
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 477 of file colorutils.cpp.hpp.

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