Skip to content

Commit

Permalink
Lambda XY()
Browse files Browse the repository at this point in the history
  • Loading branch information
blazoncek committed Feb 6, 2025
1 parent e088f46 commit 8c71753
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 11 deletions.
5 changes: 4 additions & 1 deletion wled00/FX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4854,7 +4854,6 @@ static const char _data_FX_MODE_FLOWSTRIPE[] PROGMEM = "Flow Stripe@Hue speed,Ef
#ifndef WLED_DISABLE_2D
///////////////////////////////////////////////////////////////////////////////
//*************************** 2D routines ***********************************
#define XY(x,y) SEGMENT.XY(x,y)


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

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

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

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

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

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

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

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

typedef struct {
Expand Down
2 changes: 0 additions & 2 deletions wled00/FX.h
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,6 @@ typedef struct Segment {
}
#ifndef WLED_DISABLE_2D
inline bool is2D() const { return (width()>1 && height()>1); }
[[gnu::hot]] int XY(int x, int y) const; // support function to get relative index within segment
[[gnu::hot]] void setPixelColorXY(int x, int y, uint32_t c) const; // set relative pixel within segment with color
inline void setPixelColorXY(unsigned x, unsigned y, uint32_t c) const { setPixelColorXY(int(x), int(y), c); }
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)); }
Expand Down Expand Up @@ -712,7 +711,6 @@ typedef struct Segment {
inline void fill_solid(CRGB c) { fill(RGBW32(c.r,c.g,c.b,0)); }
#else
inline constexpr bool is2D() const { return false; }
inline int XY(int x, int y) const { return x; }
inline void setPixelColorXY(int x, int y, uint32_t c) { setPixelColor(x, c); }
inline void setPixelColorXY(unsigned x, unsigned y, uint32_t c) { setPixelColor(int(x), c); }
inline void setPixelColorXY(int x, int y, byte r, byte g, byte b, byte w = 0) { setPixelColor(x, RGBW32(r,g,b,w)); }
Expand Down
8 changes: 0 additions & 8 deletions wled00/FX_2Dfcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,6 @@ void WS2812FX::setUpMatrix() {

#ifndef WLED_DISABLE_2D

// XY(x,y) - gets pixel index within current segment (often used to reference leds[] array element)
int IRAM_ATTR_YN Segment::XY(int x, int y) const
{
const int vW = vWidth(); // segment width in logical pixels (can be 0 if segment is inactive)
const int vH = vHeight(); // segment height in logical pixels (is always >= 1)
return isActive() ? (x%vW) + (y%vH) * vW : 0;
}

// raw setColor function without checks (checks are done in setPixelColorXY())
void IRAM_ATTR_YN Segment::_setPixelColorXY_raw(const int& x, const int& y, uint32_t& col) const
{
Expand Down

0 comments on commit 8c71753

Please sign in to comment.