diff options
author | Jon Lund Steffensen <jonlst@gmail.com> | 2011-04-21 00:23:50 +0200 |
---|---|---|
committer | Jon Lund Steffensen <jonlst@gmail.com> | 2011-04-21 00:23:50 +0200 |
commit | 38af3a0d5e22399b515ceb037870c3ef22662bb7 (patch) | |
tree | b458a9e17fdf8aa7fb21cb03b28beb107c1587cb /src | |
parent | w32gdi: Remember to release the DC handle on error. (diff) | |
download | redshift-ng-38af3a0d5e22399b515ceb037870c3ef22662bb7.tar.gz redshift-ng-38af3a0d5e22399b515ceb037870c3ef22662bb7.tar.bz2 redshift-ng-38af3a0d5e22399b515ceb037870c3ef22662bb7.tar.xz |
Allow brightness to be adjusted (between 10% and 100%, the latter being the default).
Diffstat (limited to 'src')
-rw-r--r-- | src/colorramp.c | 8 | ||||
-rw-r--r-- | src/colorramp.h | 2 | ||||
-rw-r--r-- | src/gamma-randr.c | 12 | ||||
-rw-r--r-- | src/gamma-randr.h | 3 | ||||
-rw-r--r-- | src/gamma-vidmode.c | 5 | ||||
-rw-r--r-- | src/gamma-vidmode.h | 3 | ||||
-rw-r--r-- | src/gamma-w32gdi.c | 7 | ||||
-rw-r--r-- | src/gamma-w32gdi.h | 3 | ||||
-rw-r--r-- | src/redshift.c | 34 | ||||
-rw-r--r-- | src/redshift.h | 1 |
10 files changed, 56 insertions, 22 deletions
diff --git a/src/colorramp.c b/src/colorramp.c index 7241a8d..ed399f8 100644 --- a/src/colorramp.c +++ b/src/colorramp.c @@ -128,7 +128,7 @@ interpolate_color(float a, const float *c1, const float *c2, float *c) void colorramp_fill(uint16_t *gamma_r, uint16_t *gamma_g, uint16_t *gamma_b, - int size, int temp, float gamma[3]) + int size, int temp, float brightness, float gamma[3]) { /* Approximate white point */ float white_point[3]; @@ -139,10 +139,10 @@ colorramp_fill(uint16_t *gamma_r, uint16_t *gamma_g, uint16_t *gamma_b, for (int i = 0; i < size; i++) { gamma_r[i] = pow((float)i/size, 1.0/gamma[0]) * - UINT16_MAX * white_point[0]; + UINT16_MAX * brightness * white_point[0]; gamma_g[i] = pow((float)i/size, 1.0/gamma[1]) * - UINT16_MAX * white_point[1]; + UINT16_MAX * brightness * white_point[1]; gamma_b[i] = pow((float)i/size, 1.0/gamma[2]) * - UINT16_MAX * white_point[2]; + UINT16_MAX * brightness * white_point[2]; } } diff --git a/src/colorramp.h b/src/colorramp.h index 88aa984..326969e 100644 --- a/src/colorramp.h +++ b/src/colorramp.h @@ -23,6 +23,6 @@ #include <stdint.h> void colorramp_fill(uint16_t *gamma_r, uint16_t *gamma_g, uint16_t *gamma_b, - int size, int temp, float gamma[3]); + int size, int temp, float brightness, float gamma[3]); #endif /* ! _REDSHIFT_COLORRAMP_H */ diff --git a/src/gamma-randr.c b/src/gamma-randr.c index be8bdd9..8781e92 100644 --- a/src/gamma-randr.c +++ b/src/gamma-randr.c @@ -301,7 +301,7 @@ randr_set_option(randr_state_t *state, const char *key, const char *value) static int randr_set_temperature_for_crtc(randr_state_t *state, int crtc_num, int temp, - float gamma[3]) + float brightness, float gamma[3]) { xcb_generic_error_t *error; @@ -333,7 +333,7 @@ randr_set_temperature_for_crtc(randr_state_t *state, int crtc_num, int temp, uint16_t *gamma_b = &gamma_ramps[2*ramp_size]; colorramp_fill(gamma_r, gamma_g, gamma_b, ramp_size, - temp, gamma); + temp, brightness, gamma); /* Set new gamma ramps */ xcb_void_cookie_t gamma_set_cookie = @@ -355,7 +355,8 @@ randr_set_temperature_for_crtc(randr_state_t *state, int crtc_num, int temp, } int -randr_set_temperature(randr_state_t *state, int temp, float gamma[3]) +randr_set_temperature(randr_state_t *state, int temp, float brightness, + float gamma[3]) { int r; @@ -364,12 +365,13 @@ randr_set_temperature(randr_state_t *state, int temp, float gamma[3]) if (state->crtc_num < 0) { for (int i = 0; i < state->crtc_count; i++) { r = randr_set_temperature_for_crtc(state, i, - temp, gamma); + temp, brightness, + gamma); if (r < 0) return -1; } } else { return randr_set_temperature_for_crtc(state, state->crtc_num, - temp, gamma); + temp, brightness, gamma); } return 0; diff --git a/src/gamma-randr.h b/src/gamma-randr.h index 4ccad8f..11818fa 100644 --- a/src/gamma-randr.h +++ b/src/gamma-randr.h @@ -54,7 +54,8 @@ void randr_print_help(FILE *f); int randr_set_option(randr_state_t *state, const char *key, const char *value); void randr_restore(randr_state_t *state); -int randr_set_temperature(randr_state_t *state, int temp, float gamma[3]); +int randr_set_temperature(randr_state_t *state, int temp, float brightness, + float gamma[3]); #endif /* ! _REDSHIFT_GAMMA_RANDR_H */ diff --git a/src/gamma-vidmode.c b/src/gamma-vidmode.c index 7b891d8..a083658 100644 --- a/src/gamma-vidmode.c +++ b/src/gamma-vidmode.c @@ -169,7 +169,8 @@ vidmode_restore(vidmode_state_t *state) } int -vidmode_set_temperature(vidmode_state_t *state, int temp, float gamma[3]) +vidmode_set_temperature(vidmode_state_t *state, int temp, float brightness, + float gamma[3]) { int r; @@ -185,7 +186,7 @@ vidmode_set_temperature(vidmode_state_t *state, int temp, float gamma[3]) uint16_t *gamma_b = &gamma_ramps[2*state->ramp_size]; colorramp_fill(gamma_r, gamma_g, gamma_b, state->ramp_size, - temp, gamma); + temp, brightness, gamma); /* Set new gamma ramps */ r = XF86VidModeSetGammaRamp(state->display, state->screen_num, diff --git a/src/gamma-vidmode.h b/src/gamma-vidmode.h index 18a4a88..735ba1f 100644 --- a/src/gamma-vidmode.h +++ b/src/gamma-vidmode.h @@ -42,7 +42,8 @@ int vidmode_set_option(vidmode_state_t *state, const char *key, const char *value); void vidmode_restore(vidmode_state_t *state); -int vidmode_set_temperature(vidmode_state_t *state, int temp, float gamma[3]); +int vidmode_set_temperature(vidmode_state_t *state, int temp, float brightness, + float gamma[3]); #endif /* ! _REDSHIFT_GAMMA_VIDMODE_H */ diff --git a/src/gamma-w32gdi.c b/src/gamma-w32gdi.c index 7ea8f42..d23bf72 100644 --- a/src/gamma-w32gdi.c +++ b/src/gamma-w32gdi.c @@ -129,7 +129,8 @@ w32gdi_restore(w32gdi_state_t *state) } int -w32gdi_set_temperature(w32gdi_state_t *state, int temp, float gamma[3]) +w32gdi_set_temperature(w32gdi_state_t *state, int temp, float brightness, + float gamma[3]) { BOOL r; @@ -153,7 +154,7 @@ w32gdi_set_temperature(w32gdi_state_t *state, int temp, float gamma[3]) WORD *gamma_b = &gamma_ramps[2*GAMMA_RAMP_SIZE]; colorramp_fill(gamma_r, gamma_g, gamma_b, GAMMA_RAMP_SIZE, - temp, gamma); + temp, brightness, gamma); /* Set new gamma ramps */ r = SetDeviceGammaRamp(hDC, gamma_ramps); @@ -161,7 +162,7 @@ w32gdi_set_temperature(w32gdi_state_t *state, int temp, float gamma[3]) /* TODO it happens that SetDeviceGammaRamp returns FALSE on occasions where the adjustment seems to be successful. Does this only happen with multiple monitors connected? */ - fputs(_("Unable to set gamma ramps.\n"), stderr);s + fputs(_("Unable to set gamma ramps.\n"), stderr); free(gamma_ramps); ReleaseDC(NULL, hDC); return -1; diff --git a/src/gamma-w32gdi.h b/src/gamma-w32gdi.h index 9dc2657..57a604f 100644 --- a/src/gamma-w32gdi.h +++ b/src/gamma-w32gdi.h @@ -38,7 +38,8 @@ int w32gdi_set_option(w32gdi_state_t *state, const char *key, const char *value); void w32gdi_restore(w32gdi_state_t *state); -int w32gdi_set_temperature(w32gdi_state_t *state, int temp, float gamma[3]); +int w32gdi_set_temperature(w32gdi_state_t *state, int temp, float brightness, + float gamma[3]); #endif /* ! _REDSHIFT_GAMMA_W32GDI_H */ diff --git a/src/redshift.c b/src/redshift.c index ac191fc..0cff308 100644 --- a/src/redshift.c +++ b/src/redshift.c @@ -201,12 +201,15 @@ static const location_provider_t location_providers[] = { #define MAX_LON 180.0 #define MIN_TEMP 1000 #define MAX_TEMP 10000 +#define MIN_BRIGHTNESS 0.1 +#define MAX_BRIGHTNESS 1.0 #define MIN_GAMMA 0.1 #define MAX_GAMMA 10.0 /* Default values for parameters. */ #define DEFAULT_DAY_TEMP 5500 #define DEFAULT_NIGHT_TEMP 3700 +#define DEFAULT_BRIGHTNESS 1.0 #define DEFAULT_GAMMA 1.0 /* The color temperature when no adjustment is applied. */ @@ -610,6 +613,7 @@ main(int argc, char *argv[]) int temp_day = -1; int temp_night = -1; float gamma[3] = { NAN, NAN, NAN }; + float brightness = NAN; const gamma_method_t *method = NULL; char *method_args = NULL; @@ -624,8 +628,11 @@ main(int argc, char *argv[]) /* Parse command line arguments. */ int opt; - while ((opt = getopt(argc, argv, "c:g:hl:m:ort:vx")) != -1) { + while ((opt = getopt(argc, argv, "b:c:g:hl:m:ort:vx")) != -1) { switch (opt) { + case 'b': + brightness = atof(optarg); + break; case 'c': if (config_filepath != NULL) free(config_filepath); config_filepath = strdup(optarg); @@ -781,6 +788,11 @@ main(int argc, char *argv[]) if (transition < 0) { transition = !!atoi(setting->value); } + } else if (strcasecmp(setting->name, + "brightness") == 0) { + if (isnan(brightness)) { + brightness = atof(setting->value); + } } else if (strcasecmp(setting->name, "gamma") == 0) { if (isnan(gamma[0])) { r = parse_gamma_string(setting->value, @@ -833,6 +845,7 @@ main(int argc, char *argv[]) the config file nor on the command line. */ if (temp_day < 0) temp_day = DEFAULT_DAY_TEMP; if (temp_night < 0) temp_night = DEFAULT_NIGHT_TEMP; + if (isnan(brightness)) brightness = DEFAULT_BRIGHTNESS; if (isnan(gamma[0])) gamma[0] = gamma[1] = gamma[2] = DEFAULT_GAMMA; if (transition < 0) transition = 1; @@ -931,6 +944,18 @@ main(int argc, char *argv[]) exit(EXIT_FAILURE); } + /* Brightness */ + if (brightness < MIN_BRIGHTNESS || brightness > MAX_BRIGHTNESS) { + fprintf(stderr, + _("Brightness value must be between %.1f and %.1f.\n"), + MIN_BRIGHTNESS, MAX_BRIGHTNESS); + exit(EXIT_FAILURE); + } + + if (verbose) { + printf(_("Brightness: %.2f\n"), brightness); + } + /* Gamma */ if (gamma[0] < MIN_GAMMA || gamma[0] > MAX_GAMMA || gamma[1] < MIN_GAMMA || gamma[1] > MAX_GAMMA || @@ -1004,7 +1029,7 @@ main(int argc, char *argv[]) if (verbose) printf(_("Color temperature: %uK\n"), temp); /* Adjust temperature */ - r = method->set_temperature(&state, temp, gamma); + r = method->set_temperature(&state, temp, brightness, gamma); if (r < 0) { fputs(_("Temperature adjustment failed.\n"), stderr); method->free(&state); @@ -1015,7 +1040,7 @@ main(int argc, char *argv[]) case PROGRAM_MODE_RESET: { /* Reset screen */ - r = method->set_temperature(&state, NEUTRAL_TEMP, gamma); + r = method->set_temperature(&state, NEUTRAL_TEMP, 1.0, gamma); if (r < 0) { fputs(_("Temperature adjustment failed.\n"), stderr); method->free(&state); @@ -1179,7 +1204,8 @@ main(int argc, char *argv[]) /* Adjust temperature */ if (!disabled || short_trans) { r = method->set_temperature(&state, - temp, gamma); + temp, brightness, + gamma); if (r < 0) { fputs(_("Temperature adjustment" " failed.\n"), stderr); diff --git a/src/redshift.h b/src/redshift.h index 8f488f6..c3d1239 100644 --- a/src/redshift.h +++ b/src/redshift.h @@ -33,6 +33,7 @@ typedef int gamma_method_set_option_func(void *state, const char *key, const char *value); typedef void gamma_method_restore_func(void *state); typedef int gamma_method_set_temperature_func(void *state, int temp, + float brightness, float gamma[3]); typedef struct { |