From e910550880b9911c30ce4dead1c98acdde17cb4b Mon Sep 17 00:00:00 2001 From: Eric Piel 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