Feature/scale palette fallback (#1484)

* scale color_from_palette fallback by brightnes

* reuse `crgb_to_col` function

Co-authored-by: Florian Baumann <derflob@derflob.de>
This commit is contained in:
Florian Baumann 2020-12-13 18:36:18 +01:00 committed by GitHub
parent 35998df05c
commit 153e6b56ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -912,13 +912,24 @@ void WS2812FX::handle_palette(void)
*/ */
uint32_t WS2812FX::color_from_palette(uint16_t i, bool mapping, bool wrap, uint8_t mcol, uint8_t pbri) uint32_t WS2812FX::color_from_palette(uint16_t i, bool mapping, bool wrap, uint8_t mcol, uint8_t pbri)
{ {
if (SEGMENT.palette == 0 && mcol < 3) return SEGCOLOR(mcol); //WS2812FX default if (SEGMENT.palette == 0 && mcol < 3) {
uint32_t color = SEGCOLOR(mcol);
if (pbri != 255) {
CRGB crgb_color = col_to_crgb(color);
crgb_color.nscale8_video(pbri);
return crgb_to_col(crgb_color);
} else {
return color;
}
}
uint8_t paletteIndex = i; uint8_t paletteIndex = i;
if (mapping) paletteIndex = (i*255)/(SEGLEN -1); if (mapping) paletteIndex = (i*255)/(SEGLEN -1);
if (!wrap) paletteIndex = scale8(paletteIndex, 240); //cut off blend at palette "end" if (!wrap) paletteIndex = scale8(paletteIndex, 240); //cut off blend at palette "end"
CRGB fastled_col; CRGB fastled_col;
fastled_col = ColorFromPalette( currentPalette, paletteIndex, pbri, (paletteBlend == 3)? NOBLEND:LINEARBLEND); fastled_col = ColorFromPalette( currentPalette, paletteIndex, pbri, (paletteBlend == 3)? NOBLEND:LINEARBLEND);
return fastled_col.r*65536 + fastled_col.g*256 + fastled_col.b;
return crgb_to_col(fastled_col);
} }
//@returns `true` if color, mode, speed, intensity and palette match //@returns `true` if color, mode, speed, intensity and palette match