Skip to content

Commit 93b8c63

Browse files
committed
post PR3904 fixes and improvements
* fix compiler warnings (uninitialized vars, ambiguous functions calls) * restore some lost function prototypes * avoid negative pixel indices * only use "fast" color_add when there is no risk of "overshooting" results * minor optimizations
1 parent 48c64ae commit 93b8c63

File tree

7 files changed

+45
-39
lines changed

7 files changed

+45
-39
lines changed

wled00/FX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5627,7 +5627,7 @@ uint16_t mode_2DPlasmaball(void) { // By: Stepko https://edito
56275627
(rows - 1 - cy == 0)) ? ColorFromPalette(SEGPALETTE, beat8(5), thisVal, LINEARBLEND) : CRGB::Black);
56285628
}
56295629
}
5630-
SEGMENT.blur(SEGMENT.custom2>>5);
5630+
SEGMENT.blur(SEGMENT.custom2>>5, (SEGMENT.custom2 > 132)); // WLEDMM
56315631

56325632
return FRAMETIME;
56335633
} // mode_2DPlasmaball()

wled00/FX.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -661,11 +661,11 @@ typedef struct Segment {
661661
inline void setPixelColorXY(unsigned x, unsigned y, uint32_t c) { setPixelColorXY(int(x), int(y), c); }
662662
inline void setPixelColorXY(int x, int y, byte r, byte g, byte b, byte w = 0) { setPixelColorXY(x, y, RGBW32(r,g,b,w)); }
663663
inline void setPixelColorXY(int x, int y, CRGB c) { setPixelColorXY(x, y, RGBW32(c.r,c.g,c.b,0)); }
664-
#ifdef WLED_USE_AA_PIXELS
665-
void setPixelColorXY(float x, float y, uint32_t c, bool aa = true);
664+
//#ifdef WLED_USE_AA_PIXELS
665+
void setPixelColorXY(float x, float y, uint32_t c, bool aa = true, bool fast=true);
666666
inline void setPixelColorXY(float x, float y, byte r, byte g, byte b, byte w = 0, bool aa = true) { setPixelColorXY(x, y, RGBW32(r,g,b,w), aa); }
667667
inline void setPixelColorXY(float x, float y, CRGB c, bool aa = true) { setPixelColorXY(x, y, RGBW32(c.r,c.g,c.b,0), aa); }
668-
#endif
668+
//#endif
669669
uint32_t __attribute__((pure)) getPixelColorXY(int x, int y);
670670
// 2D support functions
671671
void blendPixelColorXY(uint16_t x, uint16_t y, uint32_t color, uint8_t blend);
@@ -700,11 +700,11 @@ typedef struct Segment {
700700
inline void setPixelColorXY(unsigned x, unsigned y, uint32_t c) { setPixelColor(int(x), c); }
701701
inline void setPixelColorXY(int x, int y, byte r, byte g, byte b, byte w = 0) { setPixelColor(x, RGBW32(r,g,b,w)); }
702702
inline void setPixelColorXY(int x, int y, CRGB c) { setPixelColor(x, RGBW32(c.r,c.g,c.b,0)); }
703-
#ifdef WLED_USE_AA_PIXELS
703+
//#ifdef WLED_USE_AA_PIXELS
704704
inline void setPixelColorXY(float x, float y, uint32_t c, bool aa = true) { setPixelColor(x, c, aa); }
705705
inline void setPixelColorXY(float x, float y, byte r, byte g, byte b, byte w = 0, bool aa = true) { setPixelColor(x, RGBW32(r,g,b,w), aa); }
706706
inline void setPixelColorXY(float x, float y, CRGB c, bool aa = true) { setPixelColor(x, RGBW32(c.r,c.g,c.b,0), aa); }
707-
#endif
707+
//#endif
708708
inline uint32_t getPixelColorXY(uint16_t x, uint16_t y) { return getPixelColor(x); }
709709
inline void blendPixelColorXY(uint16_t x, uint16_t y, uint32_t c, uint8_t blend) { blendPixelColor(x, c, blend); }
710710
inline void blendPixelColorXY(uint16_t x, uint16_t y, CRGB c, uint8_t blend) { blendPixelColor(x, RGBW32(c.r,c.g,c.b,0), blend); }

wled00/FX_2Dfcn.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ uint32_t WS2812FX::getPixelColorXY(uint16_t x, uint16_t y) {
214214
void IRAM_ATTR_YN Segment::setPixelColorXY(int x, int y, uint32_t col) //WLEDMM: IRAM_ATTR conditionally
215215
{
216216
if (Segment::maxHeight==1) return; // not a matrix set-up
217-
if (x >= virtualWidth() || y >= virtualHeight() || x<0 || y<0) return; // if pixel would fall out of virtual segment just exit
217+
if (x<0 || y<0 || x >= virtualWidth() || y >= virtualHeight()) return; // if pixel would fall out of virtual segment just exit
218218

219219
if (ledsrgb) ledsrgb[XY(x,y)] = col;
220220

@@ -307,7 +307,7 @@ void Segment::setPixelColorXY(float x, float y, uint32_t col, bool aa, bool fast
307307

308308
// returns RGBW values of pixel
309309
uint32_t IRAM_ATTR_YN Segment::getPixelColorXY(int x, int y) {
310-
if (!isActive()) return 0; // not active
310+
if (x<0 || y<0 || !isActive()) return 0; // not active or out-of range
311311
int i = XY(x,y);
312312
if (ledsrgb) return RGBW32(ledsrgb[i].r, ledsrgb[i].g, ledsrgb[i].b, 0);
313313
if (reverse ) x = virtualWidth() - x - 1;
@@ -353,7 +353,7 @@ void Segment::fadePixelColorXY(uint16_t x, uint16_t y, uint8_t fade) {
353353

354354
// blurRow: perform a blur on a row of a rectangular matrix
355355
void Segment::blurRow(uint32_t row, fract8 blur_amount, bool smear){
356-
if (!isActive() || blur_amount == 0) return; // not active
356+
if (!isActive()) return; // not active
357357
const uint_fast16_t cols = virtualWidth();
358358
const uint_fast16_t rows = virtualHeight();
359359

@@ -364,30 +364,30 @@ void Segment::blurRow(uint32_t row, fract8 blur_amount, bool smear){
364364
uint32_t carryover = BLACK;
365365
uint32_t lastnew;
366366
uint32_t last;
367-
uint32_t curnew;
367+
uint32_t curnew = 0;
368368
for (unsigned x = 0; x < cols; x++) {
369369
uint32_t cur = getPixelColorXY(x, row);
370370
uint32_t part = color_fade(cur, seep);
371371
curnew = color_fade(cur, keep);
372372
if (x > 0) {
373373
if (carryover)
374-
curnew = color_add(curnew, carryover, true);
375-
uint32_t prev = color_add(lastnew, part, true);
374+
curnew = color_add(curnew, carryover, !smear); // WLEDMM don't use "fast" when smear==true (better handling of bright colors)
375+
uint32_t prev = color_add(lastnew, part, !smear);// WLEDMM
376376
if (last != prev) // optimization: only set pixel if color has changed
377-
setPixelColorXY(x - 1, row, prev);
377+
setPixelColorXY(int(x - 1), int(row), prev);
378378
}
379379
else // first pixel
380-
setPixelColorXY(x, row, curnew);
380+
setPixelColorXY(int(x), int(row), curnew);
381381
lastnew = curnew;
382382
last = cur; // save original value for comparison on next iteration
383383
carryover = part;
384384
}
385-
setPixelColorXY(cols-1, row, curnew); // set last pixel
385+
setPixelColorXY(int(cols-1), int(row), curnew); // set last pixel
386386
}
387387

388388
// blurCol: perform a blur on a column of a rectangular matrix
389389
void Segment::blurCol(uint32_t col, fract8 blur_amount, bool smear) {
390-
if (!isActive() || blur_amount == 0) return; // not active
390+
if (!isActive()) return; // not active
391391
const uint_fast16_t cols = virtualWidth();
392392
const uint_fast16_t rows = virtualHeight();
393393

@@ -398,25 +398,25 @@ void Segment::blurCol(uint32_t col, fract8 blur_amount, bool smear) {
398398
uint32_t carryover = BLACK;
399399
uint32_t lastnew;
400400
uint32_t last;
401-
uint32_t curnew;
401+
uint32_t curnew = 0;
402402
for (unsigned y = 0; y < rows; y++) {
403403
uint32_t cur = getPixelColorXY(col, y);
404404
uint32_t part = color_fade(cur, seep);
405405
curnew = color_fade(cur, keep);
406406
if (y > 0) {
407407
if (carryover)
408-
curnew = color_add(curnew, carryover, true);
409-
uint32_t prev = color_add(lastnew, part, true);
408+
curnew = color_add(curnew, carryover, !smear); // WLEDMM don't use "fast" when smear==true (better handling of bright colors)
409+
uint32_t prev = color_add(lastnew, part, !smear); // WLEDMM
410410
if (last != prev) // optimization: only set pixel if color has changed
411-
setPixelColorXY(col, y - 1, prev);
411+
setPixelColorXY(int(col), int(y - 1), prev);
412412
}
413413
else // first pixel
414-
setPixelColorXY(col, y, curnew);
414+
setPixelColorXY(int(col), int(y), curnew);
415415
lastnew = curnew;
416416
last = cur; //save original value for comparison on next iteration
417417
carryover = part;
418418
}
419-
setPixelColorXY(col, rows - 1, curnew);
419+
setPixelColorXY(int(col), int(rows - 1), curnew);
420420
}
421421

422422
// 1D Box blur (with added weight - blur_amount: [0=no blur, 255=max blur])

wled00/FX_fcn.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,10 +1358,10 @@ void Segment::blur(uint8_t blur_amount, bool smear) {
13581358
#ifndef WLED_DISABLE_2D
13591359
if (is2D()) {
13601360
// compatibility with 2D
1361-
const unsigned cols = virtualWidth();
1362-
const unsigned rows = virtualHeight();
1363-
for (unsigned i = 0; i < rows; i++) blurRow(i, blur_amount, smear); // blur all rows
1364-
for (unsigned k = 0; k < cols; k++) blurCol(k, blur_amount, smear); // blur all columns
1361+
const uint_fast32_t cols = virtualWidth();
1362+
const uint_fast32_t rows = virtualHeight();
1363+
for (uint_fast32_t i = 0; i < rows; i++) blurRow(i, blur_amount, smear); // blur all rows
1364+
for (uint_fast32_t k = 0; k < cols; k++) blurCol(k, blur_amount, smear); // blur all columns
13651365
return;
13661366
}
13671367
#endif
@@ -1371,25 +1371,25 @@ void Segment::blur(uint8_t blur_amount, bool smear) {
13711371
uint32_t carryover = BLACK;
13721372
uint32_t lastnew;
13731373
uint32_t last;
1374-
uint32_t curnew;
1374+
uint32_t curnew = 0;
13751375
for (unsigned i = 0; i < vlength; i++) {
13761376
uint32_t cur = getPixelColor(i);
13771377
uint32_t part = color_fade(cur, seep);
13781378
curnew = color_fade(cur, keep);
13791379
if (i > 0) {
13801380
if (carryover)
1381-
curnew = color_add(curnew, carryover, true);
1382-
uint32_t prev = color_add(lastnew, part, true);
1381+
curnew = color_add(curnew, carryover, !smear); // WLEDMM
1382+
uint32_t prev = color_add(lastnew, part, !smear); // WLEDMM
13831383
if (last != prev) // optimization: only set pixel if color has changed
1384-
setPixelColor(i - 1, prev);
1384+
setPixelColor(int(i - 1), prev);
13851385
}
13861386
else // first pixel
1387-
setPixelColor(i, curnew);
1387+
setPixelColor(int(i), curnew);
13881388
lastnew = curnew;
13891389
last = cur; // save original value for comparison on next iteration
13901390
carryover = part;
13911391
}
1392-
setPixelColor(vlength - 1, curnew);
1392+
setPixelColor(int(vlength - 1), curnew);
13931393
}
13941394

13951395
/*

wled00/colors.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ IRAM_ATTR_YN uint32_t color_blend(uint32_t color1, uint32_t color2, uint_fast16_
3535
* color add function that preserves ratio
3636
* idea: https://github.com/Aircoookie/WLED/pull/2465 by https://github.com/Proto-molecule
3737
*/
38-
IRAM_ATTR_YN uint32_t color_add(uint32_t c1, uint32_t c2) // WLEDMM added IRAM_ATTR_YN
38+
IRAM_ATTR_YN uint32_t color_add(uint32_t c1, uint32_t c2, bool fast) // WLEDMM added IRAM_ATTR_YN
3939
{
40+
if (c2 == 0) return c1; // WLEDMM shortcut
41+
if (c1 == 0) return c2; // WLEDMM shortcut
42+
4043
if (fast) {
4144
uint8_t r = R(c1);
4245
uint8_t g = G(c1);
@@ -52,7 +55,7 @@ IRAM_ATTR_YN uint32_t color_add(uint32_t c1, uint32_t c2) // WLEDMM added IRAM
5255
uint32_t g = G(c1) + G(c2);
5356
uint32_t b = B(c1) + B(c2);
5457
uint32_t w = W(c1) + W(c2);
55-
uint_fast16_t max = r;
58+
uint32_t max = r;
5659
if (g > max) max = g;
5760
if (b > max) max = b;
5861
if (w > max) max = w;
@@ -66,8 +69,10 @@ IRAM_ATTR_YN uint32_t color_add(uint32_t c1, uint32_t c2) // WLEDMM added IRAM
6669
* if using "video" method the resulting color will never become black unless it is already black
6770
*/
6871

69-
uint32_t color_fade(uint32_t c1, uint8_t amount, bool video)
72+
IRAM_ATTR_YN uint32_t color_fade(uint32_t c1, uint8_t amount, bool video)
7073
{
74+
if (amount == 0) return 0; // WLEDMM shortcut
75+
7176
uint32_t scaledcolor; // color order is: W R G B from MSB to LSB
7277
uint32_t r = R(c1);
7378
uint32_t g = G(c1);
@@ -78,15 +83,15 @@ uint32_t color_fade(uint32_t c1, uint8_t amount, bool video)
7883
scaledcolor = (((r * scale) >> 8) << 16) + ((r && scale) ? 1 : 0);
7984
scaledcolor |= (((g * scale) >> 8) << 8) + ((g && scale) ? 1 : 0);
8085
scaledcolor |= ((b * scale) >> 8) + ((b && scale) ? 1 : 0);
81-
scaledcolor |= (((w * scale) >> 8) << 24) + ((w && scale) ? 1 : 0);
86+
if (w>0) scaledcolor |= (((w * scale) >> 8) << 24) + ((scale) ? 1 : 0); // WLEDMM small speedup when no white channel
8287
return scaledcolor;
8388
}
8489
else {
8590
uint32_t scale = 1 + amount;
8691
scaledcolor = ((r * scale) >> 8) << 16;
8792
scaledcolor |= ((g * scale) >> 8) << 8;
8893
scaledcolor |= (b * scale) >> 8;
89-
scaledcolor |= ((w * scale) >> 8) << 24;
94+
if (w>0) scaledcolor |= ((w * scale) >> 8) << 24; // WLEDMM small speedup when no white channel
9095
return scaledcolor;
9196
}
9297
}

wled00/fcn_declare.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ bool getJsonValue(const JsonVariant& element, DestType& destination, const Defau
5151

5252
//colors.cpp
5353
uint32_t __attribute__((const)) color_blend(uint32_t,uint32_t,uint_fast16_t,bool b16=false); // WLEDMM: added attribute const
54-
uint32_t __attribute__((const)) color_add(uint32_t,uint32_t); // WLEDMM: added attribute const
54+
uint32_t __attribute__((const)) color_add(uint32_t,uint32_t, bool fast=false); // WLEDMM: added attribute const
55+
uint32_t __attribute__((const)) color_fade(uint32_t c1, uint8_t amount, bool video=false);
5556
inline uint32_t colorFromRgbw(byte* rgbw) { return uint32_t((byte(rgbw[3]) << 24) | (byte(rgbw[0]) << 16) | (byte(rgbw[1]) << 8) | (byte(rgbw[2]))); }
5657
void colorHStoRGB(uint16_t hue, byte sat, byte* rgb); //hue, sat to rgb
5758
void colorKtoRGB(uint16_t kelvin, byte* rgb);

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 2404161
11+
#define VERSION 2404181
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)