forked from raplin/OpenNX4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreate_Intensity_Lookup.py
59 lines (46 loc) · 1.76 KB
/
Create_Intensity_Lookup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# coding=utf-8
"""
//////////////////////////////////////////////////////////////////////////////////
// OpenNX4 - Open source firmware for Barco NX4 tiles
// Company: Bohemian Bits
// Engineer: Richard Aplin (Twitter: @DrTune)
// Copyright (C) 2017 Richard Aplin
// Released under the Attribution-NonCommercial 2.0 Generic (CC BY-NC 2.0)
// You may not use this code or a derived work for commercial purposes unless you have a commercial license, contact [email protected]
//////////////////////////////////////////////////////////////////////////////////
"""
from __future__ import division, print_function
from NX4CommsHeaderReader import NX4
# output Xilinx ISE "COE" file (coeffs) to be includes in the ram 8b->12b pixel lookup
with open("ipcore_dir/Intensity_Lookup.coe", "w") as fout:
# http://jared.geek.nz/2013/feb/linear-led-pwm
bits = NX4.INTERNAL_PIXEL_WIDTH_BITS
res = """
;GENERATED BY CREATE_INTENSITY_LOOKUP.PY DO NOT EDIT
; Generated for a 256x{:d} dual port BRAM
memory_initialization_radix=16;
memory_initialization_vector=
""".format(bits)
fullScale = 1 << bits
def cie1931(L):
L = L * 100.0
if L <= 8:
return L / 902.3
else:
return ((L + 16.0) / 116.0) ** 3
if True:
out = []
for n in range(256):
# adjust for eye response
if False:
gamma = pow(fullScale - 1, (n / 256.0))
gamma = int(gamma * fullScale) >> bits
else:
gamma = round(cie1931(float(n) / 255) * (fullScale - 1))
if n == 0:
gamma = 0
out.append(gamma)
res += (",".join(["{:03x}".format(n) for n in out]))
res += ";\n"
print(res, file=fout)
print(res)