Skip to content

Commit

Permalink
mode_copy_segment: Map mirror/reverse/transpose
Browse files Browse the repository at this point in the history
Use a local formulation of getRenderedPixelXY() to copy from the
mirrored, reversed, and transposed output.  Grouping, spacing, and
offset used in the source segment are discarded.
  • Loading branch information
willmmiles committed Sep 5, 2024
1 parent 434ba3f commit 0d54743
Showing 1 changed file with 30 additions and 34 deletions.
64 changes: 30 additions & 34 deletions wled00/FX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,47 +97,43 @@ static const char _data_FX_MODE_STATIC[] PROGMEM = "Solid";
/*
* Copy selected segment
*/
static CRGB shift_color(CRGB sourcecolor, uint8_t shift) {
CHSV pxHSV = rgb2hsv(sourcecolor); //convert to HSV
pxHSV.h += shift; // shift hue
hsv2rgb_spectrum(pxHSV, sourcecolor); // convert back to RGB
return sourcecolor;
}

static CRGB getRenderedPixelXY(Segment& seg, int x, int y = 0) {
// We read pixels back following mirror/reverse/transpose but ignoring grouping
// For every group-length pixels, add spacing
x *= seg.groupLength(); // expand to physical pixels
y *= seg.groupLength(); // expand to physical pixels
if (x >= seg.width() || y >= seg.height()) return 0; // fill out of range pixels with black
return strip.getPixelColorXY(seg.start + seg.offset + x, seg.startY + y);
}


uint16_t mode_copy_segment(void) {

uint32_t sourceid = SEGMENT.custom1;
SEGMENT.fadeToBlackBy(16); // fades out unused pixels, still allows overlay (also fades out if invalid ID is set)
if (sourceid >= strip._segments.size() || sourceid == strip.getCurrSegmentId()) return FRAMETIME; // invalid source
CRGB sourcecolor;

if (strip._segments[sourceid].isActive()) {
// note: copying 1D to 2D as well as 2D to 1D is not supported
if(SEGMENT.is2D() && strip._segments[sourceid].is2D()) { // 2D setup
uint32_t cx, cy; // sizes to copy
cx = std::min(strip._segments[sourceid].virtualWidth(), SEGMENT.virtualWidth()); // get smaller width
cy = std::min(strip._segments[sourceid].virtualHeight(), SEGMENT.virtualHeight()); // get smaller height
for (unsigned x = 0; x < cx; x++) {
for (unsigned y = 0; y < cy; y++) {
sourcecolor = strip._segments[sourceid].getPixelColorXY(x, y);
if(SEGMENT.custom2 > 0) // color shifting enabled
{
CHSV pxHSV = rgb2hsv(sourcecolor); //convert to HSV
pxHSV.h += SEGMENT.custom2; // shift hue
hsv2rgb_spectrum(pxHSV, sourcecolor); // convert back to RGB

}
SEGMENT.setPixelColorXY(x, y, sourcecolor);
//SEGMENT.setPixelColorXY(x, y, strip._segments[sourceid].getPixelColorXY(x, y)); //use this for no colorshift option
}

}
}
else if(!SEGMENT.is2D() && !strip._segments[sourceid].is2D()) { // 1D strip
// note: copying 1D to 2D is not supported
if(!strip._segments[sourceid].is2D()) { // 1D source; can be expanded into 2D
uint32_t cl; // length to copy
cl = std::min(strip._segments[sourceid].virtualLength(), SEGMENT.virtualLength()); // get smaller length
for (unsigned i = 0; i < cl; i++) {
sourcecolor = strip._segments[sourceid].getPixelColor(i);
if(SEGMENT.custom2 > 0) // color shifting enabled
{
CHSV pxHSV = rgb2hsv(sourcecolor); //convert to HSV
pxHSV.h += SEGMENT.custom2; // shift hue
sourcecolor = (CRGB)pxHSV; // convert back to RGB
}
SEGMENT.setPixelColor(i, sourcecolor);
// SEGMENT.setPixelColor(i, strip._segments[sourceid].getPixelColor(i)); //use this for no colorshift option
for (unsigned i = 0; i < SEGMENT.virtualLength(); i++) {
CRGB sourcecolor = getRenderedPixelXY(strip._segments[sourceid], i);
SEGMENT.setPixelColor(i, shift_color(sourcecolor, SEGMENT.custom2));
}
} else if(SEGMENT.is2D()) { // 2D setup
for (unsigned x = 0; x < SEGMENT.virtualWidth(); x++) {
for (unsigned y = 0; y < SEGMENT.virtualHeight(); y++) {
CRGB sourcecolor = getRenderedPixelXY(strip._segments[sourceid], x, y);
SEGMENT.setPixelColorXY(x, y, shift_color(sourcecolor, SEGMENT.custom2));
}
}
}
}
Expand Down

0 comments on commit 0d54743

Please sign in to comment.