|
41 | 41 | #define HELP \
|
42 | 42 | USAGE \
|
43 | 43 | " Set color temperature of display according to time of day.\n" \
|
44 |
| - " -g GAMMA\tAdditional gamma correction to apply\n" \ |
| 44 | + " -g R:G:B\tAdditional gamma correction to apply\n" \ |
45 | 45 | " -h\t\tDisplay this help message\n" \
|
46 | 46 | " -l LAT:LON\tYour current location\n" \
|
47 |
| - " -t DAY:NIGHT\tColor temperature to set at night/day\n" \ |
| 47 | + " -t DAY:NIGHT\tColor temperature to set at daytime/night\n" \ |
48 | 48 | " -v\t\tVerbose output\n"
|
49 | 49 |
|
50 | 50 | /* DEGREE SIGN is Unicode U+00b0 */
|
@@ -74,15 +74,34 @@ main(int argc, char *argv[])
|
74 | 74 | float lon = NAN;
|
75 | 75 | int temp_day = DEFAULT_DAY_TEMP;
|
76 | 76 | int temp_night = DEFAULT_NIGHT_TEMP;
|
77 |
| - float gamma = DEFAULT_GAMMA; |
| 77 | + float gamma[3] = { DEFAULT_GAMMA, DEFAULT_GAMMA, DEFAULT_GAMMA }; |
78 | 78 | int verbose = 0;
|
79 | 79 | char *s;
|
80 | 80 |
|
81 | 81 | int opt;
|
82 | 82 | while ((opt = getopt(argc, argv, "g:hl:t:v")) != -1) {
|
83 | 83 | switch (opt) {
|
84 | 84 | case 'g':
|
85 |
| - gamma = atof(optarg); |
| 85 | + s = strchr(optarg, ':'); |
| 86 | + if (s == NULL) { |
| 87 | + /* Use value for all channels */ |
| 88 | + float g = atof(optarg); |
| 89 | + gamma[0] = gamma[1] = gamma[2] = g; |
| 90 | + } else { |
| 91 | + /* Parse separate value for each channel */ |
| 92 | + *(s++) = '\0'; |
| 93 | + gamma[0] = atof(optarg); /* Red */ |
| 94 | + char *g_s = s; |
| 95 | + s = strchr(s, ':'); |
| 96 | + if (s == NULL) { |
| 97 | + fprintf(stderr, USAGE, argv[0]); |
| 98 | + exit(EXIT_FAILURE); |
| 99 | + } |
| 100 | + |
| 101 | + *(s++) = '\0'; |
| 102 | + gamma[1] = atof(g_s); /* Blue */ |
| 103 | + gamma[2] = atof(s); /* Green */ |
| 104 | + } |
86 | 105 | break;
|
87 | 106 | case 'h':
|
88 | 107 | printf(HELP, argv[0]);
|
@@ -160,7 +179,9 @@ main(int argc, char *argv[])
|
160 | 179 | }
|
161 | 180 |
|
162 | 181 | /* Gamma */
|
163 |
| - if (gamma < MIN_GAMMA || gamma > MAX_GAMMA) { |
| 182 | + if (gamma[0] < MIN_GAMMA || gamma[0] > MAX_GAMMA || |
| 183 | + gamma[1] < MIN_GAMMA || gamma[1] > MAX_GAMMA || |
| 184 | + gamma[2] < MIN_GAMMA || gamma[2] > MAX_GAMMA) { |
164 | 185 | fprintf(stderr, "Gamma value must be between %.1f and %.1f.\n",
|
165 | 186 | MIN_GAMMA, MAX_GAMMA);
|
166 | 187 | exit(EXIT_FAILURE);
|
@@ -194,6 +215,8 @@ main(int argc, char *argv[])
|
194 | 215 |
|
195 | 216 | if (verbose) {
|
196 | 217 | printf("Color temperature: %uK\n", temp);
|
| 218 | + printf("Gamma: %.3f, %.3f, %.3f\n", |
| 219 | + gamma[0], gamma[1], gamma[2]); |
197 | 220 | }
|
198 | 221 |
|
199 | 222 | /* Set color temperature */
|
|
0 commit comments