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

Animatrix gamma correction #85

Closed
wants to merge 7 commits into from
Closed
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Add gamma correction config option
netmindz committed Oct 21, 2023
commit 47131500ad17f8eebc424312112d8cbc35678c2f
51 changes: 46 additions & 5 deletions usermods/usermod_v2_animartrix/usermod_v2_animartrix.h
Original file line number Diff line number Diff line change
@@ -107,19 +107,29 @@ class ANIMartRIXMod:public ANIMartRIX {
}

CRGB applyGamma(rgb pixel) {
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));
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, 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;

@@ -390,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() {
@@ -474,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;
};