Skip to content

Commit

Permalink
some drawing speedups
Browse files Browse the repository at this point in the history
* speedups for addPixelColorXY, fadePixelColorXY, fadeToBlackBy
  • Loading branch information
softhack007 committed Sep 28, 2024
1 parent 0555b8e commit b245112
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
3 changes: 3 additions & 0 deletions wled00/FX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 9 additions & 7 deletions wled00/FX_2Dfcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion wled00/FX_fcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion wled00/wled.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down

0 comments on commit b245112

Please sign in to comment.