Op 11-01-10 12:46, Matthias Hopf schreef:
>  inline double min (double x, double y)
> {
>   return x < y ? x : y;
> }
> 
> instead.

Here is a fixed version.

Cheers,
Eric
>From 8ce20ec5e2d52a13df8c5999dd6db49d64693c59 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=89ric=20Piel?= <[email protected]>
Date: Wed, 6 Jan 2010 14:42:15 +0100
Subject: [PATCH] xrandr: fix brightness to prevent gamma to overflow and to 
allow 0
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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 <[email protected]>
---
 xrandr.c |   22 +++++++++++++---------
 1 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/xrandr.c b/xrandr.c
index 2fc0b81..5418235 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] = (CARD16)(dmin(pow((double)i/(double)(size - 1),
                            (double)output->gamma.red) * (double)(size - 1)
-                           * (double)output->brightness * 256);
+                           * (double)output->brightness * 256, 65535));
 
            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] = (CARD16)(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] = (CARD16)(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);
-- 
1.6.6

_______________________________________________
xorg-devel mailing list
[email protected]
http://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to