diff --git a/wled00/colors.cpp b/wled00/colors.cpp index 6546043b..465fefbb 100644 --- a/wled00/colors.cpp +++ b/wled00/colors.cpp @@ -9,9 +9,11 @@ */ IRAM_ATTR_YN uint32_t color_blend(uint32_t color1, uint32_t color2, uint_fast16_t blend, bool b16) { if(blend == 0) return color1; - uint_fast16_t blendmax = b16 ? 0xFFFF : 0xFF; + if (color1 == color2) return color1; // WLEDMM shortcut + const uint_fast16_t blendmax = b16 ? 0xFFFF : 0xFF; if(blend == blendmax) return color2; const uint_fast8_t shift = b16 ? 16 : 8; + const uint_fast16_t blend2 = blendmax - blend; // WLEDMM pre-calculate value uint32_t w1 = W(color1); uint32_t r1 = R(color1); @@ -23,10 +25,10 @@ IRAM_ATTR_YN uint32_t color_blend(uint32_t color1, uint32_t color2, uint_fast16_ uint32_t g2 = G(color2); uint32_t b2 = B(color2); - uint32_t w3 = ((w2 * blend) + (w1 * (blendmax - blend))) >> shift; - uint32_t r3 = ((r2 * blend) + (r1 * (blendmax - blend))) >> shift; - uint32_t g3 = ((g2 * blend) + (g1 * (blendmax - blend))) >> shift; - uint32_t b3 = ((b2 * blend) + (b1 * (blendmax - blend))) >> shift; + uint32_t w3 = ((w2 * blend) + (w1 * blend2)) >> shift; + uint32_t r3 = ((r2 * blend) + (r1 * blend2)) >> shift; + uint32_t g3 = ((g2 * blend) + (g1 * blend2)) >> shift; + uint32_t b3 = ((b2 * blend) + (b1 * blend2)) >> shift; return RGBW32(r3, g3, b3, w3); }