All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hai Lan <hai.lan@intel.com>
To: intel-gfx@lists.freedesktop.org
Subject: [PATCH] intel-gpu-tools:testdisplay: add gamma test
Date: Wed, 13 Jul 2011 17:32:00 -0400	[thread overview]
Message-ID: <1310592720-3760-1-git-send-email-hai.lan@intel.com> (raw)

Signed-off-by: Hai Lan <hai.lan@intel.com>
---
 tests/testdisplay.c |   50 ++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/tests/testdisplay.c b/tests/testdisplay.c
index e8e3309..9ea4e7f 100644
--- a/tests/testdisplay.c
+++ b/tests/testdisplay.c
@@ -62,6 +62,7 @@
 #include <sys/time.h>
 #include <sys/mman.h>
 #include <sys/ioctl.h>
+#include <math.h>
 
 #include "xf86drm.h"
 #include "xf86drmMode.h"
@@ -75,7 +76,7 @@ struct udev_monitor *uevent_monitor;
 drmModeRes *resources;
 int fd, modes;
 int dump_info = 0, test_all_modes =0, test_preferred_mode = 0, force_mode = 0,
-	test_plane, enable_tiling;
+	test_plane, enable_tiling, test_gamma=0;
 int sleep_between_modes = 5;
 uint32_t depth = 24;
 
@@ -88,6 +89,13 @@ int	force_vdisplay;
 int	force_vsync_start;
 int	force_vsync_end;
 int	force_vtotal;
+uint16_t red[256], green[256], blue[256];
+float gamma_red, gamma_green, gamma_blue;
+
+static inline double dmin (double x, double y)
+{
+	return x < y ? x : y;
+}
 
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
 
@@ -237,7 +245,6 @@ static void dump_crtcs(void)
 		       crtc->x, crtc->y,
 		       crtc->width, crtc->height);
 		dump_mode(&crtc->mode);
-
 		drmModeFreeCrtc(crtc);
 	}
 	printf("\n");
@@ -784,7 +791,6 @@ set_mode(struct connector *c)
 	char buf[128];
 	int j, test_mode_num;
 	uint32_t bpp = 32;
-
 	if (depth <= 8)
 		bpp = 8;
 	else if (depth > 8 && depth <= 16)
@@ -881,7 +887,33 @@ set_mode(struct connector *c)
 				strerror(errno));
 			continue;
 		}
-
+		if (test_gamma) {
+			int size = 256;
+			float brightness = 1.0;
+			for (int i = 0; i < size; i++) {
+				if (gamma_red == 1.0 && brightness == 1.0)
+					red[i] = (i << 8) + i;
+				else
+					red[i] = dmin(pow((double)i/(double)(size - 1),
+						gamma_red) * brightness,
+						1.0) * 65535.0;
+
+				if (gamma_green == 1.0 && brightness == 1.0)
+					green[i] = (i << 8) + i;
+				else
+					green[i] = dmin(pow((double)i/(double)(size - 1),
+								gamma_green) * brightness,
+								1.0) * 65535.0;
+
+				if (gamma_blue == 1.0 && brightness == 1.0)
+					blue[i] = (i << 8) + i;
+				else
+					blue[i] = dmin(pow((double)i/(double)(size - 1),
+								gamma_blue) * brightness,
+								1.0) * 65535.0;
+			}
+			drmModeCrtcSetGamma(fd, c->crtc, 256, red, green, blue);
+		}
 		if (test_plane)
 			enable_plane(c);
 
@@ -939,11 +971,11 @@ static void update_display(void)
 
 extern char *optarg;
 extern int optind, opterr, optopt;
-static char optstr[] = "hiaf:s:d:pt";
+static char optstr[] = "hiaf:s:d:ptg:s";
 
 static void usage(char *name)
 {
-	fprintf(stderr, "usage: %s [-hiafs]\n", name);
+	fprintf(stderr, "usage: %s [-hiafsgpt]\n", name);
 	fprintf(stderr, "\t-i\tdump info\n");
 	fprintf(stderr, "\t-a\ttest all modes\n");
 	fprintf(stderr, "\t-s\t<duration>\tsleep between each mode test\n");
@@ -953,6 +985,7 @@ static void usage(char *name)
 	fprintf(stderr, "\t-f\t<clock MHz>,<hdisp>,<hsync-start>,<hsync-end>,<htotal>,\n");
 	fprintf(stderr, "\t\t<vdisp>,<vsync-start>,<vsync-end>,<vtotal>\n");
 	fprintf(stderr, "\t\ttest force mode\n");
+	fprintf(stderr, "\t-g\t<red>,<green>,<blue> test gamma\n");
 	fprintf(stderr, "\tDefault is to test the preferred mode.\n");
 	exit(0);
 }
@@ -1039,6 +1072,11 @@ int main(int argc, char **argv)
 		case 't':
 			enable_tiling = 1;
 			break;
+         case 'g':
+             test_gamma = 1;
+             if(sscanf(optarg,"%f,%f,%f",&gamma_red,&gamma_green,&gamma_blue)!= 3)
+                 usage(argv[0]);
+             break;
 		default:
 			fprintf(stderr, "unknown option %c\n", c);
 			/* fall through */
-- 
1.7.3.4

                 reply	other threads:[~2011-07-13 14:03 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1310592720-3760-1-git-send-email-hai.lan@intel.com \
    --to=hai.lan@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.