diff --git a/src/application.cpp b/src/application.cpp index 751af11..f38fb9c 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -1,6 +1,7 @@ #include "application.h" #include "night_mode.h" +#include "sys_macro.h" #include "fx/fx.h" #include "fx/palette.h" @@ -33,6 +34,12 @@ void Application::load() { } else { current_palette = palette->value; } + +#if GAMMA_CORRECTION_RT == DISABLED + if (config.gamma != 0) { + napplyGamma_video(current_palette.entries, 16, GAMMA_V(config.gamma)); + } +#endif } void Application::update() { diff --git a/src/constants.h b/src/constants.h index 8b5ccb0..bc4b5af 100644 --- a/src/constants.h +++ b/src/constants.h @@ -29,4 +29,8 @@ #define HEIGHT (16u) #define CALIBRATION_TIMEOUT (5000u) // Timeout for calibration mode -#define POWER_CHANGE_TIMEOUT (1000u) // Timeout for power change animation \ No newline at end of file +#define POWER_CHANGE_TIMEOUT (1000u) // Timeout for power change animation + +#define GAMMA_CORRECTION_RT DISABLED // Real-time gamma correction. + // Warning: rt-correction may have significant performance impact + // when disabled - gamma correction will be applied to palette \ No newline at end of file diff --git a/src/fx/color_efect.cpp b/src/fx/color_efect.cpp index 09cd9c3..be95b37 100644 --- a/src/fx/color_efect.cpp +++ b/src/fx/color_efect.cpp @@ -1,5 +1,7 @@ #include "color_effect.h" +#include "sys_macro.h" + #include "misc/led.h" #include "utils/palette.h" @@ -30,8 +32,13 @@ void ColorEffectManager::call(Led &led, const PaletteT *palette, const PresetCon _state.params.scale = config.scale; _state.params.palette = palette; +#if GAMMA_CORRECTION_RT == ENABLED _state.params.gamma_correction = gamma > 0; - _state.params.gamma = 2.2f + (float) (gamma - 128) / 128.f; + _state.params.gamma = GAMMA_V(gamma); +#else + _state.params.gamma_correction = false; + _state.params.gamma = 0; +#endif _config.entries[(int) _fx].value(led, _state); _after_call(); diff --git a/src/sys_macro.h b/src/sys_macro.h index 0572913..f9669fe 100644 --- a/src/sys_macro.h +++ b/src/sys_macro.h @@ -6,4 +6,6 @@ #define BUTTON_FN(x) (x) #else #define BUTTON_FN(x) -#endif \ No newline at end of file +#endif + +#define GAMMA_V(x) (2.2f + (float) (x - 128) / 128.f) \ No newline at end of file