Allow brightness to be adjusted (between 10% and 100%, the latter being the default).
This commit is contained in:
+4
-4
@@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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 */
|
||||
|
||||
+7
-5
@@ -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;
|
||||
|
||||
+2
-1
@@ -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 */
|
||||
|
||||
+3
-2
@@ -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,
|
||||
|
||||
+2
-1
@@ -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 */
|
||||
|
||||
+4
-3
@@ -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;
|
||||
|
||||
+2
-1
@@ -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 */
|
||||
|
||||
+30
-4
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user