@@ -989,8 +989,8 @@ void Segment::fade_out(uint8_t rate) const {
989989 if (!isActive ()) return ; // not active
990990 rate = (256 -rate) >> 1 ;
991991 const int mappedRate = 256 / (rate + 1 );
992- const size_t length = is2D () ? ( vWidth () * vHeight ()) : vLength ();
993- for (unsigned j = 0 ; j < length ; j++) {
992+ const size_t rlength = rawLength (); // calculate only once
993+ for (unsigned j = 0 ; j < rlength ; j++) {
994994 uint32_t color = getPixelColorRaw (j);
995995 if (color == colors[1 ]) continue ; // already at target color
996996 for (int i = 0 ; i < 32 ; i += 8 ) {
@@ -1011,13 +1011,15 @@ void Segment::fade_out(uint8_t rate) const {
10111011// fades all pixels to secondary color
10121012void Segment::fadeToSecondaryBy (uint8_t fadeBy) const {
10131013 if (!isActive () || fadeBy == 0 ) return ; // optimization - no scaling to apply
1014- for (unsigned i = 0 ; i < vLength (); i++) setPixelColorRaw (i, color_blend (getPixelColorRaw (i), colors[1 ], fadeBy));
1014+ const size_t rlength = rawLength (); // calculate only once
1015+ for (unsigned i = 0 ; i < rlength; i++) setPixelColorRaw (i, color_blend (getPixelColorRaw (i), colors[1 ], fadeBy));
10151016}
10161017
10171018// fades all pixels to black using nscale8()
10181019void Segment::fadeToBlackBy (uint8_t fadeBy) const {
10191020 if (!isActive () || fadeBy == 0 ) return ; // optimization - no scaling to apply
1020- for (unsigned i = 0 ; i < vLength (); i++) setPixelColorRaw (i, color_fade (getPixelColorRaw (i), 255 -fadeBy));
1021+ const size_t rlength = rawLength (); // calculate only once
1022+ for (unsigned i = 0 ; i < rlength; i++) setPixelColorRaw (i, color_fade (getPixelColorRaw (i), 255 -fadeBy));
10211023}
10221024
10231025/*
@@ -1036,12 +1038,12 @@ void Segment::blur(uint8_t blur_amount, bool smear) const {
10361038#endif
10371039 uint8_t keep = smear ? 255 : 255 - blur_amount;
10381040 uint8_t seep = blur_amount >> 1 ;
1039- unsigned vlength = vLength ();
1041+ unsigned rlength = rawLength ();
10401042 uint32_t carryover = BLACK;
10411043 uint32_t lastnew; // not necessary to initialize lastnew and last, as both will be initialized by the first loop iteration
10421044 uint32_t last;
10431045 uint32_t curnew = BLACK;
1044- for (unsigned i = 0 ; i < vlength ; i++) {
1046+ for (unsigned i = 0 ; i < rlength ; i++) {
10451047 uint32_t cur = getPixelColorRaw (i);
10461048 uint32_t part = color_fade (cur, seep);
10471049 curnew = color_fade (cur, keep);
@@ -1055,7 +1057,7 @@ void Segment::blur(uint8_t blur_amount, bool smear) const {
10551057 last = cur; // save original value for comparison on next iteration
10561058 carryover = part;
10571059 }
1058- setPixelColorRaw (vlength - 1 , curnew);
1060+ setPixelColorRaw (rlength - 1 , curnew);
10591061}
10601062
10611063/*
0 commit comments