segment functions for better upstream compatibility
* added vLength(), vHeight(), vWidth() and mapped them to their WLED-MM counterparts * added SEG_W and SEG_H macros * minor variable renaming to avoid name clashes with vWidth, vHeight, vLength
This commit is contained in:
@@ -19,6 +19,11 @@
|
||||
#undef SEGENV
|
||||
#define SEGMENT (*strip._currentSeg) // saves us many calls to strip._segments[strip.getCurrSegmentId()]
|
||||
#define SEGENV SEGMENT
|
||||
// need to re-define SEG_W and SEG_H to get the fast SEGMENT macro
|
||||
#undef SEG_W
|
||||
#undef SEG_H
|
||||
#define SEG_W (SEGMENT.virtualWidth())
|
||||
#define SEG_H (SEGMENT.virtualHeight())
|
||||
#endif
|
||||
|
||||
#if !(defined(WLED_DISABLE_PARTICLESYSTEM2D) && defined(WLED_DISABLE_PARTICLESYSTEM1D))
|
||||
@@ -8380,10 +8385,10 @@ uint16_t mode_2DGEQ(void) { // By Will Tatam. Code reduction by Ewoud Wijma. Fla
|
||||
bool flatMode = !SEGMENT.is2D() || (SEGMENT.width() < 3) || (SEGMENT.height() < 3); // also use flat mode when less than 3 colums or rows
|
||||
|
||||
const int NUM_BANDS = map2(SEGMENT.custom1, 0, 255, 1, 16);
|
||||
const int vLength = SEGLEN; // for flat mode
|
||||
const uint16_t cols = flatMode ? min(max(2, NUM_BANDS), (vLength+1)/2) : SEGMENT.virtualWidth();
|
||||
const uint16_t rows = flatMode ? vLength / cols : SEGMENT.virtualHeight();
|
||||
const unsigned offset = flatMode ? max(0, (vLength - rows*cols +1) / 2) : 0; // flatmode: always center effect
|
||||
const int virtLength = SEGLEN; // for flat mode
|
||||
const uint16_t cols = flatMode ? min(max(2, NUM_BANDS), (virtLength+1)/2) : SEGMENT.virtualWidth();
|
||||
const uint16_t rows = flatMode ? virtLength / cols : SEGMENT.virtualHeight();
|
||||
const unsigned offset = flatMode ? max(0, (virtLength - rows*cols +1) / 2) : 0; // flatmode: always center effect
|
||||
|
||||
if ((cols <=1) || (rows <=1)) return mode_oops(); // too small
|
||||
|
||||
|
||||
44
wled00/FX.h
44
wled00/FX.h
@@ -105,6 +105,8 @@ extern BusManager busses; // same as wled.h
|
||||
#define SEGCOLOR(x) strip.segColor(x) /* saves us a few kbytes of code */
|
||||
#define SEGPALETTE Segment::getCurrentPalette()
|
||||
#define SEGLEN strip._virtualSegmentLength /* saves us a few kbytes of code */
|
||||
#define SEG_W (SEGMENT.virtualWidth())
|
||||
#define SEG_H (SEGMENT.virtualHeight())
|
||||
#define SPEED_FORMULA_L (4U + (50U*(255U - SEGMENT.speed))/min(SEGLEN, uint16_t(512))) // WLEDMM limiting the formula to 512 virtual pixels
|
||||
|
||||
// some common colors
|
||||
@@ -722,16 +724,16 @@ typedef struct Segment {
|
||||
#ifndef WLEDMM_FASTPATH
|
||||
inline uint16_t virtualWidth() const { // WLEDMM use fast types, and make function inline
|
||||
uint_fast16_t groupLen = groupLength();
|
||||
uint_fast16_t vWidth = ((transpose ? height() : width()) + groupLen - 1) / groupLen;
|
||||
if (mirror) vWidth = (vWidth + 1) /2; // divide by 2 if mirror, leave at least a single LED
|
||||
return vWidth;
|
||||
uint_fast16_t virtWidth = ((transpose ? height() : width()) + groupLen - 1) / groupLen;
|
||||
if (mirror) virtWidth = (virtWidth + 1) /2; // divide by 2 if mirror, leave at least a single LED
|
||||
return virtWidth;
|
||||
}
|
||||
inline uint16_t calc_virtualWidth() const { return virtualWidth();}
|
||||
inline uint16_t virtualHeight() const { // WLEDMM use fast types, and make function inline
|
||||
uint_fast16_t groupLen = groupLength();
|
||||
uint_fast16_t vHeight = ((transpose ? width() : height()) + groupLen - 1) / groupLen;
|
||||
if (mirror_y) vHeight = (vHeight + 1) /2; // divide by 2 if mirror, leave at least a single LED
|
||||
return vHeight;
|
||||
uint_fast16_t virtHeight = ((transpose ? width() : height()) + groupLen - 1) / groupLen;
|
||||
if (mirror_y) virtHeight = (virtHeight + 1) /2; // divide by 2 if mirror, leave at least a single LED
|
||||
return virtHeight;
|
||||
}
|
||||
inline uint16_t calc_virtualHeight() const { return virtualHeight();}
|
||||
#else
|
||||
@@ -740,22 +742,38 @@ typedef struct Segment {
|
||||
|
||||
uint16_t calc_virtualWidth() const {
|
||||
uint_fast16_t groupLen = groupLength();
|
||||
uint_fast16_t vWidth = ((transpose ? height() : width()) + groupLen - 1) / groupLen;
|
||||
if (mirror) vWidth = (vWidth + 1) /2; // divide by 2 if mirror, leave at least a single LED
|
||||
return vWidth;
|
||||
uint_fast16_t virtWidth = ((transpose ? height() : width()) + groupLen - 1) / groupLen;
|
||||
if (mirror) virtWidth = (virtWidth + 1) /2; // divide by 2 if mirror, leave at least a single LED
|
||||
return virtWidth;
|
||||
}
|
||||
uint16_t calc_virtualHeight() const {
|
||||
uint_fast16_t groupLen = groupLength();
|
||||
uint_fast16_t vHeight = ((transpose ? width() : height()) + groupLen - 1) / groupLen;
|
||||
if (mirror_y) vHeight = (vHeight + 1) /2; // divide by 2 if mirror, leave at least a single LED
|
||||
return vHeight;
|
||||
uint_fast16_t virtHeight = ((transpose ? width() : height()) + groupLen - 1) / groupLen;
|
||||
if (mirror_y) virtHeight = (virtHeight + 1) /2; // divide by 2 if mirror, leave at least a single LED
|
||||
return virtHeight;
|
||||
}
|
||||
#endif
|
||||
|
||||
uint16_t nrOfVStrips(void) const;
|
||||
void createjMap(); //WLEDMM jMap
|
||||
void deletejMap(); //WLEDMM jMap
|
||||
|
||||
|
||||
// WLEDMM upstream compatibility functions
|
||||
#ifdef WLEDMM_FASTPATH
|
||||
inline unsigned vLength() const { return calc_virtualLength(); }
|
||||
inline unsigned vWidth() const { return _2dWidth; }
|
||||
inline unsigned vHeight() const { return _2dHeight; }
|
||||
inline void setDrawDimensions() { startFrame(); }
|
||||
inline void beginDraw(uint16_t prog = 0xFFFFU) { startFrame(); }
|
||||
//void setGeometry(uint16_t i1, uint16_t i2, uint8_t grp=1, uint8_t spc=0, uint16_t ofs=UINT16_MAX, uint16_t i1Y=0, uint16_t i2Y=1, uint8_t m12=0); // not availeable in MM
|
||||
#else
|
||||
inline unsigned vLength() const { return virtualLength(); }
|
||||
inline unsigned vWidth() const { return virtualWidth(); }
|
||||
inline unsigned vHeight() const { return virtualHeight(); }
|
||||
inline void setDrawDimensions() { return; }
|
||||
inline void beginDraw(uint16_t prog = 0xFFFFU) { return; }
|
||||
#endif
|
||||
|
||||
#ifndef WLED_DISABLE_2D
|
||||
[[gnu::hot]] inline uint16_t XY(uint_fast16_t x, uint_fast16_t y) const { // support function to get relative index within segment (for leds[]) // WLEDMM inline for speed
|
||||
uint_fast16_t width = max(uint16_t(1), virtualWidth()); // segment width in logical pixels -- softhack007 avoid div/0
|
||||
|
||||
Reference in New Issue
Block a user