mirror of
https://github.com/wled/WLED.git
synced 2025-07-12 13:26:33 +00:00
Lambda XY()
This commit is contained in:
parent
e088f4654a
commit
8c717537c4
@ -4854,7 +4854,6 @@ static const char _data_FX_MODE_FLOWSTRIPE[] PROGMEM = "Flow Stripe@Hue speed,Ef
|
|||||||
#ifndef WLED_DISABLE_2D
|
#ifndef WLED_DISABLE_2D
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
//*************************** 2D routines ***********************************
|
//*************************** 2D routines ***********************************
|
||||||
#define XY(x,y) SEGMENT.XY(x,y)
|
|
||||||
|
|
||||||
|
|
||||||
// Black hole
|
// Black hole
|
||||||
@ -5103,6 +5102,7 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https:
|
|||||||
|
|
||||||
const int cols = SEG_W;
|
const int cols = SEG_W;
|
||||||
const int rows = SEG_H;
|
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 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)
|
const int crcBufferLen = 2; //(SEGMENT.width() + SEGMENT.height())*71/100; // roughly sqrt(2)/2 for better repetition detection (Ewowi)
|
||||||
|
|
||||||
@ -5376,6 +5376,7 @@ uint16_t mode_2Dmatrix(void) { // Matrix2D. By Jeremy Williams.
|
|||||||
|
|
||||||
const int cols = SEG_W;
|
const int cols = SEG_W;
|
||||||
const int rows = SEG_H;
|
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
|
unsigned dataSize = (SEGMENT.length()+7) >> 3; //1 bit per LED for trails
|
||||||
if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed
|
if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed
|
||||||
@ -7473,6 +7474,7 @@ uint16_t mode_2Dsoap() {
|
|||||||
|
|
||||||
const int cols = SEG_W;
|
const int cols = SEG_W;
|
||||||
const int rows = SEG_H;
|
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
|
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
|
if (!SEGENV.allocateData(dataSize + sizeof(uint32_t)*3)) return mode_static(); //allocation failed
|
||||||
@ -7585,6 +7587,7 @@ uint16_t mode_2Doctopus() {
|
|||||||
|
|
||||||
const int cols = SEG_W;
|
const int cols = SEG_W;
|
||||||
const int rows = SEG_H;
|
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);
|
const uint8_t mapp = 180 / MAX(cols,rows);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -674,7 +674,6 @@ typedef struct Segment {
|
|||||||
}
|
}
|
||||||
#ifndef WLED_DISABLE_2D
|
#ifndef WLED_DISABLE_2D
|
||||||
inline bool is2D() const { return (width()>1 && height()>1); }
|
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
|
[[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(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)); }
|
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 {
|
|||||||
inline void fill_solid(CRGB c) { fill(RGBW32(c.r,c.g,c.b,0)); }
|
inline void fill_solid(CRGB c) { fill(RGBW32(c.r,c.g,c.b,0)); }
|
||||||
#else
|
#else
|
||||||
inline constexpr bool is2D() const { return false; }
|
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(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(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)); }
|
inline void setPixelColorXY(int x, int y, byte r, byte g, byte b, byte w = 0) { setPixelColor(x, RGBW32(r,g,b,w)); }
|
||||||
|
@ -145,14 +145,6 @@ void WS2812FX::setUpMatrix() {
|
|||||||
|
|
||||||
#ifndef WLED_DISABLE_2D
|
#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())
|
// 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
|
void IRAM_ATTR_YN Segment::_setPixelColorXY_raw(const int& x, const int& y, uint32_t& col) const
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user