forked from jedypod/nuke-colortools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompressionFunctions.nk
436 lines (436 loc) · 11.4 KB
/
CompressionFunctions.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
433
434
435
436
set cut_paste_input [stack 0]
push $cut_paste_input
Group {
name CompressionFunctions
addUserKnob {20 CompressionFunctions_tab l CompressionFunctions}
addUserKnob {4 method t "The type of compression function to use. " M {log reinhard power exp arctan tanh}}
method power
addUserKnob {7 threshold t "The minimum threshold. Values below this number will not be affected." R 0 6}
threshold 1
addUserKnob {7 limit t "The asymptotic maximum value. For example, the value that inf becomes." R 1 10}
limit 5
addUserKnob {7 power t "adjust slope of power function (power method only)" R 0 4}
power 1.2
addUserKnob {4 direction M {forward inverse}}
}
Input {
inputs 0
name Input
xpos -40
ypos -610
}
Dot {
name Dot6
xpos -6
ypos -510
}
set Nb798f200 [stack 0]
Dot {
name Dot5
xpos 654
ypos -510
}
set Nb798eb00 [stack 0]
Expression {
expr0 "r < t ? r : t+(l-t)*log((1+(r/(l-t)-t/(l-t)))/(1-(r/(l-t)-t/(l-t))))/2"
expr1 "g < t ? g : t+(l-t)*log((1+(g/(l-t)-t/(l-t)))/(1-(g/(l-t)-t/(l-t))))/2"
expr2 "b < t ? b : t+(l-t)*log((1+(b/(l-t)-t/(l-t)))/(1-(b/(l-t)-t/(l-t))))/2"
name uncompress_tanh
xpos 1170
ypos -442
addUserKnob {20 Params_tab l Params}
addUserKnob {7 t}
t {{"min(parent.threshold, parent.limit)"}}
addUserKnob {7 l R 1 2}
l {{max(th,parent.limit)}}
}
push $Nb798eb00
Expression {
temp_name0 pi
temp_expr0 3.14159265359
expr0 "r < t ? r : t+(l-t)*2/pi*tan(pi/2*(r-t)/(l-t))"
expr1 "g < t ? g : t+(l-t)*2/pi*tan(pi/2*(g-t)/(l-t))"
expr2 "b < t ? b : t+(l-t)*2/pi*tan(pi/2*(b-t)/(l-t))"
name uncompress_atan
xpos 1060
ypos -442
addUserKnob {20 Params_tab l Params}
addUserKnob {7 t}
t {{"min(parent.threshold, parent.limit)"}}
addUserKnob {7 l R 1 2}
l {{max(th,parent.limit)}}
}
push $Nb798eb00
Expression {
expr0 r<th?r:-log((r-lm)/(th-lm))*(-th+lm)/sc+th
expr1 g<th?g:-log((g-lm)/(th-lm))*(-th+lm)/sc+th
expr2 b<th?b:-log((b-lm)/(th-lm))*(-th+lm)/sc+th
name uncompress_exp
xpos 950
ypos -442
addUserKnob {20 Params_tab l Params}
addUserKnob {7 th}
th {{"min(parent.threshold, parent.limit)"}}
addUserKnob {7 lm R 1 2}
lm {{max(th,parent.limit)}}
addUserKnob {7 sc}
sc 1
}
push $Nb798eb00
Expression {
expr0 r<th?r:th+(lm-th)*pow(-pow((r-th)/(lm-th),p)/(pow((r-th)/(lm-th),p)-1),1/p)
expr1 g<th?g:th+(lm-th)*pow(-pow((g-th)/(lm-th),p)/(pow((g-th)/(lm-th),p)-1),1/p)
expr2 b<th?b:th+(lm-th)*pow(-pow((b-th)/(lm-th),p)/(pow((b-th)/(lm-th),p)-1),1/p)
name uncompress_power
xpos 840
ypos -442
addUserKnob {20 Params_tab l Params}
addUserKnob {7 th}
th {{parent.threshold}}
addUserKnob {7 lm}
lm {{parent.limit}}
addUserKnob {7 p R 1 5}
p {{parent.power}}
}
push $Nb798eb00
Expression {
expr0 r<th?r:th+1/(1/(r-th)-1/(lm-th))
expr1 g<th?g:th+1/(1/(g-th)-1/(lm-th))
expr2 b<th?b:th+1/(1/(b-th)-1/(lm-th))
name uncompress_hyperbolic
xpos 730
ypos -442
addUserKnob {20 Params_tab l Params}
addUserKnob {7 th}
th {{"min(parent.threshold, parent.limit)"}}
addUserKnob {7 lm R 1 2}
lm {{parent.limit}}
}
push $Nb798eb00
Expression {
expr0 r<th?r:exp((r-th+th*log(1-lm)-lm*th*log(1-lm))/(th*(1-lm)))*th+lm*th
expr1 g<th?g:exp((g-th+th*log(1-lm)-lm*th*log(1-lm))/(th*(1-lm)))*th+lm*th
expr2 b<th?b:exp((b-th+th*log(1-lm)-lm*th*log(1-lm))/(th*(1-lm)))*th+lm*th
name uncompress_log
xpos 620
ypos -441
addUserKnob {20 Params_tab l Params}
addUserKnob {7 th}
th {{parent.threshold}}
addUserKnob {7 lm}
lm {{min(0.999999,(1-parent.limit)+1)}}
}
Switch {
inputs 6
which {{parent.method}}
name switch_method1
xpos 620
ypos -345
}
Dot {
name Dot2
xpos 654
ypos -198
}
push $Nb798f200
Expression {
expr0 "r < t ? r : t+(l-t)*tanh( ( (r-t)/( l-t)))"
expr1 "g < t ? g : t+(l-t)*tanh( ( (g-t)/( l-t)))"
expr2 "b < t ? b : t+(l-t)*tanh( ( (b-t)/( l-t)))"
name compress_tanh
xpos 510
ypos -442
addUserKnob {20 Params_tab l Params}
addUserKnob {7 t}
t {{"min(parent.threshold, parent.limit)"}}
addUserKnob {7 l R 1 2}
l {{max(th,parent.limit)}}
}
push $Nb798f200
Expression {
temp_name0 pi
temp_expr0 3.14159265359
expr0 "r < t ? r : t+(l-t)*2/pi*atan(pi/2*(r-t)/(l-t))"
expr1 "g < t ? g : t+(l-t)*2/pi*atan(pi/2*(g-t)/(l-t))"
expr2 "b < t ? b : t+(l-t)*2/pi*atan(pi/2*(b-t)/(l-t))"
name compress_atan
xpos 400
ypos -442
addUserKnob {20 Params_tab l Params}
addUserKnob {7 t}
t {{"min(parent.threshold, parent.limit)"}}
addUserKnob {7 l R 1 2}
l {{max(th,parent.limit)}}
}
push $Nb798f200
Expression {
expr0 r<th?r:lm-(lm-th)*exp(-(((r-th)*((sc*lm)/(lm-th))/lm)))
expr1 g<th?g:lm-(lm-th)*exp(-(((g-th)*((sc*lm)/(lm-th))/lm)))
expr2 b<th?b:lm-(lm-th)*exp(-(((b-th)*((sc*lm)/(lm-th))/lm)))
name compress_exp
xpos 290
ypos -442
addUserKnob {20 Params_tab l Params}
addUserKnob {7 th}
th {{"min(parent.threshold, parent.limit)"}}
addUserKnob {7 lm R 1 2}
lm {{max(th,parent.limit)}}
addUserKnob {7 sc}
sc 1
}
push $Nb798f200
Expression {
expr0 r<th?r:th+((r-th)*(lm-th))/pow(pow((lm-th),p)+pow((r-th),p),1/p)
expr1 g<th?g:th+((g-th)*(lm-th))/pow(pow((lm-th),p)+pow((g-th),p),1/p)
expr2 b<th?b:th+((b-th)*(lm-th))/pow(pow((lm-th),p)+pow((b-th),p),1/p)
name compress_power
xpos 180
ypos -443
addUserKnob {20 Params_tab l Params}
addUserKnob {7 th}
th {{parent.threshold}}
addUserKnob {7 lm}
lm {{parent.limit}}
addUserKnob {7 p R 1 5}
p {{parent.power}}
}
push $Nb798f200
Expression {
expr0 r<th?r:th+1/(1/(r-th)+1/(lm-th))
expr1 g<th?g:th+1/(1/(g-th)+1/(lm-th))
expr2 b<th?b:th+1/(1/(b-th)+1/(lm-th))
name compress_hyperbolic
xpos 70
ypos -442
addUserKnob {20 Params_tab l Params}
addUserKnob {7 th}
th {{min(parent.threshold,parent.limit)}}
addUserKnob {7 lm R 1 2}
lm {{parent.limit}}
}
push $Nb798f200
Expression {
expr0 r<th?r:th*log(r/th-lm)-lm*th*log(r/th-lm)+th-th*log(1-lm)+lm*th*log(1-lm)
expr1 g<th?g:th*log(g/th-lm)-lm*th*log(g/th-lm)+th-th*log(1-lm)+lm*th*log(1-lm)
expr2 b<th?b:th*log(b/th-lm)-lm*th*log(b/th-lm)+th-th*log(1-lm)+lm*th*log(1-lm)
name compress_log
xpos -40
ypos -441
addUserKnob {20 Params_tab l Params}
addUserKnob {7 th}
th {{parent.threshold}}
addUserKnob {7 lm}
lm {{min(0.999999,(1-parent.limit)+1)}}
}
Switch {
inputs 6
which {{parent.method}}
name switch_method
xpos -40
ypos -345
}
Switch {
inputs 2
which {{parent.direction}}
name switch_reverse
xpos -40
ypos -202
}
Output {
name Output
xpos -40
ypos -106
}
Expression {
inputs 0
expr0 r<th?r:sc*((r-th)/sc)/pow(1+pow((r-th)/sc,p),1/p)+th
expr1 g<th?g:sc*((g-th)/sc)/pow(1+pow((g-th)/sc,p),1/p)+th
expr2 b<th?b:sc*((b-th)/sc)/pow(1+pow((b-th)/sc,p),1/p)+th
name compress_hyperbolic_power
xpos 1390
ypos -442
addUserKnob {20 Params_tab l Params}
addUserKnob {7 th t "threshold to start compression" R 0 2}
th 0.5
addUserKnob {7 x0 t "x coordinate to compress to" R 0 2}
x0 2
addUserKnob {7 y0 t "y coordinate to compress to" R 0 2}
y0 0.825
addUserKnob {7 p R 1 2}
p 1.2
addUserKnob {7 sc}
sc {{(x0-th)/pow(pow((y0-th)/(x0-th),-p)-1,1/p)}}
}
Expression {
inputs 0
expr0 r<th?r:sc*pow(-pow((r-th)/sc,p)/(pow((r-th)/sc,p)-1),1/p)+th
expr1 g<th?g:sc*pow(-pow((g-th)/sc,p)/(pow((g-th)/sc,p)-1),1/p)+th
expr2 b<th?b:sc*pow(-pow((b-th)/sc,p)/(pow((b-th)/sc,p)-1),1/p)+th
name uncompress_hyperbolic_power
xpos 1500
ypos -442
addUserKnob {20 Params_tab l Params}
addUserKnob {7 th t "threshold to start compression" R 0 2}
th 0.5
addUserKnob {7 x0 t "x coordinate to compress to" R 0 2}
x0 2
addUserKnob {7 y0 t "y coordinate to compress to" R 0 2}
y0 0.825
addUserKnob {7 p R 1 2}
p 1.2
addUserKnob {7 sc}
sc {{(x0-th)/pow(pow((y0-th)/(x0-th),-p)-1,1/p)}}
}
StickyNote {
inputs 0
name StickyNote1
tile_color 0x272727ff
label "<left>Hyperbolic Power Compression Function with (x0, y0) intersection constraint\nhttps://www.desmos.com/calculator/ht27poixiw"
note_font_size 8
note_font_color 0xa8a8a8ff
xpos 1387
ypos -496
}
Expression {
inputs 0
expr0 r<t0?r:sc*sqrt(r-ox)+oy
expr1 g<t0?g:sc*sqrt(g-ox)+oy
expr2 b<t0?b:sc*sqrt(b-ox)+oy
name compress_parabolic
xpos 1718
ypos -442
addUserKnob {20 Params_tab l Params}
addUserKnob {7 t0 t "threshold to start compression" R 0 2}
t0 0.3
addUserKnob {7 x0 t "x coordinate to compress to" R 0 2}
x0 1
addUserKnob {7 y0 t "y coordinate to compress to" R 0 2}
y0 0.5
addUserKnob {7 sc}
sc {{(y0-t0)/sqrt(x0-y0)}}
addUserKnob {7 ox R -2 2}
ox {{t0-sc*sc/4}}
addUserKnob {7 oy R -2 2}
oy {{t0-sc*sqrt(sc*sc/4)}}
}
Expression {
inputs 0
expr0 r<t0?r:pow((oy-r)/sc,2)+ox
expr1 g<t0?g:pow((oy-g)/sc,2)+ox
expr2 b<t0?b:pow((oy-b)/sc,2)+ox
name uncompress_parabolic
xpos 1833
ypos -442
addUserKnob {20 Params_tab l Params}
addUserKnob {7 t0 t "threshold to start compression" R 0 2}
t0 0.3
addUserKnob {7 x0 t "x coordinate to compress to" R 0 2}
x0 1
addUserKnob {7 y0 t "y coordinate to compress to" R 0 2}
y0 0.5
addUserKnob {7 sc}
sc {{(y0-t0)/sqrt(x0-y0)}}
addUserKnob {7 ox R -2 2}
ox {{t0-sc*sc/4}}
addUserKnob {7 oy R -2 2}
oy {{t0-sc*sqrt(sc*sc/4)}}
}
StickyNote {
inputs 0
name StickyNote2
tile_color 0x272727ff
label "<left>Parabolic Compression Function with (x0, y0) intersection constraint\nhttps://www.desmos.com/calculator/khowxlu6xh"
note_font_size 8
note_font_color 0xa8a8a8ff
xpos 1711
ypos -496
}
Expression {
inputs 0
expr0 !x0?r:r>t0?r:sc*sqrt(-r-ox)+oy
expr1 !x0?g:g>t0?g:sc*sqrt(-g-ox)+oy
expr2 !x0?b:b>t0?b:sc*sqrt(-b-ox)+oy
name compress_toe_parabolic
xpos 2050
ypos -442
addUserKnob {20 Params_tab l Params}
addUserKnob {7 t0 t "threshold to start compression" R 0 2}
t0 0.3
addUserKnob {7 x0 t "x coordinate to compress to" R 0 2}
x0 1
addUserKnob {7 sc}
sc {{-t0/sqrt(x0)}}
addUserKnob {7 ox R -2 2}
ox {{-sc*sc/4-t0}}
addUserKnob {7 oy R -2 2}
oy {{t0-sc*sqrt(sc*sc/4)}}
}
Expression {
inputs 0
expr0 r>t0?r:-pow((oy-r)/sc,2)-ox
expr1 g>t0?g:-pow((oy-g)/sc,2)-ox
expr2 b>t0?b:-pow((oy-b)/sc,2)-ox
name uncompress_toe_parabolic
xpos 2160
ypos -442
addUserKnob {20 Params_tab l Params}
addUserKnob {7 t0 t "threshold to start compression" R 0 2}
t0 0.3
addUserKnob {7 x0 t "x coordinate to compress to" R 0 2}
x0 1
addUserKnob {7 sc}
sc {{-t0/sqrt(x0)}}
addUserKnob {7 ox R -2 2}
ox {{-sc*sc/4-t0}}
addUserKnob {7 oy R -2 2}
oy {{t0-sc*sqrt(sc*sc/4)}}
}
Expression {
inputs 0
temp_name0 n
temp_expr0 max(r,g,b)
temp_name1 s
temp_expr1 n<t0?1:invert?(_b-_a/(n-s1))/n:(_a/(_b-n)+s1)/n
expr0 r*s
expr1 g*s
expr2 b*s
expr3 a*s
name HyperbolicCompression
xpos 2490
ypos -442
addUserKnob {20 Params}
addUserKnob {7 t0}
t0 0.18
addUserKnob {7 w0 t "input x" R 0 20}
w0 4
addUserKnob {7 w1 t "output y" R 0 4}
w1 1
addUserKnob {7 s1 R 0 4}
s1 {{(w0*w1-t0*(2*w1-t0))/(w0-w1)}}
addUserKnob {7 _a R 0 4}
_a {{(t0-s1)**2}}
addUserKnob {7 _b R 0 4}
_b {{2*t0-s1}}
addUserKnob {6 invert +STARTLINE}
}
StickyNote {
inputs 0
name StickyNote3
tile_color 0x272727ff
label "<left>Parabolic Toe Compression Function with (x0, 0) intersection constraint\nhttps://www.desmos.com/calculator/wfw5rzrv5x"
note_font_size 8
note_font_color 0xa8a8a8ff
xpos 2033
ypos -502
}
StickyNote {
inputs 0
name StickyNote4
tile_color 0x272727ff
label "<left>Simpler hyperbolic compression function\nhttps://www.desmos.com/calculator/e4ik6xh0tz"
note_font_size 8
note_font_color 0xa8a8a8ff
xpos 2440
ypos -509
}
end_group