Commit 6bf48ae8 authored by Andy Ritger's avatar Andy Ritger Committed by Aaron Plattner
Browse files

xrandr: use 1/gamma to compute gamma-correction

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: default avatarAndy Ritger <aritger@nvidia.com>
Reviewed-by: Aaron Plattner's avatarAaron Plattner <aplattner@nvidia.com>
Signed-off-by: Aaron Plattner's avatarAaron Plattner <aplattner@nvidia.com>
parent 755234bd
......@@ -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;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment