Skip to content

Commit 365c198

Browse files
committed
Missing clipping fix
- small speed optimisations
1 parent c03422e commit 365c198

File tree

3 files changed

+35
-28
lines changed

3 files changed

+35
-28
lines changed

wled00/FX.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ typedef enum mapping1D2D {
351351
M12_sPinwheel = 4
352352
} mapping1D2D_t;
353353

354-
// segment, 80 bytes
354+
// segment, 68 bytes
355355
typedef struct Segment {
356356
public:
357357
uint16_t start; // start index / start X coordinate 2D (left)
@@ -639,7 +639,7 @@ typedef struct Segment {
639639
uint16_t virtualHeight(void) const; // segment height in virtual pixels (accounts for groupping and spacing)
640640
uint16_t nrOfVStrips(void) const; // returns number of virtual vertical strips in 2D matrix (used to expand 1D effects into 2D)
641641
#ifndef WLED_DISABLE_2D
642-
uint16_t XY(uint16_t x, uint16_t y); // support function to get relative index within segment
642+
uint16_t XY(int x, int y); // support function to get relative index within segment
643643
void setPixelColorXY(int x, int y, uint32_t c); // set relative pixel within segment with color
644644
inline void setPixelColorXY(unsigned x, unsigned y, uint32_t c) { setPixelColorXY(int(x), int(y), c); }
645645
inline void setPixelColorXY(int x, int y, byte r, byte g, byte b, byte w = 0) { setPixelColorXY(x, y, RGBW32(r,g,b,w)); }
@@ -678,7 +678,7 @@ typedef struct Segment {
678678
inline void blur2d(fract8 blur_amount) { blur(blur_amount); }
679679
inline void fill_solid(CRGB c) { fill(RGBW32(c.r,c.g,c.b,0)); }
680680
#else
681-
inline uint16_t XY(uint16_t x, uint16_t y) { return x; }
681+
inline uint16_t XY(int x, int y) { return x; }
682682
inline void setPixelColorXY(int x, int y, uint32_t c) { setPixelColor(x, c); }
683683
inline void setPixelColorXY(unsigned x, unsigned y, uint32_t c) { setPixelColor(int(x), c); }
684684
inline void setPixelColorXY(int x, int y, byte r, byte g, byte b, byte w = 0) { setPixelColor(x, RGBW32(r,g,b,w)); }

wled00/FX_2Dfcn.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ void WS2812FX::setUpMatrix() {
161161
#ifndef WLED_DISABLE_2D
162162

163163
// XY(x,y) - gets pixel index within current segment (often used to reference leds[] array element)
164-
uint16_t IRAM_ATTR Segment::XY(uint16_t x, uint16_t y)
165-
{
164+
uint16_t IRAM_ATTR Segment::XY(int x, int y) {
166165
unsigned width = virtualWidth(); // segment width in logical pixels (can be 0 if segment is inactive)
167166
unsigned height = virtualHeight(); // segment height in logical pixels (is always >= 1)
168167
return isActive() ? (x%width) + (y%height) * width : 0;
@@ -207,7 +206,7 @@ void IRAM_ATTR Segment::setPixelColorXY(int x, int y, uint32_t col)
207206
int vH = virtualHeight();
208207

209208
#ifndef WLED_DISABLE_MODE_BLEND
210-
if (!_modeBlend &&
209+
if (isInTransition() && !_modeBlend &&
211210
(blendingStyle == BLEND_STYLE_PUSH_RIGHT ||
212211
blendingStyle == BLEND_STYLE_PUSH_LEFT ||
213212
blendingStyle == BLEND_STYLE_PUSH_UP ||
@@ -239,13 +238,16 @@ void IRAM_ATTR Segment::setPixelColorXY(int x, int y, uint32_t col)
239238

240239
x *= groupLength(); // expand to physical pixels
241240
y *= groupLength(); // expand to physical pixels
242-
if (x >= width() || y >= height()) return; // if pixel would fall out of segment just exit
241+
242+
int W = width();
243+
int H = height();
244+
if (x >= W || y >= H) return; // if pixel would fall out of segment just exit
243245

244246
uint32_t tmpCol = col;
245247
for (int j = 0; j < grouping; j++) { // groupping vertically
246248
for (int g = 0; g < grouping; g++) { // groupping horizontally
247249
unsigned xX = (x+g), yY = (y+j);
248-
if (xX >= width() || yY >= height()) continue; // we have reached one dimension's end
250+
if (xX >= W || yY >= H) continue; // we have reached one dimension's end
249251

250252
#ifndef WLED_DISABLE_MODE_BLEND
251253
// if blending modes, blend with underlying pixel
@@ -255,15 +257,15 @@ void IRAM_ATTR Segment::setPixelColorXY(int x, int y, uint32_t col)
255257
strip.setPixelColorXY(start + xX, startY + yY, tmpCol);
256258

257259
if (mirror) { //set the corresponding horizontally mirrored pixel
258-
if (transpose) strip.setPixelColorXY(start + xX, startY + height() - yY - 1, tmpCol);
259-
else strip.setPixelColorXY(start + width() - xX - 1, startY + yY, tmpCol);
260+
if (transpose) strip.setPixelColorXY(start + xX, startY + H - yY - 1, tmpCol);
261+
else strip.setPixelColorXY(start + W - xX - 1, startY + yY, tmpCol);
260262
}
261263
if (mirror_y) { //set the corresponding vertically mirrored pixel
262-
if (transpose) strip.setPixelColorXY(start + width() - xX - 1, startY + yY, tmpCol);
263-
else strip.setPixelColorXY(start + xX, startY + height() - yY - 1, tmpCol);
264+
if (transpose) strip.setPixelColorXY(start + W - xX - 1, startY + yY, tmpCol);
265+
else strip.setPixelColorXY(start + xX, startY + H - yY - 1, tmpCol);
264266
}
265267
if (mirror_y && mirror) { //set the corresponding vertically AND horizontally mirrored pixel
266-
strip.setPixelColorXY(width() - xX - 1, height() - yY - 1, tmpCol);
268+
strip.setPixelColorXY(W - xX - 1, H - yY - 1, tmpCol);
267269
}
268270
}
269271
}

wled00/FX_fcn.cpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ uint16_t IRAM_ATTR Segment::virtualLength() const {
754754
bool IRAM_ATTR Segment::isPixelClipped(int i) {
755755
#ifndef WLED_DISABLE_MODE_BLEND
756756
if (_clipStart != _clipStop && blendingStyle > BLEND_STYLE_FADE) {
757-
bool invert = _clipStart > _clipStop; // ineverted start & stop
757+
bool invert = _clipStart > _clipStop; // ineverted start & stop
758758
int start = invert ? _clipStop : _clipStart;
759759
int stop = invert ? _clipStart : _clipStop;
760760
if (blendingStyle == BLEND_STYLE_FAIRY_DUST) {
@@ -892,7 +892,8 @@ void IRAM_ATTR Segment::setPixelColor(int i, uint32_t col)
892892
#endif
893893

894894
#ifndef WLED_DISABLE_MODE_BLEND
895-
if (!_modeBlend && (blendingStyle == BLEND_STYLE_PUSH_RIGHT || blendingStyle == BLEND_STYLE_PUSH_LEFT)) {
895+
// if we blend using "push" style we need to "shift" new mode to left or right
896+
if (isInTransition() && !_modeBlend && (blendingStyle == BLEND_STYLE_PUSH_RIGHT || blendingStyle == BLEND_STYLE_PUSH_LEFT)) {
896897
unsigned prog = 0xFFFF - progress();
897898
unsigned dI = prog * vL / 0xFFFF;
898899
if (blendingStyle == BLEND_STYLE_PUSH_RIGHT) i -= dI;
@@ -1043,7 +1044,7 @@ uint32_t IRAM_ATTR Segment::getPixelColor(int i)
10431044
#endif
10441045

10451046
#ifndef WLED_DISABLE_MODE_BLEND
1046-
if (!_modeBlend && (blendingStyle == BLEND_STYLE_PUSH_RIGHT || blendingStyle == BLEND_STYLE_PUSH_LEFT)) {
1047+
if (isInTransition() && !_modeBlend && (blendingStyle == BLEND_STYLE_PUSH_RIGHT || blendingStyle == BLEND_STYLE_PUSH_LEFT)) {
10471048
unsigned prog = 0xFFFF - progress();
10481049
unsigned dI = prog * vL / 0xFFFF;
10491050
if (blendingStyle == BLEND_STYLE_PUSH_RIGHT) i -= dI;
@@ -1425,43 +1426,47 @@ void WS2812FX::service() {
14251426
unsigned dw = p * w / 0xFFFFU + 1;
14261427
unsigned dh = p * h / 0xFFFFU + 1;
14271428
switch (blendingStyle) {
1428-
case BLEND_STYLE_FAIRY_DUST: // fairy dust (must set entire segment, see isPixelXYClipped())
1429+
case BLEND_STYLE_FAIRY_DUST: // fairy dust (must set entire segment, see isPixelXYClipped())
14291430
Segment::setClippingRect(0, w, 0, h);
14301431
break;
14311432
case BLEND_STYLE_SWIPE_RIGHT: // left-to-right
1433+
case BLEND_STYLE_PUSH_RIGHT: // left-to-right
14321434
Segment::setClippingRect(0, dw, 0, h);
14331435
break;
1434-
case BLEND_STYLE_SWIPE_LEFT: // right-to-left
1436+
case BLEND_STYLE_SWIPE_LEFT: // right-to-left
1437+
case BLEND_STYLE_PUSH_LEFT: // right-to-left
14351438
Segment::setClippingRect(w - dw, w, 0, h);
14361439
break;
1437-
case BLEND_STYLE_PINCH_OUT: // corners
1440+
case BLEND_STYLE_PINCH_OUT: // corners
14381441
Segment::setClippingRect((w + dw)/2, (w - dw)/2, (h + dh)/2, (h - dh)/2); // inverted!!
14391442
break;
1440-
case BLEND_STYLE_INSIDE_OUT: // outward
1443+
case BLEND_STYLE_INSIDE_OUT: // outward
14411444
Segment::setClippingRect((w - dw)/2, (w + dw)/2, (h - dh)/2, (h + dh)/2);
14421445
break;
1443-
case BLEND_STYLE_SWIPE_DOWN: // top-to-bottom (2D)
1446+
case BLEND_STYLE_SWIPE_DOWN: // top-to-bottom (2D)
1447+
case BLEND_STYLE_PUSH_DOWN: // top-to-bottom (2D)
14441448
Segment::setClippingRect(0, w, 0, dh);
14451449
break;
1446-
case BLEND_STYLE_SWIPE_UP: // bottom-to-top (2D)
1450+
case BLEND_STYLE_SWIPE_UP: // bottom-to-top (2D)
1451+
case BLEND_STYLE_PUSH_UP: // bottom-to-top (2D)
14471452
Segment::setClippingRect(0, w, h - dh, h);
14481453
break;
1449-
case BLEND_STYLE_OPEN_H: // horizontal-outward (2D) same look as INSIDE_OUT on 1D
1454+
case BLEND_STYLE_OPEN_H: // horizontal-outward (2D) same look as INSIDE_OUT on 1D
14501455
Segment::setClippingRect((w - dw)/2, (w + dw)/2, 0, h);
14511456
break;
1452-
case BLEND_STYLE_OPEN_V: // vertical-outward (2D)
1457+
case BLEND_STYLE_OPEN_V: // vertical-outward (2D)
14531458
Segment::setClippingRect(0, w, (h - dh)/2, (h + dh)/2);
14541459
break;
1455-
case BLEND_STYLE_PUSH_TL: // TL-to-BR (2D)
1460+
case BLEND_STYLE_PUSH_TL: // TL-to-BR (2D)
14561461
Segment::setClippingRect(0, dw, 0, dh);
14571462
break;
1458-
case BLEND_STYLE_PUSH_TR: // TR-to-BL (2D)
1463+
case BLEND_STYLE_PUSH_TR: // TR-to-BL (2D)
14591464
Segment::setClippingRect(w - dw, w, 0, dh);
14601465
break;
1461-
case BLEND_STYLE_PUSH_BR: // BR-to-TL (2D)
1466+
case BLEND_STYLE_PUSH_BR: // BR-to-TL (2D)
14621467
Segment::setClippingRect(w - dw, w, h - dh, h);
14631468
break;
1464-
case BLEND_STYLE_PUSH_BL: // BL-to-TR (2D)
1469+
case BLEND_STYLE_PUSH_BL: // BL-to-TR (2D)
14651470
Segment::setClippingRect(0, dw, h - dh, h);
14661471
break;
14671472
}

0 commit comments

Comments
 (0)