Skip to content

Commit

Permalink
Move opacity into blend
Browse files Browse the repository at this point in the history
- fix UI
  • Loading branch information
blazoncek committed Feb 17, 2025
1 parent a88bb90 commit 9b82b25
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 40 deletions.
2 changes: 1 addition & 1 deletion wled00/FX.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ typedef struct Segment {
static unsigned _vLength; // 1D dimension used for current effect
static unsigned _vWidth, _vHeight; // 2D dimensions used for current effect
static uint32_t _currentColors[NUM_COLORS]; // colors used for current effect
static bool _colorScaled; // color has been scaled prior to setPixelColor() call
//static bool _colorScaled; // color has been scaled prior to setPixelColor() call
static CRGBPalette16 _currentPalette; // palette used for current effect (includes transition, used in color_from_palette())
static CRGBPalette16 _randomPalette; // actual random palette
static CRGBPalette16 _newRandomPalette; // target random palette
Expand Down
26 changes: 13 additions & 13 deletions wled00/FX_2Dfcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void IRAM_ATTR Segment::setPixelColorXY(int x, int y, uint32_t col) const
if (x >= vW || y >= vH || x < 0 || y < 0 || isPixelXYClipped(x,y)) return; // if pixel would fall out of virtual segment just exit

// if color is unscaled
if (!_colorScaled) col = color_fade(col, _segBri);
//if (!_colorScaled) col = color_fade(col, _segBri);

#ifndef WLED_DISABLE_MODE_BLEND
// if blending modes, blend with underlying pixel
Expand Down Expand Up @@ -559,8 +559,8 @@ void Segment::drawCircle(uint16_t cx, uint16_t cy, uint8_t radius, uint32_t col,
}
} else {
// pre-scale color for all pixels
col = color_fade(col, _segBri);
_colorScaled = true;
//col = color_fade(col, _segBri);
//_colorScaled = true;
// Bresenham’s Algorithm
int d = 3 - (2*radius);
int y = radius, x = 0;
Expand All @@ -579,7 +579,7 @@ void Segment::drawCircle(uint16_t cx, uint16_t cy, uint8_t radius, uint32_t col,
d += 4 * x + 6;
}
}
_colorScaled = false;
//_colorScaled = false;
}
}

Expand All @@ -591,8 +591,8 @@ void Segment::fillCircle(uint16_t cx, uint16_t cy, uint8_t radius, uint32_t col,
// draw soft bounding circle
if (soft) drawCircle(cx, cy, radius, col, soft);
// pre-scale color for all pixels
col = color_fade(col, _segBri);
_colorScaled = true;
//col = color_fade(col, _segBri);
//_colorScaled = true;
// fill it
for (int y = -radius; y <= radius; y++) {
for (int x = -radius; x <= radius; x++) {
Expand All @@ -602,7 +602,7 @@ void Segment::fillCircle(uint16_t cx, uint16_t cy, uint8_t radius, uint32_t col,
setPixelColorXY(cx + x, cy + y, col);
}
}
_colorScaled = false;
//_colorScaled = false;
}

//line function
Expand Down Expand Up @@ -649,8 +649,8 @@ void Segment::drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint3
}
} else {
// pre-scale color for all pixels
c = color_fade(c, _segBri);
_colorScaled = true;
//c = color_fade(c, _segBri);
//_colorScaled = true;
// Bresenham's algorithm
int err = (dx>dy ? dx : -dy)/2; // error direction
for (;;) {
Expand All @@ -660,7 +660,7 @@ void Segment::drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint3
if (e2 >-dx) { err -= dy; x0 += sx; }
if (e2 < dy) { err += dx; y0 += sy; }
}
_colorScaled = false;
//_colorScaled = false;
}
}

Expand Down Expand Up @@ -694,8 +694,8 @@ void Segment::drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w,
}
uint32_t c = ColorFromPalette(grad, (i+1)*255/h, 255, LINEARBLEND_NOWRAP);
// pre-scale color for all pixels
c = color_fade(c, _segBri);
_colorScaled = true;
//c = color_fade(c, _segBri);
//_colorScaled = true;
for (int j = 0; j<w; j++) { // character width
int x0, y0;
switch (rotate) {
Expand All @@ -710,7 +710,7 @@ void Segment::drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w,
setPixelColorXY(x0, y0, c);
}
}
_colorScaled = false;
//_colorScaled = false;
}
}

Expand Down
28 changes: 15 additions & 13 deletions wled00/FX_fcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ unsigned Segment::_vWidth = 0;
unsigned Segment::_vHeight = 0;
uint8_t Segment::_segBri = 0;
uint32_t Segment::_currentColors[NUM_COLORS] = {0,0,0};
bool Segment::_colorScaled = false;
//bool Segment::_colorScaled = false;
CRGBPalette16 Segment::_currentPalette = CRGBPalette16(CRGB::Black);
CRGBPalette16 Segment::_randomPalette = generateRandomPalette(); // was CRGBPalette16(DEFAULT_COLOR);
CRGBPalette16 Segment::_newRandomPalette = generateRandomPalette(); // was CRGBPalette16(DEFAULT_COLOR);
Expand Down Expand Up @@ -800,8 +800,8 @@ void IRAM_ATTR Segment::setPixelColor(int i, uint32_t col) 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)
// pre-scale color for all pixels
col = color_fade(col, _segBri);
_colorScaled = true;
//col = color_fade(col, _segBri);
//_colorScaled = true;
switch (map1D2D) {
case M12_Pixels:
// use all available pixels as a long strip
Expand Down Expand Up @@ -893,7 +893,7 @@ void IRAM_ATTR Segment::setPixelColor(int i, uint32_t col) const
break;
}
}
_colorScaled = false;
//_colorScaled = false;
return;
} else if (Segment::maxHeight != 1 && (width() == 1 || height() == 1)) {
if (start < Segment::maxWidth*Segment::maxHeight) {
Expand Down Expand Up @@ -921,7 +921,7 @@ void IRAM_ATTR Segment::setPixelColor(int i, uint32_t col) const
if (i >= vL || i < 0 || isPixelClipped(i)) return; // handle clipping on 1D

// if color is unscaled
if (!_colorScaled) col = color_fade(col, _segBri);
//if (!_colorScaled) col = color_fade(col, _segBri);

#ifndef WLED_DISABLE_MODE_BLEND
// _modeBlend==true -> old effect
Expand Down Expand Up @@ -1191,13 +1191,13 @@ void Segment::fill(uint32_t c) const {
const int cols = is2D() ? vWidth() : vLength();
const int rows = vHeight(); // will be 1 for 1D
// pre-scale color for all pixels
c = color_fade(c, _segBri);
_colorScaled = true;
//c = color_fade(c, _segBri);
//_colorScaled = true;
for (int y = 0; y < rows; y++) for (int x = 0; x < cols; x++) {
if (is2D()) setPixelColorXY(x, y, c);
else setPixelColor(x, c);
}
_colorScaled = false;
//_colorScaled = false;
}

/*
Expand Down Expand Up @@ -1549,12 +1549,12 @@ void WS2812FX::service() {
// would need to be allocated for each effect and then blended together for each pixel.
seg.beginDraw(); // set up parameters for get/setPixelColor()
#ifndef WLED_DISABLE_MODE_BLEND
Segment::setClippingRect(0, 0); // disable clipping (just in case)
Segment::setClippingRect(0, 0); // disable clipping (just in case)
if (seg.isInTransition()) {
// a hack to determine if effect has changed
uint8_t m = seg.currentMode();
uint8_t m = seg.currentMode();
Segment::modeBlend(true); // set semaphore
bool sameEffect = (m == seg.currentMode());
bool sameEffect = (m == seg.currentMode());
Segment::modeBlend(false); // clear semaphore
// set clipping rectangle
// new mode is run inside clipping area and old mode outside clipping area
Expand Down Expand Up @@ -1655,7 +1655,7 @@ void WS2812FX::service() {
#endif
if (doShow) {
for (size_t i = 0; i < getLengthTotal(); i++) pixels[i] = BLACK; // clear frame buffer; memset(pixels, 0, sizeof(uint32_t) * getLengthTotal());
for (const auto &seg : _segments) if (seg.isActive()) blendSegment(seg); // blend all render buffers into frame buffer
for (const auto &seg : _segments) if (seg.isActive() && seg.on) blendSegment(seg); // blend all render buffers into frame buffer
for (size_t i = 0; i < getLengthTotal(); i++) setPixelColor(i, pixels[i]);

yield();
Expand Down Expand Up @@ -1695,7 +1695,7 @@ void WS2812FX::blendSegment(const Segment &topSegment) {
const size_t matrixSize = Segment::maxWidth * Segment::maxHeight;
const size_t startIndx = XY(topSegment.start, topSegment.startY);
const size_t stopIndx = startIndx + len;
const unsigned opacity = topSegment.opacity; // determines amount of a applied over b in blend fuctions (not yet used)
const unsigned opacity = topSegment.currentBri(); // determines amount of a applied over b in blend fuctions (not yet used)

if (isMatrix && stopIndx <= matrixSize) {
#ifndef WLED_DISABLE_2D
Expand All @@ -1704,6 +1704,7 @@ void WS2812FX::blendSegment(const Segment &topSegment) {
for (int r = 0; r < rows; r++) for (int c = 0; c < cols; c++) {
// get segment's pixel
uint32_t c_a = topSegment.getPixelColorXY(c,r);
c_a = color_fade(c_a, opacity);
auto r_a = R(c_a);
auto g_a = G(c_a);
auto b_a = B(c_a);
Expand Down Expand Up @@ -1778,6 +1779,7 @@ void WS2812FX::blendSegment(const Segment &topSegment) {
} else {
for (int k = 0; k < len; k++) {
uint32_t c_a = topSegment.getPixelColor(k);
c_a = color_fade(c_a, opacity);
auto r_a = R(c_a);
auto g_a = G(c_a);
auto b_a = B(c_a);
Expand Down
26 changes: 13 additions & 13 deletions wled00/data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -805,20 +805,20 @@ function populateSegments(s)
`<option value="4" ${inst.m12==4?' selected':''}>Pinwheel</option>`+
`</select></div>`+
`</div>`;
let blend = `<div data-snd="si" class="lbl-s hide">Blend mode<br>`+
let blend = `<div class="lbl-s">Blend mode<br>`+
`<div class="sel-p"><select class="sel-p" id="seg${i}bm" onchange="setBm(${i})">`+
`<option value="0" ${inst.si==0?' selected':''}>Top/Default</option>`+
`<option value="1" ${inst.si==1?' selected':''}>Bottom/None</option>`+
`<option value="2" ${inst.si==2?' selected':''}>Add</option>`+
`<option value="3" ${inst.si==3?' selected':''}>Subtract</option>`+
`<option value="4" ${inst.si==4?' selected':''}>Difference</option>`+
`<option value="5" ${inst.si==5?' selected':''}>Average</option>`+
`<option value="6" ${inst.si==6?' selected':''}>Multiply</option>`+
`<option value="7" ${inst.si==7?' selected':''}>Divide</option>`+
`<option value="8" ${inst.si==8?' selected':''}>Lighten</option>`+
`<option value="9" ${inst.si==9?' selected':''}>Darken</option>`+
`<option value="10" ${inst.si==10?' selected':''}>Screen</option>`+
`<option value="11" ${inst.si==11?' selected':''}>Overlay</option>`+
`<option value="0" ${inst.bm==0?' selected':''}>Top/Default</option>`+
`<option value="1" ${inst.bm==1?' selected':''}>Bottom/None</option>`+
`<option value="2" ${inst.bm==2?' selected':''}>Add</option>`+
`<option value="3" ${inst.bm==3?' selected':''}>Subtract</option>`+
`<option value="4" ${inst.bm==4?' selected':''}>Difference</option>`+
`<option value="5" ${inst.bm==5?' selected':''}>Average</option>`+
`<option value="6" ${inst.bm==6?' selected':''}>Multiply</option>`+
`<option value="7" ${inst.bm==7?' selected':''}>Divide</option>`+
`<option value="8" ${inst.bm==8?' selected':''}>Lighten</option>`+
`<option value="9" ${inst.bm==9?' selected':''}>Darken</option>`+
`<option value="10" ${inst.bm==10?' selected':''}>Screen</option>`+
`<option value="11" ${inst.bm==11?' selected':''}>Overlay</option>`+
`</select></div>`+
`</div>`;
// let sndSim = `<div data-snd="si" class="lbl-s hide">Sound sim<br>`+
Expand Down
1 change: 1 addition & 0 deletions wled00/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ static void serializeSegment(JsonObject& root, const Segment& seg, byte id, bool
root["o3"] = seg.check3;
root["si"] = seg.soundSim;
root["m12"] = seg.map1D2D;
root["bm"] = seg.blendMode;
}

void serializeState(JsonObject root, bool forPreset, bool includeBri, bool segmentBounds, bool selectedSegmentsOnly)
Expand Down

0 comments on commit 9b82b25

Please sign in to comment.