diff options
author | Jon Lund Steffensen <jonlst@gmail.com> | 2009-11-04 22:25:26 +0100 |
---|---|---|
committer | Jon Lund Steffensen <jonlst@gmail.com> | 2009-11-04 22:25:26 +0100 |
commit | 485c19ef3080c1492130f7032dbc8ee907a9a582 (patch) | |
tree | e5e88a0a65bb5aeca21faa8a6e3792e71989575e | |
parent | Make transition period a bit shorter. (diff) | |
download | redshift-ng-485c19ef3080c1492130f7032dbc8ee907a9a582.tar.gz redshift-ng-485c19ef3080c1492130f7032dbc8ee907a9a582.tar.bz2 redshift-ng-485c19ef3080c1492130f7032dbc8ee907a9a582.tar.xz |
Allow individual adjustment of each gamma channel.
-rw-r--r-- | colortemp.c | 8 | ||||
-rw-r--r-- | colortemp.h | 2 | ||||
-rw-r--r-- | redshift.c | 33 |
3 files changed, 33 insertions, 10 deletions
diff --git a/colortemp.c b/colortemp.c index c2ed83d..f0c5a19 100644 --- a/colortemp.c +++ b/colortemp.c @@ -153,7 +153,7 @@ colortemp_check_extension() } int -colortemp_set_temperature(int temp, float gamma) +colortemp_set_temperature(int temp, float gamma[3]) { xcb_generic_error_t *error; @@ -226,11 +226,11 @@ colortemp_set_temperature(int temp, float gamma) uint16_t *gamma_b = &gamma_ramps[2*gamma_ramp_size]; for (int i = 0; i < gamma_ramp_size; i++) { - gamma_r[i] = pow((float)i/gamma_ramp_size, 1.0/gamma) * + gamma_r[i] = pow((float)i/gamma_ramp_size, 1.0/gamma[0]) * UINT16_MAX * white_point[0]; - gamma_g[i] = pow((float)i/gamma_ramp_size, 1.0/gamma) * + gamma_g[i] = pow((float)i/gamma_ramp_size, 1.0/gamma[1]) * UINT16_MAX * white_point[1]; - gamma_b[i] = pow((float)i/gamma_ramp_size, 1.0/gamma) * + gamma_b[i] = pow((float)i/gamma_ramp_size, 1.0/gamma[2]) * UINT16_MAX * white_point[2]; } diff --git a/colortemp.h b/colortemp.h index d2e9630..fae5947 100644 --- a/colortemp.h +++ b/colortemp.h @@ -4,6 +4,6 @@ #define _COLORTEMP_H int colortemp_check_extension(); -int colortemp_set_temperature(int temp, float gamma); +int colortemp_set_temperature(int temp, float gamma[3]); #endif /* ! _COLORTEMP_H */ @@ -41,10 +41,10 @@ #define HELP \ USAGE \ " Set color temperature of display according to time of day.\n" \ - " -g GAMMA\tAdditional gamma correction to apply\n" \ + " -g R:G:B\tAdditional gamma correction to apply\n" \ " -h\t\tDisplay this help message\n" \ " -l LAT:LON\tYour current location\n" \ - " -t DAY:NIGHT\tColor temperature to set at night/day\n" \ + " -t DAY:NIGHT\tColor temperature to set at daytime/night\n" \ " -v\t\tVerbose output\n" /* DEGREE SIGN is Unicode U+00b0 */ @@ -74,7 +74,7 @@ main(int argc, char *argv[]) float lon = NAN; int temp_day = DEFAULT_DAY_TEMP; int temp_night = DEFAULT_NIGHT_TEMP; - float gamma = DEFAULT_GAMMA; + float gamma[3] = { DEFAULT_GAMMA, DEFAULT_GAMMA, DEFAULT_GAMMA }; int verbose = 0; char *s; @@ -82,7 +82,26 @@ main(int argc, char *argv[]) while ((opt = getopt(argc, argv, "g:hl:t:v")) != -1) { switch (opt) { case 'g': - gamma = atof(optarg); + s = strchr(optarg, ':'); + if (s == NULL) { + /* Use value for all channels */ + float g = atof(optarg); + gamma[0] = gamma[1] = gamma[2] = g; + } else { + /* Parse separate value for each channel */ + *(s++) = '\0'; + gamma[0] = atof(optarg); /* Red */ + char *g_s = s; + s = strchr(s, ':'); + if (s == NULL) { + fprintf(stderr, USAGE, argv[0]); + exit(EXIT_FAILURE); + } + + *(s++) = '\0'; + gamma[1] = atof(g_s); /* Blue */ + gamma[2] = atof(s); /* Green */ + } break; case 'h': printf(HELP, argv[0]); @@ -160,7 +179,9 @@ main(int argc, char *argv[]) } /* Gamma */ - if (gamma < MIN_GAMMA || gamma > MAX_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) { fprintf(stderr, "Gamma value must be between %.1f and %.1f.\n", MIN_GAMMA, MAX_GAMMA); exit(EXIT_FAILURE); @@ -194,6 +215,8 @@ main(int argc, char *argv[]) if (verbose) { printf("Color temperature: %uK\n", temp); + printf("Gamma: %.3f, %.3f, %.3f\n", + gamma[0], gamma[1], gamma[2]); } /* Set color temperature */ |