Better palette blends.

This commit is contained in:
Blaz Kristan 2022-09-06 21:47:50 +02:00
parent 4f3de8646a
commit 4480abc646
2 changed files with 24 additions and 4 deletions

View File

@ -388,14 +388,31 @@ typedef struct Segment {
uint8_t _briT; // temporary brightness uint8_t _briT; // temporary brightness
uint8_t _cctT; // temporary CCT uint8_t _cctT; // temporary CCT
CRGBPalette16 _palT; // temporary palette CRGBPalette16 _palT; // temporary palette
uint8_t _prevPaletteBlends; // number of previous palette blends (there are max 128 belnds possible)
uint8_t _modeP; // previous mode/effect uint8_t _modeP; // previous mode/effect
//uint16_t _aux0, _aux1; // previous mode/effect runtime data //uint16_t _aux0, _aux1; // previous mode/effect runtime data
//uint32_t _step, _call; // previous mode/effect runtime data //uint32_t _step, _call; // previous mode/effect runtime data
//byte *_data; // previous mode/effect runtime data //byte *_data; // previous mode/effect runtime data
uint32_t _start; uint32_t _start;
uint16_t _dur; uint16_t _dur;
Transition(uint16_t dur=750) : _briT(255), _cctT(127), _palT(CRGBPalette16(CRGB::Black)), _modeP(FX_MODE_STATIC), _start(millis()), _dur(dur) {} Transition(uint16_t dur=750)
Transition(uint16_t d, uint8_t b, uint8_t c, const uint32_t *o) : _briT(b), _cctT(c), _palT(CRGBPalette16(CRGB::Black)), _modeP(FX_MODE_STATIC), _start(millis()), _dur(d) { : _briT(255)
, _cctT(127)
, _palT(CRGBPalette16(CRGB::Black))
, _prevPaletteBlends(0)
, _modeP(FX_MODE_STATIC)
, _start(millis())
, _dur(dur)
{}
Transition(uint16_t d, uint8_t b, uint8_t c, const uint32_t *o)
: _briT(b)
, _cctT(c)
, _palT(CRGBPalette16(CRGB::Black))
, _prevPaletteBlends(0)
, _modeP(FX_MODE_STATIC)
, _start(millis())
, _dur(d)
{
for (size_t i=0; i<NUM_COLORS; i++) _colorT[i] = o[i]; for (size_t i=0; i<NUM_COLORS; i++) _colorT[i] = o[i];
} }
} *_t; } *_t;

View File

@ -341,8 +341,11 @@ CRGBPalette16 &Segment::currentPalette(CRGBPalette16 &targetPalette, uint8_t pal
loadPalette(targetPalette, pal); loadPalette(targetPalette, pal);
if (transitional && _t && progress() < 0xFFFFU) { if (transitional && _t && progress() < 0xFFFFU) {
// blend palettes // blend palettes
uint8_t blends = map(_t->_dur, 0, 0xFFFF, 48, 6); // do not blend palettes too quickly (0-65.5s) // there are about 255 blend passes of 48 "blends" to completely blend two palettes (in _dur time)
nblendPaletteTowardPalette(_t->_palT, targetPalette, blends); // minimum blend time is 100ms maximum is 65535ms
uint32_t timeMS = millis() - _t->_start;
uint16_t noOfBlends = (255U * timeMS / _t->_dur) - _t->_prevPaletteBlends;
for (int i=0; i<noOfBlends; i++, _t->_prevPaletteBlends++) nblendPaletteTowardPalette(_t->_palT, targetPalette, 48);
targetPalette = _t->_palT; // copy transitioning/temporary palette targetPalette = _t->_palT; // copy transitioning/temporary palette
} }
return targetPalette; return targetPalette;