From 94243ac60513a2770bc38d5f2e15614a4a68d393 Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Tue, 6 Sep 2022 21:44:11 +0200 Subject: [PATCH] Better palette blending. --- wled00/FX.h | 21 +++++++++++++++++++-- wled00/FX_fcn.cpp | 7 +++++-- wled00/wled.h | 2 +- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/wled00/FX.h b/wled00/FX.h index afa8edec..ddb4bd12 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -388,14 +388,31 @@ typedef struct Segment { uint8_t _briT; // temporary brightness uint8_t _cctT; // temporary CCT CRGBPalette16 _palT; // temporary palette + uint8_t _prevPaletteBlends; // number of previous palette blends (there are max 128 belnds possible) uint8_t _modeP; // previous mode/effect //uint16_t _aux0, _aux1; // previous mode/effect runtime data //uint32_t _step, _call; // previous mode/effect runtime data //byte *_data; // previous mode/effect runtime data uint32_t _start; 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 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) { + Transition(uint16_t dur=750) + : _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_dur, 0, 0xFFFF, 48, 6); // do not blend palettes too quickly (0-65.5s) - nblendPaletteTowardPalette(_t->_palT, targetPalette, blends); + // there are about 255 blend passes of 48 "blends" to completely blend two palettes (in _dur time) + // 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_prevPaletteBlends++) nblendPaletteTowardPalette(_t->_palT, targetPalette, 48); targetPalette = _t->_palT; // copy transitioning/temporary palette } return targetPalette; diff --git a/wled00/wled.h b/wled00/wled.h index 5b1b2b79..055d65d3 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2209052 +#define VERSION 2209061 //uncomment this if you have a "my_config.h" file you'd like to use //#define WLED_USE_MY_CONFIG