restoreColorLossy small optimization

minor optimizations that give up to 10% speedup in my tests
* use "fast" integer types (where possible)
* replaced _bri with _restaurationBri (no use of globals)
This commit is contained in:
Frank 2023-07-04 16:22:19 +02:00
parent 66616e1cab
commit 8831c76fb4

View File

@ -236,13 +236,13 @@ class BusDigital : public Bus {
void * _busPtr = nullptr; void * _busPtr = nullptr;
const ColorOrderMap &_colorOrderMap; const ColorOrderMap &_colorOrderMap;
inline uint32_t restoreColorLossy(uint32_t c, uint8_t _restaurationBri) { inline uint32_t restoreColorLossy(uint32_t c, uint_fast8_t _restaurationBri) {
if (_bri == 255) return c; if (_restaurationBri == 255) return c;
uint8_t* chan = (uint8_t*) &c; uint8_t* chan = (uint8_t*) &c;
for (uint8_t i=0; i<4; i++) for (uint_fast8_t i=0; i<4; i++)
{ {
uint16_t val = chan[i]; uint_fast16_t val = chan[i];
chan[i] = ((val << 8) + _restaurationBri) / (_restaurationBri + 1); //adding _bri slighly improves recovery / stops degradation on re-scale chan[i] = ((val << 8) + _restaurationBri) / (_restaurationBri + 1); //adding _bri slighly improves recovery / stops degradation on re-scale
} }
return c; return c;