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

◆ ColorFromPalette() [7/8]

CRGB fl::ColorFromPalette ( const TProgmemRGBPalette16 & pal,
uint8_t index,
uint8_t brightness,
TBlendType blendType )

Definition at line 437 of file colorutils.cpp.

438 {
439 if (blendType == LINEARBLEND_NOWRAP) {
440 index = map8(index, 0, 239); // Blend range is affected by lo4 blend of
441 // values, remap to avoid wrapping
442 }
443
444 // hi4 = index >> 4;
445 uint8_t hi4 = lsrX4(index);
446 uint8_t lo4 = index & 0x0F;
447
448 CRGB entry(FL_PGM_READ_DWORD_NEAR(&(pal[0]) + hi4));
449
450 uint8_t red1 = entry.red;
451 uint8_t green1 = entry.green;
452 uint8_t blue1 = entry.blue;
453
454 uint8_t blend = lo4 && (blendType != NOBLEND);
455
456 if (blend) {
457
458 if (hi4 == 15) {
459 entry = FL_PGM_READ_DWORD_NEAR(&(pal[0]));
460 } else {
461 entry = FL_PGM_READ_DWORD_NEAR(&(pal[1]) + hi4);
462 }
463
464 uint8_t f2 = lo4 << 4;
465 uint8_t f1 = 255 - f2;
466
467 uint8_t red2 = entry.red;
468 red1 = scale8_LEAVING_R1_DIRTY(red1, f1);
469 red2 = scale8_LEAVING_R1_DIRTY(red2, f2);
470 red1 += red2;
471
472 uint8_t green2 = entry.green;
473 green1 = scale8_LEAVING_R1_DIRTY(green1, f1);
474 green2 = scale8_LEAVING_R1_DIRTY(green2, f2);
475 green1 += green2;
476
477 uint8_t blue2 = entry.blue;
478 blue1 = scale8_LEAVING_R1_DIRTY(blue1, f1);
479 blue2 = scale8_LEAVING_R1_DIRTY(blue2, f2);
480 blue1 += blue2;
481
482 cleanup_R1();
483 }
484
485 if (brightness != 255) {
486 if (brightness) {
487 ++brightness; // adjust for rounding
488 // Now, since brightness is nonzero, we don't need the full
489 // scale8_video logic; we can just to scale8 and then add one
490 // (unless scale8 fixed) to all nonzero inputs.
491 if (red1) {
493#if !(FASTLED_SCALE8_FIXED == 1)
494 ++red1;
495#endif
496 }
497 if (green1) {
498 green1 = scale8_LEAVING_R1_DIRTY(green1, brightness);
499#if !(FASTLED_SCALE8_FIXED == 1)
500 ++green1;
501#endif
502 }
503 if (blue1) {
504 blue1 = scale8_LEAVING_R1_DIRTY(blue1, brightness);
505#if !(FASTLED_SCALE8_FIXED == 1)
506 ++blue1;
507#endif
508 }
509 cleanup_R1();
510 } else {
511 red1 = 0;
512 green1 = 0;
513 blue1 = 0;
514 }
515 }
516
517 return CRGB(red1, green1, blue1);
518}
UISlider brightness("Brightness", 255, 0, 255, 1)
CRGB blend(const CRGB &p1, const CRGB &p2, fract8 amountOfP2)
#define FL_PGM_READ_DWORD_NEAR(x)
Read a double word (32-bit) from PROGMEM memory.
LIB8STATIC uint8_t map8(uint8_t in, uint8_t rangeStart, uint8_t 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:541
LIB8STATIC_ALWAYS_INLINE void cleanup_R1()
Clean up the r1 register after a series of *LEAVING_R1_DIRTY calls.
Definition scale8.h:339
LIB8STATIC_ALWAYS_INLINE uint8_t scale8_LEAVING_R1_DIRTY(uint8_t i, fract8 scale)
This version of scale8() does not clean up the R1 register on AVR.
Definition scale8.h:176
uint8_t lsrX4(uint8_t dividend)
Helper function to divide a number by 16, aka four logical shift right (LSR)'s.
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:55

References blend(), brightness, cleanup_R1(), FL_PGM_READ_DWORD_NEAR, lsrX4(), map8(), and scale8_LEAVING_R1_DIRTY().

+ Here is the call graph for this function: