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

◆ ColorFromPalette() [7/8]

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

Definition at line 438 of file colorutils.cpp.

439 {
440 if (blendType == LINEARBLEND_NOWRAP) {
441 index = map8(index, 0, 239); // Blend range is affected by lo4 blend of
442 // values, remap to avoid wrapping
443 }
444
445 // hi4 = index >> 4;
446 fl::u8 hi4 = lsrX4(index);
447 fl::u8 lo4 = index & 0x0F;
448
449 CRGB entry(FL_PGM_READ_DWORD_NEAR(&(pal[0]) + hi4));
450
451 fl::u8 red1 = entry.red;
452 fl::u8 green1 = entry.green;
453 fl::u8 blue1 = entry.blue;
454
455 fl::u8 blend = lo4 && (blendType != NOBLEND);
456
457 if (blend) {
458
459 if (hi4 == 15) {
460 entry = FL_PGM_READ_DWORD_NEAR(&(pal[0]));
461 } else {
462 entry = FL_PGM_READ_DWORD_NEAR(&(pal[1]) + hi4);
463 }
464
465 fl::u8 f2 = lo4 << 4;
466 fl::u8 f1 = 255 - f2;
467
468 fl::u8 red2 = entry.red;
469 red1 = scale8_LEAVING_R1_DIRTY(red1, f1);
470 red2 = scale8_LEAVING_R1_DIRTY(red2, f2);
471 red1 += red2;
472
473 fl::u8 green2 = entry.green;
474 green1 = scale8_LEAVING_R1_DIRTY(green1, f1);
475 green2 = scale8_LEAVING_R1_DIRTY(green2, f2);
476 green1 += green2;
477
478 fl::u8 blue2 = entry.blue;
479 blue1 = scale8_LEAVING_R1_DIRTY(blue1, f1);
480 blue2 = scale8_LEAVING_R1_DIRTY(blue2, f2);
481 blue1 += blue2;
482
483 cleanup_R1();
484 }
485
486 if (brightness != 255) {
487 if (brightness) {
488 ++brightness; // adjust for rounding
489 // Now, since brightness is nonzero, we don't need the full
490 // scale8_video logic; we can just to scale8 and then add one
491 // (unless scale8 fixed) to all nonzero inputs.
492 if (red1) {
494#if !(FASTLED_SCALE8_FIXED == 1)
495 ++red1;
496#endif
497 }
498 if (green1) {
499 green1 = scale8_LEAVING_R1_DIRTY(green1, brightness);
500#if !(FASTLED_SCALE8_FIXED == 1)
501 ++green1;
502#endif
503 }
504 if (blue1) {
505 blue1 = scale8_LEAVING_R1_DIRTY(blue1, brightness);
506#if !(FASTLED_SCALE8_FIXED == 1)
507 ++blue1;
508#endif
509 }
510 cleanup_R1();
511 } else {
512 red1 = 0;
513 green1 = 0;
514 blue1 = 0;
515 }
516 }
517
518 return CRGB(red1, green1, blue1);
519}
UISlider brightness("Brightness", 128, 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:397
LIB8STATIC_ALWAYS_INLINE void cleanup_R1()
Clean up the r1 register after a series of *LEAVING_R1_DIRTY calls.
Definition scale8.h:343
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:180
unsigned char u8
Definition int.h:17
fl::u8 lsrX4(fl::u8 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:86

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: