From 0429850835a9b49f60c317b6a50502693dc712e3 Mon Sep 17 00:00:00 2001 From: beta-tester Date: Tue, 8 Aug 2023 23:01:54 +0200 Subject: [PATCH] optimized color565to888() remove expensive multiplication --- src/ESP32-HUB75-MatrixPanel-I2S-DMA.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ESP32-HUB75-MatrixPanel-I2S-DMA.h b/src/ESP32-HUB75-MatrixPanel-I2S-DMA.h index 978715b..a598c43 100644 --- a/src/ESP32-HUB75-MatrixPanel-I2S-DMA.h +++ b/src/ESP32-HUB75-MatrixPanel-I2S-DMA.h @@ -880,9 +880,12 @@ private: */ inline void MatrixPanel_I2S_DMA::color565to888(const uint16_t color, uint8_t &r, uint8_t &g, uint8_t &b) { - r = ((((color >> 11) & 0x1F) * 527) + 23) >> 6; - g = ((((color >> 5) & 0x3F) * 259) + 33) >> 6; - b = (((color & 0x1F) * 527) + 23) >> 6; + r = (color >> 8) & 0xf8; + g = (color >> 3) & 0xfc; + b = (color << 3) & 0xf8; + r |= r >> 5; + g |= g >> 6; + b |= b >> 5; } inline void MatrixPanel_I2S_DMA::drawPixel(int16_t x, int16_t y, uint16_t color) // adafruit virtual void override