[PATCH 1/3] xrandr: use 1/gamma to compute gamma-correction

Andy Ritger aritger at nvidia.com
Mon Aug 13 16:25:10 PDT 2012


To compute a gamma *correction* lookup table, use the specified gamma
value as the divisor in (1.0/gamma).  This matches the semantics of
xgamma(1) and the "gamma-value" and "{red,green,blue}-gamma" xorg.conf(5)
options.

For more details, see:
http://www.poynton.com/PDFs/TIDV/Gamma.pdf (Gamma in computer graphics, page 17)
http://cgit.freedesktop.org/xorg/xserver/tree/hw/xfree86/common/xf86cmap.c:ComputeGamma()

Signed-off-by: Andy Ritger <aritger at nvidia.com>
Reviewed-by: Aaron Plattner <aplattner at nvidia.com>
---
 xrandr.c |   27 +++++++++++++++++++--------
 1 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/xrandr.c b/xrandr.c
index 6683ceb..75ed2ee 100644
--- a/xrandr.c
+++ b/xrandr.c
@@ -1326,6 +1326,9 @@ set_gamma(void)
 	int i, size;
 	crtc_t *crtc;
 	XRRCrtcGamma *gamma;
+	float gammaRed;
+	float gammaGreen;
+	float gammaBlue;
 
 	if (!(output->changes & changes_gamma))
 	    continue;
@@ -1350,29 +1353,37 @@ set_gamma(void)
 	    continue;
 	}
 
-	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->gamma.red == 0.0)
+	    output->gamma.red = 1.0;
+	if (output->gamma.green == 0.0)
+	    output->gamma.green = 1.0;
+	if (output->gamma.blue == 0.0)
+	    output->gamma.blue = 1.0;
+
+	gammaRed = 1.0 / output->gamma.red;
+	gammaGreen = 1.0 / output->gamma.green;
+	gammaBlue = 1.0 / output->gamma.blue;
 
 	for (i = 0; i < size; i++) {
-	    if (output->gamma.red == 1.0 && output->brightness == 1.0)
+	    if (gammaRed == 1.0 && output->brightness == 1.0)
 		gamma->red[i] = (i << 8) + i;
 	    else
 		gamma->red[i] = dmin(pow((double)i/(double)(size - 1),
-					 output->gamma.red) * output->brightness,
+					 gammaRed) * output->brightness,
 				     1.0) * 65535.0;
 
-	    if (output->gamma.green == 1.0 && output->brightness == 1.0)
+	    if (gammaGreen == 1.0 && output->brightness == 1.0)
 		gamma->green[i] = (i << 8) + i;
 	    else
 		gamma->green[i] = dmin(pow((double)i/(double)(size - 1),
-					   output->gamma.green) * output->brightness,
+					   gammaGreen) * output->brightness,
 				       1.0) * 65535.0;
 
-	    if (output->gamma.blue == 1.0 && output->brightness == 1.0)
+	    if (gammaBlue == 1.0 && output->brightness == 1.0)
 		gamma->blue[i] = (i << 8) + i;
 	    else
 		gamma->blue[i] = dmin(pow((double)i/(double)(size - 1),
-					  output->gamma.blue) * output->brightness,
+					  gammaBlue) * output->brightness,
 				      1.0) * 65535.0;
 	}
 
-- 
1.7.2.5



More information about the xorg-devel mailing list