1 """
2 A collection of tools and functions to help manage LUTs and color configuration
3 """
4 from _nuke_color import *
5 import callbacks
6 import types
7 import nuke
8
9 defaultLUTMappers = {}
10
11
13 """ Look through all options in the colorpsace knob, and see if we have an
14 exact match to one of the items. """
15 allColorspaces = getColorspaceList(nuke.thisNode()['colorspace'])
16 return colorspaceName in allColorspaces
17
18
20 """
21 Nuke's default handling of colorspace lookups.
22
23 Maps applicable dataTypeHint values to knobs on the Preferecne panel
24
25 Possible values for dataTypeHint are
26 Nuke inbuilt data-type hints (map to knobs)
27 nuke.MONITOR == 0
28 nuke.VIEWER == 1
29 nuke.INT8 == 2
30 nuke.INT16 == 3
31 nuke.LOG == 4
32 nuke.FLOAT == 5
33 Other numeric values which map to those in DDImage/LUT.h
34 6 == DD::Image::LUT::GAMMA1_8
35 7 == DD::Image::LUT::GAMMA2_2
36 8 == DD::Image::LUT::GAMMA2_4
37 9 == DD::Image::LUT::PANALOG
38 10 == DD::Image::LUT::REDLOG
39 11 == DD::Image::LUT::VIPERLOG
40 12 == DD::Image::LUT::ALEXAV3LOGC
41 13 == DD::Image::LUT::PLOGLIN
42 14 == DD::Image::LUT::SLOG
43 15 == DD::Image::LUT::SLOG1
44 16 == DD::Image::LUT::SLOG2
45 17 == DD::Image::LUT::SLOG3
46 18 == DD::Image::LUT::CLOG
47 19 == DD::Image::LUT::PROTUNE
48 """
49 def getKnobValue( knobName ) :
50 return nuke.root()[ knobName ].value()
51
52 retString = colorspaceName
53 if dataTypeHint == nuke.MONITOR:
54 retString = getKnobValue( "monitorLut" )
55 elif dataTypeHint == nuke.VIEWER:
56 pass
57 elif dataTypeHint == nuke.INT8:
58 retString = getKnobValue( "int8Lut" )
59 elif dataTypeHint == nuke.INT16:
60 retString = getKnobValue( "int16Lut" )
61 elif dataTypeHint == nuke.LOG:
62 retString = getKnobValue( "logLut" )
63 elif dataTypeHint == nuke.FLOAT:
64 retString = getKnobValue( "floatLut" )
65 return retString
66
67
69 """
70 Allows colorspaces selections to be altered before use on Readers and Writers
71 """
72 if colorspaceName == "." :
73 raise RuntimeError( "Nuke has provided invalid colorspace name" )
74 retName = _lookUpDataTypeDefaultSettings(colorspaceName, dataTypeHint)
75
76 return retName
77
78
80 """
81 Add a function to modify default colorspaces before Nuke passes them to
82 Readers or Writers.
83
84 Functions should have the same positional argument as in the definition of
85 defaultLUTMapper()
86
87 All added functions are called in backwards order.
88 """
89 callbacks._addCallback(defaultLUTMappers, call, args, kwargs, nodeClass)
90
91
97
98
100 """
101 Perform the colorspace callbacks
102 expects a string or 'None' to be returned.
103 """
104 for funcData in callbacks:
105 func = funcData[0]
106 args = funcData[1]
107 kwargs = funcData[2]
108 s = func(colorspace, dataTypeHint, *args, **kwargs)
109 if not isinstance(s, str) and s is not None:
110 raise TypeError( errorMsg + ". Got type %s"%str(type(s)) )
111 if s is not None:
112 colorspace = s
113 return colorspace
114
115
117 """
118 Called by libnuke.
119 Calls into Node-level callbacks first, then global callbacks
120
121 Arguments:
122 colorspace - the name string of the initial colorspace
123 dataTypeHint - sometimes Readers/Writer request the default for a
124 particular data-type, i.e. int8, in16, float, etc.
125 Return:
126 The return should be the transformed/modified colorspace name.
127 None is the same as returning the string unchanged.
128 """
129 import __main__
130
131
132 colorspace = _nukeDefaultColorSpaceMapper(colorspace, dataTypeHint)
133
134
135 colorspaceCbs = defaultLUTMappers.get(nuke.thisClass())
136 if colorspaceCbs:
137 nodeErrMsg = ( "Colorspace Filter on Node '%s' returned invalid type,"
138 "expected string or None"%( nuke.theClass() ) )
139 colorspace = _doColorSpaceCallbacks( colorspace, dataTypeHint, colorspaceCbs, nodeErrMsg )
140
141
142 globalCbs = defaultLUTMappers.get('*')
143 if globalCbs:
144 globalErrMsg = ( "Global Colorspace Filter returned invalid type,"
145 "expected string or None" )
146 colorspace = _doColorSpaceCallbacks( colorspace, dataTypeHint, globalCbs, globalErrMsg )
147
148 return colorspace
149
151 """
152 Get a list of all colorspaces listed in an enumeration knob.
153 This will strip family names if the knob has the STRIP_CASCADE_PREFIX flag set.
154 """
155
156 allColorspaces = colorspaceKnob.values()
157 strippedColorspaces = []
158
159 if not colorspaceKnob.getFlag(nuke.STRIP_CASCADE_PREFIX) :
160 return allColorspaces
161 else:
162 for strippedColorspace in allColorspaces:
163
164 strippedColorspace = strippedColorspace.split('/')[-1]
165 strippedColorspaces.append(strippedColorspace)
166
167 return strippedColorspaces
168