summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2016-06-17 01:41:54 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2016-06-20 12:24:22 +0300
commit25342673c441b00baf661e89cc3e4dd1a2cf7213 (patch)
treefd41955697adb10114c16823679752695d7e4ec3
parent9944d12c8692600229b59857bb4622035ab70551 (diff)
Add LUT generation script
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
-rw-r--r--README3
-rw-r--r--data/frames/.gitignore1
-rw-r--r--data/frames/Makefile3
-rwxr-xr-xdata/frames/gen-lut.py82
4 files changed, 88 insertions, 1 deletions
diff --git a/README b/README
index fb6abb9..972a296 100644
--- a/README
+++ b/README
@@ -14,10 +14,11 @@ Building
--------
The vsp-tests suite requires the following tools to be installed on the host
-to generate the test scripts and applications
+to generate the test scripts, applications and data.
* gcc
* make
+* python
After installing the needed packages, you can build the test suite by running
diff --git a/data/frames/.gitignore b/data/frames/.gitignore
new file mode 100644
index 0000000..a8a0dce
--- /dev/null
+++ b/data/frames/.gitignore
@@ -0,0 +1 @@
+*.bin
diff --git a/data/frames/Makefile b/data/frames/Makefile
index 04ea2b2..dba2799 100644
--- a/data/frames/Makefile
+++ b/data/frames/Makefile
@@ -1,6 +1,8 @@
all:
+ ./gen-lut.py
clean:
+ @rm -f *.bin
install:
mkdir -p $(INSTALL_DIR)/frames/
@@ -8,3 +10,4 @@ install:
gzip -dk $(frame)
mv ${frame/.gz/} $(INSTALL_DIR)/frames/
done
+ cp *.bin $(INSTALL_DIR)/frames/
diff --git a/data/frames/gen-lut.py b/data/frames/gen-lut.py
new file mode 100755
index 0000000..f180ad6
--- /dev/null
+++ b/data/frames/gen-lut.py
@@ -0,0 +1,82 @@
+#!/usr/bin/python
+
+import math
+import sys
+
+clu_configs = (
+ ('zero', {
+ 'scale': 0.0,
+ 'a': 0.0,
+ 'freq': 1.0,
+ 'weights': (1.0, 1.0, 1.0)
+ } ),
+ ('identity', {
+ 'scale': 1.0,
+ 'a': 0.0,
+ 'freq': 1.0,
+ 'weights': (1.0, 1.0, 1.0)
+ } ),
+ # Keep the three weights different to generate an anisothropic
+ # look up table.
+ ('wave', {
+ 'scale': 1.0,
+ 'a': 0.1,
+ 'freq': 3.0,
+ 'weights': (1.0, 2.0, 3.0)
+ } ),
+)
+
+lut_configs = (
+ ('zero', 0.0, 1.0, 1.0, 1.0),
+ ('identity', 1.0, 1.0, 1.0, 1.0),
+ ('gamma', 1.0, 0.5, 1.0, 2.0),
+)
+
+def clu_value(x, y, z, scale, a, freq, weights):
+ x = x / 16.
+ y = y / 16.
+ z = z / 16.
+
+ dist = math.sqrt((x*x*weights[0] + y*y*weights[1] + z*z*weights[2]) / 3. / sum(weights))
+ offset = a * math.sin(dist * freq * 2 * math.pi)
+
+ x = max(0, min(255, int((x*scale + offset) * 256)))
+ y = max(0, min(255, int((y*scale + offset) * 256)))
+ z = max(0, min(255, int((z*scale + offset) * 256)))
+
+ return (z, y, x, 0)
+
+def generate_clu(config):
+ clu = []
+
+ for z in xrange(17):
+ for y in xrange(17):
+ for x in xrange(17):
+ clu.extend(clu_value(x, y, z, **config[1]))
+
+ file('clu-%s.bin' % config[0], 'wb').write(''.join([chr(c) for c in clu]))
+
+
+def gamma(vin, gamma, scale):
+ return int(255 * scale * math.pow(vin / 255., gamma))
+
+def generate_lut(config):
+ lut = []
+ for i in xrange(256):
+ lut.extend([gamma(i, g, config[1]) for g in config[2:]])
+ lut.append(0)
+
+ file('lut-%s.bin' % config[0], 'wb').write(''.join([chr(c) for c in lut]))
+
+
+def main(argv):
+ for config in clu_configs:
+ generate_clu(config)
+
+ for config in lut_configs:
+ generate_lut(config)
+
+ return 0
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))