Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions wled00/FX.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions wled00/FX_fcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 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) {
Expand All @@ -1010,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));
}

/*
Expand Down