MCPcopy Create free account
hub / github.com/FastLED/FastLED / ColorFromPalette

Function ColorFromPalette

src/fl/gfx/colorutils.cpp.hpp:395–483  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

393}
394
395CRGB ColorFromPalette(const CRGBPalette16 &pal, fl::u8 index,
396 fl::u8 brightness, TBlendType blendType) {
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

Callers 15

acceptMethod · 0.85
acceptMethod · 0.85
fill_paletteFunction · 0.85
fill_palette_circularFunction · 0.85
pacifica_one_layerMethod · 0.85
noiseCircleDrawMethod · 0.85
renderAmbientMethod · 0.85
drawMethod · 0.85
computeOneTwinkleMethod · 0.85

Calls 8

map8Function · 0.85
lsrX4Function · 0.85
CRGBClass · 0.70
scale8_LEAVING_R1_DIRTYFunction · 0.50
cleanup_R1Function · 0.50
scale8Function · 0.50
scale8_videoFunction · 0.50

Tested by

no test coverage detected