added improvements to color scaling and blurring

-changes save roughly 600bytes of flash
-made blurring faster by not writing the color and then reading it back but keeping it as a variable: on a C3, FX black hole goes from 55FPS to 71FPS
-added optional parameter to blur (smear) that can be used in combination with SEGMENT.clear(), blurring the frame without dimming the current frame (repeated calls without clearing will result in white). this is useful to blur without 'motion blurring' being added
-scale8 is inlined and repeated calls uses flash, plus it is slower than native 32bit, so I added 'color_scale' function which is native 32bit and scales 32bit colors (RGBW).
This commit is contained in:
Damian Schneider
2024-04-15 21:20:45 +02:00
parent 94cdd88474
commit 459156fe57
5 changed files with 105 additions and 74 deletions

View File

@@ -61,28 +61,40 @@ uint32_t color_add(uint32_t c1, uint32_t c2, bool fast)
}
}
/*
* color scale function that replaces scale8 for 32bit colors
*/
uint32_t color_scale(uint32_t c1, uint8_t scale)
{
uint32_t fixedscale = 1 + scale;
uint32_t scaledcolor; //color order is: W R G B from MSB to LSB
scaledcolor = ((R(c1) * fixedscale) >> 8) << 16;
scaledcolor |= ((G(c1) * fixedscale) >> 8) << 8;
scaledcolor |= (B(c1) * fixedscale) >> 8;
scaledcolor |= ((W(c1) * fixedscale) >> 8) << 24;
return scaledcolor;
}
/*
* fades color toward black
* if using "video" method the resulting color will never become black unless it is already black
*/
uint32_t color_fade(uint32_t c1, uint8_t amount, bool video)
{
uint8_t r = R(c1);
uint8_t g = G(c1);
uint8_t b = B(c1);
uint8_t w = W(c1);
if (video) {
r = scale8_video(r, amount);
g = scale8_video(g, amount);
b = scale8_video(b, amount);
w = scale8_video(w, amount);
} else {
r = scale8(r, amount);
g = scale8(g, amount);
b = scale8(b, amount);
w = scale8(w, amount);
if (video)
{
uint8_t r = scale8_video(R(c1), amount);
uint8_t g = scale8_video(G(c1), amount);
uint8_t b = scale8_video(B(c1), amount);
uint8_t w = scale8_video(W(c1), amount);
return RGBW32(r, g, b, w);
}
else
{
return color_scale(c1, amount);
}
return RGBW32(r, g, b, w);
}
void setRandomColor(byte* rgb)