[PATCH] xrandr: fix brightness to prevent gamma to overflow and to allow 0
Mikhail Gusarov
dottedmag at dottedmag.net
Sun Jan 10 07:28:22 PST 2010
Twas brillig at 00:25:34 10.01.2010 UTC+01 when E.A.B.Piel at tudelft.nl did gyre and gimble:
EP> Hello,
EP> This fix the behaviour of brightness for 0 and values above 1. You can
EP> still can funky display with negative values so all is safe ;-)
EP> Cheers,
EP> Eric
EP> From 2d8896857441a51b9ac14c76a39662c9ee08d566 Mon Sep 17 00:00:00 2001
EP> From: =?UTF-8?q?=C3=89ric=20Piel?= <eric.piel at tremplin-utc.net>
EP> Date: Wed, 6 Jan 2010 14:42:15 +0100
EP> Subject: [PATCH] xrandr: fix brightness to prevent gamma to overflow and to allow 0
EP> MIME-Version: 1.0
EP> Content-Type: text/plain; charset=UTF-8
EP> Content-Transfer-Encoding: 8bit
EP> With the new brightness option, gamma would overflow with values > 1,
EP> leading to rainbow looking screen.
EP> In addition, have the brightness by default to 1, so that specifying 0
EP> actually does the expected behaviour of leading to a black screen.
EP> Signed-off-by: Éric Piel <eric.piel at tremplin-utc.net>
EP> ---
EP> xrandr.c | 16 +++++++---------
EP> 1 files changed, 7 insertions(+), 9 deletions(-)
EP> diff --git a/xrandr.c b/xrandr.c
EP> index 2fc0b81..17715ae 100644
EP> --- a/xrandr.c
EP> +++ b/xrandr.c
EP> @@ -626,6 +626,7 @@ add_output (void)
EP> fatal ("out of memory\n");
EP> output->next = NULL;
EP> output->found = False;
EP> + output->brightness = 1.0;
EP> *outputs_tail = output;
EP> outputs_tail = &output->next;
EP> return output;
EP> @@ -1216,30 +1217,27 @@ set_gamma(void)
EP> if(output->gamma.red == 0.0 && output->gamma.green == 0.0 && output->gamma.blue == 0.0)
EP> output->gamma.red = output->gamma.green = output->gamma.blue = 1.0;
EP>
EP> - if (output->brightness == 0.0)
EP> - output->brightness = 1.0;
EP> -
EP> for (i = 0; i < size; i++) {
EP> if (output->gamma.red == 1.0 && output->brightness == 1.0)
EP> gamma->red[i] = i << 8;
EP> else
EP> - gamma->red[i] = (CARD16)(pow((double)i/(double)(size - 1),
EP> + gamma->red[i] = (CARD16)(fmin(pow((double)i/(double)(size - 1),
EP> (double)output->gamma.red) * (double)(size - 1)
EP> - * (double)output->brightness * 256);
EP> + * (double)output->brightness * 256, 65535));
EP>
EP> if (output->gamma.green == 1.0 && output->brightness == 1.0)
EP> gamma->green[i] = i << 8;
EP> else
EP> - gamma->green[i] = (CARD16)(pow((double)i/(double)(size - 1),
EP> + gamma->green[i] = (CARD16)(fmin(pow((double)i/(double)(size - 1),
EP> (double)output->gamma.green) * (double)(size - 1)
EP> - * (double)output->brightness * 256);
EP> + * (double)output->brightness * 256, 65535));
EP>
EP> if (output->gamma.blue == 1.0 && output->brightness == 1.0)
EP> gamma->blue[i] = i << 8;
EP> else
EP> - gamma->blue[i] = (CARD16)(pow((double)i/(double)(size - 1),
EP> + gamma->blue[i] = (CARD16)(fmin(pow((double)i/(double)(size - 1),
EP> (double)output->gamma.blue) * (double)(size - 1)
EP> - * (double)output->brightness * 256);
EP> + * (double)output->brightness * 256, 65535));
EP> }
EP>
EP> XRRSetCrtcGamma(dpy, crtc->crtc.xid, gamma);
EP> --
EP> 1.6.6
Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>
--
http://fossarchy.blogspot.com/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
Url : http://lists.x.org/archives/xorg-devel/attachments/20100110/694bac0a/attachment-0001.pgp
More information about the xorg-devel
mailing list