| 393 | } |
| 394 | |
| 395 | CRGB 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 |
no test coverage detected