From 787f5f06dfd4d739c57853fd42b90cecba04daba Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Sun, 4 Sep 2022 20:17:05 +0200 Subject: [PATCH] Global gamma. Randomcycle palette bugfix. --- wled00/FX.cpp | 5 +---- wled00/FX.h | 4 ---- wled00/FX_fcn.cpp | 34 ++++++++++++++++++---------------- wled00/cfg.cpp | 12 ++++++------ wled00/colors.cpp | 2 +- wled00/json.cpp | 7 ++----- wled00/set.cpp | 4 ++-- wled00/udp.cpp | 2 +- wled00/wled.h | 8 +++++--- wled00/wled_eeprom.cpp | 4 ++-- wled00/xml.cpp | 4 ++-- 11 files changed, 40 insertions(+), 46 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 30019c9d..5f22e573 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -1927,10 +1927,7 @@ uint16_t mode_palette() for (int i = 0; i < SEGLEN; i++) { uint8_t colorIndex = (i * 255 / SEGLEN) - counter; - - if (noWrap) colorIndex = map(colorIndex, 0, 255, 0, 240); //cut off blend at palette "end" - - SEGMENT.setPixelColor(i, SEGMENT.color_from_palette(colorIndex, false, true, 255)); + SEGMENT.setPixelColor(i, SEGMENT.color_from_palette(colorIndex, false, noWrap, 255)); } return FRAMETIME; } diff --git a/wled00/FX.h b/wled00/FX.h index 38539a9d..e7b1800d 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -647,8 +647,6 @@ class WS2812FX { // 96 bytes public: WS2812FX() : - gammaCorrectBri(false), - gammaCorrectCol(true), paletteFade(0), paletteBlend(0), milliampsPerLed(55), @@ -747,8 +745,6 @@ class WS2812FX { // 96 bytes inline void appendSegment(const Segment &seg = Segment()) { _segments.push_back(seg); } bool - gammaCorrectBri, - gammaCorrectCol, checkSegmentAlignment(void), hasRGBWBus(void), hasCCTBus(void), diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index a193f8c8..6aa92360 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -208,6 +208,7 @@ void Segment::setUpLeds() { CRGBPalette16 &Segment::loadPalette(CRGBPalette16 &targetPalette, uint8_t pal) { static unsigned long _lastPaletteChange = 0; // perhaps it should be per segment + static CRGBPalette16 randomPalette = CRGBPalette16(DEFAULT_COLOR); byte tcp[72]; if (pal < 245 && pal > GRADIENT_PALETTE_COUNT+13) pal = 0; if (pal > 245 && (strip.customPalettes.size() == 0 || 255U-pal > strip.customPalettes.size()-1)) pal = 0; @@ -229,30 +230,31 @@ CRGBPalette16 &Segment::loadPalette(CRGBPalette16 &targetPalette, uint8_t pal) { targetPalette = PartyColors_p; break; case 1: //periodically replace palette with a random one. Doesn't work with multiple FastLED segments if (millis() - _lastPaletteChange > 5000 /*+ ((uint32_t)(255-intensity))*100*/) { - targetPalette = CRGBPalette16( - CHSV(random8(), 255, random8(128, 255)), - CHSV(random8(), 255, random8(128, 255)), - CHSV(random8(), 192, random8(128, 255)), - CHSV(random8(), 255, random8(128, 255))); + randomPalette = CRGBPalette16( + CHSV(random8(), random8(160, 255), random8(128, 255)), + CHSV(random8(), random8(160, 255), random8(128, 255)), + CHSV(random8(), random8(160, 255), random8(128, 255)), + CHSV(random8(), random8(160, 255), random8(128, 255))); _lastPaletteChange = millis(); - } break; + } + targetPalette = randomPalette; break; case 2: {//primary color only - CRGB prim = strip.gammaCorrectCol ? gamma32(colors[0]) : colors[0]; + CRGB prim = gamma32(colors[0]); targetPalette = CRGBPalette16(prim); break;} case 3: {//primary + secondary - CRGB prim = strip.gammaCorrectCol ? gamma32(colors[0]) : colors[0]; - CRGB sec = strip.gammaCorrectCol ? gamma32(colors[1]) : colors[1]; + CRGB prim = gamma32(colors[0]); + CRGB sec = gamma32(colors[1]); targetPalette = CRGBPalette16(prim,prim,sec,sec); break;} case 4: {//primary + secondary + tertiary - 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]; + CRGB prim = gamma32(colors[0]); + CRGB sec = gamma32(colors[1]); + CRGB ter = gamma32(colors[2]); targetPalette = CRGBPalette16(ter,sec,prim); break;} case 5: {//primary + secondary (+tert if not off), more distinct - CRGB prim = strip.gammaCorrectCol ? gamma32(colors[0]) : colors[0]; - CRGB sec = strip.gammaCorrectCol ? gamma32(colors[1]) : colors[1]; + CRGB prim = gamma32(colors[0]); + CRGB sec = gamma32(colors[1]); if (colors[2]) { - CRGB ter = strip.gammaCorrectCol ? gamma32(colors[2]) : colors[2]; + CRGB ter = gamma32(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); @@ -823,7 +825,7 @@ uint32_t Segment::color_from_palette(uint16_t i, bool mapping, bool wrap, uint8_ // default palette or no RGB support on segment if ((palette == 0 && mcol < NUM_COLORS) || !(_capabilities & 0x01)) { uint32_t color = (transitional && _t) ? _t->_colorT[mcol] : colors[mcol]; - color = strip.gammaCorrectCol ? gamma32(color) : color; + color = gamma32(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)); } diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index d1ec845b..fe0ae194 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -302,10 +302,10 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { float light_gc_bri = light["gc"]["bri"]; float light_gc_col = light["gc"]["col"]; // 2.8 - if (light_gc_bri > 1.5) strip.gammaCorrectBri = true; - else if (light_gc_bri > 0.5) strip.gammaCorrectBri = false; - if (light_gc_col > 1.5) strip.gammaCorrectCol = true; - else if (light_gc_col > 0.5) strip.gammaCorrectCol = false; + if (light_gc_bri > 1.5) gammaCorrectBri = true; + else if (light_gc_bri > 0.5) gammaCorrectBri = false; + if (light_gc_col > 1.5) gammaCorrectCol = true; + else if (light_gc_col > 0.5) gammaCorrectCol = false; JsonObject light_tr = light["tr"]; CJSON(fadeTransition, light_tr["mode"]); @@ -759,8 +759,8 @@ void serializeConfig() { light[F("aseg")] = autoSegments; JsonObject light_gc = light.createNestedObject("gc"); - light_gc["bri"] = (strip.gammaCorrectBri) ? 2.8 : 1.0; - light_gc["col"] = (strip.gammaCorrectCol) ? 2.8 : 1.0; + light_gc["bri"] = (gammaCorrectBri) ? 2.8 : 1.0; + light_gc["col"] = (gammaCorrectCol) ? 2.8 : 1.0; JsonObject light_tr = light.createNestedObject("tr"); light_tr["mode"] = fadeTransition; diff --git a/wled00/colors.cpp b/wled00/colors.cpp index c42c9076..0b8c7811 100644 --- a/wled00/colors.cpp +++ b/wled00/colors.cpp @@ -358,7 +358,7 @@ uint8_t gamma8(uint8_t b) uint32_t gamma32(uint32_t color) { - //if (!strip.gammaCorrectCol) return color; + if (!gammaCorrectCol) return color; uint8_t w = W(color); uint8_t r = R(color); uint8_t g = G(color); diff --git a/wled00/json.cpp b/wled00/json.cpp index fdb3a9dc..11bf2073 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -265,12 +265,9 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId) } if (set < 2) stop = start + 1; + uint32_t c = gamma32(RGBW32(rgbw[0], rgbw[1], rgbw[2], rgbw[3])); for (int i = start; i < stop; i++) { - if (strip.gammaCorrectCol) { - 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]); - } + seg.setPixelColor(i, c); } if (!set) start++; set = 0; diff --git a/wled00/set.cpp b/wled00/set.cpp index 9f3198f4..c1a6b3f5 100644 --- a/wled00/set.cpp +++ b/wled00/set.cpp @@ -184,8 +184,8 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) turnOnAtBoot = request->hasArg(F("BO")); t = request->arg(F("BP")).toInt(); if (t <= 250) bootPreset = t; - strip.gammaCorrectBri = request->hasArg(F("GB")); - strip.gammaCorrectCol = request->hasArg(F("GC")); + gammaCorrectBri = request->hasArg(F("GB")); + gammaCorrectCol = request->hasArg(F("GC")); fadeTransition = request->hasArg(F("TF")); t = request->arg(F("TD")).toInt(); diff --git a/wled00/udp.cpp b/wled00/udp.cpp index e33ac96b..d2547c60 100644 --- a/wled00/udp.cpp +++ b/wled00/udp.cpp @@ -564,7 +564,7 @@ void setRealtimePixel(uint16_t i, byte r, byte g, byte b, byte w) { uint16_t pix = i + arlsOffset; if (pix < strip.getLengthTotal()) { - if (!arlsDisableGammaCorrection && strip.gammaCorrectCol) { + if (!arlsDisableGammaCorrection && gammaCorrectCol) { r = gamma8(r); g = gamma8(g); b = gamma8(b); diff --git a/wled00/wled.h b/wled00/wled.h index 80eb4809..8fdc529d 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -287,9 +287,11 @@ WLED_GLOBAL byte bootPreset _INIT(0); // save preset to load //if true, a segment per bus will be created on boot and LED settings save //if false, only one segment spanning the total LEDs is created, //but not on LED settings save if there is more than one segment currently -WLED_GLOBAL bool autoSegments _INIT(false); -WLED_GLOBAL bool correctWB _INIT(false); //CCT color correction of RGB color -WLED_GLOBAL bool cctFromRgb _INIT(false); //CCT is calculated from RGB instead of using seg.cct +WLED_GLOBAL bool autoSegments _INIT(false); +WLED_GLOBAL bool correctWB _INIT(false); // CCT color correction of RGB color +WLED_GLOBAL bool cctFromRgb _INIT(false); // CCT is calculated from RGB instead of using seg.cct +WLED_GLOBAL bool gammaCorrectCol _INIT(false); // use gamma correction on colors +WLED_GLOBAL bool gammaCorrectBri _INIT(false); // use gamma correction on brightness WLED_GLOBAL byte col[] _INIT_N(({ 255, 160, 0, 0 })); // current RGB(W) primary color. col[] should be updated if you want to change the color. WLED_GLOBAL byte colSec[] _INIT_N(({ 0, 0, 0, 0 })); // current RGB(W) secondary color diff --git a/wled00/wled_eeprom.cpp b/wled00/wled_eeprom.cpp index 076a7f40..a05f1431 100644 --- a/wled00/wled_eeprom.cpp +++ b/wled00/wled_eeprom.cpp @@ -140,8 +140,8 @@ void loadSettingsFromEEPROM() ntpEnabled = EEPROM.read(327); currentTimezone = EEPROM.read(328); useAMPM = EEPROM.read(329); - strip.gammaCorrectBri = EEPROM.read(330); - strip.gammaCorrectCol = EEPROM.read(331); + gammaCorrectBri = EEPROM.read(330); + gammaCorrectCol = EEPROM.read(331); overlayCurrent = EEPROM.read(332); alexaEnabled = EEPROM.read(333); diff --git a/wled00/xml.cpp b/wled00/xml.cpp index fb3216cc..507478b1 100644 --- a/wled00/xml.cpp +++ b/wled00/xml.cpp @@ -394,8 +394,8 @@ void getSettingsJS(byte subPage, char* dest) sappend('c',SET_F("BO"),turnOnAtBoot); sappend('v',SET_F("BP"),bootPreset); - sappend('c',SET_F("GB"),strip.gammaCorrectBri); - sappend('c',SET_F("GC"),strip.gammaCorrectCol); + sappend('c',SET_F("GB"),gammaCorrectBri); + sappend('c',SET_F("GC"),gammaCorrectCol); sappend('c',SET_F("TF"),fadeTransition); sappend('v',SET_F("TD"),transitionDelayDefault); sappend('c',SET_F("PF"),strip.paletteFade);