summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉric Piel <eric.piel@tremplin-utc.net>2010-01-06 14:42:15 +0100
committerMatthias Hopf <mhopf@suse.de>2010-01-12 13:07:54 +0100
commitac6606d8da914610446c5327813798bfbba4d6c2 (patch)
tree6fc0339d0bced0b786e28e59f3eb2a95682aa533
parentccb3f8a42b25819cd1812f179544b52c2f03d1aa (diff)
xrandr: fix brightness to prevent gamma to overflow and to allow 0
With the new brightness option, gamma would overflow with values > 1, leading to rainbow looking screen. In addition, have the brightness by default to 1, so that specifying 0 actually does the expected behaviour of leading to a black screen. Signed-off-by: Éric Piel <eric.piel@tremplin-utc.net> Reviewed-by: Matthias Hopf <mhopf@suse.de> Reviewed-by: Mikhail Gusarov <dottedmag@dottedmag.net>
-rw-r--r--xrandr.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/xrandr.c b/xrandr.c
index 2fc0b81..65e0623 100644
--- a/xrandr.c
+++ b/xrandr.c
@@ -169,6 +169,12 @@ warning (const char *format, ...)
va_end (ap);
}
+/* Because fmin requires C99 suppport */
+static inline double dmin (double x, double y)
+{
+ return x < y ? x : y;
+}
+
static char *
rotation_name (Rotation rotation)
{
@@ -626,6 +632,7 @@ add_output (void)
fatal ("out of memory\n");
output->next = NULL;
output->found = False;
+ output->brightness = 1.0;
*outputs_tail = output;
outputs_tail = &output->next;
return output;
@@ -1216,30 +1223,27 @@ set_gamma(void)
if(output->gamma.red == 0.0 && output->gamma.green == 0.0 && output->gamma.blue == 0.0)
output->gamma.red = output->gamma.green = output->gamma.blue = 1.0;
- if (output->brightness == 0.0)
- output->brightness = 1.0;
-
for (i = 0; i < size; i++) {
if (output->gamma.red == 1.0 && output->brightness == 1.0)
gamma->red[i] = i << 8;
else
- gamma->red[i] = (CARD16)(pow((double)i/(double)(size - 1),
+ gamma->red[i] = dmin(pow((double)i/(double)(size - 1),
(double)output->gamma.red) * (double)(size - 1)
- * (double)output->brightness * 256);
+ * (double)output->brightness * 256, 65535.0);
if (output->gamma.green == 1.0 && output->brightness == 1.0)
gamma->green[i] = i << 8;
else
- gamma->green[i] = (CARD16)(pow((double)i/(double)(size - 1),
+ gamma->green[i] = dmin(pow((double)i/(double)(size - 1),
(double)output->gamma.green) * (double)(size - 1)
- * (double)output->brightness * 256);
+ * (double)output->brightness * 256, 65535);
if (output->gamma.blue == 1.0 && output->brightness == 1.0)
gamma->blue[i] = i << 8;
else
- gamma->blue[i] = (CARD16)(pow((double)i/(double)(size - 1),
+ gamma->blue[i] = dmin(pow((double)i/(double)(size - 1),
(double)output->gamma.blue) * (double)(size - 1)
- * (double)output->brightness * 256);
+ * (double)output->brightness * 256, 65535);
}
XRRSetCrtcGamma(dpy, crtc->crtc.xid, gamma);