diff options
author | Andy Ritger <aritger@nvidia.com> | 2012-08-24 15:53:07 -0700 |
---|---|---|
committer | Aaron Plattner <aplattner@nvidia.com> | 2012-08-24 20:49:11 -0700 |
commit | 6bf48ae8d8db58ab74182383e54332f120f024c2 (patch) | |
tree | 4f78a0af963fe41f27ea4737cad50438123fa7e4 | |
parent | 755234bd2ce0f3acde6507aba94b1e53a5a72f9b (diff) |
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: Andy Ritger <aritger@nvidia.com>
Reviewed-by: Aaron Plattner <aplattner@nvidia.com>
Signed-off-by: Aaron Plattner <aplattner@nvidia.com>
-rw-r--r-- | xrandr.c | 27 |
1 files changed, 19 insertions, 8 deletions
@@ -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; } |