Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 38 additions & 37 deletions Create_Intensity_Lookup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# coding=utf-8
"""
//////////////////////////////////////////////////////////////////////////////////
// OpenNX4 - Open source firmware for Barco NX4 tiles
Expand All @@ -8,51 +9,51 @@
// You may not use this code or a derived work for commercial purposes unless you have a commercial license, contact drtune@gmail.com
//////////////////////////////////////////////////////////////////////////////////
"""
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:

#output Xilinx ISE "COE" file (coeffs) to be includes in the ram 8b->12b pixel lookup
fout=open("ipcore_dir/Intensity_Lookup.coe","wt")
# http://jared.geek.nz/2013/feb/linear-led-pwm

#http://jared.geek.nz/2013/feb/linear-led-pwm
bits = NX4.INTERNAL_PIXEL_WIDTH_BITS

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)

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=
""" % bits
fullScale = 1 << 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
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=[]
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" % n for n in out]))

res+=";\n"

print >>fout,res
print res
fout.close()
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)
Loading