Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Effect blending styles #3877

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
0c8d9d5
Mode blending styles
blazoncek Apr 3, 2024
f5199d2
Fix compile.
blazoncek Apr 3, 2024
c680527
Merge branch '0_15' into blending-styles
blazoncek Apr 8, 2024
a3a8fa1
Remove conditional fade/blend
blazoncek Apr 8, 2024
b3810a1
Merge branch '0_15' into blending-styles
blazoncek Apr 9, 2024
ef017fd
Revert FX.cpp
blazoncek Apr 14, 2024
9735d1c
Merge branch '0_15' into blending-styles
blazoncek Apr 14, 2024
8e8ffa3
Merge branch '0_15' into blending-styles
blazoncek Apr 26, 2024
f441ce9
Merge branch '0_15' into blending-styles
blazoncek May 12, 2024
ccce0f2
Merge branch '0_15' into blending-styles
blazoncek May 15, 2024
de5632b
Merge branch '0_15' into blending-styles
blazoncek Jun 1, 2024
20c0916
Merge branch '0_15' into blending-styles
blazoncek Jun 2, 2024
da484b0
Use transition style for palette and color change
blazoncek Jun 2, 2024
296df26
Merge branch '0_15' into blending-styles
blazoncek Jun 16, 2024
a4ac444
Merge branch '0_15' into blending-styles
blazoncek Jun 23, 2024
bee75a4
Hide 2D blending styles on non-2D set-up
blazoncek Jun 23, 2024
593970e
Merge branch '0_15' into blending-styles
blazoncek Jun 30, 2024
f3891c3
Merge branch '0_15' into blending-styles
blazoncek Jul 5, 2024
0275bd1
On/Off blending respected
blazoncek Jul 5, 2024
13ed78b
Merge branch '0_15' into blending-styles
blazoncek Jul 11, 2024
d88bb3c
Merge branch '0_15' into blending-styles
blazoncek Jul 18, 2024
1975c9c
Merge branch '0_15' into blending-styles
blazoncek Jul 24, 2024
c03422e
Push variants
blazoncek Jul 30, 2024
365c198
Missing clipping fix
blazoncek Aug 1, 2024
e1598a9
Merge branch '0_15' into blending-styles
blazoncek Aug 5, 2024
77723b6
Fix compiler warning
blazoncek Aug 8, 2024
011afd0
Merge branch '0_15' into blending-styles
blazoncek Aug 17, 2024
0430dc5
Merge branch '0_15' into blending-styles
blazoncek Aug 17, 2024
434ba3f
Added FX to copy a segment in 1D or 2D
DedeHai Aug 28, 2024
ebd8a10
Prevent styles on 1px segments
blazoncek Sep 3, 2024
24df6bf
Added copying source settings
DedeHai Sep 4, 2024
696f74b
Update integrating new ideas as discussed
DedeHai Sep 7, 2024
1e0ceab
Merge remote-tracking branch 'upstream/0_15' into 0_15_copy_segment
DedeHai Sep 7, 2024
8aa82ab
fixes and optimizations
DedeHai Sep 8, 2024
dd8353a
moved getRenderedPixelXY() into SEGMENT class, plus little improvement
DedeHai Sep 9, 2024
1cee1c3
Merge branch '0_15' into blending-styles
blazoncek Sep 11, 2024
ce5ee65
Merge branch '0_15' into blending-styles
blazoncek Sep 15, 2024
bdd8747
Merge remote-tracking branch 'upstream/0_15' into 0_15_copy_segment
DedeHai Sep 22, 2024
df33a36
rgb2hsv now returns the CHSV value instead of using a reference
DedeHai Sep 22, 2024
7db1adc
added forgotten returnvalue
DedeHai Sep 22, 2024
60ea7ce
Merge branch '015_copy_segment_blendingstyles' into blending-styles
DedeHai Sep 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
- v0.15.0-b2
- WS2805 support (RGB + WW + CW, 600kbps)
- Unified PSRAM use
- NeoPixelBus v2.7.9
- NeoPixelBus v2.7.9 (for future WS2805 support)
- Ubiquitous PSRAM mode for all variants of ESP32
- SSD1309_64 I2C Support for FLD Usermod (#3836 by @THATDONFC)
- Palette cycling fix (add support for `{"seg":[{"pal":"X~Y~"}]}` or `{"seg":[{"pal":"X~Yr"}]}`)
Expand Down
2 changes: 1 addition & 1 deletion usermods/stairway_wipe_basic/stairway-wipe-usermod-v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void setup() {
jsonTransitionOnce = true;
strip.setTransition(0); //no transition
effectCurrent = FX_MODE_COLOR_WIPE;
resetTimebase(); //make sure wipe starts from beginning
strip.resetTimebase(); //make sure wipe starts from beginning

//set wipe direction
Segment& seg = strip.getSegment(0);
Expand Down
111 changes: 0 additions & 111 deletions usermods/stairway_wipe_basic/wled06_usermod.ino

This file was deleted.

33 changes: 33 additions & 0 deletions wled00/FX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ static um_data_t* getAudioData() {
return um_data;
}


// effect functions

/*
Expand All @@ -93,6 +94,37 @@ uint16_t mode_static(void) {
}
static const char _data_FX_MODE_STATIC[] PROGMEM = "Solid";

/*
* Copy a segment and perform (optional) color adjustments
*/
uint16_t mode_copy_segment(void) {
uint32_t sourceid = SEGMENT.custom3;
if (sourceid >= strip._segments.size() || sourceid == strip.getCurrSegmentId()) { // invalid source
SEGMENT.fadeToBlackBy(5); // fade out, clears pixels and allows overlapping segments
return FRAMETIME;
}
if (strip._segments[sourceid].isActive()) {
uint32_t sourcecolor;
if(!strip._segments[sourceid].is2D()) { // 1D source, source can be expanded into 2D
uint32_t cl; // length to copy
for (unsigned i = 0; i < SEGMENT.virtualLength(); i++) {
sourcecolor = SEGMENT.getRenderedPixelXY(strip._segments[sourceid], i);
SEGMENT.setPixelColor(i, adjust_color(sourcecolor, SEGMENT.intensity, SEGMENT.custom1, SEGMENT.custom2));
}
} else { // 2D source, note: 2D to 1D just copies the first row (or first column if 'Switch axis' is checked in FX)
for (unsigned y = 0; y < SEGMENT.virtualHeight(); y++) {
for (unsigned x = 0; x < SEGMENT.virtualWidth(); x++) {
if(SEGMENT.check2) sourcecolor = SEGMENT.getRenderedPixelXY(strip._segments[sourceid], y, x); // flip axis (for 2D -> 1D, in 2D Segments this does the same as 'Transpose')
else sourcecolor = SEGMENT.getRenderedPixelXY(strip._segments[sourceid], x, y);
SEGMENT.setPixelColorXY(x, y, adjust_color(sourcecolor, SEGMENT.intensity, SEGMENT.custom1, SEGMENT.custom2));
}
}
}
}
return FRAMETIME;
}
static const char _data_FX_MODE_COPY[] PROGMEM = "Copy Segment@,Color shift,Lighten,Brighten,ID,,Switch axis(2D);;;1;ix=0,c1=0,c2=0,c3=0,o2=0";


/*
* Blink/strobe function
Expand Down Expand Up @@ -7830,6 +7862,7 @@ void WS2812FX::setupEffectData() {
_modeData.push_back(_data_RESERVED);
}
// now replace all pre-allocated effects
addEffect(FX_MODE_COPY, &mode_copy_segment, _data_FX_MODE_COPY);
// --- 1D non-audio effects ---
addEffect(FX_MODE_BLINK, &mode_blink, _data_FX_MODE_BLINK);
addEffect(FX_MODE_BREATH, &mode_breath, _data_FX_MODE_BREATH);
Expand Down
46 changes: 39 additions & 7 deletions wled00/FX.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,31 @@
#define FX_MODE_WAVESINS 184
#define FX_MODE_ROCKTAVES 185
#define FX_MODE_2DAKEMI 186
#define FX_MODE_COPY 187
#define MODE_COUNT 188


#define BLEND_STYLE_FADE 0
#define BLEND_STYLE_FAIRY_DUST 1
#define BLEND_STYLE_SWIPE_RIGHT 2
#define BLEND_STYLE_SWIPE_LEFT 3
#define BLEND_STYLE_PUSH_RIGHT 4
#define BLEND_STYLE_PUSH_LEFT 5
#define BLEND_STYLE_PINCH_OUT 6
#define BLEND_STYLE_INSIDE_OUT 7
#define BLEND_STYLE_SWIPE_UP 8
#define BLEND_STYLE_SWIPE_DOWN 9
#define BLEND_STYLE_OPEN_H 10
#define BLEND_STYLE_OPEN_V 11
#define BLEND_STYLE_PUSH_UP 12
#define BLEND_STYLE_PUSH_DOWN 13
#define BLEND_STYLE_PUSH_TL 14
#define BLEND_STYLE_PUSH_TR 15
#define BLEND_STYLE_PUSH_BR 16
#define BLEND_STYLE_PUSH_BL 17

#define BLEND_STYLE_COUNT 18

#define MODE_COUNT 187

typedef enum mapping1D2D {
M12_Pixels = 0,
Expand All @@ -328,7 +351,7 @@ typedef enum mapping1D2D {
M12_sPinwheel = 4
} mapping1D2D_t;

// segment, 80 bytes
// segment, 68 bytes
typedef struct Segment {
public:
uint16_t start; // start index / start X coordinate 2D (left)
Expand Down Expand Up @@ -425,6 +448,9 @@ typedef struct Segment {
static uint16_t _lastPaletteBlend; // blend palette according to set Transition Delay in millis()%0xFFFF
#ifndef WLED_DISABLE_MODE_BLEND
static bool _modeBlend; // mode/effect blending semaphore
// clipping
static uint16_t _clipStart, _clipStop;
static uint8_t _clipStartY, _clipStopY;
#endif

// transition data, valid only if transitional==true, holds values during transition (72 bytes)
Expand All @@ -435,6 +461,7 @@ typedef struct Segment {
#else
uint32_t _colorT[NUM_COLORS];
#endif
uint8_t _palTid; // previous palette
uint8_t _briT; // temporary brightness
uint8_t _cctT; // temporary CCT
CRGBPalette16 _palT; // temporary palette
Expand Down Expand Up @@ -572,6 +599,7 @@ typedef struct Segment {
[[gnu::hot]] uint16_t progress() const; // transition progression between 0-65535
[[gnu::hot]] uint8_t currentBri(bool useCct = false) const; // current segment brightness/CCT (blended while in transition)
uint8_t currentMode() const; // currently active effect/mode (while in transition)
[[gnu::hot]] uint8_t currentPalette(void) const; // currently active palette (while in transition)
[[gnu::hot]] uint32_t currentColor(uint8_t slot) const; // currently active segment color (blended while in transition)
CRGBPalette16 &loadPalette(CRGBPalette16 &tgt, uint8_t pal);
void setCurrentPalette();
Expand All @@ -587,7 +615,12 @@ typedef struct Segment {
inline void setPixelColor(float i, uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0, bool aa = true) { setPixelColor(i, RGBW32(r,g,b,w), aa); }
inline void setPixelColor(float i, CRGB c, bool aa = true) { setPixelColor(i, RGBW32(c.r,c.g,c.b,0), aa); }
#endif
#ifndef WLED_DISABLE_MODE_BLEND
static inline void setClippingRect(int startX, int stopX, int startY = 0, int stopY = 1) { _clipStart = startX; _clipStop = stopX; _clipStartY = startY; _clipStopY = stopY; };
#endif
bool isPixelClipped(int i) const;
[[gnu::hot]] uint32_t getPixelColor(int i) const;
uint32_t getRenderedPixelXY(Segment& seg, unsigned x, unsigned y = 0);
// 1D support functions (some implement 2D as well)
void blur(uint8_t, bool smear = false);
void fill(uint32_t c);
Expand Down Expand Up @@ -628,6 +661,7 @@ typedef struct Segment {
inline void setPixelColorXY(float x, float y, byte r, byte g, byte b, byte w = 0, bool aa = true) { setPixelColorXY(x, y, RGBW32(r,g,b,w), aa); }
inline void setPixelColorXY(float x, float y, CRGB c, bool aa = true) { setPixelColorXY(x, y, RGBW32(c.r,c.g,c.b,0), aa); }
#endif
[[gnu::hot]] bool isPixelXYClipped(int x, int y) const;
[[gnu::hot]] uint32_t getPixelColorXY(int x, int y) const;
// 2D support functions
inline void blendPixelColorXY(uint16_t x, uint16_t y, uint32_t color, uint8_t blend) { setPixelColorXY(x, y, color_blend(getPixelColorXY(x,y), color, blend)); }
Expand Down Expand Up @@ -656,7 +690,7 @@ typedef struct Segment {
inline void blur2d(fract8 blur_amount) { blur(blur_amount); }
inline void fill_solid(CRGB c) { fill(RGBW32(c.r,c.g,c.b,0)); }
#else
inline uint16_t XY(uint16_t x, uint16_t y) { return x; }
inline uint16_t XY(int x, int y) { 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 All @@ -667,6 +701,7 @@ typedef struct Segment {
inline void setPixelColorXY(float x, float y, byte r, byte g, byte b, byte w = 0, bool aa = true) { setPixelColor(x, RGBW32(r,g,b,w), aa); }
inline void setPixelColorXY(float x, float y, CRGB c, bool aa = true) { setPixelColor(x, RGBW32(c.r,c.g,c.b,0), aa); }
#endif
inline bool isPixelXYClipped(int x, int y) { return isPixelClipped(x); }
inline uint32_t getPixelColorXY(int x, int y) { return getPixelColor(x); }
inline void blendPixelColorXY(uint16_t x, uint16_t y, uint32_t c, uint8_t blend) { blendPixelColor(x, c, blend); }
inline void blendPixelColorXY(uint16_t x, uint16_t y, CRGB c, uint8_t blend) { blendPixelColor(x, RGBW32(c.r,c.g,c.b,0), blend); }
Expand Down Expand Up @@ -711,9 +746,7 @@ class WS2812FX { // 96 bytes
public:

WS2812FX() :
paletteFade(0),
paletteBlend(0),
cctBlending(0),
now(millis()),
timebase(0),
isMatrix(false),
Expand Down Expand Up @@ -788,6 +821,7 @@ class WS2812FX { // 96 bytes
setTargetFps(uint8_t fps),
setupEffectData(); // add default effects to the list; defined in FX.cpp

inline void resetTimebase() { timebase = 0U - millis(); }
inline void restartRuntime() { for (Segment &seg : _segments) seg.markForReset(); }
inline void setTransitionMode(bool t) { for (Segment &seg : _segments) seg.startTransition(t ? _transitionDur : 0); }
inline void setColor(uint8_t slot, uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0) { setColor(slot, RGBW32(r,g,b,w)); }
Expand All @@ -802,7 +836,6 @@ class WS2812FX { // 96 bytes
inline void resume() { _suspend = false; } // will resume strip.service() execution

bool
paletteFade,
checkSegmentAlignment(),
hasRGBWBus() const,
hasCCTBus() const,
Expand All @@ -817,7 +850,6 @@ class WS2812FX { // 96 bytes

uint8_t
paletteBlend,
cctBlending,
getActiveSegmentsNum() const,
getFirstSelectedSegId() const,
getLastActiveSegmentId() const,
Expand Down
Loading