hot path optimization: make gamma correction inline

* make sure that gamma LUT is always initialized
* remove some unnecessary safety checks
* make gamma8() inline, for more speed
* use fast unGamma8 for preview
* add super-fast unGamma8 for HUB75 - old function lost 3-10 fps, this version does not reduce fps at all *grins*
This commit is contained in:
Frank
2025-11-10 23:17:16 +01:00
parent 4a323ba057
commit 36648d1936
6 changed files with 50 additions and 17 deletions

View File

@@ -610,6 +610,20 @@ uint8_t BusHub75Matrix::activeType = 0;
uint8_t BusHub75Matrix::instanceCount = 0;
uint8_t BusHub75Matrix::last_bri = 0;
#ifndef NO_CIE1931
// WLEDMM speedup: create a version of "unGamma8" that can be inlined by the compiler
extern uint8_t gammaTinv[256]; // defined in colors.cpp
static uint8_t const* myGammaTable = gammaTinv; // local alias for gammaTinv
static inline uint8_t unGamma8_bus(uint8_t value) {
return myGammaTable[value];
}
static inline uint32_t unGamma24_bus(uint32_t c) {
return RGBW32(myGammaTable[R(c)], myGammaTable[G(c)], myGammaTable[B(c)], W(c));
}
#endif
// --------------------------
// Bitdepth reduction based on panel size
@@ -1080,6 +1094,13 @@ BusHub75Matrix::BusHub75Matrix(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWh
activeFourScanPanel = fourScanPanel;
if (newDisplay) memcpy(&activeMXconfig, &mxconfig, sizeof(mxconfig));
}
#ifndef NO_CIE1931
// force initial calculation of gamma correction tables
if ((gammaCorrectVal < 0.999f) || (gammaCorrectVal > 3.0f)) calcGammaTable(1.0f);
else calcGammaTable(gammaCorrectVal);
#endif
instanceCount++;
USER_PRINT(F("heap usage: ")); USER_PRINTLN(int(lastHeap - ESP.getFreeHeap()));
}
@@ -1142,13 +1163,12 @@ void __attribute__((hot)) IRAM_ATTR BusHub75Matrix::show(void) {
for (int y=0; y<height; y++) for (int x=0; x<width; x++) {
if (getBitFromArray(ledsDirty, pix) == true) { // only repaint the "dirty" pixels
#ifndef NO_CIE1931
uint32_t c = uint32_t(ledBuffer[pix]) & 0x00FFFFFF; // get RGB color, removing FastLED "alpha" component
c = unGamma24(c); // to use the driver linear brightness feature, we first need to undo WLED gamma correction
uint8_t r = R(c);
uint8_t g = G(c);
uint8_t b = B(c);
const CRGB& c = ledBuffer[pix]; // c is an alias for ledBuffer[pix] - avoid creation of a temporary CRGB object instance
uint8_t r = unGamma8_bus(c.r);
uint8_t g = unGamma8_bus(c.g);
uint8_t b = unGamma8_bus(c.b);
#else
const CRGB c = ledBuffer[pix]; // we stay on CRGB, instead of packing/unpacking the color value to uint32_t
const CRGB& c = ledBuffer[pix]; // we stay on CRGB, instead of packing/unpacking the color value to uint32_t
uint8_t r = c.r;
uint8_t g = c.g;
uint8_t b = c.b;