-
Notifications
You must be signed in to change notification settings - Fork 14
/
GamutCompress.nk
357 lines (357 loc) · 10.5 KB
/
GamutCompress.nk
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
set cut_paste_input [stack 0]
push $cut_paste_input
Group {
name GamutCompress1
label "\[value direction]"
addUserKnob {20 GamutCompress}
addUserKnob {41 threshold t "Percentage of the gamut to protect. A value of 0.8 means 20% of the outer gamut will be utilized for gamut compression." T compress.threshold}
addUserKnob {41 power T compress.power}
addUserKnob {26 distance_limit_label l " " t "Specifies the distance beyond the gamut boundary to map to the gamut boundary for each color component." T "<b>distance limit"}
addUserKnob {41 cyan t "Maximum distance beyond the green-blue gamut boundary to compress to the gamut boundary." T compress.cyan}
addUserKnob {41 magenta t "Maximum distance beyond the blue-red gamut boundary to compress to the gamut boundary." T compress.magenta}
addUserKnob {41 yellow t "Maximum distance beyond the red-green gamut boundary to compress to the gamut boundary." T compress.yellow}
addUserKnob {6 overlay l "graph overlay" +STARTLINE}
addUserKnob {22 reset t "Reset knobs to default values. Distance limits are calculated based on an the average of a selection of digital cinema cameras." T "n = nuke.thisNode()\nnuke.root().begin()\ndefaults = \{\n 'threshold': (0.815, 0.803, 0.88),\n 'power': 1.2,\n 'cyan': 0.147,\n 'magenta':0.264,\n 'yellow': 0.312,\n\}\nfor k, v in defaults.items():\n n\[k].setValue(v)" +STARTLINE}
addUserKnob {26 ""}
addUserKnob {4 direction M {forward inverse}}
addUserKnob {20 info_tab l Info}
addUserKnob {26 info_label l " " T "<style> a:link \{ color: #ccc \}</style>\n<font color=#ccc>\n<b>GamutCompress</b><br>\nmaps out of gamut colors back into gamut.\n<br><br><a href=https://github.com/colour-science/aces-vwg-gamut-mapping-2020/tree/master/model>Documentation</a>"}
addUserKnob {26 about_label l " " T "<style> a:link \{ color: #ccc \}</style>\n<font color=#ccc><br>\n<b>About</b><br>\nWritten by <a href=https://github.com/jedypod color=red>Jed Smith</a> <br> with <a href=https://community.acescentral.com/t/rgb-saturation-gamut-mapping-approach-and-a-comp-vfx-perspective>help</a> from the <a href=https://community.acescentral.com/c/aces-development-acesnext/vwg-aces-gamut-mapping-working-group>ACES Gamut Mapping VWG</a>"}
}
Input {
inputs 0
name Input
xpos -40
ypos -274
}
Dot {
name Dot4
xpos -6
ypos -174
}
set N5a326400 [stack 0]
Dot {
name Dot2
xpos -226
ypos -174
}
Expression {
channel0 {rgba.red rgba.green rgba.blue none}
expr0 max(r,g,b)
name achromatic
xpos -260
ypos -130
}
set N78acdc00 [stack 0]
push $N5a326400
Merge2 {
inputs 2
operation minus
bbox B
Achannels rgb
Bchannels rgb
output rgb
name Merge1
xpos -40
ypos -130
}
push $N78acdc00
Dot {
name Dot1
xpos -226
ypos -78
}
set N78acd400 [stack 0]
Expression {
expr0 abs(r)
expr1 abs(g)
expr2 abs(b)
name abs
xpos -167
ypos -81
}
set N78acd000 [stack 0]
Merge2 {
inputs 2
operation divide
bbox B
Achannels rgb
Bchannels rgb
output rgb
name Merge2
xpos -40
ypos -82
}
set N78accc00 [stack 0]
Expression {
expr0 "2 * x / (width - 1)"
expr1 "2 * x / (width - 1)"
expr2 "2 * x / (width - 1)"
name Grad
xpos 180
ypos -82
}
Group {
name compress1
xpos 180
ypos 63
addUserKnob {20 compress}
addUserKnob {18 threshold R 0.4 1}
threshold {{parent.compress.threshold}}
addUserKnob {6 threshold_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
addUserKnob {7 power R 1 3}
power {{parent.compress.power}}
addUserKnob {7 cyan}
cyan {{parent.compress.cyan}}
addUserKnob {7 magenta}
magenta {{parent.compress.magenta}}
addUserKnob {7 yellow}
yellow {{parent.compress.yellow}}
addUserKnob {26 ""}
addUserKnob {26 ""}
addUserKnob {6 invert +STARTLINE}
invert {{parent.direction}}
}
Input {
inputs 0
name Input
xpos -40
ypos -130
}
Dot {
name Dot2
xpos -6
ypos -30
}
set N78acc000 [stack 0]
Dot {
name Dot1
xpos 434
ypos -30
}
Expression {
expr0 (r<thr.r||lim.r<1.0001||r>thr.r+s.r)?r:thr.r+s.r*pow(-(pow((r-thr.r)/s.r,p)/(pow((r-thr.r)/s.r,p)-1)),1/p)
expr1 (g<thr.g||lim.g<1.0001||g>thr.g+s.g)?g:thr.g+s.g*pow(-(pow((g-thr.g)/s.g,p)/(pow((g-thr.g)/s.g,p)-1)),1/p)
expr2 (b<thr.b||lim.b<1.0001||b>thr.b+s.b)?b:thr.b+s.b*pow(-(pow((b-thr.b)/s.b,p)/(pow((b-thr.b)/s.b,p)-1)),1/p)
name uncompress_power
xpos 400
ypos 50
addUserKnob {20 Params_tab l Params}
addUserKnob {18 thr}
thr {{min(0.9999,parent.threshold)} {min(0.9999,parent.threshold)} {min(0.9999,parent.threshold)}}
addUserKnob {6 thr_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
addUserKnob {18 lim}
lim {{parent.cyan+1} {parent.magenta+1} {parent.yellow+1}}
addUserKnob {6 lim_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
addUserKnob {18 s}
s {{(lim-thr)/pow(pow((1-thr)/(lim-thr),-p)-1,1/p)} {(lim-thr)/pow(pow((1-thr)/(lim-thr),-p)-1,1/p)} {(lim-thr)/pow(pow((1-thr)/(lim-thr),-p)-1,1/p)}}
addUserKnob {6 s_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
addUserKnob {7 p R 1 5}
p {{parent.power}}
}
push $N78acc000
Dot {
name Dot6
xpos -446
ypos -30
}
Expression {
expr0 (r<thr.r||lim.r<1.0001)?r:thr.r+s.r*((r-thr.r)/s.r)/(pow(1+pow((r-thr.r)/s.r,p),1/p))
expr1 (g<thr.g||lim.g<1.0001)?g:thr.g+s.g*((g-thr.g)/s.g)/(pow(1+pow((g-thr.g)/s.g,p),1/p))
expr2 (b<thr.b||lim.b<1.0001)?b:thr.b+s.b*((b-thr.b)/s.b)/(pow(1+pow((b-thr.b)/s.b,p),1/p))
name compress_power1
xpos -480
ypos 38
addUserKnob {20 Params_tab l Params}
addUserKnob {18 thr}
thr {{"min(0.9999, parent.threshold)"} {"min(0.9999, parent.threshold)"} {"min(0.9999, parent.threshold)"}}
addUserKnob {6 thr_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
addUserKnob {18 lim}
lim {{parent.cyan+1} {parent.magenta+1} {parent.yellow+1}}
addUserKnob {6 lim_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
addUserKnob {18 s}
s {{(lim-thr)/pow(pow((1-thr)/(lim-thr),-p)-1,1/p)} {(lim-thr)/pow(pow((1-thr)/(lim-thr),-p)-1,1/p)} {(lim-thr)/pow(pow((1-thr)/(lim-thr),-p)-1,1/p)}}
addUserKnob {6 s_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
addUserKnob {7 p R 1 5}
p {{parent.power}}
}
Switch {
inputs 2
which {{parent.invert}}
name switch_reverse
xpos -40
ypos 230
}
Output {
name Output
xpos -40
ypos 326
}
end_group
Expression {
expr0 "abs(g - 2 * y / height) < 0.004 || abs(b - 2 * y / height) < 0.004 || abs(y - height / 2) < 0.002 ? 1 : 0"
expr1 "abs(b - 2 * y / height) < 0.004 || abs(r - 2 * y / height) < 0.004 || abs(y - height / 2) < 0.002 ? 1 : 0"
expr2 "abs(r - 2 * y / height) < 0.004 || abs(g - 2 * y / height) < 0.004 || abs(y - height / 2) < 0.002 ? 1 : 0"
expr3 "abs(r - 2 * y / height) < 0.004 || abs(g - 2 * y / height) < 0.004 || abs(b - 2 * y / height) < 0.004 || abs(y - height / 2) < 0.002 ? 1 : 0"
name Plot
xpos 180
ypos 185
}
push $N78acd400
Dot {
name Dot3
xpos -226
ypos 234
}
push $N78acd000
Dot {
name Dot7
xpos -133
ypos 185
}
push $N78accc00
Group {
name compress
xpos -40
ypos 62
addUserKnob {20 compress}
addUserKnob {18 threshold R 0.4 1}
threshold {0.815 0.803 0.88}
addUserKnob {6 threshold_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
addUserKnob {7 power R 1 3}
power 1.2
addUserKnob {7 cyan}
cyan 0.147
addUserKnob {7 magenta}
magenta 0.264
addUserKnob {7 yellow}
yellow 0.312
addUserKnob {26 ""}
addUserKnob {26 ""}
addUserKnob {6 invert +STARTLINE}
invert {{parent.direction}}
}
Input {
inputs 0
name Input
xpos -40
ypos -130
}
Dot {
name Dot2
xpos -6
ypos -30
}
set N73b23800 [stack 0]
Dot {
name Dot1
xpos 434
ypos -30
}
Expression {
expr0 (r<thr.r||lim.r<1.0001||r>thr.r+s.r)?r:thr.r+s.r*pow(-(pow((r-thr.r)/s.r,p)/(pow((r-thr.r)/s.r,p)-1)),1/p)
expr1 (g<thr.g||lim.g<1.0001||g>thr.g+s.g)?g:thr.g+s.g*pow(-(pow((g-thr.g)/s.g,p)/(pow((g-thr.g)/s.g,p)-1)),1/p)
expr2 (b<thr.b||lim.b<1.0001||b>thr.b+s.b)?b:thr.b+s.b*pow(-(pow((b-thr.b)/s.b,p)/(pow((b-thr.b)/s.b,p)-1)),1/p)
name uncompress_power
xpos 400
ypos 50
addUserKnob {20 Params_tab l Params}
addUserKnob {18 thr}
thr {{min(0.9999,parent.threshold)} {min(0.9999,parent.threshold)} {min(0.9999,parent.threshold)}}
addUserKnob {6 thr_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
addUserKnob {18 lim}
lim {{parent.cyan+1} {parent.magenta+1} {parent.yellow+1}}
addUserKnob {6 lim_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
addUserKnob {18 s}
s {{(lim-thr)/pow(pow((1-thr)/(lim-thr),-p)-1,1/p)} {(lim-thr)/pow(pow((1-thr)/(lim-thr),-p)-1,1/p)} {(lim-thr)/pow(pow((1-thr)/(lim-thr),-p)-1,1/p)}}
addUserKnob {6 s_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
addUserKnob {7 p R 1 5}
p {{parent.power}}
}
push $N73b23800
Dot {
name Dot6
xpos -446
ypos -30
}
Expression {
expr0 (r<thr.r||lim.r<1.0001)?r:thr.r+s.r*((r-thr.r)/s.r)/(pow(1+pow((r-thr.r)/s.r,p),1/p))
expr1 (g<thr.g||lim.g<1.0001)?g:thr.g+s.g*((g-thr.g)/s.g)/(pow(1+pow((g-thr.g)/s.g,p),1/p))
expr2 (b<thr.b||lim.b<1.0001)?b:thr.b+s.b*((b-thr.b)/s.b)/(pow(1+pow((b-thr.b)/s.b,p),1/p))
name compress_power1
xpos -480
ypos 38
addUserKnob {20 Params_tab l Params}
addUserKnob {18 thr}
thr {{"min(0.9999, parent.threshold)"} {"min(0.9999, parent.threshold)"} {"min(0.9999, parent.threshold)"}}
addUserKnob {6 thr_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
addUserKnob {18 lim}
lim {{parent.cyan+1} {parent.magenta+1} {parent.yellow+1}}
addUserKnob {6 lim_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
addUserKnob {18 s}
s {{(lim-thr)/pow(pow((1-thr)/(lim-thr),-p)-1,1/p)} {(lim-thr)/pow(pow((1-thr)/(lim-thr),-p)-1,1/p)} {(lim-thr)/pow(pow((1-thr)/(lim-thr),-p)-1,1/p)}}
addUserKnob {6 s_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
addUserKnob {7 p R 1 5}
p {{parent.power}}
}
Switch {
inputs 2
which {{parent.invert}}
name switch_reverse
xpos -40
ypos 230
}
Output {
name Output
xpos -40
ypos 326
}
end_group
Merge2 {
inputs 2
operation multiply
bbox B
Achannels rgb
Bchannels rgb
output rgb
name Merge3
xpos -40
ypos 182
}
Merge2 {
inputs 2
operation minus
bbox B
Achannels rgb
Bchannels rgb
output rgb
name Merge5
xpos -40
ypos 230
}
set N6a8a9c00 [stack 0]
Merge2 {
inputs 2
name Merge7
xpos 180
ypos 231
}
Dot {
name Dot9
xpos 214
ypos 268
}
push $N6a8a9c00
Switch {
inputs 2
which {{parent.overlay}}
name Switch1
xpos -40
ypos 265
}
Output {
name Output
xpos -40
ypos 302
}
end_group