Skip to content

Instantly share code, notes, and snippets.

@dbr
Created January 15, 2013 23:27
Show Gist options
  • Save dbr/4543134 to your computer and use it in GitHub Desktop.
Save dbr/4543134 to your computer and use it in GitHub Desktop.
"""Exports a Nuke ColorLookup node as a 1D CSP
The "master" curve becomes the prelut curve, and the red/green/blue curves
are the R/G/B curves
All curves are linearly sampled between 0 and 1
"""
import nuke
def make_log_to_lin(node = None, metadata = None):
if node is None:
node = nuke.selectedNode()
assert node.Class() == "ColorLookup" # probably not necessary, but safe for now
out = ["CSPLUTV100"]
out.append("1D")
out.append("")
out.append("BEGIN METADATA")
if metadata is not None:
out.append(metadata)
out.append("END METADATA")
prelut_numsamples = 1025
prelut_in = []
prelut_out = []
for x in range(prelut_numsamples):
interpo = float(x)/(prelut_numsamples-1)
prelut_in.append(interpo)
prelut_out.append(
node['lut'].getValueAt(interpo, 0))
for x in range(3):
out.append("%s" % prelut_numsamples)
out.append(" ".join(["%.05f" % x for x in prelut_in]))
out.append(" ".join(["%.05f" % x for x in prelut_out]))
out.append("")
out.append("1025")
numsamples = 1025
for x in range(numsamples):
interpo = float(x)/(numsamples-1)
r = node['lut'].getValueAt(interpo, 1)
g = node['lut'].getValueAt(interpo, 2)
b = node['lut'].getValueAt(interpo, 3)
formatted_float = "%.05f %.05f %.05f" % (r, g, b)
out.append(formatted_float)
return out
if __name__ == "__main__":
print "\n".join(make_log_to_lin())
@zachlewis
Copy link

this is so awesome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment