summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo (Sunpeng) Li <sunpeng.li@amd.com>2018-03-05 16:32:35 -0500
committerLeo (Sunpeng) Li <sunpeng.li@amd.com>2018-05-02 10:13:30 -0400
commitfd3eb68772d2867f71fd72bd3732c97a0944ccc6 (patch)
tree18f445a1a3f1f11b3432a790b27cfc21edd9eb25
parent748f8d49a1fc0deb1c9d58e97598232707876ab3 (diff)
Adding makefile, Init app .c file.
Signed-off-by: Leo (Sunpeng) Li <sunpeng.li@amd.com>
-rw-r--r--Makefile13
-rwxr-xr-xdreamcolor-demobin0 -> 15496 bytes
-rw-r--r--dreamcolor-demo.c129
3 files changed, 142 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..ff3019e
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,13 @@
+CFLAGS=-g -Wall
+CC=gcc
+
+LDFLAGS=$(shell pkg-config --cflags --libs libdrm)
+LDLIBS = -lm
+
+SOURCES=$(wildcard *.c)
+EXECUTABLES=$(patsubst %.c,%,$(SOURCES))
+
+all: $(EXECUTABLES)
+
+clean:
+ rm -f $(EXECUTABLES)
diff --git a/dreamcolor-demo b/dreamcolor-demo
new file mode 100755
index 0000000..d5c90b9
--- /dev/null
+++ b/dreamcolor-demo
Binary files differ
diff --git a/dreamcolor-demo.c b/dreamcolor-demo.c
new file mode 100644
index 0000000..094a594
--- /dev/null
+++ b/dreamcolor-demo.c
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2018 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+
+#include <xf86drm.h>
+#include <stdio.h>
+#include <math.h>
+
+
+#define LUT_SIZE 16
+
+
+/* Data structures for gamma/degamma ramps & ctm matrix. */
+struct _drm_color_ctm {
+ /* Transformation matrix in S31.32 format. */
+ __s64 matrix[9];
+};
+
+struct _drm_color_lut {
+ /*
+ * Data is U0.16 fixed point format.
+ */
+ __u16 red;
+ __u16 green;
+ __u16 blue;
+ __u16 reserved;
+};
+
+struct color3d {
+ double r;
+ double g;
+ double b;
+};
+
+
+/**
+ * Helper functions
+ */
+
+static void coeffs_to_lut(struct color3d *coeffs,
+ struct _drm_color_lut *lut,
+ int lut_size)
+{
+ int i;
+ __u16 max_value = 0xFFFF;
+
+ for (i = 0; i < lut_size; i++) {
+ lut[i].red = coeffs[i].r * max_value;
+ lut[i].green = coeffs[i].g * max_value;
+ lut[i].blue = coeffs[i].b * max_value;
+ }
+}
+
+static void load_table_max(struct color3d *coeffs, int lut_size)
+{
+ int i;
+ coeffs[0].r = coeffs[0].g = coeffs[0].b = 0.0;
+ for (i = 1; i < lut_size; i++)
+ coeffs[i].r = coeffs[i].g = coeffs[i].b = 1.0;
+}
+
+static void load_table_zero(struct color3d *coeffs, int lut_size)
+{
+ int i;
+ for (i = 0; i < lut_size; i++)
+ coeffs[i].r = coeffs[i].g = coeffs[i].b = 0.0;
+}
+
+static void load_table(struct color3d *coeffs, int lut_size, double exp)
+{
+ int i;
+ for (i = 0; i < lut_size; i++) {
+ coeffs[i].r = coeffs[i].g = coeffs[i].b =
+ pow((double) i * 1.0 / (double) (lut_size - 1), exp);
+ }
+}
+
+static void print_coeffs(const struct color3d *coeffs, int lut_size)
+{
+ int i;
+ for (i = 0; i < lut_size; i++) {
+ printf("[%d] R:%.2f G:%.2f B:%.2f\n",
+ i, coeffs[i].r, coeffs[i].g, coeffs[i].b);
+ }
+}
+
+static void print_lut(const struct _drm_color_lut *lut, int lut_size)
+{
+ int i;
+ for (i = 0; i < lut_size; i++) {
+ printf("[%d] R:%4x G:%4x B:%4x\n",
+ i, lut[i].red, lut[i].green, lut[i].blue);
+ }
+}
+
+
+int main(int argc, char const *argv[])
+{
+ struct color3d coeffs[LUT_SIZE];
+ struct _drm_color_lut lut[LUT_SIZE];
+
+ load_table(coeffs, LUT_SIZE, 1);
+ print_coeffs(coeffs, LUT_SIZE);
+
+ coeffs_to_lut(coeffs, lut, LUT_SIZE);
+ print_lut(lut, LUT_SIZE);
+ return 0;
+} \ No newline at end of file