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 all commits
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
58 changes: 54 additions & 4 deletions usermods/usermod_v2_animartrix/usermod_v2_animartrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
};


Expand Down
Loading