From 453c5e602303f1df9759b726b73ca9a124967172 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Thu, 26 Mar 2026 12:14:49 +0100 Subject: [PATCH] HUB75 color re-ordering optimization only perform color re-ordering when needed. This allows for better optimization by the compiler. --- wled00/bus_manager.cpp | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/wled00/bus_manager.cpp b/wled00/bus_manager.cpp index 47ec11e9..623ca6b5 100644 --- a/wled00/bus_manager.cpp +++ b/wled00/bus_manager.cpp @@ -1171,12 +1171,14 @@ void __attribute__((hot)) IRAM_ATTR BusHub75Matrix::show(void) { if (_ledBuffer) { // write out buffered LEDs + // cache values, to avoid repeated global access inside the hot path VirtualMatrixPanel* fourScanPanel = BusHub75Matrix::activeFourScanPanel; - bool isFourScan = (fourScanPanel != nullptr); + const bool isFourScan = (fourScanPanel != nullptr); //if (isFourScan) fourScanPanel->setRotation(0); - unsigned height = isFourScan ? fourScanPanel->height() : display->height(); - unsigned width = _panelWidth; - + const unsigned height = isFourScan ? fourScanPanel->height() : display->height(); + const unsigned width = _panelWidth; + const uint_fast8_t colOrder = _colorOrder & 0x0F; + const bool needReorder = colOrder != COL_ORDER_RGB; // fast path when no color re-ordering needed // Cache pointers to LED array and bitmask array, to avoid repeated accesses const byte* ledsDirty = _ledsDirty; const CRGB* ledBuffer = _ledBuffer; @@ -1197,19 +1199,22 @@ void __attribute__((hot)) IRAM_ATTR BusHub75Matrix::show(void) { uint8_t g = c.g; uint8_t b = c.b; #endif - // apply color order mapping (COL_ORDER_* values from const.h) - uint8_t r2=r, g2=g, b2=b; - switch (_colorOrder & 0x0F) { - case COL_ORDER_RGB: /* 1 */ break; // no swap (HUB75 default) - case COL_ORDER_GRB: /* 0 */ r2=g; g2=r; break; // swap R and G - case COL_ORDER_BRG: /* 2 */ r2=b; g2=r; b2=g; break; - case COL_ORDER_RBG: /* 3 */ g2=b; b2=g; break; // swap G and B - case COL_ORDER_BGR: /* 4 */ r2=b; b2=r; break; // swap R and B - case COL_ORDER_GBR: /* 5 */ r2=g; g2=b; b2=r; break; - default: break; + if (needReorder) { + // apply color order mapping (COL_ORDER_* values from const.h) + uint8_t r2=r, g2=g, b2=b; + switch (colOrder) { + case COL_ORDER_RGB: /* 1 */ break; // no swap (HUB75 default) + case COL_ORDER_GRB: /* 0 */ r2=g; g2=r; break; // swap R and G + case COL_ORDER_BRG: /* 2 */ r2=b; g2=r; b2=g; break; + case COL_ORDER_RBG: /* 3 */ g2=b; b2=g; break; // swap G and B + case COL_ORDER_BGR: /* 4 */ r2=b; b2=r; break; // swap R and B + case COL_ORDER_GBR: /* 5 */ r2=g; g2=b; b2=r; break; + default: break; + } + r=r2; g=g2; b=b2; } - if (isFourScan) fourScanPanel->drawPixelRGB888(int16_t(x), int16_t(y), r2, g2, b2); - else display->drawPixelRGB888(int16_t(x), int16_t(y), r2, g2, b2); + if (isFourScan) fourScanPanel->drawPixelRGB888(int16_t(x), int16_t(y), r, g, b); + else display->drawPixelRGB888(int16_t(x), int16_t(y), r, g, b); } pix ++; }