Skip to content

Commit c0875b3

Browse files
authored
Merge pull request #4712 from willmmiles/2d-expansion-fadeout-fix
Fix Segment::fade_out for 2d expansion
2 parents 929a5a8 + 16a8877 commit c0875b3

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

wled00/FX.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,13 @@ class Segment {
723723
return 1;
724724
#endif
725725
}
726+
inline unsigned rawLength() const { // returns length of used raw pixel buffer (eg. get/setPixelColorRaw())
727+
#ifndef WLED_DISABLE_2D
728+
if (is2D()) return virtualWidth() * virtualHeight();
729+
#endif
730+
return virtualLength();
731+
}
732+
726733
#ifndef WLED_DISABLE_2D
727734
inline bool is2D() const { return (width()>1 && height()>1); }
728735
[[gnu::hot]] void setPixelColorXY(int x, int y, uint32_t c) const; // set relative pixel within segment with color

wled00/FX_fcn.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,8 @@ void Segment::fade_out(uint8_t rate) const {
987987
if (!isActive()) return; // not active
988988
rate = (256-rate) >> 1;
989989
const int mappedRate = 256 / (rate + 1);
990-
for (unsigned j = 0; j < vLength(); j++) {
990+
const size_t rlength = rawLength(); // calculate only once
991+
for (unsigned j = 0; j < rlength; j++) {
991992
uint32_t color = getPixelColorRaw(j);
992993
if (color == colors[1]) continue; // already at target color
993994
for (int i = 0; i < 32; i += 8) {
@@ -1008,13 +1009,15 @@ void Segment::fade_out(uint8_t rate) const {
10081009
// fades all pixels to secondary color
10091010
void Segment::fadeToSecondaryBy(uint8_t fadeBy) const {
10101011
if (!isActive() || fadeBy == 0) return; // optimization - no scaling to apply
1011-
for (unsigned i = 0; i < vLength(); i++) setPixelColorRaw(i, color_blend(getPixelColorRaw(i), colors[1], fadeBy));
1012+
const size_t rlength = rawLength(); // calculate only once
1013+
for (unsigned i = 0; i < rlength; i++) setPixelColorRaw(i, color_blend(getPixelColorRaw(i), colors[1], fadeBy));
10121014
}
10131015

10141016
// fades all pixels to black using nscale8()
10151017
void Segment::fadeToBlackBy(uint8_t fadeBy) const {
10161018
if (!isActive() || fadeBy == 0) return; // optimization - no scaling to apply
1017-
for (unsigned i = 0; i < vLength(); i++) setPixelColorRaw(i, color_fade(getPixelColorRaw(i), 255-fadeBy));
1019+
const size_t rlength = rawLength(); // calculate only once
1020+
for (unsigned i = 0; i < rlength; i++) setPixelColorRaw(i, color_fade(getPixelColorRaw(i), 255-fadeBy));
10181021
}
10191022

10201023
/*

0 commit comments

Comments
 (0)