From 017fc230be20bf3be605559fcb4cadccaa89b098 Mon Sep 17 00:00:00 2001 From: Jon Lund Steffensen Date: Wed, 31 Dec 2014 01:17:50 -0500 Subject: redshift: Add gamma_is_valid function to check gamma This checks whether the gamma values are within the bounds of MIN_GAMMA and MAX_GAMMA. --- src/redshift.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'src/redshift.c') diff --git a/src/redshift.c b/src/redshift.c index b35e9d4..b45507f 100644 --- a/src/redshift.c +++ b/src/redshift.c @@ -731,6 +731,19 @@ parse_brightness_string(const char *str, float *bright_day, float *bright_night) } } +/* Check whether gamma is within allowed levels. */ +static int +gamma_is_valid(const float gamma[3]) +{ + return !(gamma[0] < MIN_GAMMA || + gamma[0] > MAX_GAMMA || + gamma[1] < MIN_GAMMA || + gamma[1] > MAX_GAMMA || + gamma[2] < MIN_GAMMA || + gamma[2] > MAX_GAMMA); + +} + static const gamma_method_t * find_gamma_method(const char *name) { @@ -1511,18 +1524,8 @@ main(int argc, char *argv[]) } /* Gamma */ - if (scheme.day.gamma[0] < MIN_GAMMA || - scheme.day.gamma[0] > MAX_GAMMA || - scheme.day.gamma[1] < MIN_GAMMA || - scheme.day.gamma[1] > MAX_GAMMA || - scheme.day.gamma[2] < MIN_GAMMA || - scheme.day.gamma[2] > MAX_GAMMA || - scheme.night.gamma[0] < MIN_GAMMA || - scheme.night.gamma[0] > MAX_GAMMA || - scheme.night.gamma[1] < MIN_GAMMA || - scheme.night.gamma[1] > MAX_GAMMA || - scheme.night.gamma[2] < MIN_GAMMA || - scheme.night.gamma[2] > MAX_GAMMA) { + if (!gamma_is_valid(scheme.day.gamma) || + !gamma_is_valid(scheme.night.gamma)) { fprintf(stderr, _("Gamma value must be between %.1f and %.1f.\n"), MIN_GAMMA, MAX_GAMMA); -- cgit v1.2.3-70-g09d2