bugfix: make pseudo-1D segments (width=1, height=x) work again

This commit is contained in:
Frank
2024-11-07 19:34:19 +01:00
parent 53ecf16ab1
commit aafebf7aad
3 changed files with 12 additions and 11 deletions

View File

@@ -565,9 +565,9 @@ typedef struct Segment {
inline bool hasRGB(void) const { return _isRGB; }
inline bool hasWhite(void) const { return _hasW; }
inline bool isCCT(void) const { return _isCCT; }
inline uint16_t width(void) const { return isActive() ? (stop - start) : 0; } // segment width in physical pixels (length if 1D)
inline uint16_t width(void) const { return (stop > start) ? (stop - start) : 0; } // segment width in physical pixels (length if 1D)
inline uint16_t height(void) const { return (stopY > startY) ? (stopY - startY) : 0; } // segment height (if 2D) in physical pixels // WLEDMM make sure its always > 0
inline uint16_t length(void) const { return width() * height(); } // segment length (count) in physical pixels
inline uint16_t length(void) const { return width() * height(); } // segment length (count) in physical pixels // WLEDMM fishy ... need to double-check if this is correct
inline uint16_t groupLength(void) const { return max(1, grouping + spacing); } // WLEDMM length = 0 could lead to div/0 in virtualWidth() and virtualHeight()
inline uint8_t getLightCapabilities(void) const { return _capabilities; }

View File

@@ -252,11 +252,12 @@ void Segment::startFrame(void) {
_isSuperSimpleSegment = !mirror && !mirror_y && (grouping == 1) && (spacing == 0); // fastest - we only draw one pixel per call
#ifdef WLEDMM_FASTPATH
_isValid2D = isActive() && is2D();
//_isValid2D = isActive() && is2D();
_isValid2D = isActive() && strip.isMatrix && length() > 1;
_brightness = currentBri(on ? opacity : 0);
// if (reverse_y) _isSimpleSegment = false; // for A/B testing
_2dWidth = is2D() ? calc_virtualWidth() : calc_virtualLength();
_2dHeight = calc_virtualHeight();
_2dWidth = _isValid2D ? calc_virtualWidth() : calc_virtualLength();
_virtuallength = calc_virtualLength();
#if 0 && defined(WLED_ENABLE_HUB75MATRIX)
_firstFill = true; // dirty HACK
@@ -300,9 +301,9 @@ void IRAM_ATTR __attribute__((hot)) Segment::setPixelColorXY_fast(int x, int y,
#endif
if (simpleSegment) return; // WLEDMM shortcut when no mirroring needed
// handle mirroring
const int_fast16_t wid_ = stop - start;
const int_fast16_t hei_ = stopY - startY;
// handle mirroring - minimum width/height is 1 !!!
const int_fast16_t wid_ = max(1,stop - start);
const int_fast16_t hei_ = max(1, stopY - startY);
if (mirror) { //set the corresponding horizontally mirrored pixel
if (transpose) strip.setPixelColorXY_fast(start + x, startY + hei_ - y - 1, scaled_col);
else strip.setPixelColorXY_fast(start + wid_ - x - 1, startY + y, scaled_col);
@@ -364,8 +365,8 @@ void IRAM_ATTR_YN Segment::setPixelColorXY(int x, int y, uint32_t col) //WLEDMM:
}
const uint_fast16_t glen_ = groupLength(); // WLEDMM optimization
const uint_fast16_t wid_ = width();
const uint_fast16_t hei_ = height();
const uint_fast16_t wid_ = max(uint16_t(1), width());
const uint_fast16_t hei_ = max(uint16_t(1), height());
x *= glen_; // expand to physical pixels
y *= glen_; // expand to physical pixels

View File

@@ -899,7 +899,7 @@ uint16_t Segment::calc_virtualLength() const {
#endif
uint16_t groupLen = groupLength();
uint16_t vLength = (length() + groupLen - 1) / groupLen;
if (mirror) vLength = (vLength + 1) /2; // divide by 2 if mirror, leave at least a single LED
if (mirror && width() > 1) vLength = (vLength + 1) /2; // divide by 2 if mirror, leave at least a single LED // WLEDMM bugfix for pseudo 2d strips
return vLength;
}
@@ -1115,7 +1115,7 @@ void IRAM_ATTR_YN __attribute__((hot)) Segment::setPixelColor(int i, uint32_t co
// we have a vertical or horizontal 1D segment (WARNING: virtual...() may be transposed)
int x = 0, y = 0;
if (virtualHeight()>1) y = i;
if (virtualWidth() >1) x = i;
else if (virtualWidth() >1) x = i;
setPixelColorXY(x, y, col);
return;
}