FastLED 3.9.15
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 395 of file colorutils.cpp.hpp.

396 {
397 if (blendType == LINEARBLEND_NOWRAP) {
398 index = map8(index, 0, 239); // Blend range is affected by lo4 blend of
399 // values, remap to avoid wrapping
400 }
401
402 // hi4 = index >> 4;
403 fl::u8 hi4 = lsrX4(index);
404 fl::u8 lo4 = index & 0x0F;
405
406 // const CRGB* entry = &(pal[0]) + hi4;
407 // since hi4 is always 0..15, hi4 * sizeof(CRGB) can be a single-byte value,
408 // instead of the two byte 'int' that avr-gcc defaults to.
409 // So, we multiply hi4 X sizeof(CRGB), giving hi4XsizeofCRGB;
410 fl::u8 hi4XsizeofCRGB = hi4 * sizeof(CRGB);
411 // We then add that to a base array pointer.
412 const CRGB *entry = (CRGB *)((fl::u8 *)(&(pal[0])) + hi4XsizeofCRGB);
413
414 fl::u8 blend = lo4 && (blendType != NOBLEND);
415
416 fl::u8 red1 = entry->red;
417 fl::u8 green1 = entry->green;
418 fl::u8 blue1 = entry->blue;
419
420 if (blend) {
421
422 if (hi4 == 15) {
423 entry = &(pal[0]);
424 } else {
425 ++entry;
426 }
427
428 fl::u8 f2 = lo4 << 4;
429 fl::u8 f1 = 255 - f2;
430
431 // rgb1.nscale8(f1);
432 fl::u8 red2 = entry->red;
433 red1 = scale8_LEAVING_R1_DIRTY(red1, f1);
434 red2 = scale8_LEAVING_R1_DIRTY(red2, f2);
435 red1 += red2;
436
437 fl::u8 green2 = entry->green;
438 green1 = scale8_LEAVING_R1_DIRTY(green1, f1);
439 green2 = scale8_LEAVING_R1_DIRTY(green2, f2);
440 green1 += green2;
441
442 fl::u8 blue2 = entry->blue;
443 blue1 = scale8_LEAVING_R1_DIRTY(blue1, f1);
444 blue2 = scale8_LEAVING_R1_DIRTY(blue2, f2);
445 blue1 += blue2;
446
447 cleanup_R1();
448 }
449
450 if (brightness != 255) {
451 if (brightness) {
452 ++brightness; // adjust for rounding
453 // Now, since brightness is nonzero, we don't need the full
454 // scale8_video logic; we can just to scale8 and then add one
455 // (unless scale8 fixed) to all nonzero inputs.
456 if (red1) {
457 red1 = scale8_LEAVING_R1_DIRTY(red1, brightness);
458#if !(FASTLED_SCALE8_FIXED == 1)
459 ++red1;
460#endif
461 }
462 if (green1) {
463 green1 = scale8_LEAVING_R1_DIRTY(green1, brightness);
464#if !(FASTLED_SCALE8_FIXED == 1)
465 ++green1;
466#endif
467 }
468 if (blue1) {
469 blue1 = scale8_LEAVING_R1_DIRTY(blue1, brightness);
470#if !(FASTLED_SCALE8_FIXED == 1)
471 ++blue1;
472#endif
473 }
474 cleanup_R1();
475 } else {
476 red1 = 0;
477 green1 = 0;
478 blue1 = 0;
479 }
480 }
481
482 return CRGB(red1, green1, blue1);
483}
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: