From 4ac4d9ee2df567e26c374493d2407a894672faeb Mon Sep 17 00:00:00 2001 From: Jon Lund Steffensen Date: Sat, 27 Dec 2014 19:38:25 -0500 Subject: redshift: Move color settings into struct for period Move color settings (temperature, gamma and brightness) into a struct for each period (day, night). Change the interpolation function to interpolate all values between these structs. --- src/redshift.c | 189 ++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 119 insertions(+), 70 deletions(-) (limited to 'src/redshift.c') diff --git a/src/redshift.c b/src/redshift.c index 8fb2ddf..5f2598e 100644 --- a/src/redshift.c +++ b/src/redshift.c @@ -356,6 +356,29 @@ calculate_interpolated_value(double elevation, double day, double night) return result; } +/* Interpolate color setting structs based on solar elevation */ +static void +interpolate_color_settings(double elevation, + const color_setting_t *day, + const color_setting_t *night, + color_setting_t *result) +{ + result->temperature = + (int)calculate_interpolated_value(elevation, + day->temperature, + night->temperature); + result->brightness = + calculate_interpolated_value(elevation, + day->brightness, + night->brightness); + for (int i = 0; i < 3; i++) { + result->gamma[i] = + calculate_interpolated_value(elevation, + day->gamma[i], + night->gamma[i]); + } +} + static void print_help(const char *program_name) @@ -719,12 +742,21 @@ main(int argc, char *argv[]) /* Initialize settings to NULL values. */ char *config_filepath = NULL; + /* Settings for day and night. + Initialized to indicate that the values are not set yet. */ + color_setting_t day; + color_setting_t night; + + day.temperature = -1; + day.gamma[0] = NAN; + day.brightness = NAN; + + night.temperature = -1; + night.gamma[0] = NAN; + night.brightness = NAN; + + /* Temperature for manual mode */ int temp_set = -1; - int temp_day = -1; - int temp_night = -1; - float gamma[3] = { NAN, NAN, NAN }; - float brightness_day = NAN; - float brightness_night = NAN; const gamma_method_t *method = NULL; char *method_args = NULL; @@ -748,14 +780,15 @@ main(int argc, char *argv[]) while ((opt = getopt(argc, argv, "b:c:g:hl:m:oO:prt:vVx")) != -1) { switch (opt) { case 'b': - parse_brightness_string(optarg, &brightness_day, &brightness_night); + parse_brightness_string(optarg, &day.brightness, + &night.brightness); break; case 'c': if (config_filepath != NULL) free(config_filepath); config_filepath = strdup(optarg); break; case 'g': - r = parse_gamma_string(optarg, gamma); + r = parse_gamma_string(optarg, day.gamma); if (r < 0) { fputs(_("Malformed gamma argument.\n"), stderr); @@ -763,6 +796,9 @@ main(int argc, char *argv[]) " information.\n"), stderr); exit(EXIT_FAILURE); } + + /* Set night gamma to the same value as day gamma. */ + memcpy(night.gamma, day.gamma, sizeof(night.gamma)); break; case 'h': print_help(argv[0]); @@ -866,8 +902,8 @@ main(int argc, char *argv[]) exit(EXIT_FAILURE); } *(s++) = '\0'; - temp_day = atoi(optarg); - temp_night = atoi(s); + day.temperature = atoi(optarg); + night.temperature = atoi(s); break; case 'v': verbose = 1; @@ -903,13 +939,15 @@ main(int argc, char *argv[]) config_ini_setting_t *setting = section->settings; while (setting != NULL) { if (strcasecmp(setting->name, "temp-day") == 0) { - if (temp_day < 0) { - temp_day = atoi(setting->value); + if (day.temperature < 0) { + day.temperature = + atoi(setting->value); } } else if (strcasecmp(setting->name, "temp-night") == 0) { - if (temp_night < 0) { - temp_night = atoi(setting->value); + if (night.temperature < 0) { + night.temperature = + atoi(setting->value); } } else if (strcasecmp(setting->name, "transition") == 0) { @@ -918,21 +956,21 @@ main(int argc, char *argv[]) } } else if (strcasecmp(setting->name, "brightness") == 0) { - if (isnan(brightness_day)) { - brightness_day = atof(setting->value); + if (isnan(day.brightness)) { + day.brightness = atof(setting->value); } - if (isnan(brightness_night)) { - brightness_night = atof(setting->value); + if (isnan(night.brightness)) { + night.brightness = atof(setting->value); } } else if (strcasecmp(setting->name, "brightness-day") == 0) { - if (isnan(brightness_day)) { - brightness_day = atof(setting->value); + if (isnan(day.brightness)) { + day.brightness = atof(setting->value); } } else if (strcasecmp(setting->name, "brightness-night") == 0) { - if (isnan(brightness_night)) { - brightness_night = atof(setting->value); + if (isnan(night.brightness)) { + night.brightness = atof(setting->value); } } else if (strcasecmp(setting->name, "elevation-high") == 0) { @@ -941,15 +979,17 @@ main(int argc, char *argv[]) "elevation-low") == 0) { transition_low = atof(setting->value); } else if (strcasecmp(setting->name, "gamma") == 0) { - if (isnan(gamma[0])) { + if (isnan(day.gamma[0])) { r = parse_gamma_string(setting->value, - gamma); + day.gamma); if (r < 0) { fputs(_("Malformed gamma" " setting.\n"), stderr); exit(EXIT_FAILURE); } + memcpy(night.gamma, day.gamma, + sizeof(night.gamma)); } } else if (strcasecmp(setting->name, "adjustment-method") == 0) { @@ -990,11 +1030,19 @@ main(int argc, char *argv[]) /* Use default values for settings that were neither defined in 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_day)) brightness_day = DEFAULT_BRIGHTNESS; - if (isnan(brightness_night)) brightness_night = DEFAULT_BRIGHTNESS; - if (isnan(gamma[0])) gamma[0] = gamma[1] = gamma[2] = DEFAULT_GAMMA; + if (day.temperature < 0) day.temperature = DEFAULT_DAY_TEMP; + if (night.temperature < 0) night.temperature = DEFAULT_NIGHT_TEMP; + + if (isnan(day.brightness)) day.brightness = DEFAULT_BRIGHTNESS; + if (isnan(night.brightness)) night.brightness = DEFAULT_BRIGHTNESS; + + if (isnan(day.gamma[0])) { + day.gamma[0] = day.gamma[1] = day.gamma[2] = DEFAULT_GAMMA; + } + if (isnan(night.gamma[0])) { + night.gamma[0] = night.gamma[1] = night.gamma[2] = DEFAULT_GAMMA; + } + if (transition < 0) transition = 1; float lat = NAN; @@ -1060,7 +1108,7 @@ main(int argc, char *argv[]) fabs(lat), lat >= 0.f ? _("N") : _("S"), fabs(lon), lon >= 0.f ? _("E") : _("W")); printf(_("Temperatures: %dK at day, %dK at night\n"), - temp_day, temp_night); + day.temperature, night.temperature); /* TRANSLATORS: Append degree symbols if possible. */ printf(_("Solar elevations: day above %.1f, night below %.1f\n"), transition_high, transition_low); @@ -1084,16 +1132,11 @@ main(int argc, char *argv[]) exit(EXIT_FAILURE); } - /* Color temperature at daytime */ - if (temp_day < MIN_TEMP || temp_day > MAX_TEMP) { - fprintf(stderr, - _("Temperature must be between %uK and %uK.\n"), - MIN_TEMP, MAX_TEMP); - exit(EXIT_FAILURE); - } - - /* Color temperature at night */ - if (temp_night < MIN_TEMP || temp_night > MAX_TEMP) { + /* Color temperature */ + if (day.temperature < MIN_TEMP || + day.temperature > MAX_TEMP || + night.temperature < MIN_TEMP || + night.temperature > MAX_TEMP) { fprintf(stderr, _("Temperature must be between %uK and %uK.\n"), MIN_TEMP, MAX_TEMP); @@ -1120,10 +1163,10 @@ main(int argc, char *argv[]) } /* Brightness */ - if (brightness_day < MIN_BRIGHTNESS || - brightness_day > MAX_BRIGHTNESS || - brightness_night < MIN_BRIGHTNESS || - brightness_night > MAX_BRIGHTNESS) { + if (day.brightness < MIN_BRIGHTNESS || + day.brightness > MAX_BRIGHTNESS || + night.brightness < MIN_BRIGHTNESS || + night.brightness > MAX_BRIGHTNESS) { fprintf(stderr, _("Brightness values must be between %.1f and %.1f.\n"), MIN_BRIGHTNESS, MAX_BRIGHTNESS); @@ -1131,13 +1174,17 @@ main(int argc, char *argv[]) } if (verbose) { - printf(_("Brightness: %.2f:%.2f\n"), brightness_day, brightness_night); + printf(_("Brightness: %.2f:%.2f\n"), + day.brightness, night.brightness); } /* Gamma */ - if (gamma[0] < MIN_GAMMA || gamma[0] > MAX_GAMMA || - gamma[1] < MIN_GAMMA || gamma[1] > MAX_GAMMA || - gamma[2] < MIN_GAMMA || gamma[2] > MAX_GAMMA) { + if (day.gamma[0] < MIN_GAMMA || day.gamma[0] > MAX_GAMMA || + day.gamma[1] < MIN_GAMMA || day.gamma[1] > MAX_GAMMA || + day.gamma[2] < MIN_GAMMA || day.gamma[2] > MAX_GAMMA || + night.gamma[0] < MIN_GAMMA || night.gamma[0] > MAX_GAMMA || + night.gamma[1] < MIN_GAMMA || night.gamma[1] > MAX_GAMMA || + night.gamma[2] < MIN_GAMMA || night.gamma[2] > MAX_GAMMA) { fprintf(stderr, _("Gamma value must be between %.1f and %.1f.\n"), MIN_GAMMA, MAX_GAMMA); @@ -1145,8 +1192,10 @@ main(int argc, char *argv[]) } if (verbose) { - printf(_("Gamma: %.3f, %.3f, %.3f\n"), - gamma[0], gamma[1], gamma[2]); + printf(_("Gamma (%s): %.3f, %.3f, %.3f\n"), + "Day", day.gamma[0], day.gamma[1], day.gamma[2]); + printf(_("Gamma (%s): %.3f, %.3f, %.3f\n"), + "Night", night.gamma[0], night.gamma[1], night.gamma[2]); } /* Initialize gamma adjustment method. If method is NULL @@ -1209,15 +1258,13 @@ main(int argc, char *argv[]) } /* Use elevation of sun to set color temperature */ - int temp = (int)calculate_interpolated_value(elevation, - temp_day, temp_night); - float brightness = calculate_interpolated_value(elevation, - brightness_day, brightness_night); + color_setting_t interp; + interpolate_color_settings(elevation, &day, &night, &interp); if (verbose || mode == PROGRAM_MODE_PRINT) { print_period(elevation); - printf(_("Color temperature: %uK\n"), temp); - printf(_("Brightness: %.2f\n"), brightness); + printf(_("Color temperature: %uK\n"), interp.temperature); + printf(_("Brightness: %.2f\n"), interp.brightness); } if (mode == PROGRAM_MODE_PRINT) { @@ -1225,7 +1272,8 @@ main(int argc, char *argv[]) } /* Adjust temperature */ - r = method->set_temperature(&state, temp, brightness, gamma); + r = method->set_temperature(&state, interp.temperature, + interp.brightness, interp.gamma); if (r < 0) { fputs(_("Temperature adjustment failed.\n"), stderr); method->free(&state); @@ -1238,7 +1286,8 @@ main(int argc, char *argv[]) if (verbose) printf(_("Color temperature: %uK\n"), temp_set); /* Adjust temperature */ - r = method->set_temperature(&state, temp_set, brightness_day, gamma); + r = method->set_temperature(&state, temp_set, day.brightness, + day.gamma); if (r < 0) { fputs(_("Temperature adjustment failed.\n"), stderr); method->free(&state); @@ -1250,7 +1299,8 @@ main(int argc, char *argv[]) case PROGRAM_MODE_RESET: { /* Reset screen */ - r = method->set_temperature(&state, NEUTRAL_TEMP, 1.0, gamma); + r = method->set_temperature(&state, NEUTRAL_TEMP, 1.0, + day.gamma); if (r < 0) { fputs(_("Temperature adjustment failed.\n"), stderr); method->free(&state); @@ -1359,10 +1409,8 @@ main(int argc, char *argv[]) double elevation = solar_elevation(now, lat, lon); /* Use elevation of sun to set color temperature */ - int temp = (int)calculate_interpolated_value(elevation, - temp_day, temp_night); - float brightness = calculate_interpolated_value(elevation, - brightness_day, brightness_night); + color_setting_t interp; + interpolate_color_settings(elevation, &day, &night, &interp); if (verbose) print_period(elevation); @@ -1385,25 +1433,26 @@ main(int argc, char *argv[]) /* Interpolate between 6500K and calculated temperature */ - temp = adjustment_alpha*6500 + - (1.0-adjustment_alpha)*temp; + interp.temperature = adjustment_alpha*6500 + + (1.0-adjustment_alpha)*interp.temperature; - brightness = adjustment_alpha*1.0 + - (1.0-adjustment_alpha)*brightness; + interp.brightness = adjustment_alpha*1.0 + + (1.0-adjustment_alpha)*interp.brightness; /* Quit loop when done */ if (done && !short_trans_delta) break; if (verbose) { - printf(_("Color temperature: %uK\n"), temp); - printf(_("Brightness: %.2f\n"), brightness); + printf(_("Color temperature: %uK\n"), interp.temperature); + printf(_("Brightness: %.2f\n"), interp.brightness); } /* Adjust temperature */ if (!disabled || short_trans_delta || set_adjustments) { r = method->set_temperature(&state, - temp, brightness, - gamma); + interp.temperature, + interp.brightness, + interp.gamma); if (r < 0) { fputs(_("Temperature adjustment" " failed.\n"), stderr); -- cgit v1.2.3-70-g09d2 From a4052e2a7b7859db9435056c51b799b9dbf61f58 Mon Sep 17 00:00:00 2001 From: Jon Lund Steffensen Date: Sat, 27 Dec 2014 19:40:49 -0500 Subject: redshift: Add config setting to set gamma separately for day/night These settings are gamma-day and gamma-night. The setting gamma will still override both the daytime and nighttime gamma setting. --- src/redshift.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/redshift.c') diff --git a/src/redshift.c b/src/redshift.c index 5f2598e..a19fe5c 100644 --- a/src/redshift.c +++ b/src/redshift.c @@ -797,7 +797,9 @@ main(int argc, char *argv[]) exit(EXIT_FAILURE); } - /* Set night gamma to the same value as day gamma. */ + /* Set night gamma to the same value as day gamma. + To set these to distinct values use the config + file. */ memcpy(night.gamma, day.gamma, sizeof(night.gamma)); break; case 'h': @@ -991,6 +993,28 @@ main(int argc, char *argv[]) memcpy(night.gamma, day.gamma, sizeof(night.gamma)); } + } else if (strcasecmp(setting->name, "gamma-day") == 0) { + if (isnan(day.gamma[0])) { + r = parse_gamma_string(setting->value, + day.gamma); + if (r < 0) { + fputs(_("Malformed gamma" + " setting.\n"), + stderr); + exit(EXIT_FAILURE); + } + } + } else if (strcasecmp(setting->name, "gamma-night") == 0) { + if (isnan(night.gamma[0])) { + r = parse_gamma_string(setting->value, + night.gamma); + if (r < 0) { + fputs(_("Malformed gamma" + " setting.\n"), + stderr); + exit(EXIT_FAILURE); + } + } } else if (strcasecmp(setting->name, "adjustment-method") == 0) { if (method == NULL) { -- cgit v1.2.3-70-g09d2 From ec5aa19acf1b768586688dd7c82ee0d64d314b40 Mon Sep 17 00:00:00 2001 From: Jon Lund Steffensen Date: Sat, 27 Dec 2014 20:22:04 -0500 Subject: redshift: Simplify set_temperature by passing color_setting_t Changes all set_temperature function in gamma adjustment methods to take a color_setting_t pointer with the color settings. Colorramp functions are similarly changed to take a color settings struct. --- src/colorramp.c | 17 +++++++++-------- src/colorramp.h | 7 ++++--- src/gamma-drm.c | 4 ++-- src/gamma-drm.h | 5 ++++- src/gamma-dummy.c | 9 +++++---- src/gamma-dummy.h | 6 +++--- src/gamma-quartz.c | 13 ++++++------- src/gamma-quartz.h | 4 ++-- src/gamma-randr.c | 18 +++++++++--------- src/gamma-randr.h | 6 +++--- src/gamma-vidmode.c | 9 +++++---- src/gamma-vidmode.h | 8 +++++--- src/gamma-w32gdi.c | 8 ++++---- src/gamma-w32gdi.h | 8 +++++--- src/redshift.c | 18 ++++++++---------- src/redshift.h | 7 +++---- 16 files changed, 77 insertions(+), 70 deletions(-) (limited to 'src/redshift.c') diff --git a/src/colorramp.c b/src/colorramp.c index 3521195..d732a18 100644 --- a/src/colorramp.c +++ b/src/colorramp.c @@ -21,6 +21,7 @@ #include #include +#include "redshift.h" /* Whitepoint values for temperatures at 100K intervals. These will be interpolated for the actual temperature. @@ -281,16 +282,17 @@ interpolate_color(float a, const float *c1, const float *c2, float *c) } /* Helper macro used in the fill functions */ -#define F(Y, C) pow((Y) * brightness * white_point[C], 1.0/gamma[C]) +#define F(Y, C) pow((Y) * setting->brightness * \ + white_point[C], 1.0/setting->gamma[C]) void colorramp_fill(uint16_t *gamma_r, uint16_t *gamma_g, uint16_t *gamma_b, - int size, int temp, float brightness, const float gamma[3]) + int size, const color_setting_t *setting) { /* Approximate white point */ float white_point[3]; - float alpha = (temp % 100) / 100.0; - int temp_index = ((temp - 1000) / 100)*3; + float alpha = (setting->temperature % 100) / 100.0; + int temp_index = ((setting->temperature - 1000) / 100)*3; interpolate_color(alpha, &blackbody_color[temp_index], &blackbody_color[temp_index+3], white_point); @@ -303,13 +305,12 @@ colorramp_fill(uint16_t *gamma_r, uint16_t *gamma_g, uint16_t *gamma_b, void colorramp_fill_float(float *gamma_r, float *gamma_g, float *gamma_b, - int size, int temp, float brightness, - const float gamma[3]) + int size, const color_setting_t *setting) { /* Approximate white point */ float white_point[3]; - float alpha = (temp % 100) / 100.0; - int temp_index = ((temp - 1000) / 100)*3; + float alpha = (setting->temperature % 100) / 100.0; + int temp_index = ((setting->temperature - 1000) / 100)*3; interpolate_color(alpha, &blackbody_color[temp_index], &blackbody_color[temp_index+3], white_point); diff --git a/src/colorramp.h b/src/colorramp.h index f8df478..438c563 100644 --- a/src/colorramp.h +++ b/src/colorramp.h @@ -22,10 +22,11 @@ #include +#include "redshift.h" + void colorramp_fill(uint16_t *gamma_r, uint16_t *gamma_g, uint16_t *gamma_b, - int size, int temp, float brightness, const float gamma[3]); + int size, const color_setting_t *setting); void colorramp_fill_float(float *gamma_r, float *gamma_g, float *gamma_b, - int size, int temp, float brightness, - const float gamma[3]); + int size, const color_setting_t *setting); #endif /* ! REDSHIFT_COLORRAMP_H */ diff --git a/src/gamma-drm.c b/src/gamma-drm.c index e784b47..cbdafe5 100644 --- a/src/gamma-drm.c +++ b/src/gamma-drm.c @@ -241,7 +241,7 @@ drm_set_option(drm_state_t *state, const char *key, const char *value) } int -drm_set_temperature(drm_state_t *state, int temp, float brightness, const float gamma[3]) +drm_set_temperature(drm_state_t *state, const color_setting_t *setting) { drm_crtc_state_t *crtcs = state->crtcs; int last_gamma_size = 0; @@ -269,7 +269,7 @@ drm_set_temperature(drm_state_t *state, int temp, float brightness, const float last_gamma_size = crtcs->gamma_size; } colorramp_fill(r_gamma, g_gamma, b_gamma, crtcs->gamma_size, - temp, brightness, gamma); + setting); drmModeCrtcSetGamma(state->fd, crtcs->crtc_id, crtcs->gamma_size, r_gamma, g_gamma, b_gamma); } diff --git a/src/gamma-drm.h b/src/gamma-drm.h index f4c0df5..ae97d00 100644 --- a/src/gamma-drm.h +++ b/src/gamma-drm.h @@ -25,6 +25,8 @@ #include #include +#include "redshift.h" + typedef struct { int crtc_num; @@ -52,7 +54,8 @@ void drm_print_help(FILE *f); int drm_set_option(drm_state_t *state, const char *key, const char *value); void drm_restore(drm_state_t *state); -int drm_set_temperature(drm_state_t *state, int temp, float brightness, const float gamma[3]); +int drm_set_temperature(drm_state_t *state, + const color_setting_t *setting); #endif /* ! REDSHIFT_GAMMA_DRM_H */ diff --git a/src/gamma-dummy.c b/src/gamma-dummy.c index 0ebb12d..ba62d93 100644 --- a/src/gamma-dummy.c +++ b/src/gamma-dummy.c @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with Redshift. If not, see . - Copyright (c) 2013 Jon Lund Steffensen + Copyright (c) 2013-2014 Jon Lund Steffensen */ #include @@ -27,6 +27,8 @@ # define _(s) s #endif +#include "redshift.h" + int gamma_dummy_init(void *state) @@ -66,9 +68,8 @@ gamma_dummy_set_option(void *state, const char *key, const char *value) } int -gamma_dummy_set_temperature(void *state, int temp, float brightness, - const float gamma[3]) +gamma_dummy_set_temperature(void *state, const color_setting_t *setting) { - printf(_("Temperature: %i\n"), temp); + printf(_("Temperature: %i\n"), setting->temperature); return 0; } diff --git a/src/gamma-dummy.h b/src/gamma-dummy.h index 64bc40d..3e58ec1 100644 --- a/src/gamma-dummy.h +++ b/src/gamma-dummy.h @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with Redshift. If not, see . - Copyright (c) 2013 Jon Lund Steffensen + Copyright (c) 2013-2014 Jon Lund Steffensen */ #ifndef REDSHIFT_GAMMA_DUMMY_H @@ -31,8 +31,8 @@ void gamma_dummy_print_help(FILE *f); int gamma_dummy_set_option(void *state, const char *key, const char *value); void gamma_dummy_restore(void *state); -int gamma_dummy_set_temperature(void *state, int temp, float brightness, - const float gamma[3]); +int gamma_dummy_set_temperature(void *state, + const color_setting_t *setting); #endif /* ! REDSHIFT_GAMMA_DUMMY_H */ diff --git a/src/gamma-quartz.c b/src/gamma-quartz.c index 2f439da..f28955f 100644 --- a/src/gamma-quartz.c +++ b/src/gamma-quartz.c @@ -75,8 +75,8 @@ quartz_set_option(quartz_state_t *state, const char *key, const char *value) } static void -quartz_set_temperature_for_display(CGDirectDisplayID display, int temp, - float brightness, const float gamma[3]) +quartz_set_temperature_for_display(CGDirectDisplayID display, + const color_setting_t *setting) { uint32_t ramp_size = CGDisplayGammaTableCapacity(display); if (ramp_size == 0) { @@ -97,7 +97,7 @@ quartz_set_temperature_for_display(CGDirectDisplayID display, int temp, float *gamma_b = &gamma_ramps[2*ramp_size]; colorramp_fill_float(gamma_r, gamma_g, gamma_b, ramp_size, - temp, brightness, gamma); + setting); CGError error = CGSetDisplayTransferByTable(display, ramp_size, @@ -111,8 +111,8 @@ quartz_set_temperature_for_display(CGDirectDisplayID display, int temp, } int -quartz_set_temperature(quartz_state_t *state, int temp, float brightness, - const float gamma[3]) +quartz_set_temperature(quartz_state_t *state, + const color_setting_t *setting) { int r; CGError error; @@ -136,8 +136,7 @@ quartz_set_temperature(quartz_state_t *state, int temp, float brightness, } for (int i = 0; i < display_count; i++) { - quartz_set_temperature_for_display(displays[i], temp, - brightness, gamma); + quartz_set_temperature_for_display(displays[i], setting); } free(displays); diff --git a/src/gamma-quartz.h b/src/gamma-quartz.h index c8bfef7..b5bc213 100644 --- a/src/gamma-quartz.h +++ b/src/gamma-quartz.h @@ -37,8 +37,8 @@ int quartz_set_option(quartz_state_t *state, const char *key, const char *value); void quartz_restore(quartz_state_t *state); -int quartz_set_temperature(quartz_state_t *state, int temp, float brightness, - const float gamma[3]); +int quartz_set_temperature(quartz_state_t *state, + const color_setting_t *setting); #endif /* ! REDSHIFT_GAMMA_QUARTZ_H */ diff --git a/src/gamma-randr.c b/src/gamma-randr.c index 9e528b5..4f6b0f0 100644 --- a/src/gamma-randr.c +++ b/src/gamma-randr.c @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with Redshift. If not, see . - Copyright (c) 2010 Jon Lund Steffensen + Copyright (c) 2010-2014 Jon Lund Steffensen */ #include @@ -33,6 +33,7 @@ #include #include "gamma-randr.h" +#include "redshift.h" #include "colorramp.h" @@ -294,8 +295,8 @@ 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 brightness, const float gamma[3]) +randr_set_temperature_for_crtc(randr_state_t *state, int crtc_num, + const color_setting_t *setting) { xcb_generic_error_t *error; @@ -327,7 +328,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, brightness, gamma); + setting); /* Set new gamma ramps */ xcb_void_cookie_t gamma_set_cookie = @@ -349,8 +350,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 brightness, - const float gamma[3]) +randr_set_temperature(randr_state_t *state, + const color_setting_t *setting) { int r; @@ -359,13 +360,12 @@ randr_set_temperature(randr_state_t *state, int temp, float brightness, if (state->crtc_num < 0) { for (int i = 0; i < state->crtc_count; i++) { r = randr_set_temperature_for_crtc(state, i, - temp, brightness, - gamma); + setting); if (r < 0) return -1; } } else { return randr_set_temperature_for_crtc(state, state->crtc_num, - temp, brightness, gamma); + setting); } return 0; diff --git a/src/gamma-randr.h b/src/gamma-randr.h index cef0021..e541379 100644 --- a/src/gamma-randr.h +++ b/src/gamma-randr.h @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with Redshift. If not, see . - Copyright (c) 2010 Jon Lund Steffensen + Copyright (c) 2010-2014 Jon Lund Steffensen */ #ifndef REDSHIFT_GAMMA_RANDR_H @@ -54,8 +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 brightness, - const float gamma[3]); +int randr_set_temperature(randr_state_t *state, + const color_setting_t *setting); #endif /* ! REDSHIFT_GAMMA_RANDR_H */ diff --git a/src/gamma-vidmode.c b/src/gamma-vidmode.c index 656ce00..58a552f 100644 --- a/src/gamma-vidmode.c +++ b/src/gamma-vidmode.c @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with Redshift. If not, see . - Copyright (c) 2010 Jon Lund Steffensen + Copyright (c) 2010-2014 Jon Lund Steffensen */ #include @@ -33,6 +33,7 @@ #include #include "gamma-vidmode.h" +#include "redshift.h" #include "colorramp.h" @@ -163,8 +164,8 @@ vidmode_restore(vidmode_state_t *state) } int -vidmode_set_temperature(vidmode_state_t *state, int temp, float brightness, - const float gamma[3]) +vidmode_set_temperature(vidmode_state_t *state, + const color_setting_t *setting) { int r; @@ -180,7 +181,7 @@ vidmode_set_temperature(vidmode_state_t *state, int temp, float brightness, uint16_t *gamma_b = &gamma_ramps[2*state->ramp_size]; colorramp_fill(gamma_r, gamma_g, gamma_b, state->ramp_size, - temp, brightness, gamma); + setting); /* Set new gamma ramps */ r = XF86VidModeSetGammaRamp(state->display, state->screen_num, diff --git a/src/gamma-vidmode.h b/src/gamma-vidmode.h index 8afd8fd..05f5919 100644 --- a/src/gamma-vidmode.h +++ b/src/gamma-vidmode.h @@ -14,12 +14,14 @@ You should have received a copy of the GNU General Public License along with Redshift. If not, see . - Copyright (c) 2010 Jon Lund Steffensen + Copyright (c) 2010-2014 Jon Lund Steffensen */ #ifndef REDSHIFT_GAMMA_VIDMODE_H #define REDSHIFT_GAMMA_VIDMODE_H +#include "redshift.h" + #include #include @@ -42,8 +44,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 brightness, - const float gamma[3]); +int vidmode_set_temperature(vidmode_state_t *state, + const color_setting_t *setting); #endif /* ! REDSHIFT_GAMMA_VIDMODE_H */ diff --git a/src/gamma-w32gdi.c b/src/gamma-w32gdi.c index 7193bc9..ee603e6 100644 --- a/src/gamma-w32gdi.c +++ b/src/gamma-w32gdi.c @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with Redshift. If not, see . - Copyright (c) 2010 Jon Lund Steffensen + Copyright (c) 2010-2014 Jon Lund Steffensen */ #include @@ -129,8 +129,8 @@ w32gdi_restore(w32gdi_state_t *state) } int -w32gdi_set_temperature(w32gdi_state_t *state, int temp, float brightness, - const float gamma[3]) +w32gdi_set_temperature(w32gdi_state_t *state, + const color_setting_t *setting) { BOOL r; @@ -154,7 +154,7 @@ w32gdi_set_temperature(w32gdi_state_t *state, int temp, float brightness, WORD *gamma_b = &gamma_ramps[2*GAMMA_RAMP_SIZE]; colorramp_fill(gamma_r, gamma_g, gamma_b, GAMMA_RAMP_SIZE, - temp, brightness, gamma); + setting); /* Set new gamma ramps */ r = SetDeviceGammaRamp(hDC, gamma_ramps); diff --git a/src/gamma-w32gdi.h b/src/gamma-w32gdi.h index e81f4c5..1f985c8 100644 --- a/src/gamma-w32gdi.h +++ b/src/gamma-w32gdi.h @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with Redshift. If not, see . - Copyright (c) 2010 Jon Lund Steffensen + Copyright (c) 2010-2014 Jon Lund Steffensen */ #ifndef REDSHIFT_GAMMA_W32GDI_H @@ -23,6 +23,8 @@ #include #include +#include "redshift.h" + typedef struct { WORD *saved_ramps; @@ -38,8 +40,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 brightness, - const float gamma[3]); +int w32gdi_set_temperature(w32gdi_state_t *state, + const color_setting_t *color); #endif /* ! REDSHIFT_GAMMA_W32GDI_H */ diff --git a/src/redshift.c b/src/redshift.c index a19fe5c..f8c0d30 100644 --- a/src/redshift.c +++ b/src/redshift.c @@ -1296,8 +1296,7 @@ main(int argc, char *argv[]) } /* Adjust temperature */ - r = method->set_temperature(&state, interp.temperature, - interp.brightness, interp.gamma); + r = method->set_temperature(&state, &interp); if (r < 0) { fputs(_("Temperature adjustment failed.\n"), stderr); method->free(&state); @@ -1310,8 +1309,10 @@ main(int argc, char *argv[]) if (verbose) printf(_("Color temperature: %uK\n"), temp_set); /* Adjust temperature */ - r = method->set_temperature(&state, temp_set, day.brightness, - day.gamma); + color_setting_t manual; + memcpy(&manual, &day, sizeof(color_setting_t)); + manual.temperature = temp_set; + r = method->set_temperature(&state, &manual); if (r < 0) { fputs(_("Temperature adjustment failed.\n"), stderr); method->free(&state); @@ -1323,8 +1324,8 @@ main(int argc, char *argv[]) case PROGRAM_MODE_RESET: { /* Reset screen */ - r = method->set_temperature(&state, NEUTRAL_TEMP, 1.0, - day.gamma); + color_setting_t reset = { NEUTRAL_TEMP, { 1.0, 1.0, 1.0 }, 1.0 }; + r = method->set_temperature(&state, &reset); if (r < 0) { fputs(_("Temperature adjustment failed.\n"), stderr); method->free(&state); @@ -1473,10 +1474,7 @@ main(int argc, char *argv[]) /* Adjust temperature */ if (!disabled || short_trans_delta || set_adjustments) { - r = method->set_temperature(&state, - interp.temperature, - interp.brightness, - interp.gamma); + r = method->set_temperature(&state, &interp); if (r < 0) { fputs(_("Temperature adjustment" " failed.\n"), stderr); diff --git a/src/redshift.h b/src/redshift.h index 7e38c42..e8be4e6 100644 --- a/src/redshift.h +++ b/src/redshift.h @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with Redshift. If not, see . - Copyright (c) 2013 Jon Lund Steffensen + Copyright (c) 2013-2014 Jon Lund Steffensen */ #ifndef REDSHIFT_REDSHIFT_H @@ -40,9 +40,8 @@ typedef void gamma_method_print_help_func(FILE *f); 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, - const float gamma[3]); +typedef int gamma_method_set_temperature_func(void *state, + const color_setting_t *setting); typedef struct { char *name; -- cgit v1.2.3-70-g09d2