[xrandr] Add --brightness for CRTC

Mikhail Gusarov dottedmag at dottedmag.net
Sat Oct 24 14:41:05 PDT 2009


--brightness n.m adjusts gamma set for CRTC in order to compensate
for overly bright or overly dark unmanageable outputs.
---
 xrandr.c   |   32 ++++++++++++++++++++++++++------
 xrandr.man |    4 ++++
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/xrandr.c b/xrandr.c
index f7eba11..5b3064b 100644
--- a/xrandr.c
+++ b/xrandr.c
@@ -333,6 +333,8 @@ struct _output {
 	float blue;
     } gamma;
 
+    float	    brightness;
+
     Bool	    primary;
 
     Bool	    found;
@@ -1226,24 +1228,33 @@ 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->brightness == 0.0)
+	    output->brightness = 1.0;
+
 	for (i = 0; i < size; i++) {
-	    if (output->gamma.red == 1.0)
+	    if (output->gamma.red == 1.0 && output->brightness == 1.0)
 		gamma->red[i] = i << 8;
 	    else
 		gamma->red[i] = (CARD16)(pow((double)i/(double)(size - 1),
-			    (double)output->gamma.red) * (double)(size - 1) * 256);
+			    (double)output->gamma.red) * (double)(size - 1)
+			    * (double)output->brightness * 256);
 
-	    if (output->gamma.green == 1.0)
+	    if (output->gamma.green == 1.0 && output->brightness == 1.0)
 		gamma->green[i] = i << 8;
 	    else
 		gamma->green[i] = (CARD16)(pow((double)i/(double)(size - 1),
-			    (double)output->gamma.green) * (double)(size - 1) * 256);
+			    (double)output->gamma.green) * (double)(size - 1)
+			    * (double)output->brightness * 256);
 
-	    if (output->gamma.blue == 1.0)
+	    if (output->gamma.blue == 1.0 && output->brightness == 1.0)
 		gamma->blue[i] = i << 8;
 	    else
 		gamma->blue[i] = (CARD16)(pow((double)i/(double)(size - 1),
-			    (double)output->gamma.blue) * (double)(size - 1) * 256);
+			    (double)output->gamma.blue) * (double)(size - 1)
+			    * (double)output->brightness * 256);
 	}
 
 	XRRSetCrtcGamma(dpy, crtc->crtc.xid, gamma);
@@ -2330,6 +2341,15 @@ main (int argc, char **argv)
 	    setit_1_2 = True;
 	    continue;
 	}
+	if (!strcmp ("--brightness", argv[i])) {
+	    if (!output) usage();
+	    if (++i>=argc) usage();
+	    if (sscanf(argv[i], "%f", &output->brightness) != 1)
+		usage ();
+	    output->changes |= changes_gamma;
+	    setit_1_2 = True;
+	    continue;
+	}
 	if (!strcmp ("--primary", argv[i])) {
 	    if (!output) usage();
 	    output->changes |= changes_primary;
diff --git a/xrandr.man b/xrandr.man
index 1fceeb6..6f64ac3 100644
--- a/xrandr.man
+++ b/xrandr.man
@@ -77,6 +77,7 @@ xrandr \- primitive command line interface to RandR extension
 [\-\-off]
 [\-\-crtc \fIcrtc\fP]
 [\-\-gamma \fIred\fP:\fIgreen\fP:\fIblue\fP]
+[\-\-brightness \fIbrightness\fP]
 
 .br
 .B RandR version 1.0 and version 1.1 options
@@ -270,6 +271,9 @@ Set the specified floating point values as gamma correction on the crtc
 currently attached to this output. Note that you cannot get two different values
 for cloned outputs and that switching an output to another crtc doesn't change
 the crtc gamma corrections at all.
+.IP "\-\-brightness \fIbrightness\fP"
+Multiply the gamma values on the crtc currently attached to the output to
+specified floating value. Useful for overly bright or overly dim outputs.
 .PP
 .SH "RandR version 1.1 options"
 These options are available for X servers supporting RandR version 1.1 or
-- 
1.6.3.3



More information about the xorg-devel mailing list