From 348c4b4431ab4275706f3cecb41d2d6569a3a0c4 Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Mon, 4 Jul 2022 14:13:17 +0200 Subject: [PATCH] Fix for 2D peek. --- wled00/FX_2Dfcn.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/wled00/FX_2Dfcn.cpp b/wled00/FX_2Dfcn.cpp index 2b0eeac12..72aa875c3 100644 --- a/wled00/FX_2Dfcn.cpp +++ b/wled00/FX_2Dfcn.cpp @@ -250,18 +250,20 @@ void /*IRAM_ATTR*/ WS2812FX::setPixelColorXY(float x, float y, byte r, byte g, b // returns RGBW values of pixel uint32_t WS2812FX::getPixelColorXY(uint16_t x, uint16_t y) { - if (SEGMENT.getOption(SEG_OPTION_REVERSED) ) x = SEGMENT.virtualWidth() - x - 1; - if (SEGMENT.getOption(SEG_OPTION_REVERSED_Y)) y = SEGMENT.virtualHeight() - y - 1; - if (SEGMENT.getOption(SEG_OPTION_TRANSPOSED)) { uint16_t t = x; x = y; y = t; } // swap X & Y if segment transposed + uint16_t index; + if (SEGLEN) { + if (SEGMENT.getOption(SEG_OPTION_REVERSED) ) x = SEGMENT.virtualWidth() - x - 1; + if (SEGMENT.getOption(SEG_OPTION_REVERSED_Y)) y = SEGMENT.virtualHeight() - y - 1; + if (SEGMENT.getOption(SEG_OPTION_TRANSPOSED)) { uint16_t t = x; x = y; y = t; } // swap X & Y if segment transposed - x *= SEGMENT.groupLength(); // expand to physical pixels - y *= SEGMENT.groupLength(); // expand to physical pixels - if (x >= SEGMENT.width() || y >= SEGMENT.height()) return 0; + x *= SEGMENT.groupLength(); // expand to physical pixels + y *= SEGMENT.groupLength(); // expand to physical pixels + if (x >= SEGMENT.width() || y >= SEGMENT.height()) return 0; - //if (SEGMENT.getOption(SEG_OPTION_REVERSED) ) x = SEGMENT.width() - x - 1; - //if (SEGMENT.getOption(SEG_OPTION_REVERSED_Y)) y = SEGMENT.height() - y - 1; - - uint16_t index = get2DPixelIndex(x, y); + index = get2DPixelIndex(x, y); + } else { + index = y * matrixWidth + x; + } if (index < customMappingSize) index = customMappingTable[index]; return busses.getPixelColor(index);