From 4abaf13598b751a4e849cf129ff1084e191a9ccb Mon Sep 17 00:00:00 2001 From: Will Miles Date: Sat, 7 Jun 2025 11:08:11 -0400 Subject: [PATCH 1/3] Fix Segment::fade_out for 2d expansion Since we're using get/setPixelColorRaw, we need the true length, not the virtual length. --- wled00/FX_fcn.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 438c36d5a..34d668e3e 100755 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -989,7 +989,8 @@ void Segment::fade_out(uint8_t rate) const { if (!isActive()) return; // not active rate = (256-rate) >> 1; const int mappedRate = 256 / (rate + 1); - for (unsigned j = 0; j < vLength(); j++) { + const size_t length = is2D() ? (vWidth() * vHeight()) : vLength(); + for (unsigned j = 0; j < length; j++) { uint32_t color = getPixelColorRaw(j); if (color == colors[1]) continue; // already at target color for (int i = 0; i < 32; i += 8) { From 94f226aadfd9bf4fd74b1d779fd012d6de58ab17 Mon Sep 17 00:00:00 2001 From: Will Miles Date: Mon, 9 Jun 2025 12:15:36 -0400 Subject: [PATCH 2/3] Fix additional mapping expansion locations --- wled00/FX.h | 7 +++++++ wled00/FX_fcn.cpp | 16 +++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/wled00/FX.h b/wled00/FX.h index 1b9bbaac3..5894f29b0 100755 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -723,6 +723,13 @@ class Segment { return 1; #endif } + inline unsigned rawLength() const { // returns length of used raw pixel buffer (eg. get/setPixelColorRaw()) + #ifndef WLED_DISABLE_2D + if (is2D()) return virtualWidth() * virtualHeight(); + #endif + return virtualLength(); + } + #ifndef WLED_DISABLE_2D inline bool is2D() const { return (width()>1 && height()>1); } [[gnu::hot]] void setPixelColorXY(int x, int y, uint32_t c) const; // set relative pixel within segment with color diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 34d668e3e..ffe43b005 100755 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -989,8 +989,8 @@ void Segment::fade_out(uint8_t rate) const { if (!isActive()) return; // not active rate = (256-rate) >> 1; const int mappedRate = 256 / (rate + 1); - const size_t length = is2D() ? (vWidth() * vHeight()) : vLength(); - for (unsigned j = 0; j < length; j++) { + const size_t rlength = rawLength(); // calculate only once + for (unsigned j = 0; j < rlength; j++) { uint32_t color = getPixelColorRaw(j); if (color == colors[1]) continue; // already at target color for (int i = 0; i < 32; i += 8) { @@ -1011,13 +1011,15 @@ void Segment::fade_out(uint8_t rate) const { // fades all pixels to secondary color void Segment::fadeToSecondaryBy(uint8_t fadeBy) const { if (!isActive() || fadeBy == 0) return; // optimization - no scaling to apply - for (unsigned i = 0; i < vLength(); i++) setPixelColorRaw(i, color_blend(getPixelColorRaw(i), colors[1], fadeBy)); + const size_t rlength = rawLength(); // calculate only once + for (unsigned i = 0; i < rlength; i++) setPixelColorRaw(i, color_blend(getPixelColorRaw(i), colors[1], fadeBy)); } // fades all pixels to black using nscale8() void Segment::fadeToBlackBy(uint8_t fadeBy) const { if (!isActive() || fadeBy == 0) return; // optimization - no scaling to apply - for (unsigned i = 0; i < vLength(); i++) setPixelColorRaw(i, color_fade(getPixelColorRaw(i), 255-fadeBy)); + const size_t rlength = rawLength(); // calculate only once + for (unsigned i = 0; i < rlength; i++) setPixelColorRaw(i, color_fade(getPixelColorRaw(i), 255-fadeBy)); } /* @@ -1036,12 +1038,12 @@ void Segment::blur(uint8_t blur_amount, bool smear) const { #endif uint8_t keep = smear ? 255 : 255 - blur_amount; uint8_t seep = blur_amount >> 1; - unsigned vlength = vLength(); + unsigned rlength = rawLength(); uint32_t carryover = BLACK; uint32_t lastnew; // not necessary to initialize lastnew and last, as both will be initialized by the first loop iteration uint32_t last; uint32_t curnew = BLACK; - for (unsigned i = 0; i < vlength; i++) { + for (unsigned i = 0; i < rlength; i++) { uint32_t cur = getPixelColorRaw(i); uint32_t part = color_fade(cur, seep); curnew = color_fade(cur, keep); @@ -1055,7 +1057,7 @@ void Segment::blur(uint8_t blur_amount, bool smear) const { last = cur; // save original value for comparison on next iteration carryover = part; } - setPixelColorRaw(vlength - 1, curnew); + setPixelColorRaw(rlength - 1, curnew); } /* From 16a88775c3d486d9e30a37513d9d9f8e2f2e52ba Mon Sep 17 00:00:00 2001 From: Will Miles Date: Sat, 14 Jun 2025 15:21:12 -0400 Subject: [PATCH 3/3] Revert changes to blur() No need to rely on a sufficiently smart compiler. --- wled00/FX_fcn.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index ffe43b005..16076d745 100755 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -1038,12 +1038,12 @@ void Segment::blur(uint8_t blur_amount, bool smear) const { #endif uint8_t keep = smear ? 255 : 255 - blur_amount; uint8_t seep = blur_amount >> 1; - unsigned rlength = rawLength(); + unsigned vlength = vLength(); uint32_t carryover = BLACK; uint32_t lastnew; // not necessary to initialize lastnew and last, as both will be initialized by the first loop iteration uint32_t last; uint32_t curnew = BLACK; - for (unsigned i = 0; i < rlength; i++) { + for (unsigned i = 0; i < vlength; i++) { uint32_t cur = getPixelColorRaw(i); uint32_t part = color_fade(cur, seep); curnew = color_fade(cur, keep); @@ -1057,7 +1057,7 @@ void Segment::blur(uint8_t blur_amount, bool smear) const { last = cur; // save original value for comparison on next iteration carryover = part; } - setPixelColorRaw(rlength - 1, curnew); + setPixelColorRaw(vlength - 1, curnew); } /*