Hello,
I did this out of curiosity, but maybe it could useful for others. For
now in xrandr, even in verbose mode, the current gamma is not displayed
because it's too much info (3*256 floats typically). Therefore the user
is able to set the gamma and the brightness, but cannot know the current
value. The idea is to retrieve the values in the same simple form out of
the gamma ramps. It assumes that the gamma ramps follows just a normal
gamma correction.

Do you think it could be useful? If so, I can try to clean it up and
send it again :-)

See you,
Eric
From e910550880b9911c30ce4dead1c98acdde17cb4b Mon Sep 17 00:00:00 2001
From: Eric Piel <e...@triangle.(none)>
Date: Sun, 10 Jan 2010 00:08:53 +0100
Subject: [PATCH] xrandr: get gamma and brightness

basic idea of getting an approximation of the gamma and brightness
---
 xrandr.c |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/xrandr.c b/xrandr.c
index 17715ae..07dd5d0 100644
--- a/xrandr.c
+++ b/xrandr.c
@@ -1049,6 +1049,38 @@ set_output_info (output_t *output, RROutput xid, 
XRROutputInfo *output_info)
               rotation_name (output->rotation),
               reflection_name (output->rotation));
 
+    /* set gamma */
+    if (!(output->changes & changes_gamma))
+    {
+       if (output->crtc_info) {
+           crtc_t *crtc = output->crtc_info;
+           XRRCrtcGamma *gamma;
+           int i, size;
+
+           size = XRRGetCrtcGammaSize(dpy, crtc->crtc.xid);
+           if (!size)
+               fatal("output %s cannot get gamma size\n", 
output->output.string);
+
+           gamma = XRRGetCrtcGamma(dpy, crtc->crtc.xid);
+           if (!gamma)
+               fatal("output %s cannot get gamma\n", output->output.string);
+
+           for (i = 0; i < size; i++) {
+               printf("gamma %d = %d, %d, %d\n", i, gamma->red[i], 
gamma->green[i], gamma->blue[i]);
+           }
+           /* approximation of the gamma by supposing it follows a gamma curve 
+            * multiplied by a brightness (= the same as we apply) */
+           output->brightness = ((double)(gamma->red[size - 1] + 
gamma->green[size - 1] + gamma->blue[size - 1]) / 65280.0) / 3; /* works only 
btw 0 and 1, if >= 1, we would need to check the highest i which is not 65536, 
and interpolate */
+           output->gamma.red = log(((double)(gamma->red[size/2]) / 
output->brightness) /65536.0)/log(0.5);
+           output->gamma.green = log(((double)(gamma->green[size/2]) / 
output->brightness) /65536.0)/log(0.5);
+           output->gamma.blue = log(((double)(gamma->blue[size/2]) / 
output->brightness) /65536.0)/log(0.5);
+
+           XRRFreeGamma(gamma);
+       }
+
+
+    }
+
     /* set transformation */
     if (!(output->changes & changes_transform))
     {
@@ -2913,6 +2945,8 @@ main (int argc, char **argv)
                printf ("\tIdentifier: 0x%x\n", (int)output->output.xid);
                printf ("\tTimestamp:  %d\n", (int)output_info->timestamp);
                printf ("\tSubpixel:   %s\n", 
order[output_info->subpixel_order]);
+               printf ("\tGamma:      %f:%f:%f\n", output->gamma.red, 
output->gamma.green, output->gamma.blue);
+               printf ("\tBrightness: %f\n", output->brightness);
                printf ("\tClones:    ");
                for (j = 0; j < output_info->nclone; j++)
                {
-- 
1.6.6

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

Reply via email to