Fix (almost good) for unbuffered ABL calculations.

This commit is contained in:
Blaz Kristan 2023-07-17 17:06:04 +02:00
parent 82e01f7b17
commit abfb8bbc34
3 changed files with 13 additions and 12 deletions

View File

@ -1230,8 +1230,7 @@ void WS2812FX::show(void) {
unsigned long microsStart = micros();
#endif
uint8_t busBrightness = estimateCurrentAndLimitBri();
busses.setBrightness(busBrightness);
busses.setBrightness(estimateCurrentAndLimitBri());
#ifdef WLED_DEBUG
sumCurrent += micros() - microsStart;
#endif

View File

@ -153,7 +153,10 @@ void BusDigital::show() {
PolyBus::applyPostAdjustments(_busPtr, _iType);
}
PolyBus::show(_busPtr, _iType);
PolyBus::setBrightness(_busPtr, _iType, 255); // restore full brightness at bus level (setting unscaled pixel color)
// looks like the following causes periodic miscalculations in ABL when not using double buffering
// when we no longer restore full brightness at busl level we only get a single frame with incorrect brightness
// when turning WLED off otherwise ABL calculations are OK
//PolyBus::setBrightness(_busPtr, _iType, 255); // restore full brightness at bus level (setting unscaled pixel color)
}
bool BusDigital::canShow() {
@ -228,7 +231,7 @@ uint32_t BusDigital::getPixelColor(uint16_t pix) {
if (_reversed) pix = _len - pix -1;
else pix += _skip;
uint8_t co = _colorOrderMap.getPixelColorOrder(pix+_start, _colorOrder);
uint32_t c = restoreColorLossy(PolyBus::getPixelColor(_busPtr, _iType, (_type==TYPE_WS2812_1CH_X3) ? IC_INDEX_WS2812_1CH_3X(pix) : pix, co), _bri);
uint32_t c = restoreColorLossy(PolyBus::getPixelColor(_busPtr, _iType, (_type==TYPE_WS2812_1CH_X3) ? IC_INDEX_WS2812_1CH_3X(pix) : pix, co));
if (_type == TYPE_WS2812_1CH_X3) { // map to correct IC, each controls 3 LEDs
uint8_t r = R(c);
uint8_t g = _reversed ? B(c) : G(c); // should G and B be switched if _reversed?

View File

@ -224,14 +224,13 @@ class BusDigital : public Bus {
const ColorOrderMap &_colorOrderMap;
bool buffering; // temporary until we figure out why comparison "_data != nullptr" causes severe FPS drop
inline uint32_t restoreColorLossy(uint32_t c, uint_fast8_t _restaurationBri) {
if (_bri == 255) return c;
inline uint32_t restoreColorLossy(uint32_t c) {
if (_bri < 255) {
uint8_t* chan = (uint8_t*) &c;
for (uint_fast8_t i=0; i<4; i++)
{
for (uint_fast8_t i=0; i<4; 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) + _bri) / (_bri + 1); //adding _bri slighly improves recovery / stops degradation on re-scale
}
}
return c;
}