Skip to content

Commit b363b61

Browse files
committed
revert using color_fade() as it is slower
- ran a few more tests, it is 30% faster like it was originally so reverting. The conversion to 32bit color appears to be wasteful in resources.
1 parent 3baa4f8 commit b363b61

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

wled00/colors.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,32 +86,33 @@ uint32_t color_fade(uint32_t c1, uint8_t amount, bool video)
8686
// 1:1 replacement of fastled function optimized for ESP, slightly faster, more accurate and uses less flash (~ -200bytes)
8787
uint32_t ColorFromPaletteWLED(const CRGBPalette16& pal, unsigned index, uint8_t brightness, TBlendType blendType)
8888
{
89+
8990
if (blendType == LINEARBLEND_NOWRAP) {
9091
index = (index * 0xF0) >> 8; // Blend range is affected by lo4 blend of values, remap to avoid wrapping
9192
}
9293
uint32_t clr32;
9394
unsigned hi4 = byte(index) >> 4;
9495
unsigned lo4 = (index & 0x0F);
9596
const CRGB* entry = (CRGB*)&(pal[0]) + hi4;
97+
unsigned red1 = entry->r;
98+
unsigned green1 = entry->g;
99+
unsigned blue1 = entry->b;
96100
if(lo4 && blendType != NOBLEND) {
97-
unsigned red1 = entry->r;
98-
unsigned green1 = entry->g;
99-
unsigned blue1 = entry->b;
100101
if (hi4 == 15) entry = &(pal[0]);
101102
else ++entry;
102103
unsigned f2 = (lo4 << 4);
103104
unsigned f1 = 256 - f2;
104-
red1 = (red1 * f1 + (unsigned)entry->r * f2) >> 8; // note: using color_blend() is 20% slower
105+
red1 = (red1 * f1 + (unsigned)entry->r * f2) >> 8; // note: using color_blend() is 20% slower
105106
green1 = (green1 * f1 + (unsigned)entry->g * f2) >> 8;
106107
blue1 = (blue1 * f1 + (unsigned)entry->b * f2) >> 8;
107-
clr32 = RGBW32(red1, green1, blue1, 0);
108108
}
109-
else
110-
clr32 = RGBW32(entry->r, entry->g, entry->b, 0);
111109
if (brightness < 255) { // note: zero checking could be done to return black but that is hardly ever used so it is omitted
112-
clr32 = color_fade(clr32, brightness);
110+
uint32_t scale = brightness + 1; // adjust for rounding (bitshift)
111+
red1 = (red1 * scale) >> 8; // note: using color_fade() is 30% slower
112+
green1 = (green1 * scale) >> 8;
113+
blue1 = (blue1 * scale) >> 8;
113114
}
114-
return clr32;
115+
return RGBW32(red1,green1,blue1,0);
115116
}
116117

117118
void setRandomColor(byte* rgb)

0 commit comments

Comments
 (0)