Skip to content

Commit 8c71753

Browse files
committed
Lambda XY()
1 parent e088f46 commit 8c71753

File tree

3 files changed

+4
-11
lines changed

3 files changed

+4
-11
lines changed

wled00/FX.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4854,7 +4854,6 @@ static const char _data_FX_MODE_FLOWSTRIPE[] PROGMEM = "Flow Stripe@Hue speed,Ef
48544854
#ifndef WLED_DISABLE_2D
48554855
///////////////////////////////////////////////////////////////////////////////
48564856
//*************************** 2D routines ***********************************
4857-
#define XY(x,y) SEGMENT.XY(x,y)
48584857

48594858

48604859
// Black hole
@@ -5103,6 +5102,7 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https:
51035102

51045103
const int cols = SEG_W;
51055104
const int rows = SEG_H;
5105+
const auto XY = [&](int x, int y) { return (x%cols) + (y%rows) * cols; };
51065106
const unsigned dataSize = sizeof(CRGB) * SEGMENT.length(); // using width*height prevents reallocation if mirroring is enabled
51075107
const int crcBufferLen = 2; //(SEGMENT.width() + SEGMENT.height())*71/100; // roughly sqrt(2)/2 for better repetition detection (Ewowi)
51085108

@@ -5376,6 +5376,7 @@ uint16_t mode_2Dmatrix(void) { // Matrix2D. By Jeremy Williams.
53765376

53775377
const int cols = SEG_W;
53785378
const int rows = SEG_H;
5379+
const auto XY = [&](int x, int y) { return (x%cols) + (y%rows) * cols; };
53795380

53805381
unsigned dataSize = (SEGMENT.length()+7) >> 3; //1 bit per LED for trails
53815382
if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed
@@ -7473,6 +7474,7 @@ uint16_t mode_2Dsoap() {
74737474

74747475
const int cols = SEG_W;
74757476
const int rows = SEG_H;
7477+
const auto XY = [&](int x, int y) { return (x%cols) + (y%rows) * cols; };
74767478

74777479
const size_t dataSize = SEGMENT.width() * SEGMENT.height() * sizeof(uint8_t); // prevent reallocation if mirrored or grouped
74787480
if (!SEGENV.allocateData(dataSize + sizeof(uint32_t)*3)) return mode_static(); //allocation failed
@@ -7585,6 +7587,7 @@ uint16_t mode_2Doctopus() {
75857587

75867588
const int cols = SEG_W;
75877589
const int rows = SEG_H;
7590+
const auto XY = [&](int x, int y) { return (x%cols) + (y%rows) * cols; };
75887591
const uint8_t mapp = 180 / MAX(cols,rows);
75897592

75907593
typedef struct {

wled00/FX.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,6 @@ typedef struct Segment {
674674
}
675675
#ifndef WLED_DISABLE_2D
676676
inline bool is2D() const { return (width()>1 && height()>1); }
677-
[[gnu::hot]] int XY(int x, int y) const; // support function to get relative index within segment
678677
[[gnu::hot]] void setPixelColorXY(int x, int y, uint32_t c) const; // set relative pixel within segment with color
679678
inline void setPixelColorXY(unsigned x, unsigned y, uint32_t c) const { setPixelColorXY(int(x), int(y), c); }
680679
inline void setPixelColorXY(int x, int y, byte r, byte g, byte b, byte w = 0) const { setPixelColorXY(x, y, RGBW32(r,g,b,w)); }
@@ -712,7 +711,6 @@ typedef struct Segment {
712711
inline void fill_solid(CRGB c) { fill(RGBW32(c.r,c.g,c.b,0)); }
713712
#else
714713
inline constexpr bool is2D() const { return false; }
715-
inline int XY(int x, int y) const { return x; }
716714
inline void setPixelColorXY(int x, int y, uint32_t c) { setPixelColor(x, c); }
717715
inline void setPixelColorXY(unsigned x, unsigned y, uint32_t c) { setPixelColor(int(x), c); }
718716
inline void setPixelColorXY(int x, int y, byte r, byte g, byte b, byte w = 0) { setPixelColor(x, RGBW32(r,g,b,w)); }

wled00/FX_2Dfcn.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,6 @@ void WS2812FX::setUpMatrix() {
145145

146146
#ifndef WLED_DISABLE_2D
147147

148-
// XY(x,y) - gets pixel index within current segment (often used to reference leds[] array element)
149-
int IRAM_ATTR_YN Segment::XY(int x, int y) const
150-
{
151-
const int vW = vWidth(); // segment width in logical pixels (can be 0 if segment is inactive)
152-
const int vH = vHeight(); // segment height in logical pixels (is always >= 1)
153-
return isActive() ? (x%vW) + (y%vH) * vW : 0;
154-
}
155-
156148
// raw setColor function without checks (checks are done in setPixelColorXY())
157149
void IRAM_ATTR_YN Segment::_setPixelColorXY_raw(const int& x, const int& y, uint32_t& col) const
158150
{

0 commit comments

Comments
 (0)