op_gammatable: add a new tool to generate DSS gamma tables
authorGrazvydas Ignotas <notasas@gmail.com>
Tue, 9 Oct 2012 18:57:39 +0000 (21:57 +0300)
committerGrazvydas Ignotas <notasas@gmail.com>
Tue, 9 Oct 2012 19:15:09 +0000 (22:15 +0300)
Makefile
op_gammatable.c [new file with mode: 0644]
op_gammatool.c

index 7a9692a..ce1bbce 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ CFLAGS += -Wall -O2
 LDFLAGS += -s
 INSTALL ?= bin
 
-BIN = op_runfbapp op_gammatool op_test_inputs ofbset
+BIN = op_runfbapp op_gammatool op_gammatable op_test_inputs ofbset
 
 all: $(BIN)
 
@@ -14,6 +14,7 @@ clean:
 
 op_runfbapp: LDFLAGS += -lpthread -lX11
 op_test_inputs: LDFLAGS += -lpthread -lts
+op_gammatable: LDFLAGS += -lm
 
 $(INSTALL):
        mkdir -p $(INSTALL)
@@ -21,6 +22,7 @@ $(INSTALL):
 install: $(INSTALL) $(BIN)
        cp op_runfbapp $(INSTALL)/
        cp op_gammatool $(INSTALL)/op_gammatool_bin
+       cp op_gammatable $(INSTALL)/
        cp op_test_inputs $(INSTALL)/op_test_inputs_bin
        cp ofbset $(INSTALL)/
        cp scripts/op_gammatool $(INSTALL)/
diff --git a/op_gammatable.c b/op_gammatable.c
new file mode 100644 (file)
index 0000000..dd321ed
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * op_gammatable - generate a gamma table for OMAP's DSS
+ *
+ * Copyright (c) 2012, Gražvydas Ignotas
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of the organization nor the
+ *       names of its contributors may be used to endorse or promote products
+ *       derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+static void usage(const char *argv0)
+{
+       fprintf(stderr, "usage:\n");
+       fprintf(stderr, "%s [-n] {<gamma> | <gamma_r> <gamma_g> <gamma_b>}\n",
+               argv0);
+       exit(1);
+}
+
+int main(int argc, char *argv[])
+{
+       unsigned int v, r, g, b;
+       float gamma[3] = { 0.f, };
+       int negative = 0, ptod = 0, half = 0;
+       int i, arg = 1;
+
+       if (argc < 2)
+               usage(argv[0]);
+       while (arg < argc && argv[arg][0] == '-') {
+               if (strcmp(argv[arg], "-h") == 0)
+                       usage(argv[0]);
+               else if (strcmp(argv[arg], "-n") == 0)
+                       negative = 1;
+               else if (strcmp(argv[arg], "-ptod") == 0)
+                       ptod = 1;
+               else if (strcmp(argv[arg], "-half") == 0)
+                       half = 1;
+               else
+                       fprintf(stderr, "%s: ignoring %s\n",
+                               argv[0], argv[arg]);
+               arg++;
+       }
+
+       if (argc - arg == 3) {
+               gamma[0] = atof(argv[arg++]);
+               gamma[1] = atof(argv[arg++]);
+               gamma[2] = atof(argv[arg++]);
+       }
+       else if (argc - arg == 1)
+               gamma[0] = gamma[1] = gamma[2] = atof(argv[arg++]);
+       else
+               usage(argv[0]);
+
+       if (gamma[0] <= 0.f || gamma[1] <= 0.f || gamma[2] <= 0.f) {
+               fprintf(stderr, "invalid arguments: %.3f %.3f %.3f\n",
+                       gamma[0], gamma[1], gamma[2]);
+               usage(argv[0]);
+       }
+
+       for (i = 0; i < 256; i++) {
+               // based on http://www.teamten.com/lawrence/graphics/gamma/
+               r = (unsigned int) (255.f * powf((float)i / 255.f, 1.f / gamma[0]) + 0.5f);
+               g = (unsigned int) (255.f * powf((float)i / 255.f, 1.f / gamma[1]) + 0.5f);
+               b = (unsigned int) (255.f * powf((float)i / 255.f, 1.f / gamma[2]) + 0.5f);
+
+               v = (r << 16) | (g << 8) | b;
+               if (negative)
+                       v ^= 0xffffff;
+               if (half)
+                       v = (v >> 1) & 0x7f7f7f;
+               if (ptod)
+                       v &= 0xff7fff;
+
+               printf("0x%06x ", v);
+       }
+       printf("\n");
+
+       return 0;
+}
index 964ece3..224c222 100644 (file)
@@ -1,6 +1,7 @@
 /*
+ * op_gammatool - pandora's LCD gamma adjustment tool
+ *
  * Copyright (c) 2010, Gražvydas Ignotas
- * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met: