mirror of
https://github.com/wled/WLED.git
synced 2025-07-29 21:56:37 +00:00
Shifting bugfix & size tuning in fade_out
This commit is contained in:
parent
249c124176
commit
47a9e4aa51
@ -279,6 +279,7 @@ void Segment::startTransition(uint16_t dur) {
|
|||||||
_t->_briT = on ? opacity : 0;
|
_t->_briT = on ? opacity : 0;
|
||||||
_t->_cctT = cct;
|
_t->_cctT = cct;
|
||||||
#ifndef WLED_DISABLE_MODE_BLEND
|
#ifndef WLED_DISABLE_MODE_BLEND
|
||||||
|
if (modeBlending) {
|
||||||
swapSegenv(_t->_segT); // copy runtime data to temporary
|
swapSegenv(_t->_segT); // copy runtime data to temporary
|
||||||
_t->_modeT = mode;
|
_t->_modeT = mode;
|
||||||
_t->_segT._dataLenT = 0;
|
_t->_segT._dataLenT = 0;
|
||||||
@ -300,9 +301,9 @@ void Segment::startTransition(uint16_t dur) {
|
|||||||
_t->_segT._colorT[1],
|
_t->_segT._colorT[1],
|
||||||
_t->_segT._colorT[2],
|
_t->_segT._colorT[2],
|
||||||
(int)_t->_modeT);
|
(int)_t->_modeT);
|
||||||
#else
|
} else
|
||||||
for (size_t i=0; i<NUM_COLORS; i++) _t->_colorT[i] = colors[i];
|
|
||||||
# endif
|
# endif
|
||||||
|
for (size_t i=0; i<NUM_COLORS; i++) _t->_colorT[i] = colors[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
void Segment::stopTransition() {
|
void Segment::stopTransition() {
|
||||||
@ -1086,36 +1087,25 @@ void Segment::fade_out(uint8_t rate) {
|
|||||||
const int cols = is2D() ? virtualWidth() : virtualLength();
|
const int cols = is2D() ? virtualWidth() : virtualLength();
|
||||||
const int rows = virtualHeight(); // will be 1 for 1D
|
const int rows = virtualHeight(); // will be 1 for 1D
|
||||||
|
|
||||||
rate = (255-rate) >> 1;
|
rate = (256-rate) >> 1;
|
||||||
float mappedRate = 1.0f / (float(rate) + 1.1f);
|
const int mappedRate = 256 / (rate + 1);
|
||||||
|
|
||||||
uint32_t color = colors[1]; // SEGCOLOR(1); // target color
|
|
||||||
int w2 = W(color);
|
|
||||||
int r2 = R(color);
|
|
||||||
int g2 = G(color);
|
|
||||||
int b2 = B(color);
|
|
||||||
|
|
||||||
for (int y = 0; y < rows; y++) for (int x = 0; x < cols; x++) {
|
for (int y = 0; y < rows; y++) for (int x = 0; x < cols; x++) {
|
||||||
color = is2D() ? getPixelColorXY(x, y) : getPixelColor(x);
|
uint32_t color = is2D() ? getPixelColorXY(x, y) : getPixelColor(x);
|
||||||
if (color == colors[1]) continue; // already at target color
|
if (color == colors[1]) continue; // already at target color
|
||||||
int w1 = W(color);
|
for (int i = 0; i < 32; i += 8) {
|
||||||
int r1 = R(color);
|
uint8_t c2 = (colors[1]>>i); // get background channel
|
||||||
int g1 = G(color);
|
uint8_t c1 = (color>>i); // get foreground channel
|
||||||
int b1 = B(color);
|
// we can't use bitshift since we are using int
|
||||||
|
int delta = (c2 - c1) * mappedRate / 256;
|
||||||
int wdelta = (w2 - w1) * mappedRate;
|
|
||||||
int rdelta = (r2 - r1) * mappedRate;
|
|
||||||
int gdelta = (g2 - g1) * mappedRate;
|
|
||||||
int bdelta = (b2 - b1) * mappedRate;
|
|
||||||
|
|
||||||
// if fade isn't complete, make sure delta is at least 1 (fixes rounding issues)
|
// if fade isn't complete, make sure delta is at least 1 (fixes rounding issues)
|
||||||
wdelta += (w2 == w1) ? 0 : (w2 > w1) ? 1 : -1;
|
if (delta == 0) delta += (c2 == c1) ? 0 : (c2 > c1) ? 1 : -1;
|
||||||
rdelta += (r2 == r1) ? 0 : (r2 > r1) ? 1 : -1;
|
// stuff new value back into color
|
||||||
gdelta += (g2 == g1) ? 0 : (g2 > g1) ? 1 : -1;
|
color &= ~(0xFF<<i);
|
||||||
bdelta += (b2 == b1) ? 0 : (b2 > b1) ? 1 : -1;
|
color |= ((c1 + delta) & 0xFF) << i;
|
||||||
|
}
|
||||||
if (is2D()) setPixelColorXY(x, y, r1 + rdelta, g1 + gdelta, b1 + bdelta, w1 + wdelta);
|
if (is2D()) setPixelColorXY(x, y, color);
|
||||||
else setPixelColor(x, r1 + rdelta, g1 + gdelta, b1 + bdelta, w1 + wdelta);
|
else setPixelColor(x, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user