Skip to content

Commit 94f226a

Browse files
committed
Fix additional mapping expansion locations
1 parent 4abaf13 commit 94f226a

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
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: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -989,8 +989,8 @@ void Segment::fade_out(uint8_t rate) const {
989989
if (!isActive()) return; // not active
990990
rate = (256-rate) >> 1;
991991
const int mappedRate = 256 / (rate + 1);
992-
const size_t length = is2D() ? (vWidth() * vHeight()) : vLength();
993-
for (unsigned j = 0; j < length; j++) {
992+
const size_t rlength = rawLength(); // calculate only once
993+
for (unsigned j = 0; j < rlength; j++) {
994994
uint32_t color = getPixelColorRaw(j);
995995
if (color == colors[1]) continue; // already at target color
996996
for (int i = 0; i < 32; i += 8) {
@@ -1011,13 +1011,15 @@ void Segment::fade_out(uint8_t rate) const {
10111011
// fades all pixels to secondary color
10121012
void Segment::fadeToSecondaryBy(uint8_t fadeBy) const {
10131013
if (!isActive() || fadeBy == 0) return; // optimization - no scaling to apply
1014-
for (unsigned i = 0; i < vLength(); i++) setPixelColorRaw(i, color_blend(getPixelColorRaw(i), colors[1], fadeBy));
1014+
const size_t rlength = rawLength(); // calculate only once
1015+
for (unsigned i = 0; i < rlength; i++) setPixelColorRaw(i, color_blend(getPixelColorRaw(i), colors[1], fadeBy));
10151016
}
10161017

10171018
// fades all pixels to black using nscale8()
10181019
void Segment::fadeToBlackBy(uint8_t fadeBy) const {
10191020
if (!isActive() || fadeBy == 0) return; // optimization - no scaling to apply
1020-
for (unsigned i = 0; i < vLength(); i++) setPixelColorRaw(i, color_fade(getPixelColorRaw(i), 255-fadeBy));
1021+
const size_t rlength = rawLength(); // calculate only once
1022+
for (unsigned i = 0; i < rlength; i++) setPixelColorRaw(i, color_fade(getPixelColorRaw(i), 255-fadeBy));
10211023
}
10221024

10231025
/*
@@ -1036,12 +1038,12 @@ void Segment::blur(uint8_t blur_amount, bool smear) const {
10361038
#endif
10371039
uint8_t keep = smear ? 255 : 255 - blur_amount;
10381040
uint8_t seep = blur_amount >> 1;
1039-
unsigned vlength = vLength();
1041+
unsigned rlength = rawLength();
10401042
uint32_t carryover = BLACK;
10411043
uint32_t lastnew; // not necessary to initialize lastnew and last, as both will be initialized by the first loop iteration
10421044
uint32_t last;
10431045
uint32_t curnew = BLACK;
1044-
for (unsigned i = 0; i < vlength; i++) {
1046+
for (unsigned i = 0; i < rlength; i++) {
10451047
uint32_t cur = getPixelColorRaw(i);
10461048
uint32_t part = color_fade(cur, seep);
10471049
curnew = color_fade(cur, keep);
@@ -1055,7 +1057,7 @@ void Segment::blur(uint8_t blur_amount, bool smear) const {
10551057
last = cur; // save original value for comparison on next iteration
10561058
carryover = part;
10571059
}
1058-
setPixelColorRaw(vlength - 1, curnew);
1060+
setPixelColorRaw(rlength - 1, curnew);
10591061
}
10601062

10611063
/*

0 commit comments

Comments
 (0)