From 0d54743924d2a6db11df1b37d91f4c6d7150f788 Mon Sep 17 00:00:00 2001 From: Will Miles Date: Thu, 5 Sep 2024 19:41:16 -0400 Subject: [PATCH] mode_copy_segment: Map mirror/reverse/transpose 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. --- wled00/FX.cpp | 64 ++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index ca5a40f721..7bf0be2fa5 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -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)); + } } } }