Merge branch 'segment-api' into integrationMergeOnly

This commit is contained in:
ewowi 2022-08-01 16:17:16 +02:00
commit 8ea77ccd04
12 changed files with 1878 additions and 1796 deletions

View File

@ -249,7 +249,7 @@ class UsermodCronixie : public Usermod {
if (backlight && _digitOut[i] <11)
{
uint32_t col = strip.gamma32(strip.getSegment(0).colors[1]);
uint32_t col = gamma32(strip.getSegment(0).colors[1]);
for (uint16_t j=o; j< o+10; j++) {
if (j != excl) strip.setPixelColor(j, col);
}

File diff suppressed because it is too large Load Diff

View File

@ -502,9 +502,9 @@ typedef struct Segment {
inline bool isSelected(void) { return getOption(0); }
inline bool isActive(void) { return stop > start; }
inline bool is2D(void) { return !(startY == 0 && stopY == 1); }
inline uint16_t width(void) { return stop - start; }
inline uint16_t height(void) { return stopY - startY; }
inline uint16_t length(void) { return width(); }
inline uint16_t width(void) { return stop - start; } // segment width in physical pixels (length if 1D)
inline uint16_t height(void) { return stopY - startY; } // segment height (if 2D) in physical pixels
inline uint16_t length(void) { return width() * height(); } // segment length (count) in physical pixels
inline uint16_t groupLength(void) { return grouping + spacing; }
inline uint8_t getLightCapabilities(void) { return _capabilities; }
@ -682,7 +682,6 @@ class WS2812FX { // 96 bytes
setBrightness(uint8_t b, bool direct = false),
setRange(uint16_t i, uint16_t i2, uint32_t col),
setTransitionMode(bool t),
calcGammaTable(float),
purgeSegments(void),
setSegment(uint8_t n, uint16_t start, uint16_t stop, uint8_t grouping = 1, uint8_t spacing = 0, uint16_t offset = UINT16_MAX, uint16_t startY=0, uint16_t stopY=1),
setMainSegmentId(uint8_t n),
@ -728,9 +727,7 @@ class WS2812FX { // 96 bytes
getActiveSegmentsNum(void),
getFirstSelectedSegId(void),
getLastActiveSegmentId(void),
setPixelSegment(uint8_t n),
gamma8(uint8_t),
gamma8_cal(uint8_t, float);
setPixelSegment(uint8_t n);
inline uint8_t getBrightness(void) { return _brightness; }
inline uint8_t getMaxSegments(void) { return MAX_NUM_SEGMENTS; } // returns maximum number of supported segments (fixed value)
@ -756,7 +753,6 @@ class WS2812FX { // 96 bytes
now,
timebase,
currentColor(uint32_t colorNew, uint8_t tNr),
gamma32(uint32_t),
getPixelColor(uint16_t);
inline uint32_t getLastShow(void) { return _lastShow; }

View File

@ -114,22 +114,24 @@ void IRAM_ATTR WS2812FX::setPixelColorXY(int x, int y, uint32_t col)
#ifndef WLED_DISABLE_2D
if (!isMatrix) return; // not a matrix set-up
uint16_t index = y * matrixWidth + x;
#else
uint16_t index = x;
#endif
if (index >= _length) return;
if (index < customMappingSize) index = customMappingTable[index];
busses.setPixelColor(index, col);
#endif
}
// returns RGBW values of pixel
uint32_t WS2812FX::getPixelColorXY(uint16_t x, uint16_t y) {
#ifndef WLED_DISABLE_2D
uint16_t index = (y * matrixWidth + x);
#else
uint16_t index = x;
#endif
if (index >= _length) return 0;
if (index < customMappingSize) index = customMappingTable[index];
return busses.getPixelColor(index);
#else
return 0;
#endif
}
///////////////////////////////////////////////////////////
@ -143,7 +145,7 @@ uint16_t IRAM_ATTR Segment::XY(uint16_t x, uint16_t y) {
uint16_t height = virtualHeight(); // segment height in logical pixels
return (x%width) + (y%height) * width;
#else
return 0;
return x;
#endif
}
@ -189,6 +191,8 @@ void IRAM_ATTR Segment::setPixelColorXY(int x, int y, uint32_t col)
}
}
}
#else
setPixelColor(x, col);
#endif
}
@ -454,14 +458,12 @@ void Segment::move(uint8_t dir, uint8_t delta, CRGB *leds) {
}
void Segment::fill_solid(CRGB* leds, CRGB color) {
#ifndef WLED_DISABLE_2D
const uint16_t cols = virtualWidth();
const uint16_t cols = is2D() ? virtualWidth() : virtualLength();
const uint16_t rows = virtualHeight();
for(uint16_t y = 0; y < rows; y++) for (uint16_t x = 0; x < cols; x++) {
if (leds) leds[XY(x,y)] = color;
else setPixelColorXY(x, y, color);
}
#endif
}
// by stepko, taken from https://editor.soulmatelights.com/gallery/573-blobs

View File

@ -266,22 +266,22 @@ CRGBPalette16 &Segment::loadPalette(CRGBPalette16 &targetPalette, uint8_t pal) {
_lastPaletteChange = millis();
} break;}
case 2: {//primary color only
CRGB prim = CRGB(colors[0]);
CRGB prim = strip.gammaCorrectCol ? gamma32(colors[0]) : colors[0];
targetPalette = CRGBPalette16(prim); break;}
case 3: {//primary + secondary
CRGB prim = CRGB(colors[0]);
CRGB sec = CRGB(colors[1]);
CRGB prim = strip.gammaCorrectCol ? gamma32(colors[0]) : colors[0];
CRGB sec = strip.gammaCorrectCol ? gamma32(colors[1]) : colors[1];
targetPalette = CRGBPalette16(prim,prim,sec,sec); break;}
case 4: {//primary + secondary + tertiary
CRGB prim = CRGB(colors[0]);
CRGB sec = CRGB(colors[1]);
CRGB ter = CRGB(colors[2]);
CRGB prim = strip.gammaCorrectCol ? gamma32(colors[0]) : colors[0];
CRGB sec = strip.gammaCorrectCol ? gamma32(colors[1]) : colors[1];
CRGB ter = strip.gammaCorrectCol ? gamma32(colors[2]) : colors[2];
targetPalette = CRGBPalette16(ter,sec,prim); break;}
case 5: {//primary + secondary (+tert if not off), more distinct
CRGB prim = CRGB(colors[0]);
CRGB sec = CRGB(colors[1]);
CRGB prim = strip.gammaCorrectCol ? gamma32(colors[0]) : colors[0];
CRGB sec = strip.gammaCorrectCol ? gamma32(colors[1]) : colors[1];
if (colors[2]) {
CRGB ter = CRGB(colors[2]);
CRGB ter = strip.gammaCorrectCol ? gamma32(colors[2]) : colors[2];
targetPalette = CRGBPalette16(prim,prim,prim,prim,prim,sec,sec,sec,sec,sec,ter,ter,ter,ter,ter,prim);
} else {
targetPalette = CRGBPalette16(prim,prim,prim,prim,prim,prim,prim,prim,sec,sec,sec,sec,sec,sec,sec,sec);
@ -751,8 +751,9 @@ uint8_t Segment::get_random_wheel_index(uint8_t pos) {
uint32_t IRAM_ATTR Segment::color_from_palette(uint16_t i, bool mapping, bool wrap, uint8_t mcol, uint8_t pbri)
{
// default palette or no RGB support on segment
if (palette == 0 || !(_capabilities & 0x01)) {
uint32_t color = colors[constrain(mcol,0,NUM_COLORS-1)]; // SEGCOLOR(mcol);
if ((palette == 0 && mcol < NUM_COLORS) || !(_capabilities & 0x01)) {
uint32_t color = (transitional && _t) ? _t->_colorT[mcol] : colors[mcol];
color = strip.gammaCorrectCol ? gamma32(color) : color;
if (pbri == 255) return color;
return RGBW32(scale8_video(R(color),pbri), scale8_video(G(color),pbri), scale8_video(B(color),pbri), scale8_video(W(color),pbri));
}
@ -863,9 +864,7 @@ void WS2812FX::service() {
seg.currentPalette(_currentPalette, seg.palette);
if (!cctFromRgb || correctWB) busses.setSegmentCCT(seg.currentBri(seg.cct, true), correctWB);
for (uint8_t c = 0; c < NUM_COLORS; c++) {
_colors_t[c] = gamma32(_colors_t[c]);
}
for (uint8_t c = 0; c < NUM_COLORS; c++) _colors_t[c] = gamma32(_colors_t[c]);
seg.handleTransition();
@ -899,6 +898,39 @@ void WS2812FX::setPixelColor(int i, uint32_t col)
if (realtimeMode && useMainSegmentOnly) {
Segment &seg = _segments[_mainSegment];
uint16_t len = seg.length(); // length of segment in number of pixels
if (i >= seg.virtualLength()) return;
#ifndef WLED_DISABLE_2D
// adjust pixel index if within 2D segment
if (isMatrix) {
uint16_t vH = seg.virtualHeight(); // segment height in logical pixels
uint16_t vW = seg.virtualWidth();
switch (seg.map1D2D) {
case M12_Pixels:
// use all available pixels as a long strip
setPixelColorXY(seg.start + i % vW, seg.startY + i / vW, col);
break;
case M12_VerticalBar:
// expand 1D effect vertically
for (int y = 0; y < vH; y++) setPixelColorXY(seg.start + i, seg.startY + y, col);
break;
case M12_Circle:
// expand in circular fashion from center
for (float degrees = 0.0f; degrees <= 90.0f; degrees += 89.99f / (sqrtf((float)max(vH,vW))*i+1)) { // this may prove too many iterations on larger matrices
// may want to try float version as well (with or without antialiasing)
int x = roundf(sin_t(degrees*DEG_TO_RAD) * i);
int y = roundf(cos_t(degrees*DEG_TO_RAD) * i);
setPixelColorXY(seg.start + x, seg.startY + y, col);
}
break;
case M12_Block:
for (int x = 0; x <= i; x++) setPixelColorXY(seg.start + x, seg.startY + i, col);
for (int y = 0; y < i; y++) setPixelColorXY(seg.start + i, seg.startY + y, col);
break;
}
return;
}
#endif
if (seg.opacity < 255) {
byte r = scale8(R(col), seg.opacity);
@ -1570,54 +1602,6 @@ void WS2812FX::deserializeMap(uint8_t n) {
releaseJSONBufferLock();
}
//gamma 2.8 lookup table used for color correction
static byte gammaT[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5,
5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10,
10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16,
17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25,
25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36,
37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50,
51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68,
69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89,
90, 92, 93, 95, 96, 98, 99,101,102,104,105,107,109,110,112,114,
115,117,119,120,122,124,126,127,129,131,133,135,137,138,140,142,
144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175,
177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213,
215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 };
uint8_t WS2812FX::gamma8_cal(uint8_t b, float gamma) {
return (int)(powf((float)b / 255.0f, gamma) * 255.0f + 0.5f);
}
void WS2812FX::calcGammaTable(float gamma)
{
for (uint16_t i = 0; i < 256; i++) {
gammaT[i] = gamma8_cal(i, gamma);
}
}
uint8_t WS2812FX::gamma8(uint8_t b)
{
return gammaT[b];
}
uint32_t WS2812FX::gamma32(uint32_t color)
{
if (!gammaCorrectCol) return color;
uint8_t w = W(color);
uint8_t r = R(color);
uint8_t g = G(color);
uint8_t b = B(color);
w = gammaT[w];
r = gammaT[r];
g = gammaT[g];
b = gammaT[b];
return RGBW32(r, g, b, w);
}
WS2812FX* WS2812FX::instance = nullptr;

View File

@ -319,3 +319,53 @@ uint16_t approximateKelvinFromRGB(uint32_t rgb) {
return (k > 10091) ? 10091 : k;
}
}
//gamma 2.8 lookup table used for color correction
static byte gammaT[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5,
5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10,
10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16,
17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25,
25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36,
37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50,
51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68,
69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89,
90, 92, 93, 95, 96, 98, 99,101,102,104,105,107,109,110,112,114,
115,117,119,120,122,124,126,127,129,131,133,135,137,138,140,142,
144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175,
177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213,
215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 };
uint8_t gamma8_cal(uint8_t b, float gamma)
{
return (int)(powf((float)b / 255.0f, gamma) * 255.0f + 0.5f);
}
void calcGammaTable(float gamma)
{
for (uint16_t i = 0; i < 256; i++) {
gammaT[i] = gamma8_cal(i, gamma);
}
}
uint8_t gamma8(uint8_t b)
{
return gammaT[b];
}
uint32_t gamma32(uint32_t color)
{
//if (!strip.gammaCorrectCol) return color;
uint8_t w = W(color);
uint8_t r = R(color);
uint8_t g = G(color);
uint8_t b = B(color);
w = gammaT[w];
r = gammaT[r];
g = gammaT[g];
b = gammaT[b];
return RGBW32(r, g, b, w);
}

View File

@ -398,10 +398,10 @@ button {
.filter {
background-color: var(--c-4);
box-shadow: 0px 0px 6px 6px var(--c-1);
/*box-shadow: 0px 0px 6px 6px var(--c-1);*/
border-radius: 26px;
height: 26px;
margin: 0 auto 4px; /* 8px if you want space */
margin: 0 auto; /* add 4-8px if you want space at the bottom */
padding: 8px 2px;
position: relative;
/*width: 260px;*/
@ -1228,6 +1228,7 @@ TD .checkmark, TD .radiomark {
.lbl-s {
display: inline-block;
/* margin: 10px 4px 0 0; */
margin-top: 6px;
font-size: 13px;
width: 48%;
text-align: center;

View File

@ -60,22 +60,21 @@ bool getJsonValue(const JsonVariant& element, DestType& destination, const Defau
//colors.cpp
uint32_t color_blend(uint32_t,uint32_t,uint16_t,bool b16=false);
uint32_t color_add(uint32_t,uint32_t);
inline uint32_t colorFromRgbw(byte* rgbw) { return uint32_t((byte(rgbw[3]) << 24) | (byte(rgbw[0]) << 16) | (byte(rgbw[1]) << 8) | (byte(rgbw[2]))); }
void colorHStoRGB(uint16_t hue, byte sat, byte* rgb); //hue, sat to rgb
void colorKtoRGB(uint16_t kelvin, byte* rgb);
void colorCTtoRGB(uint16_t mired, byte* rgb); //white spectrum to rgb
void colorXYtoRGB(float x, float y, byte* rgb); // only defined if huesync disabled TODO
void colorRGBtoXY(byte* rgb, float* xy); // only defined if huesync disabled TODO
void colorFromDecOrHexString(byte* rgb, char* in);
bool colorFromHexString(byte* rgb, const char* in);
uint32_t colorBalanceFromKelvin(uint16_t kelvin, uint32_t rgb);
uint16_t approximateKelvinFromRGB(uint32_t rgb);
void setRandomColor(byte* rgb);
uint8_t gamma8_cal(uint8_t b, float gamma);
void calcGammaTable(float gamma);
uint8_t gamma8(uint8_t b);
uint32_t gamma32(uint32_t);
//dmx.cpp
void initDMX();

File diff suppressed because it is too large Load Diff

View File

@ -205,7 +205,7 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
extractModeSlider(fx, 255, buf, 4, &tmp);
if (tmp < strip.getPaletteCount() + strip.customPalettes.size()) {
if (tmp != seg.palette) {
if (strip.paletteBlend && !seg.transitional) seg.startTransition(strip.getTransition());
if (strip.paletteFade && !seg.transitional) seg.startTransition(strip.getTransition());
seg.palette = tmp;
}
}
@ -224,7 +224,7 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
sOpt = extractModeDefaults(fx, "pal");
if (sOpt >= 0 && sOpt < strip.getPaletteCount() + strip.customPalettes.size()) {
if (sOpt != seg.palette) {
if (strip.paletteBlend && !seg.transitional) seg.startTransition(strip.getTransition());
if (strip.paletteFade && !seg.transitional) seg.startTransition(strip.getTransition());
seg.palette = sOpt;
}
}
@ -238,7 +238,7 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
uint8_t pal = seg.palette;
if (getVal(elem["pal"], &pal, 1, strip.getPaletteCount())) {
if (pal != seg.palette) {
if (strip.paletteBlend && !seg.transitional) seg.startTransition(strip.getTransition());
if (strip.paletteFade && !seg.transitional) seg.startTransition(strip.getTransition());
seg.palette = pal;
}
}
@ -290,7 +290,7 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
if (set < 2) stop = start + 1;
for (int i = start; i < stop; i++) {
if (strip.gammaCorrectCol) {
seg.setPixelColor(i, strip.gamma8(rgbw[0]), strip.gamma8(rgbw[1]), strip.gamma8(rgbw[2]), strip.gamma8(rgbw[3]));
seg.setPixelColor(i, gamma8(rgbw[0]), gamma8(rgbw[1]), gamma8(rgbw[2]), gamma8(rgbw[3]));
} else {
seg.setPixelColor(i, rgbw[0], rgbw[1], rgbw[2], rgbw[3]);
}

View File

@ -567,7 +567,7 @@ void setRealtimePixel(uint16_t i, byte r, byte g, byte b, byte w)
{
if (!arlsDisableGammaCorrection && strip.gammaCorrectCol)
{
strip.setPixelColor(pix, strip.gamma8(r), strip.gamma8(g), strip.gamma8(b), strip.gamma8(w));
strip.setPixelColor(pix, gamma8(r), gamma8(g), gamma8(b), gamma8(w));
} else {
strip.setPixelColor(pix, r, g, b, w);
}

View File

@ -8,7 +8,7 @@
*/
// version code in format yymmddb (b = daily build)
#define VERSION 2207302
#define VERSION 2207303
//uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG