color_fade optimizations
* removed unnecessary conditions * optimized bit-shifting logic * use uint16_t for colors, to prevent the compiler from using 64bit integer
This commit is contained in:
@@ -84,25 +84,27 @@ IRAM_ATTR_YN __attribute__((hot)) uint32_t color_fade(uint32_t c1, uint8_t amoun
|
||||
if (amount == 255) return c1; // WLEDMM small optimization - plus it avoids over-fading in "video" mode
|
||||
if (amount == 0) return 0; // WLEDMM shortcut
|
||||
|
||||
uint32_t scaledcolor; // color order is: W R G B from MSB to LSB
|
||||
uint32_t r = R(c1);
|
||||
uint32_t g = G(c1);
|
||||
uint32_t b = B(c1);
|
||||
uint32_t w = W(c1);
|
||||
uint32_t scaledcolor = 0; // color order is: W R G B from MSB to LSB
|
||||
uint16_t w = W(c1); // WLEDMM 16bit to make sure the compiler uses 32bit (not 64bit) for the math
|
||||
uint16_t r = R(c1);
|
||||
uint16_t g = G(c1);
|
||||
uint16_t b = B(c1);
|
||||
if (video) {
|
||||
uint32_t scale = amount; // 32bit for faster calculation
|
||||
scaledcolor = (((r * scale) >> 8) << 16) + ((r && scale) ? 1 : 0);
|
||||
scaledcolor |= (((g * scale) >> 8) << 8) + ((g && scale) ? 1 : 0);
|
||||
scaledcolor |= ((b * scale) >> 8) + ((b && scale) ? 1 : 0);
|
||||
if (w>0) scaledcolor |= (((w * scale) >> 8) << 24) + ((scale) ? 1 : 0); // WLEDMM small speedup when no white channel
|
||||
uint16_t scale = amount; // 32bit for faster calculation
|
||||
// bugfix: doing "+1" after shifting is obviously wrong
|
||||
// optimization: ((r && scale) ? 1 : 0) can be simplified to "if (r > 0) +1" ; if we arive here, then scale != 0 and scale < 255
|
||||
if (w>0) scaledcolor |= (((w * scale) >> 8) +1) << 24; // WLEDMM small speedup when no white channel
|
||||
if (r>0) scaledcolor |= (((r * scale) >> 8) +1) << 16;
|
||||
if (g>0) scaledcolor |= (((g * scale) >> 8) +1) << 8;
|
||||
if (b>0) scaledcolor |= ((b * scale) >> 8) +1;
|
||||
return scaledcolor;
|
||||
}
|
||||
else {
|
||||
uint32_t scale = 1 + amount;
|
||||
scaledcolor = ((r * scale) >> 8) << 16;
|
||||
scaledcolor |= ((g * scale) >> 8) << 8;
|
||||
scaledcolor |= (b * scale) >> 8;
|
||||
uint16_t scale = 1 + amount;
|
||||
if (w>0) scaledcolor |= ((w * scale) >> 8) << 24; // WLEDMM small speedup when no white channel
|
||||
scaledcolor |= ((r * scale) >> 8) << 16;
|
||||
scaledcolor |= (g * scale) & 0x0000FF00; // WLEDMM faster than right-left shift "" >>8 ) <<8"
|
||||
scaledcolor |= (b * scale) >> 8;
|
||||
return scaledcolor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
// version code in format yymmddb (b = daily build)
|
||||
#define VERSION 2411140
|
||||
#define VERSION 2411150
|
||||
|
||||
// WLEDMM - you can check for this define in usermods, to only enabled WLEDMM specific code in the "right" fork. Its not defined in AC WLED.
|
||||
#define _MoonModules_WLED_
|
||||
|
||||
Reference in New Issue
Block a user