HUB75 driver optimization

gains up to 3 fps in some effects.
This commit is contained in:
Frank
2024-11-03 21:54:41 +01:00
parent ffa5445aec
commit 39bf245d1e

View File

@@ -11,14 +11,14 @@
// WLEDMM functions to get/set bits in an array - based on functions created by Brandon for GOL
// toDo : make this a class that's completely defined in a header file
bool getBitFromArray(const uint8_t* byteArray, size_t position) { // get bit value
inline bool getBitFromArray(const uint8_t* byteArray, size_t position) { // get bit value
size_t byteIndex = position / 8;
unsigned bitIndex = position % 8;
uint8_t byteValue = byteArray[byteIndex];
return (byteValue >> bitIndex) & 1;
}
void setBitInArray(uint8_t* byteArray, size_t position, bool value) { // set bit - with error handling for nullptr
inline void setBitInArray(uint8_t* byteArray, size_t position, bool value) { // set bit - with error handling for nullptr
//if (byteArray == nullptr) return;
size_t byteIndex = position / 8;
unsigned bitIndex = position % 8;
@@ -1018,19 +1018,13 @@ void __attribute__((hot)) BusHub75Matrix::setPixelColor(uint16_t pix, uint32_t c
}
uint32_t BusHub75Matrix::getPixelColor(uint16_t pix) const {
if (!_valid || pix >= _len) return BLACK;
if (_ledBuffer)
return uint32_t(_ledBuffer[pix].scale8(_bri)) & 0x00FFFFFF; // scale8() is needed to mimic NeoPixelBus, which returns scaled-down colours
else
return BLACK; // we don't know anything about the pixel
if (!_valid || pix >= _len || !_ledBuffer) return BLACK;
return uint32_t(_ledBuffer[pix].scale8(_bri)) & 0x00FFFFFF; // scale8() is needed to mimic NeoPixelBus, which returns scaled-down colours
}
uint32_t __attribute__((hot)) BusHub75Matrix::getPixelColorRestored(uint16_t pix) const {
if (!_valid || pix >= _len) return BLACK;
if (_ledBuffer)
return uint32_t(_ledBuffer[pix]) & 0x00FFFFFF;
else
return BLACK; // we don't know anything about the pixel
if (!_valid || pix >= _len || !_ledBuffer) return BLACK;
return uint32_t(_ledBuffer[pix]) & 0x00FFFFFF;
}
void BusHub75Matrix::setBrightness(uint8_t b, bool immediate) {
@@ -1056,19 +1050,23 @@ void __attribute__((hot)) BusHub75Matrix::show(void) {
unsigned height = isFourScan ? fourScanPanel->height() : display->height();
unsigned width = _panelWidth;
// Cache pointers to LED array and bitmask array, to avoid repeated accesses
const byte* ledsDirty = _ledsDirty;
const CRGB* ledBuffer = _ledBuffer;
//while(!previousBufferFree) delay(1); // experimental - Wait before we allow any writing to the buffer. Stop flicker.
size_t pix = 0; // running pixel index
for (int y=0; y<height; y++) for (int x=0; x<width; x++) {
if (getBitFromArray(_ledsDirty, pix) == true) { // only repaint the "dirty" pixels
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
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);
#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;