Skip to content

Commit e765531

Browse files
authored
Merge branch 'MoonModules:mdev' into Strip_Level_Color_Adjust
2 parents 0a80cbc + 59752ad commit e765531

File tree

9 files changed

+206
-130
lines changed

9 files changed

+206
-130
lines changed

usermods/audioreactive/audio_reactive.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ void FFTcode(void * parameter)
564564
newZeroCrossingCount++;
565565
}
566566
}
567-
newZeroCrossingCount = (newZeroCrossingCount*2)/3; // reduce value so it typicially stays below 256
567+
newZeroCrossingCount = (newZeroCrossingCount*2)/3; // reduce value so it typically stays below 256
568568
zeroCrossingCount = newZeroCrossingCount; // update only once, to avoid that effects pick up an intermediate value
569569

570570
// release highest sample to volume reactive effects early - not strictly necessary here - could also be done at the end of the function
@@ -602,6 +602,7 @@ void FFTcode(void * parameter)
602602
#endif
603603
FFT.compute( FFTDirection::Forward ); // Compute FFT
604604
FFT.complexToMagnitude(); // Compute magnitudes
605+
vReal[0] = 0; // The remaining DC offset on the signal produces a strong spike on position 0 that should be eliminated to avoid issues.
605606
#else
606607
FFT.DCRemoval(); // let FFT lib remove DC component, so we don't need to care about this in getSamples()
607608

wled00/FX.cpp

Lines changed: 12 additions & 5 deletions
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()
@@ -5645,6 +5645,8 @@ uint16_t mode_2DPolarLights(void) { // By: Kostyantyn Matviyevskyy https
56455645

56465646
const uint16_t cols = SEGMENT.virtualWidth();
56475647
const uint16_t rows = SEGMENT.virtualHeight();
5648+
const float maxRows = (rows <= 32) ? 32.0f : (rows <= 64) ? 64.0f : 128.0f; // WLEDMM safe up to 128x128
5649+
const float minScale = (rows <= 32) ? 12.0f : (rows <= 64) ? 4.6f : 2.1f; // WLEDMM
56485650

56495651
const CRGBPalette16 auroraPalette = {0x000000, 0x003300, 0x006600, 0x009900, 0x00cc00, 0x00ff00, 0x33ff00, 0x66ff00, 0x99ff00, 0xccff00, 0xffff00, 0xffcc00, 0xff9900, 0xff6600, 0xff3300, 0xff0000};
56505652

@@ -5653,8 +5655,11 @@ uint16_t mode_2DPolarLights(void) { // By: Kostyantyn Matviyevskyy https
56535655
SEGMENT.fill(BLACK);
56545656
}
56555657

5656-
float adjustHeight = mapf(rows, 8, 32, 28, 12); // maybe use mapf() ??? // WLEDMM yes!
5658+
float adjustHeight = mapf(rows, 8, maxRows, 28, minScale); // maybe use mapf() ??? // WLEDMM yes!
56575659
uint16_t adjScale = map(cols, 8, 64, 310, 63);
5660+
5661+
adjustHeight = max(min(adjustHeight, 28.0f), minScale); // WLEDMM bugfix for larger fixtures
5662+
adjScale = max(min(adjScale, uint16_t(310)), uint16_t(63)); // WLEDMM
56585663
/*
56595664
if (SEGENV.aux1 != SEGMENT.custom1/12) { // Hacky palette rotation. We need that black.
56605665
SEGENV.aux1 = SEGMENT.custom1/12;
@@ -5813,6 +5818,8 @@ uint16_t mode_2DSunradiation(void) { // By: ldirko https://edi
58135818

58145819
const uint16_t cols = SEGMENT.virtualWidth();
58155820
const uint16_t rows = SEGMENT.virtualHeight();
5821+
const int minSize = min(cols, rows); // WLEDMM
5822+
const int magnify = (minSize <= 32) ? 8 : 46; // WLEDMM
58165823

58175824
if (!SEGENV.allocateData(sizeof(byte)*(cols+2)*(rows+2))) return mode_static(); //allocation failed
58185825
byte *bump = reinterpret_cast<byte*>(SEGENV.data);
@@ -5841,10 +5848,10 @@ uint16_t mode_2DSunradiation(void) { // By: ldirko https://edi
58415848
++vlx;
58425849
int8_t nx = bump[x + yindex + 1] - bump[x + yindex - 1];
58435850
int8_t ny = bump[x + yindex + (cols + 2)] - bump[x + yindex - (cols + 2)];
5844-
byte difx = abs8(vlx * 7 - nx);
5845-
byte dify = abs8(vly * 7 - ny);
5851+
byte difx = min(abs(vlx * 7 - nx), 255); // WLEDMM replaced abs8 as it does not work for numbers >127
5852+
byte dify = min(abs(vly * 7 - ny), 255); // WLEDMM
58465853
int temp = difx * difx + dify * dify;
5847-
int col = 255 - temp / 8; //8 its a size of effect
5854+
int col = 255 - temp / magnify; //8 its a size of effect // WLEDMM size adjusts to matrix dimensions
58485855
if (col < 0) col = 0;
58495856
SEGMENT.setPixelColorXY(x, y, HeatColor(col / (3.0f-(float)(SEGMENT.intensity)/128.f)));
58505857
}

wled00/FX.h

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ typedef struct Segment {
617617
void setPixelColor(float i, CRGB c, bool aa = true) { setPixelColor(i, RGBW32(c.r,c.g,c.b,0), aa); }
618618
uint32_t __attribute__((pure)) getPixelColor(int i); // WLEDMM attribute added
619619
// 1D support functions (some implement 2D as well)
620-
void blur(uint8_t);
620+
void blur(uint8_t, bool smear = false);
621621
void fill(uint32_t c);
622622
void fade_out(uint8_t r);
623623
void fadeToBlackBy(uint8_t fadeBy);
@@ -658,12 +658,15 @@ typedef struct Segment {
658658
return (x%width) + (y%height) * width;
659659
}
660660
void setPixelColorXY(int x, int y, uint32_t c); // set relative pixel within segment with color
661-
void setPixelColorXY(int x, int y, byte r, byte g, byte b, byte w = 0) { setPixelColorXY(x, y, RGBW32(r,g,b,w)); } // automatically inline
662-
void setPixelColorXY(int x, int y, CRGB c) { setPixelColorXY(x, y, RGBW32(c.r,c.g,c.b,0)); } // automatically inline
663-
void setPixelColorXY(float x, float y, uint32_t c, bool aa = true, bool fast = true);
664-
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); }
665-
void setPixelColorXY(float x, float y, CRGB c, bool aa = true) { setPixelColorXY(x, y, RGBW32(c.r,c.g,c.b,0), aa); }
666-
uint32_t __attribute__((pure)) getPixelColorXY(uint16_t x, uint16_t y); // WLEDMM attribute pure
661+
inline void setPixelColorXY(unsigned x, unsigned y, uint32_t c) { setPixelColorXY(int(x), int(y), c); }
662+
inline void setPixelColorXY(int x, int y, byte r, byte g, byte b, byte w = 0) { setPixelColorXY(x, y, RGBW32(r,g,b,w)); }
663+
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, bool fast=true);
666+
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); }
667+
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
669+
uint32_t __attribute__((pure)) getPixelColorXY(int x, int y);
667670
// 2D support functions
668671
void blendPixelColorXY(uint16_t x, uint16_t y, uint32_t color, uint8_t blend);
669672
void blendPixelColorXY(uint16_t x, uint16_t y, CRGB c, uint8_t blend) { blendPixelColorXY(x, y, RGBW32(c.r,c.g,c.b,0), blend); }
@@ -672,8 +675,8 @@ typedef struct Segment {
672675
void addPixelColorXY(int x, int y, CRGB c, bool fast = false) { addPixelColorXY(x, y, RGBW32(c.r,c.g,c.b,0), fast); }
673676
void fadePixelColorXY(uint16_t x, uint16_t y, uint8_t fade);
674677
void box_blur(uint16_t i, bool vertical, fract8 blur_amount); // 1D box blur (with weight)
675-
void blurRow(uint16_t row, fract8 blur_amount);
676-
void blurCol(uint16_t col, fract8 blur_amount);
678+
void blurRow(uint32_t row, fract8 blur_amount, bool smear = false);
679+
void blurCol(uint32_t col, fract8 blur_amount, bool smear = false);
677680
void moveX(int8_t delta, bool wrap = false);
678681
void moveY(int8_t delta, bool wrap = false);
679682
void move(uint8_t dir, uint8_t delta, bool wrap = false);
@@ -692,32 +695,36 @@ typedef struct Segment {
692695
void nscale8(uint8_t scale);
693696
bool jsonToPixels(char *name, uint8_t fileNr); //WLEDMM for artifx
694697
#else
695-
uint16_t XY(uint16_t x, uint16_t y) { return x; }
696-
void setPixelColorXY(int x, int y, uint32_t c) { setPixelColor(x, c); }
697-
void setPixelColorXY(int x, int y, byte r, byte g, byte b, byte w = 0) { setPixelColor(x, RGBW32(r,g,b,w)); }
698-
void setPixelColorXY(int x, int y, CRGB c) { setPixelColor(x, RGBW32(c.r,c.g,c.b,0)); }
699-
void setPixelColorXY(float x, float y, uint32_t c, bool aa = true) { setPixelColor(x, c, aa); }
700-
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); }
701-
void setPixelColorXY(float x, float y, CRGB c, bool aa = true) { setPixelColor(x, RGBW32(c.r,c.g,c.b,0), aa); }
702-
uint32_t getPixelColorXY(uint16_t x, uint16_t y) { return getPixelColor(x); }
703-
void blendPixelColorXY(uint16_t x, uint16_t y, uint32_t c, uint8_t blend) { blendPixelColor(x, c, blend); }
704-
void blendPixelColorXY(uint16_t x, uint16_t y, CRGB c, uint8_t blend) { blendPixelColor(x, RGBW32(c.r,c.g,c.b,0), blend); }
705-
void addPixelColorXY(int x, int y, uint32_t color, bool fast = false) { addPixelColor(x, color, fast); }
706-
void addPixelColorXY(int x, int y, byte r, byte g, byte b, byte w = 0, bool fast = false) { addPixelColor(x, RGBW32(r,g,b,w), fast); }
707-
void addPixelColorXY(int x, int y, CRGB c, bool fast = false) { addPixelColor(x, RGBW32(c.r,c.g,c.b,0), fast); }
708-
void fadePixelColorXY(uint16_t x, uint16_t y, uint8_t fade) { fadePixelColor(x, fade); }
709-
void box_blur(uint16_t i, bool vertical, fract8 blur_amount) {}
710-
void blurRow(uint16_t row, fract8 blur_amount) {}
711-
void blurCol(uint16_t col, fract8 blur_amount) {}
712-
void moveX(int8_t delta, bool wrap = false) {}
713-
void moveY(int8_t delta, bool wrap = false) {}
714-
void move(uint8_t dir, uint8_t delta, bool wrap = false) {}
715-
void fill_circle(uint16_t cx, uint16_t cy, uint8_t radius, CRGB c) {}
716-
void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint32_t c) {}
717-
void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, CRGB c) {}
718-
void drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, uint8_t h, uint32_t color) {}
719-
void drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, uint8_t h, CRGB color) {}
720-
void wu_pixel(uint32_t x, uint32_t y, CRGB c) {}
698+
inline uint16_t XY(uint16_t x, uint16_t y) { return x; }
699+
inline void setPixelColorXY(int x, int y, uint32_t c) { setPixelColor(x, c); }
700+
inline void setPixelColorXY(unsigned x, unsigned y, uint32_t c) { setPixelColor(int(x), c); }
701+
inline void setPixelColorXY(int x, int y, byte r, byte g, byte b, byte w = 0) { setPixelColor(x, RGBW32(r,g,b,w)); }
702+
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
704+
inline void setPixelColorXY(float x, float y, uint32_t c, bool aa = true) { setPixelColor(x, c, aa); }
705+
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); }
706+
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
708+
inline uint32_t getPixelColorXY(uint16_t x, uint16_t y) { return getPixelColor(x); }
709+
inline void blendPixelColorXY(uint16_t x, uint16_t y, uint32_t c, uint8_t blend) { blendPixelColor(x, c, blend); }
710+
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); }
711+
inline void addPixelColorXY(int x, int y, uint32_t color, bool fast = false) { addPixelColor(x, color, fast); }
712+
inline void addPixelColorXY(int x, int y, byte r, byte g, byte b, byte w = 0, bool fast = false) { addPixelColor(x, RGBW32(r,g,b,w), fast); }
713+
inline void addPixelColorXY(int x, int y, CRGB c, bool fast = false) { addPixelColor(x, RGBW32(c.r,c.g,c.b,0), fast); }
714+
inline void fadePixelColorXY(uint16_t x, uint16_t y, uint8_t fade) { fadePixelColor(x, fade); }
715+
inline void box_blur(uint16_t i, bool vertical, fract8 blur_amount) {}
716+
inline void blurRow(uint32_t row, fract8 blur_amount, bool smear = false) {}
717+
inline void blurCol(uint32_t col, fract8 blur_amount, bool smear = false) {}
718+
inline void moveX(int8_t delta, bool wrap = false) {}
719+
inline void moveY(int8_t delta, bool wrap = false) {}
720+
inline void move(uint8_t dir, uint8_t delta, bool wrap = false) {}
721+
inline void fill_circle(uint16_t cx, uint16_t cy, uint8_t radius, CRGB c) {}
722+
inline void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint32_t c) {}
723+
inline void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, CRGB c) {}
724+
inline void drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, uint8_t h, uint32_t color, uint32_t = 0, int8_t = 0) {}
725+
inline void drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, uint8_t h, CRGB color) {}
726+
inline void drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, uint8_t h, CRGB c, CRGB c2, int8_t rotate = 0) {}
727+
inline void wu_pixel(uint32_t x, uint32_t y, CRGB c) {}
721728
#endif
722729
uint8_t * getAudioPalette(int pal); //WLEDMM netmindz ar palette
723730
} segment;

wled00/FX_2Dfcn.cpp

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,14 @@ 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

221221
uint8_t _bri_t = currentBri(on ? opacity : 0);
222222
if (!_bri_t && !transitional) return;
223223
if (_bri_t < 255) {
224-
byte r = scale8(R(col), _bri_t);
225-
byte g = scale8(G(col), _bri_t);
226-
byte b = scale8(B(col), _bri_t);
227-
byte w = scale8(W(col), _bri_t);
228-
col = RGBW32(r, g, b, w);
224+
col = color_fade(col, _bri_t);
229225
}
230226

231227
if (reverse ) x = virtualWidth() - x - 1;
@@ -310,8 +306,8 @@ void Segment::setPixelColorXY(float x, float y, uint32_t col, bool aa, bool fast
310306
}
311307

312308
// returns RGBW values of pixel
313-
uint32_t Segment::getPixelColorXY(uint16_t x, uint16_t y) {
314-
if (!isActive()) return 0; // not active
309+
uint32_t IRAM_ATTR_YN Segment::getPixelColorXY(int x, int y) {
310+
if (x<0 || y<0 || !isActive()) return 0; // not active or out-of range
315311
int i = XY(x,y);
316312
if (ledsrgb) return RGBW32(ledsrgb[i].r, ledsrgb[i].g, ledsrgb[i].b, 0);
317313
if (reverse ) x = virtualWidth() - x - 1;
@@ -356,59 +352,71 @@ void Segment::fadePixelColorXY(uint16_t x, uint16_t y, uint8_t fade) {
356352
}
357353

358354
// blurRow: perform a blur on a row of a rectangular matrix
359-
void Segment::blurRow(uint16_t row, fract8 blur_amount) {
355+
void Segment::blurRow(uint32_t row, fract8 blur_amount, bool smear){
360356
if (!isActive()) return; // not active
361357
const uint_fast16_t cols = virtualWidth();
362358
const uint_fast16_t rows = virtualHeight();
363359

364360
if (row >= rows) return;
365361
// blur one row
366-
uint8_t keep = 255 - blur_amount;
362+
uint8_t keep = smear ? 255 : 255 - blur_amount;
367363
uint8_t seep = blur_amount >> 1;
368-
CRGB carryover = CRGB::Black;
369-
for (uint_fast16_t x = 0; x < cols; x++) {
370-
CRGB cur = getPixelColorXY(x, row);
371-
uint32_t before = uint32_t(cur); // remember color before blur
372-
CRGB part = cur;
373-
part.nscale8(seep);
374-
cur.nscale8(keep);
375-
cur += carryover;
376-
if (x>0) {
377-
CRGB prev = CRGB(getPixelColorXY(x-1, row)) + part;
378-
setPixelColorXY(x-1, row, prev);
364+
uint32_t carryover = BLACK;
365+
uint32_t lastnew;
366+
uint32_t last;
367+
uint32_t curnew = 0;
368+
for (unsigned x = 0; x < cols; x++) {
369+
uint32_t cur = getPixelColorXY(x, row);
370+
uint32_t part = color_fade(cur, seep);
371+
curnew = color_fade(cur, keep);
372+
if (x > 0) {
373+
if (carryover)
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
376+
if (last != prev) // optimization: only set pixel if color has changed
377+
setPixelColorXY(int(x - 1), int(row), prev);
379378
}
380-
if (before != uint32_t(cur)) // optimization: only set pixel if color has changed
381-
setPixelColorXY(x, row, cur);
379+
else // first pixel
380+
setPixelColorXY(int(x), int(row), curnew);
381+
lastnew = curnew;
382+
last = cur; // save original value for comparison on next iteration
382383
carryover = part;
383384
}
385+
setPixelColorXY(int(cols-1), int(row), curnew); // set last pixel
384386
}
385387

386388
// blurCol: perform a blur on a column of a rectangular matrix
387-
void Segment::blurCol(uint16_t col, fract8 blur_amount) {
389+
void Segment::blurCol(uint32_t col, fract8 blur_amount, bool smear) {
388390
if (!isActive()) return; // not active
389391
const uint_fast16_t cols = virtualWidth();
390392
const uint_fast16_t rows = virtualHeight();
391393

392394
if (col >= cols) return;
393395
// blur one column
394-
uint8_t keep = 255 - blur_amount;
396+
uint8_t keep = smear ? 255 : 255 - blur_amount;
395397
uint8_t seep = blur_amount >> 1;
396-
CRGB carryover = CRGB::Black;
397-
for (uint_fast16_t y = 0; y < rows; y++) {
398-
CRGB cur = getPixelColorXY(col, y);
399-
CRGB part = cur;
400-
uint32_t before = uint32_t(cur); // remember color before blur
401-
part.nscale8(seep);
402-
cur.nscale8(keep);
403-
cur += carryover;
404-
if (y>0) {
405-
CRGB prev = CRGB(getPixelColorXY(col, y-1)) + part;
406-
setPixelColorXY(col, y-1, prev);
398+
uint32_t carryover = BLACK;
399+
uint32_t lastnew;
400+
uint32_t last;
401+
uint32_t curnew = 0;
402+
for (unsigned y = 0; y < rows; y++) {
403+
uint32_t cur = getPixelColorXY(col, y);
404+
uint32_t part = color_fade(cur, seep);
405+
curnew = color_fade(cur, keep);
406+
if (y > 0) {
407+
if (carryover)
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
410+
if (last != prev) // optimization: only set pixel if color has changed
411+
setPixelColorXY(int(col), int(y - 1), prev);
407412
}
408-
if (before != uint32_t(cur)) // optimization: only set pixel if color has changed
409-
setPixelColorXY(col, y, cur);
410-
carryover = part;
413+
else // first pixel
414+
setPixelColorXY(int(col), int(y), curnew);
415+
lastnew = curnew;
416+
last = cur; //save original value for comparison on next iteration
417+
carryover = part;
411418
}
419+
setPixelColorXY(int(col), int(rows - 1), curnew);
412420
}
413421

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

0 commit comments

Comments
 (0)