diff options
author | Mattias Andrée <m@maandree.se> | 2025-03-05 20:36:07 +0100 |
---|---|---|
committer | Mattias Andrée <m@maandree.se> | 2025-03-05 20:36:07 +0100 |
commit | 61821405d8f48117b82ce839c7196eb68c2d8266 (patch) | |
tree | 8255c88a57d6ec4771284809763349f61267356f /src/gamma-vidmode.c | |
parent | Just use double, no mixing in float (diff) | |
download | redshift-ng-61821405d8f48117b82ce839c7196eb68c2d8266.tar.gz redshift-ng-61821405d8f48117b82ce839c7196eb68c2d8266.tar.bz2 redshift-ng-61821405d8f48117b82ce839c7196eb68c2d8266.tar.xz |
Style and warnings
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'src/gamma-vidmode.c')
-rw-r--r-- | src/gamma-vidmode.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/gamma-vidmode.c b/src/gamma-vidmode.c index 164437f..f88925a 100644 --- a/src/gamma-vidmode.c +++ b/src/gamma-vidmode.c @@ -34,10 +34,12 @@ struct gamma_state { static int vidmode_init(struct gamma_state **state) { + struct gamma_state *s; + *state = malloc(sizeof(struct gamma_state)); if (*state == NULL) return -1; - struct gamma_state *s = *state; + s = *state; s->screen_num = -1; s->saved_ramps = NULL; @@ -56,12 +58,13 @@ vidmode_start(struct gamma_state *state, enum program_mode mode) { int r; int screen_num = state->screen_num; + int major, minor; + uint16_t *gamma_r, *gamma_g, *gamma_b; if (screen_num < 0) screen_num = DefaultScreen(state->display); state->screen_num = screen_num; /* Query extension version */ - int major, minor; r = XF86VidModeQueryVersion(state->display, &major, &minor); if (!r) { fprintf(stderr, _("X request failed: %s\n"), @@ -91,9 +94,9 @@ vidmode_start(struct gamma_state *state, enum program_mode mode) return -1; } - uint16_t *gamma_r = &state->saved_ramps[0*state->ramp_size]; - uint16_t *gamma_g = &state->saved_ramps[1*state->ramp_size]; - uint16_t *gamma_b = &state->saved_ramps[2*state->ramp_size]; + gamma_r = &state->saved_ramps[0 * state->ramp_size]; + gamma_g = &state->saved_ramps[1 * state->ramp_size]; + gamma_b = &state->saved_ramps[2 * state->ramp_size]; /* Save current gamma ramps so we can restore them at program exit. */ r = XF86VidModeGetGammaRamp(state->display, state->screen_num, @@ -172,18 +175,19 @@ static int vidmode_set_temperature( struct gamma_state *state, const struct color_setting *setting, int preserve) { - int r; + int r, i; + uint16_t value, *gamma_ramps, *gamma_r, *gamma_g, *gamma_b; /* Create new gamma ramps */ - uint16_t *gamma_ramps = malloc(3*state->ramp_size*sizeof(uint16_t)); + gamma_ramps = malloc(3*state->ramp_size*sizeof(uint16_t)); if (gamma_ramps == NULL) { perror("malloc"); return -1; } - uint16_t *gamma_r = &gamma_ramps[0*state->ramp_size]; - uint16_t *gamma_g = &gamma_ramps[1*state->ramp_size]; - uint16_t *gamma_b = &gamma_ramps[2*state->ramp_size]; + gamma_r = &gamma_ramps[0 * state->ramp_size]; + gamma_g = &gamma_ramps[1 * state->ramp_size]; + gamma_b = &gamma_ramps[2 * state->ramp_size]; if (preserve) { /* Initialize gamma ramps from saved state */ @@ -191,8 +195,8 @@ vidmode_set_temperature( 3*state->ramp_size*sizeof(uint16_t)); } else { /* Initialize gamma ramps to pure state */ - for (int i = 0; i < state->ramp_size; i++) { - uint16_t value = (double)i/state->ramp_size * + for (i = 0; i < state->ramp_size; i++) { + value = (double)i/state->ramp_size * (UINT16_MAX+1); gamma_r[i] = value; gamma_g[i] = value; |