Skip to content

Commit fcabef7

Browse files
committed
merge fixes, also fixed out of bounds access in rotary UM
1 parent b3e389b commit fcabef7

4 files changed

Lines changed: 15 additions & 16 deletions

File tree

usermods/rgb-rotary-encoder/rgb-rotary-encoder.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class RgbRotaryEncoderUsermod : public Usermod
3434
byte currentColors[3];
3535
byte lastKnownBri = 0;
3636

37+
inline uint32_t colorFromRgb(byte* rgb) { return uint32_t((byte(rgb[0]) << 16) | (byte(rgb[1]) << 8) | (byte(rgb[2]))); }
3738

3839
void initRotaryEncoder()
3940
{
@@ -79,7 +80,7 @@ class RgbRotaryEncoderUsermod : public Usermod
7980
for (int i = 0; i < currentPos / incrementPerClick - 1; i++) {
8081
ledBus->setPixelColor(i, 0);
8182
}
82-
ledBus->setPixelColor(currentPos / incrementPerClick - 1, colorFromRgbw(currentColors));
83+
ledBus->setPixelColor(currentPos / incrementPerClick - 1, colorFromRgb(currentColors));
8384
for (int i = currentPos / incrementPerClick; i < numLeds; i++) {
8485
ledBus->setPixelColor(i, 0);
8586
}
@@ -95,7 +96,7 @@ class RgbRotaryEncoderUsermod : public Usermod
9596
if (ledMode == 3) {
9697
hsv2rgb((i) / float(numLeds), 1, .25);
9798
}
98-
ledBus->setPixelColor(i, colorFromRgbw(currentColors));
99+
ledBus->setPixelColor(i, colorFromRgb(currentColors));
99100
}
100101
for (int i = currentPos / incrementPerClick; i < numLeds; i++) {
101102
ledBus->setPixelColor(i, 0);

wled00/FX.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,38 +148,37 @@ void mode_copy_segment(void) {
148148
Segment& sourcesegment = strip.getSegment(sourceid);
149149

150150
if (sourcesegment.isActive()) {
151-
uint32_t sourcecolor;
152-
uint32_t destcolor;
151+
CRGBW color;
153152
if(sourcesegment.is2D()) { // 2D source, note: 2D to 1D just copies the first row (or first column if 'Switch axis' is checked in FX)
154153
for (unsigned y = 0; y < SEGMENT.vHeight(); y++) {
155154
for (unsigned x = 0; x < SEGMENT.vWidth(); x++) {
156155
unsigned sx = x; // source coordinates
157156
unsigned sy = y;
158157
if(SEGMENT.check1) std::swap(sx, sy); // flip axis
159158
if(SEGMENT.check2) {
160-
sourcecolor = strip.getPixelColorXY(sx + sourcesegment.start, sy + sourcesegment.startY); // read from global buffer (reads the last rendered frame)
159+
color = strip.getPixelColorXY(sx + sourcesegment.start, sy + sourcesegment.startY); // read from global buffer (reads the last rendered frame)
161160
}
162161
else {
163162
sourcesegment.setDrawDimensions(); // set to source segment dimensions
164-
sourcecolor = sourcesegment.getPixelColorXY(sx, sy); // read from segment buffer
163+
color = sourcesegment.getPixelColorXY(sx, sy); // read from segment buffer
165164
}
166-
destcolor = adjust_color(sourcecolor, SEGMENT.intensity, SEGMENT.custom1, SEGMENT.custom2);
165+
adjust_color(color, SEGMENT.intensity, SEGMENT.custom1, SEGMENT.custom2);
167166
SEGMENT.setDrawDimensions(); // reset to current segment dimensions
168-
SEGMENT.setPixelColorXY(x, y, destcolor);
167+
SEGMENT.setPixelColorXY(x, y, color);
169168
}
170169
}
171170
} else { // 1D source, source can be expanded into 2D
172171
for (unsigned i = 0; i < SEGMENT.vLength(); i++) {
173172
if(SEGMENT.check2) {
174-
sourcecolor = strip.getPixelColorNoMap(i + sourcesegment.start); // read from global buffer (reads the last rendered frame)
173+
color = strip.getPixelColorNoMap(i + sourcesegment.start); // read from global buffer (reads the last rendered frame)
175174
}
176175
else {
177176
sourcesegment.setDrawDimensions(); // set to source segment dimensions
178-
sourcecolor = sourcesegment.getPixelColor(i);
177+
color = sourcesegment.getPixelColor(i);
179178
}
180-
destcolor = adjust_color(sourcecolor, SEGMENT.intensity, SEGMENT.custom1, SEGMENT.custom2);
179+
adjust_color(color, SEGMENT.intensity, SEGMENT.custom1, SEGMENT.custom2);
181180
SEGMENT.setDrawDimensions(); // reset to current segment dimensions
182-
SEGMENT.setPixelColor(i, destcolor);
181+
SEGMENT.setPixelColor(i, color);
183182
}
184183
}
185184
}

wled00/FX_fcn.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,9 +1106,9 @@ void Segment::blur(uint8_t blur_amount, bool smear) const {
11061106
uint32_t Segment::color_wheel(uint8_t pos) const {
11071107
if (palette) return color_from_palette(pos, false, false, 0); // only wrap if "always wrap" is set
11081108
uint8_t w = W(getCurrentColor(0));
1109-
uint32_t rgb;
1110-
hsv2rgb(CHSV32(static_cast<uint16_t>(pos << 8), 255, 255), rgb);
1111-
return rgb | (w << 24); // add white channel
1109+
CRGBW rgb;
1110+
rgb = (CHSV32(static_cast<uint16_t>(pos << 8), 255, 255), rgb);
1111+
return rgb.color32 | (w << 24); // add white channel
11121112
}
11131113

11141114
/*

wled00/wled.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ using PSRAMDynamicJsonDocument = BasicJsonDocument<PSRAM_Allocator>;
195195
#endif
196196
#include "NodeStruct.h"
197197
#include "pin_manager.h"
198-
#include "colors.h"
199198
#include "bus_manager.h"
200199
#include "FX.h"
201200
#include "wled_metadata.h"

0 commit comments

Comments
 (0)