@@ -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)
8787uint32_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
117118void setRandomColor (byte* rgb)
0 commit comments