Skip to content

Commit e886ece

Browse files
committed
Segment::setPixelColorXY optimization
use a shortcut when the segment is "simple" and just a single pixel needs to be set on HW level.
1 parent 657259a commit e886ece

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

wled00/FX_2Dfcn.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,18 +216,34 @@ void IRAM_ATTR_YN Segment::setPixelColorXY(int x, int y, uint32_t col) //WLEDMM:
216216
if (Segment::maxHeight==1) return; // not a matrix set-up
217217
if (x<0 || y<0 || x >= virtualWidth() || y >= virtualHeight()) return; // if pixel would fall out of virtual segment just exit
218218

219-
if (ledsrgb) ledsrgb[XY(x,y)] = col;
220-
219+
unsigned i = UINT_MAX;
220+
bool sameColor = false;
221+
if (ledsrgb) { // WLEDMM small optimization
222+
i = XY(x,y);
223+
if ((i < UINT_MAX) && (ledsrgb[i] == col)) sameColor = true;
224+
else ledsrgb[i] = col;
225+
}
221226
uint8_t _bri_t = currentBri(on ? opacity : 0);
222227
if (!_bri_t && !transitional) return;
223228
if (_bri_t < 255) {
224229
col = color_fade(col, _bri_t);
225230
}
226231

232+
#if 0 // this is a dangerous optimization
233+
if ((i < UINT_MAX) && sameColor && (ledsrgb[i] == col) && (_globalLeds == nullptr)) return; // WLEDMM looks like nothing to do (but we don't trust globalleds)
234+
#endif
235+
227236
if (reverse ) x = virtualWidth() - x - 1;
228237
if (reverse_y) y = virtualHeight() - y - 1;
229238
if (transpose) { uint16_t t = x; x = y; y = t; } // swap X & Y if segment transposed
230239

240+
// WLEDMM shortcut when no grouping/spacing used
241+
bool simpleSegment = !mirror && !mirror_y && (grouping == 1) && (spacing == 0);
242+
if (simpleSegment) {
243+
strip.setPixelColorXY(start + x, startY + y, col);
244+
return;
245+
}
246+
231247
x *= groupLength(); // expand to physical pixels
232248
y *= groupLength(); // expand to physical pixels
233249
if (x >= width() || y >= height()) return; // if pixel would fall out of segment just exit
@@ -308,8 +324,10 @@ void Segment::setPixelColorXY(float x, float y, uint32_t col, bool aa, bool fast
308324
// returns RGBW values of pixel
309325
uint32_t IRAM_ATTR_YN Segment::getPixelColorXY(int x, int y) {
310326
if (x<0 || y<0 || !isActive()) return 0; // not active or out-of range
311-
int i = XY(x,y);
312-
if (ledsrgb) return RGBW32(ledsrgb[i].r, ledsrgb[i].g, ledsrgb[i].b, 0);
327+
if (ledsrgb) {
328+
int i = XY(x,y);
329+
return RGBW32(ledsrgb[i].r, ledsrgb[i].g, ledsrgb[i].b, 0);
330+
}
313331
if (reverse ) x = virtualWidth() - x - 1;
314332
if (reverse_y) y = virtualHeight() - y - 1;
315333
if (transpose) { uint16_t t = x; x = y; y = t; } // swap X & Y if segment transposed
@@ -325,7 +343,7 @@ void Segment::blendPixelColorXY(uint16_t x, uint16_t y, uint32_t color, uint8_t
325343
}
326344

327345
// Adds the specified color with the existing pixel color perserving color balance.
328-
void Segment::addPixelColorXY(int x, int y, uint32_t color, bool fast) {
346+
void IRAM_ATTR_YN Segment::addPixelColorXY(int x, int y, uint32_t color, bool fast) {
329347
if (!isActive()) return; // not active
330348
if (x >= virtualWidth() || y >= virtualHeight() || x<0 || y<0) return; // if pixel would fall out of virtual segment just exit
331349
uint32_t col = getPixelColorXY(x,y);

wled00/FX_fcn.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,17 @@ void IRAM_ATTR_YN Segment::setPixelColor(int i, uint32_t col) //WLEDMM: IRAM_ATT
10441044
}
10451045
i += start; // starting pixel in a group
10461046

1047+
#if 0 // needs more testing
1048+
// WLEDMM shortcut when no grouping/spacing used
1049+
bool simpleSegment = !mirror && (grouping == 1) && (spacing == 0);
1050+
if (simpleSegment) {
1051+
int indexSet = i + offset; // offset/phase
1052+
if (indexSet >= stop) indexSet -= len; // wrap
1053+
strip.setPixelColor(indexSet, col);
1054+
return;
1055+
}
1056+
#endif
1057+
10471058
// set all the pixels in the group
10481059
for (int j = 0; j < grouping; j++) {
10491060
uint16_t indexSet = i + ((reverse) ? -j : j);

wled00/wled.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
// version code in format yymmddb (b = daily build)
11-
#define VERSION 2404181
11+
#define VERSION 2404201
1212

1313
// WLEDMM - you can check for this define in usermods, to only enabled WLEDMM specific code in the "right" fork. Its not defined in AC WLED.
1414
#define _MoonModules_WLED_

0 commit comments

Comments
 (0)