From b245112d2a80b0df5534fc957be09f6799bf374b Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Sat, 28 Sep 2024 02:19:53 +0200 Subject: [PATCH] some drawing speedups * speedups for addPixelColorXY, fadePixelColorXY, fadeToBlackBy --- wled00/FX.cpp | 3 +++ wled00/FX_2Dfcn.cpp | 16 +++++++++------- wled00/FX_fcn.cpp | 4 +++- wled00/wled.h | 2 +- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index ea5b741573..9e7a25cfda 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -37,6 +37,9 @@ #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 static uint8_t sin_gap(uint16_t in) { if (in & 0x100) return 0; diff --git a/wled00/FX_2Dfcn.cpp b/wled00/FX_2Dfcn.cpp index 73c7bf7700..9ac62e1d80 100644 --- a/wled00/FX_2Dfcn.cpp +++ b/wled00/FX_2Dfcn.cpp @@ -463,8 +463,9 @@ uint32_t IRAM_ATTR_YN Segment::getPixelColorXY(int x, int y) const { 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 - x *= groupLength(); // expand to physical pixels - y *= groupLength(); // expand to physical pixels + const uint_fast16_t groupLength_ = groupLength(); // WLEDMM small optimization + x *= groupLength_; // expand to physical pixels + y *= groupLength_; // expand to physical pixels if (x >= width() || y >= height()) return 0; 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) { // 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 - uint32_t col = getPixelColorXY(x,y); - col = color_add(col, color, fast); - setPixelColorXY(x, y, col); + uint32_t oldCol = getPixelColorXY(x,y); + uint32_t col = color_add(oldCol, color, fast); + if (col != oldCol) setPixelColorXY(x, y, col); } 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 - CRGB pix = CRGB(getPixelColorXY(x,y)).nscale8_video(fade); - setPixelColorXY(x, y, pix); + CRGB oldPix = CRGB(getPixelColorXY(x,y)); + 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 diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 9e2368ab9c..51087562aa 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -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++) { uint32_t cc = getPixelColorXY(int(x),int(y)); // WLEDMM avoid RGBW32 -> CRGB -> RGBW32 conversion 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); } } else { diff --git a/wled00/wled.h b/wled00/wled.h index 74deeacea9..33174183d5 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // 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. #define _MoonModules_WLED_