forked from jedypod/nuke-colortools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlotWaveform.nk
432 lines (432 loc) · 11.7 KB
/
PlotWaveform.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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
set cut_paste_input [stack 0]
push $cut_paste_input
Group {
name PlotWaveform
addUserKnob {20 Waveform_tab l Waveform}
addUserKnob {41 useGPUIfAvailable l "Use GPU if available" T WaveForm.useGPUIfAvailable}
addUserKnob {41 vectorize l "Vectorize on CPU" -STARTLINE T WaveForm.vectorize}
addUserKnob {26 ""}
addUserKnob {4 style M {fill add right bottom pip "" ""}}
addUserKnob {6 guides t "draw guides at integer values (0, 1, 2 etc), and 0.18" -STARTLINE}
guides true
addUserKnob {6 split_rgb l "split rgb" t "separate rgb" -STARTLINE}
addUserKnob {41 specifiedFormat l format t "specify the output format. Otherwise the input format will be used." -STARTLINE T WaveForm.specifiedFormat}
addUserKnob {41 format l "" -STARTLINE T WaveForm.format}
addUserKnob {6 log_transform l "log transform" t "display waveform in log (generic log2 shaper)" +STARTLINE}
addUserKnob {6 antialias t "enable antialiasing" -STARTLINE}
addUserKnob {7 max_value l "max value" t "The value to map to the top of frame. For example you may want to set this to the max pixel value in the image." R 1 25}
max_value 1.1
addUserKnob {7 min_value l "min value" R -1 0}
min_value -0.03
addUserKnob {7 brightness t "multiply the brightness of the waveform"}
brightness 0.2
addUserKnob {22 set_max l "set max" t "Set's the max slider to the max pixel value on the current frame of the input image." T "n = nuke.thisNode()\nnuke.root().begin()\nn.begin()\nct = nuke.toNode('CT')\nnuke.execute(ct, nuke.frame(), nuke.frame())\nmaxpx = ct\['maxlumapixvalue'].getValue()\nave = (maxpx\[0] + maxpx\[1] + maxpx\[2])/3\nn\['max_value'].setValue(ave)" +STARTLINE}
addUserKnob {41 box_size l pip_size t "set the picture in picture size" T Reformat3.box_size}
}
Input {
inputs 0
name Input
xpos 70
ypos -226
}
AddChannels {
name AddChannels1
xpos 70
ypos -184
}
Dot {
name Dot1
label " "
note_font_size 24
note_font_color 0xa5a5a501
xpos 104
ypos -102
}
set N167d8160 [stack 0]
Reformat {
format {{{parent.WaveForm.format}}}
resize distort
filter impulse
name ReScale
xpos 70
ypos -58
disable {{!parent.specifiedFormat}}
}
set N40029a00 [stack 0]
CurveTool {
operation "Max Luma Pixel"
ROI {0 0 {input.width} {input.height}}
autocropdata {0 0 {input.width} {input.height}}
maxlumapixdata {{curve x1 1047 x14 1800} {curve x1 2212 x14 436}}
maxlumapixvalue {{curve x1 5.210135937 x14 3.869687557} {curve x1 10.19536495 x14 4.130000114} {curve x1 9.513872147 x14 3.160937548}}
minlumapixdata {{curve x1 0 x14 380} {curve x1 26 x14 0}}
minlumapixvalue {{curve x1 0.01240783278 x14 0} {curve x1 0.00967685692 x14 0} {curve x1 0.02308944985 x14 0}}
name CT
xpos -40
ypos -58
}
push $N40029a00
BlinkScript {
recompileCount 39
KernelDescription "2 \"PlotWaveform\" iterate pixelWise 88b7f52352ee7ffcbd8d6465ec4ac2ee10c040557f69f3c5cce1cf1b8c43cde4 2 \"src\" Read Random \"dst\" Write Random 10 \"max_value\" Float 1 AAAAAA== \"min_value\" Float 1 AAAAAA== \"tolerance\" Float 1 AAAAAA== \"mult\" Float 1 AAAAAA== \"log_min\" Float 1 AAAAAA== \"log_max\" Float 1 AAAAAA== \"enable_log_transform\" Bool 1 AA== \"antialias\" Bool 1 AA== \"draw_lines\" Bool 1 AA== \"lines_color\" Float 4 AAAAAAAAAAAAAAAAAAAAAA== 10 \"max_value\" 1 1 \"min_value\" 1 1 \"tolerance\" 1 1 \"mult\" 1 1 \"log_min\" 1 1 \"log_max\" 1 1 \"enable_log_transform\" 1 1 \"antialias\" 1 1 \"draw_lines\" 1 1 \"lines_color\" 4 1 1 \"yscale\" Float 1 1 AAAAAA=="
kernelSource "kernel PlotWaveform : public ImageComputationKernel<ePixelWise>\n\{\n Image<eRead, eAccessRandom, eEdgeClamped> src;\n Image<eWrite, eAccessRandom> dst;\n\n param:\n float max_value;\n float min_value;\n float tolerance;\n float mult;\n float log_min;\n float log_max;\n bool enable_log_transform;\n bool antialias;\n bool draw_lines;\n float4 lines_color;\n\n local:\n float yscale;\n\n void init() \{\n yscale = dst.bounds.height() / max_value;\n \}\n\n float gaussian(float d, float a, float expv) \{\n return max(0.0f, exp(-a*d*d)-expv);\n \}\n\n float gaussian_filter(float x, float y, float r) \{\n // return gaussian weighted distance from origin (0, 0)\n // given coordinate (x, y) and radius r\n float a = 1.5f; // rate falloff\n float expv = exp(-a*r*r);\n return gaussian(x, a, expv) * gaussian(y, a, expv);\n \}\n\n void write(float x, float y, int k, float c) \{\n // Write cubic antialiased pixel value c in channel k at continuous float position x, y\n int n = 2;\n int u0 = round(x);\n int v0 = round(y);\n // skip if center pixel weight is greater than tolerance\n if ( dst.bounds.inside(u0, v0)) \{\n if (dst(u0, v0, 3) >= tolerance) return;\n \}\n // loop over neighborhood\n for (int j = -n; j <= n; j++) \{\n int v = v0 + j;\n for (int i = -n; i <= n; i++) \{\n int u = u0 + i;\n if ( dst.bounds.inside(u, v)) \{\n // get filter weight for coord (u,v)\n float w = gaussian_filter(u-x, v-y, float(n));\n float c0 = dst(u, v, k); // existing color\n // merge current color sample over existing color sample\n dst(u, v, k) = c*w*mult+c0;\n // merge current weight over existing weight\n float w0 = dst(u, v, 3);\n dst(u, v, 3) = w+w0*(1-w);\n \}\n \}\n \}\n \}\n\n float log_transform(float x) \{\n return x > 0.0f ? (log( x / 0.18f)/log(2.0f) - log_min) / (log_max - log_min) : x;\n \}\n\n void process(int2 pos) \{\n float4 source = src(pos.x, pos.y);\n if (enable_log_transform) \{\n for (int k = 0; k < 3; k++)\{\n source\[k] = log_transform(source\[k]);\n \}\n \}\n float4 source_scaled = (source - min_value) * yscale;\n if (antialias) \{\n for (int k = 0; k < 3; k++)\{\n write(pos.x, source_scaled\[k], k, source\[k]);\n \}\n \} else \{\n for (int k = 0; k < 3; k++)\{\n if ( dst.bounds.inside(pos.x, source_scaled\[k])) \{\n dst(pos.x, source_scaled\[k], k) = source\[k]*mult + dst(pos.x, source_scaled\[k], k);\n dst(pos.x, source_scaled\[k], 3) = 1.0f;\n \}\n \}\n \}\n if (draw_lines) \{\n if (pos.x > 0 && pos.y > 0) return; // only draw the lines once\n for (int i = 0; i < 50; i++) \{\n float val = i;\n if (enable_log_transform) val = log_transform(i);\n for (int k = 0; k < 3; k++) \{\n write(pos.x, (val - min_value)*yscale, k, lines_color\[k]);\n \}\n \}\n \}\n \}\n\};"
rebuild ""
PlotWaveform_max_value {{"parent.log_transform ? 1.01 : (parent.max_value+parent.min_value)"}}
PlotWaveform_min_value {{parent.min_value}}
PlotWaveform_tolerance 2
PlotWaveform_mult {{parent.brightness}}
PlotWaveform_log_min -6.5
PlotWaveform_log_max 6.5
PlotWaveform_enable_log_transform {{parent.log_transform}}
PlotWaveform_antialias {{parent.antialias}}
PlotWaveform_draw_lines {{parent.guides}}
PlotWaveform_lines_color {0.6 0 0.02 1}
format "2048 2048 0 0 2048 2048 1 square_2K"
rebuild_finalise ""
name WaveForm
xpos 70
ypos 32
}
Group {
name RGB_Split
selected true
xpos 70
ypos 110
disable {{!parent.split_rgb}}
}
Input {
inputs 0
name Input
xpos 45
ypos -59
}
Reformat {
type "to box"
box_width {{rint(input.width/3)}}
box_height {{input.height}}
scale {1 1}
resize none
name Reformat4
xpos 45
ypos 1
}
Dot {
name Dot18
label " "
note_font_size 24
note_font_color 0xa5a5a501
xpos 79
ypos 53
}
set N950fcb80 [stack 0]
Dot {
name Dot19
label " "
note_font_size 24
note_font_color 0xa5a5a501
xpos 189
ypos 53
}
Expression {
expr0 0
expr1 0
expr2 b
expr3 a
name Expression3
xpos 155
ypos 97
}
push $N950fcb80
Expression {
expr0 0
expr1 g
expr2 0
expr3 a
name Expression2
xpos 45
ypos 97
}
push $N950fcb80
Dot {
name Dot17
label " "
note_font_size 24
note_font_color 0xa5a5a501
xpos -31
ypos 53
}
Expression {
expr0 r
expr1 0
expr2 0
expr3 a
name Expression1
xpos -65
ypos 97
}
ContactSheet {
inputs 3
width {{parent.input.width}}
height {{parent.input.height}}
rows 1
columns 3
roworder TopBottom
name ContactSheet1
selected true
xpos 45
ypos 152
}
Output {
name Output
xpos 45
ypos 241
}
end_group
Keyer {
operation "luminance key"
name Keyer1
xpos 70
ypos 176
}
Dot {
name Dot5
label " "
note_font_size 24
note_font_color 0xa5a5a501
xpos 104
ypos 234
}
set N93fb1b40 [stack 0]
Dot {
name Dot3
label " Fill"
note_font_size 24
note_font_color 0xa5a5a501
xpos 104
ypos 378
}
Dot {
name Dot13
label " "
note_font_size 24
note_font_color 0xa5a5a501
xpos 104
ypos 444
}
set N758f5390 [stack 0]
Shuffle {
alpha white
name Shuffle1
label "\[value in] -> \[value out]"
xpos 747
ypos 420
}
Reformat {
type "to box"
box_width {{"min(input.width, parent.Input.width*box_size)"}}
scale 0.5
filter notch
black_outside true
pbb true
name Reformat3
xpos 747
ypos 465
addUserKnob {20 User}
addUserKnob {7 box_size R 0.05 0.6}
box_size 0.3
}
push $N167d8160
Dot {
name Dot8
label " "
note_font_size 24
note_font_color 0xa5a5a501
xpos 324
ypos -102
}
set Naa579520 [stack 0]
Dot {
name Dot2
label " "
note_font_size 24
note_font_color 0xa5a5a501
xpos 544
ypos -102
}
BlackOutside {
name BlackOutside2
xpos 510
ypos 14
}
set N1cf4bca0 [stack 0]
Dot {
name Dot7
label " "
note_font_size 24
note_font_color 0xa5a5a501
xpos 764
ypos 18
}
set N828b520 [stack 0]
Dot {
name Dot14
label " "
note_font_size 24
note_font_color 0xa5a5a501
xpos 874
ypos 18
}
Merge2 {
inputs 2
bbox B
name Merge4
xpos 840
ypos 518
}
Dot {
name Dot11
label PIP
note_font_size 24
note_font_color 0xa5a5a501
xpos 874
ypos 570
}
push $N93fb1b40
Dot {
name Dot9
label " "
note_font_size 24
note_font_color 0xa5a5a501
xpos 214
ypos 234
}
set Nca90f340 [stack 0]
Reformat {
type "to box"
box_width {{parent.Input.width}}
box_height {{parent.Input.height}}
box_fixed true
resize none
center false
black_outside true
name Reformat1
xpos 400
ypos 230
}
BlackOutside {
name BlackOutside1
xpos 400
ypos 254
}
set N87cae0 [stack 0]
Position {
translate {0 {-parent.input.height}}
name MoveDown
xpos 620
ypos 254
disable true
}
push $N828b520
Crop {
box {0 {-parent.input.height} {input.width} {input.height}}
reformat true
crop false
name Crop2
xpos 730
ypos 182
}
Merge2 {
inputs 2
name Merge2
xpos 730
ypos 326
}
Dot {
name Dot6
label " Bottom"
note_font_size 24
note_font_color 0xa5a5a501
xpos 764
ypos 378
}
push $N87cae0
Position {
translate {{parent.input.width} 0}
name MoveRight
xpos 400
ypos 278
}
push $N1cf4bca0
Crop {
box {0 0 {parent.MoveRight.bbox.r} {input.height}}
reformat true
crop false
name Crop1
xpos 510
ypos 278
}
Merge2 {
inputs 2
name Merge1
xpos 510
ypos 326
}
Dot {
name Dot4
label " Right"
note_font_size 24
note_font_color 0xa5a5a501
xpos 544
ypos 378
}
push $Nca90f340
Reformat {
type "to box"
box_width {{parent.input.width}}
box_height {{parent.input.height}}
box_fixed true
resize distort
center false
black_outside true
name Reformat2
xpos 180
ypos 279
}
push $Naa579520
Dot {
name Dot12
label " "
note_font_size 24
note_font_color 0xa5a5a501
xpos 324
ypos 190
}
Merge2 {
inputs 2
bbox B
name Merge3
xpos 290
ypos 279
}
Dot {
name Dot10
label " Add"
note_font_size 24
note_font_color 0xa5a5a501
xpos 324
ypos 378
}
push $N758f5390
Switch {
inputs 5
which {{parent.style}}
name SwitchStyle
xpos 70
ypos 566
}
Output {
name Output
xpos 70
ypos 710
}
end_group