Skip to content

Commit

Permalink
Allow to apply gamma-correction to Palette for performance reason
Browse files Browse the repository at this point in the history
  • Loading branch information
DrA1ex committed Feb 2, 2024
1 parent 39237f6 commit 2d592c8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/application.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "application.h"

#include "night_mode.h"
#include "sys_macro.h"

#include "fx/fx.h"
#include "fx/palette.h"
Expand Down Expand Up @@ -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() {
Expand Down
6 changes: 5 additions & 1 deletion src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
#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
9 changes: 8 additions & 1 deletion src/fx/color_efect.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "color_effect.h"

#include "sys_macro.h"

#include "misc/led.h"
#include "utils/palette.h"

Expand Down Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion src/sys_macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
#define BUTTON_FN(x) (x)
#else
#define BUTTON_FN(x)
#endif
#endif

#define GAMMA_V(x) (2.2f + (float) (x - 128) / 128.f)

0 comments on commit 2d592c8

Please sign in to comment.