Skip to content

Commit 566c505

Browse files
softhack007DedeHai
authored andcommitted
optimizations as per reviewer recommendations
* removed unneeded initializations in blur() and blur2D() * remove check for _t in progress() * code readability: if (_t) --> if(isInTransition()) * add `isInTransition()` checks to currentBri() and currentMode() * added missing `_transitionprogress = 0xFFFFU` in stopTransition()
1 parent cd52d7b commit 566c505

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

wled00/FX.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ typedef struct Segment {
590590
void restoreSegenv(const tmpsegd_t &tmpSegD); // restores segment data from buffer, if buffer is not transition buffer, changed values are copied to transition buffer
591591
#endif
592592
[[gnu::hot]] void updateTransitionProgress(); // set current progression of transition
593-
inline uint16_t progress() const { return _t ? Segment::_transitionprogress : 0xFFFFU; } // transition progression between 0-65535
593+
inline uint16_t progress() const { return Segment::_transitionprogress; } // transition progression between 0-65535
594594
[[gnu::hot]] uint8_t currentBri(bool useCct = false) const; // current segment brightness/CCT (blended while in transition)
595595
uint8_t currentMode() const; // currently active effect/mode (while in transition)
596596
[[gnu::hot]] uint32_t currentColor(uint8_t slot) const; // currently active segment color (blended while in transition)

wled00/FX_2Dfcn.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ void Segment::blur2D(uint8_t blur_x, uint8_t blur_y, bool smear) {
276276
if (!isActive()) return; // not active
277277
const unsigned cols = vWidth();
278278
const unsigned rows = vHeight();
279-
uint32_t lastnew = BLACK;
280-
uint32_t last = BLACK;
279+
uint32_t lastnew; // not necessary to initialize lastnew and last, as both will be initialized by the first loop iteration
280+
uint32_t last;
281281
if (blur_x) {
282282
const uint8_t keepx = smear ? 255 : 255 - blur_x;
283283
const uint8_t seepx = blur_x >> 1;

wled00/FX_fcn.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ void Segment::stopTransition() {
296296
delete _t;
297297
_t = nullptr;
298298
}
299+
_transitionprogress = 0xFFFFU; // stop means stop - transition has ended
299300
}
300301

301302
// transition progression between 0-65535
@@ -326,7 +327,7 @@ void Segment::swapSegenv(tmpsegd_t &tmpSeg) {
326327
tmpSeg._callT = call;
327328
tmpSeg._dataT = data;
328329
tmpSeg._dataLenT = _dataLen;
329-
if (_t && &tmpSeg != &(_t->_segT)) {
330+
if (isInTransition() && &tmpSeg != &(_t->_segT)) {
330331
// swap SEGENV with transitional data
331332
options = _t->_segT._optionsT;
332333
for (size_t i=0; i<NUM_COLORS; i++) colors[i] = _t->_segT._colorT[i];
@@ -349,7 +350,7 @@ void Segment::swapSegenv(tmpsegd_t &tmpSeg) {
349350

350351
void Segment::restoreSegenv(const tmpsegd_t &tmpSeg) {
351352
//DEBUG_PRINTF_P(PSTR("-- Restoring temp seg: %p->(%p) [%d->%p]\n"), &tmpSeg, this, _dataLen, data);
352-
if (_t && &(_t->_segT) != &tmpSeg) {
353+
if (isInTransition() && &(_t->_segT) != &tmpSeg) {
353354
// update possibly changed variables to keep old effect running correctly
354355
_t->_segT._aux0T = aux0;
355356
_t->_segT._aux1T = aux1;
@@ -379,7 +380,7 @@ void Segment::restoreSegenv(const tmpsegd_t &tmpSeg) {
379380
#endif
380381

381382
uint8_t Segment::currentBri(bool useCct) const {
382-
unsigned prog = progress();
383+
unsigned prog = isInTransition() ? progress() : 0xFFFFU;
383384
if (prog < 0xFFFFU) { // progress() < 0xFFFF implies that _t is a valid pointer
384385
unsigned curBri = (useCct ? cct : (on ? opacity : 0)) * prog;
385386
curBri += (useCct ? _t->_cctT : _t->_briT) * (0xFFFFU - prog);
@@ -390,7 +391,7 @@ uint8_t Segment::currentBri(bool useCct) const {
390391

391392
uint8_t Segment::currentMode() const {
392393
#ifndef WLED_DISABLE_MODE_BLEND
393-
unsigned prog = progress();
394+
unsigned prog = isInTransition() ? progress() : 0xFFFFU;
394395
if (modeBlending && prog < 0xFFFFU) return _t->_modeT; // progress() < 0xFFFF implies that _t is a valid pointer
395396
#endif
396397
return mode;
@@ -411,18 +412,18 @@ void Segment::beginDraw() {
411412
_vHeight = virtualHeight();
412413
_vLength = virtualLength();
413414
_segBri = currentBri();
415+
unsigned prog = isInTransition() ? progress() : 0xFFFFU; // transition progress; 0xFFFFU = no transition active
414416
// adjust gamma for effects
415417
for (unsigned i = 0; i < NUM_COLORS; i++) {
416418
#ifndef WLED_DISABLE_MODE_BLEND
417-
uint32_t col = isInTransition() ? color_blend16(_t->_segT._colorT[i], colors[i], progress()) : colors[i];
419+
uint32_t col = isInTransition() ? color_blend16(_t->_segT._colorT[i], colors[i], prog) : colors[i];
418420
#else
419-
uint32_t col = isInTransition() ? color_blend16(_t->_colorT[i], colors[i], progress()) : colors[i];
421+
uint32_t col = isInTransition() ? color_blend16(_t->_colorT[i], colors[i], prog) : colors[i];
420422
#endif
421423
_currentColors[i] = gamma32(col);
422424
}
423425
// load palette into _currentPalette
424426
loadPalette(_currentPalette, palette);
425-
unsigned prog = progress();
426427
if (strip.paletteFade && prog < 0xFFFFU) {
427428
// blend palettes
428429
// there are about 255 blend passes of 48 "blends" to completely blend two palettes (in _dur time)
@@ -1134,8 +1135,8 @@ void Segment::blur(uint8_t blur_amount, bool smear) {
11341135
uint8_t seep = blur_amount >> 1;
11351136
unsigned vlength = vLength();
11361137
uint32_t carryover = BLACK;
1137-
uint32_t lastnew = BLACK;
1138-
uint32_t last = BLACK;
1138+
uint32_t lastnew; // not necessary to initialize lastnew and last, as both will be initialized by the first loop iteration
1139+
uint32_t last;
11391140
uint32_t curnew = BLACK;
11401141
for (unsigned i = 0; i < vlength; i++) {
11411142
uint32_t cur = getPixelColor(i);

0 commit comments

Comments
 (0)