Segment::setPixelColorXY optimization
use a shortcut when the segment is "simple" and just a single pixel needs to be set on HW level.
This commit is contained in:
@@ -216,18 +216,34 @@ void IRAM_ATTR_YN Segment::setPixelColorXY(int x, int y, uint32_t col) //WLEDMM:
|
||||
if (Segment::maxHeight==1) return; // not a matrix set-up
|
||||
if (x<0 || y<0 || x >= virtualWidth() || y >= virtualHeight()) return; // if pixel would fall out of virtual segment just exit
|
||||
|
||||
if (ledsrgb) ledsrgb[XY(x,y)] = col;
|
||||
|
||||
unsigned i = UINT_MAX;
|
||||
bool sameColor = false;
|
||||
if (ledsrgb) { // WLEDMM small optimization
|
||||
i = XY(x,y);
|
||||
if ((i < UINT_MAX) && (ledsrgb[i] == col)) sameColor = true;
|
||||
else ledsrgb[i] = col;
|
||||
}
|
||||
uint8_t _bri_t = currentBri(on ? opacity : 0);
|
||||
if (!_bri_t && !transitional) return;
|
||||
if (_bri_t < 255) {
|
||||
col = color_fade(col, _bri_t);
|
||||
}
|
||||
|
||||
#if 0 // this is a dangerous optimization
|
||||
if ((i < UINT_MAX) && sameColor && (ledsrgb[i] == col) && (_globalLeds == nullptr)) return; // WLEDMM looks like nothing to do (but we don't trust globalleds)
|
||||
#endif
|
||||
|
||||
if (reverse ) x = virtualWidth() - x - 1;
|
||||
if (reverse_y) y = virtualHeight() - y - 1;
|
||||
if (transpose) { uint16_t t = x; x = y; y = t; } // swap X & Y if segment transposed
|
||||
|
||||
// WLEDMM shortcut when no grouping/spacing used
|
||||
bool simpleSegment = !mirror && !mirror_y && (grouping == 1) && (spacing == 0);
|
||||
if (simpleSegment) {
|
||||
strip.setPixelColorXY(start + x, startY + y, col);
|
||||
return;
|
||||
}
|
||||
|
||||
x *= groupLength(); // expand to physical pixels
|
||||
y *= groupLength(); // expand to physical pixels
|
||||
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
|
||||
// returns RGBW values of pixel
|
||||
uint32_t IRAM_ATTR_YN Segment::getPixelColorXY(int x, int y) {
|
||||
if (x<0 || y<0 || !isActive()) return 0; // not active or out-of range
|
||||
int i = XY(x,y);
|
||||
if (ledsrgb) return RGBW32(ledsrgb[i].r, ledsrgb[i].g, ledsrgb[i].b, 0);
|
||||
if (ledsrgb) {
|
||||
int i = XY(x,y);
|
||||
return RGBW32(ledsrgb[i].r, ledsrgb[i].g, ledsrgb[i].b, 0);
|
||||
}
|
||||
if (reverse ) x = virtualWidth() - x - 1;
|
||||
if (reverse_y) y = virtualHeight() - y - 1;
|
||||
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
|
||||
}
|
||||
|
||||
// Adds the specified color with the existing pixel color perserving color balance.
|
||||
void Segment::addPixelColorXY(int x, int y, uint32_t color, bool fast) {
|
||||
void IRAM_ATTR_YN Segment::addPixelColorXY(int x, int y, uint32_t color, bool fast) {
|
||||
if (!isActive()) return; // not active
|
||||
if (x >= virtualWidth() || y >= virtualHeight() || x<0 || y<0) return; // if pixel would fall out of virtual segment just exit
|
||||
uint32_t col = getPixelColorXY(x,y);
|
||||
|
||||
@@ -1044,6 +1044,17 @@ void IRAM_ATTR_YN Segment::setPixelColor(int i, uint32_t col) //WLEDMM: IRAM_ATT
|
||||
}
|
||||
i += start; // starting pixel in a group
|
||||
|
||||
#if 0 // needs more testing
|
||||
// WLEDMM shortcut when no grouping/spacing used
|
||||
bool simpleSegment = !mirror && (grouping == 1) && (spacing == 0);
|
||||
if (simpleSegment) {
|
||||
int indexSet = i + offset; // offset/phase
|
||||
if (indexSet >= stop) indexSet -= len; // wrap
|
||||
strip.setPixelColor(indexSet, col);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// set all the pixels in the group
|
||||
for (int j = 0; j < grouping; j++) {
|
||||
uint16_t indexSet = i + ((reverse) ? -j : j);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
// version code in format yymmddb (b = daily build)
|
||||
#define VERSION 2404181
|
||||
#define VERSION 2404201
|
||||
|
||||
// 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.
|
||||
#define _MoonModules_WLED_
|
||||
|
||||
Reference in New Issue
Block a user