diff --git a/usermods/usermod_v2_animartrix/usermod_v2_animartrix.h b/usermods/usermod_v2_animartrix/usermod_v2_animartrix.h index b93d3dffb5..4ecf4ff630 100644 --- a/usermods/usermod_v2_animartrix/usermod_v2_animartrix.h +++ b/usermods/usermod_v2_animartrix/usermod_v2_animartrix.h @@ -87,7 +87,6 @@ static const char _data_FX_mode_Waves[] PROGMEM = "Y💡Waves ☾@Speed;;1;2"; static const char _data_FX_mode_Chasing_Spirals[] PROGMEM = "Y💡Chasing_Spirals ☾@Speed;;1;2"; static const char _data_FX_mode_Rotating_Blob[] PROGMEM = "Y💡Rotating_Blob ☾@Speed;;1;2"; - class ANIMartRIXMod:public ANIMartRIX { public: void initEffect() { @@ -104,13 +103,33 @@ class ANIMartRIXMod:public ANIMartRIX { setSpeedFactor(speedFactor); } void setPixelColor(int x, int y, rgb pixel) { - SEGMENT.setPixelColorXY(x, y, CRGB(pixel.red, pixel.green, pixel.blue)); + SEGMENT.setPixelColorXY(x, y, applyGamma(pixel)); + } + + CRGB applyGamma(rgb pixel) { + if(enableGamma) { + uint8_t r = (uint8_t) pixel.red; + uint8_t g = (uint8_t) pixel.green; + uint8_t b = (uint8_t) pixel.blue; + return CRGB(gamma8(r), gamma8(g), gamma8(b)); + } + else { + return CRGB(pixel.red, pixel.green, pixel.blue); + } } + void setPixelColor(int index, rgb pixel) { - SEGMENT.setPixelColor(index, CRGB(pixel.red, pixel.green, pixel.blue)); + SEGMENT.setPixelColor(index, applyGamma(pixel)); } + void setEnableGamma(bool state) { + this->enableGamma = state; + } // Add any extra custom effects not part of the ANIMartRIX libary here + + private: + + bool enableGamma = true; }; ANIMartRIXMod anim; @@ -381,7 +400,9 @@ class AnimartrixUsermod : public Usermod { public: - AnimartrixUsermod(const char *name, bool enabled):Usermod(name, enabled) {} //WLEDMM + AnimartrixUsermod(const char *name, bool enabled):Usermod(name, enabled) { + anim.setEnableGamma(enableGamma); + } //WLEDMM void setup() { @@ -465,13 +486,42 @@ class AnimartrixUsermod : public Usermod { String uiDomString = F("Animartrix requires the Creative Commons Attribution License CC BY-NC 3.0"); infoArr.add(uiDomString); + infoArr.add("Gamma Correction : " + enableGamma); } + + void addToConfig(JsonObject& root) { + JsonObject top = root.createNestedObject(FPSTR(_name)); // usermodname + top[FPSTR("enabled")] = enabled; + top[FPSTR("enableGamma")] = enableGamma; + } + + bool readFromConfig(JsonObject& root) { + JsonObject top = root[FPSTR(_name)]; + if (top.isNull()) { + DEBUG_PRINT(FPSTR(_name)); + DEBUG_PRINTLN(F(": No config found. (Using defaults.)")); + return false; + } + + enabled = top[FPSTR("enabled")] | enabled; + enableGamma = top[FPSTR("enableGamma")] | enableGamma; + DEBUG_PRINT(FPSTR(_name)); + DEBUG_PRINTLN(F(" config (re)loaded.")); + + anim.setEnableGamma(enableGamma); + + return true; + } + + uint16_t getId() { return USERMOD_ID_ANIMARTRIX; } + private: + bool enableGamma; };