some drawing speedups

* speedups for addPixelColorXY, fadePixelColorXY, fadeToBlackBy
This commit is contained in:
Frank
2024-09-28 02:19:53 +02:00
parent 0555b8e5f2
commit b245112d2a
4 changed files with 16 additions and 9 deletions

View File

@@ -37,6 +37,9 @@
#define indexToVStrip(index, stripNr) ((index) | (int((stripNr)+1)<<16)) #define indexToVStrip(index, stripNr) ((index) | (int((stripNr)+1)<<16))
// WLEDMM replace abs8 by abs, as abs8 does not work for numbers >127
#define abs8(x) abs(x)
// effect utility functions // effect utility functions
static uint8_t sin_gap(uint16_t in) { static uint8_t sin_gap(uint16_t in) {
if (in & 0x100) return 0; if (in & 0x100) return 0;

View File

@@ -463,8 +463,9 @@ uint32_t IRAM_ATTR_YN Segment::getPixelColorXY(int x, int y) const {
if (reverse ) x = virtualWidth() - x - 1; if (reverse ) x = virtualWidth() - x - 1;
if (reverse_y) y = virtualHeight() - y - 1; if (reverse_y) y = virtualHeight() - y - 1;
if (transpose) { uint16_t t = x; x = y; y = t; } // swap X & Y if segment transposed if (transpose) { uint16_t t = x; x = y; y = t; } // swap X & Y if segment transposed
x *= groupLength(); // expand to physical pixels const uint_fast16_t groupLength_ = groupLength(); // WLEDMM small optimization
y *= groupLength(); // expand to physical pixels x *= groupLength_; // expand to physical pixels
y *= groupLength_; // expand to physical pixels
if (x >= width() || y >= height()) return 0; if (x >= width() || y >= height()) return 0;
return strip.getPixelColorXY(start + x, startY + y); return strip.getPixelColorXY(start + x, startY + y);
} }
@@ -479,15 +480,16 @@ void Segment::blendPixelColorXY(uint16_t x, uint16_t y, uint32_t color, uint8_t
void IRAM_ATTR_YN 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 //WLEDMM sanity check is repeated in getPixelColorXY / setPixelColorXY // if (!isActive()) return; // not active //WLEDMM sanity check is repeated in getPixelColorXY / setPixelColorXY
// if (x >= virtualWidth() || y >= virtualHeight() || x<0 || y<0) return; // if pixel would fall out of virtual segment just exit //WLEDMM // if (x >= virtualWidth() || y >= virtualHeight() || x<0 || y<0) return; // if pixel would fall out of virtual segment just exit //WLEDMM
uint32_t col = getPixelColorXY(x,y); uint32_t oldCol = getPixelColorXY(x,y);
col = color_add(col, color, fast); uint32_t col = color_add(oldCol, color, fast);
setPixelColorXY(x, y, col); if (col != oldCol) setPixelColorXY(x, y, col);
} }
void Segment::fadePixelColorXY(uint16_t x, uint16_t y, uint8_t fade) { void Segment::fadePixelColorXY(uint16_t x, uint16_t y, uint8_t fade) {
// if (!isActive()) return; // not active //WLEDMM sanity check is repeated in getPixelColorXY / setPixelColorXY // if (!isActive()) return; // not active //WLEDMM sanity check is repeated in getPixelColorXY / setPixelColorXY
CRGB pix = CRGB(getPixelColorXY(x,y)).nscale8_video(fade); CRGB oldPix = CRGB(getPixelColorXY(x,y));
setPixelColorXY(x, y, pix); CRGB pix = oldPix.nscale8_video(fade);
if (pix != oldPix) setPixelColorXY(int(x), int(y), pix);
} }
// blurRow: perform a blur on a row of a rectangular matrix // blurRow: perform a blur on a row of a rectangular matrix

View File

@@ -1510,7 +1510,9 @@ void __attribute__((hot)) Segment::fadeToBlackBy(uint8_t fadeBy) {
for (unsigned y = 0; y < rows; y++) for (unsigned x = 0; x < cols; x++) { for (unsigned y = 0; y < rows; y++) for (unsigned x = 0; x < cols; x++) {
uint32_t cc = getPixelColorXY(int(x),int(y)); // WLEDMM avoid RGBW32 -> CRGB -> RGBW32 conversion uint32_t cc = getPixelColorXY(int(x),int(y)); // WLEDMM avoid RGBW32 -> CRGB -> RGBW32 conversion
uint32_t cc2 = color_fade(cc, scaledown); // fade uint32_t cc2 = color_fade(cc, scaledown); // fade
//if (cc2 != cc) // WLEDMM only re-paint if faded color is different - disabled - causes problem with text overlay #ifdef WLEDMM_FASTPATH
if (cc2 != cc) // WLEDMM only re-paint if faded color is different - normally disabled - causes problem with text overlay
#endif
setPixelColorXY(int(x), int(y), cc2); setPixelColorXY(int(x), int(y), cc2);
} }
} else { } else {

View File

@@ -8,7 +8,7 @@
*/ */
// version code in format yymmddb (b = daily build) // version code in format yymmddb (b = daily build)
#define VERSION 2409260 #define VERSION 2409280
// 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. // 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_ #define _MoonModules_WLED_