forked from jedypod/gamut-compress
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGamutCompress.nk
240 lines (240 loc) · 7.14 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
set cut_paste_input [stack 0]
push $cut_paste_input
Group {
name GamutCompress
addUserKnob {20 GamutCompress}
addUserKnob {41 threshold t "Percentage of the outer gamut boundary to affect. A value of 0.2 means 20% of the outer gamut will be utilized for gamut compression." T compress.threshold}
addUserKnob {41 power t "Adjust the exponent of the compression function. 1 = Reinhard. Higher values have C2 continuity and result in a more \"aggressive\" curve which preserves more color purity or saturation.\n\nBe wary of high values if accurate inv\nersion is important to you." T compress.power}
addUserKnob {7 shd_rolloff l "shd rolloff" t "Shadow rolloff reduces the gamut compression effect below the specified pixel value. This reduces invertability issues with negative pixels in shadow grain." R 0 0.03}
shd_rolloff 0
addUserKnob {26 distance_limit_label l " " t "Specifies the maximum distance beyond the gamut boundary to map to the gamut boundary for each color component." T "<b>max 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 {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.2,\n 'power': 1.2,\n 'shd_rolloff': 0.0,\n 'cyan': 0.09,\n 'magenta':0.24,\n 'yellow': 0.12,\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/jedypod/gamut-compress>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 -298
}
Dot {
name Dot4
xpos -6
ypos -198
}
set N358f7310 [stack 0]
Dot {
name Dot2
xpos -226
ypos -198
}
Expression {
channel0 {rgba.red rgba.green rgba.blue none}
expr0 max(r,g,b)
name achromatic
xpos -260
ypos -154
}
set N420bd290 [stack 0]
Dot {
name Dot1
xpos -226
ypos -102
}
set N354f7b20 [stack 0]
Dot {
name Dot3
xpos -226
ypos 66
}
push $N354f7b20
Expression {
temp_name0 c_r
temp_expr0 1-r
temp_name1 c_g
temp_expr1 1-g
temp_name2 c_b
temp_expr2 1-b
expr0 1-(c_r<(1-thr)?c_r:(1-thr)+thr*tanh(((c_r-(1-thr))/thr)))
expr1 1-(c_g<(1-thr)?c_g:(1-thr)+thr*tanh(((c_g-(1-thr))/thr)))
expr2 1-(c_b<(1-thr)?c_b:(1-thr)+thr*tanh(((c_b-(1-thr))/thr)))
name toe
xpos -150
ypos -106
disable {{parent.shd_rolloff<0.004}}
addUserKnob {20 Params_tab l Params}
addUserKnob {7 thr t "complement of threshold"}
thr {{parent.shd_rolloff}}
}
Expression {
expr0 abs(r)
expr1 abs(g)
expr2 abs(b)
name abs
xpos -150
ypos -82
}
set N3539e690 [stack 0]
Dot {
name Dot7
xpos -116
ypos 18
}
push $N3539e690
push $N420bd290
push $N358f7310
Merge2 {
inputs 2
operation minus
bbox B
Achannels rgb
Bchannels rgb
output rgb
name Merge1
xpos -40
ypos -154
}
MergeExpression {
inputs 2
expr0 Ar==0?0:Br/Ar
expr1 Ag==0?0:Bg/Ag
expr2 Ab==0?0:Bb/Ab
channel3 none
name MergeDivide
xpos -40
ypos -82
}
Group {
name compress
xpos -40
ypos -34
addUserKnob {20 compress}
addUserKnob {18 threshold}
threshold 0.2
addUserKnob {6 threshold_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
addUserKnob {7 power R 1 5}
power 1.2
addUserKnob {7 cyan}
cyan 0.09
addUserKnob {7 magenta}
magenta 0.24
addUserKnob {7 yellow}
yellow 0.12
addUserKnob {26 ""}
addUserKnob {6 invert +STARTLINE}
invert {{parent.direction}}
}
Input {
inputs 0
name Input
xpos -260
ypos -250
}
set N326b77d0 [stack 0]
Expression {
temp_name0 s_x
temp_expr0 (lim_x-thr_x)/pow(pow((1-thr_x)/(lim_x-thr_x),-p)-1,1/p)
temp_name1 s_y
temp_expr1 (lim_y-thr_y)/pow(pow((1-thr_y)/(lim_y-thr_y),-p)-1,1/p)
temp_name2 s_z
temp_expr2 (lim_z-thr_z)/pow(pow((1-thr_z)/(lim_z-thr_z),-p)-1,1/p)
expr0 r<thr_x||lim_x<1.0001?r:r>(thr_x+s_x)?r:thr_x+s_x*pow(-(pow((r-thr_x)/s_x,p)/(pow((r-thr_x)/s_x,p)-1)),1/p)
expr1 g<thr_y||lim_y<1.0001?g:g>(thr_y+s_y)?g:thr_y+s_y*pow(-(pow((g-thr_y)/s_y,p)/(pow((g-thr_y)/s_y,p)-1)),1/p)
expr2 b<thr_z||lim_z<1.0001?b:b>(thr_z+s_z)?b:thr_z+s_z*pow(-(pow((b-thr_z)/s_z,p)/(pow((b-thr_z)/s_z,p)-1)),1/p)
name uncompress
xpos -150
ypos -202
addUserKnob {20 Params_tab l Params}
addUserKnob {7 thr_x}
thr_x {{1-parent.threshold.r}}
addUserKnob {7 thr_y}
thr_y {{1-parent.threshold.g}}
addUserKnob {7 thr_z}
thr_z {{1-parent.threshold.b}}
addUserKnob {7 lim_x}
lim_x {{parent.cyan+1}}
addUserKnob {7 lim_y}
lim_y {{parent.magenta+1}}
addUserKnob {7 lim_z}
lim_z {{parent.yellow+1}}
addUserKnob {7 p R 1 5}
p {{parent.power}}
}
push $N326b77d0
Expression {
temp_name0 s_x
temp_expr0 (lim_x-thr_x)/pow(pow((1-thr_x)/(lim_x-thr_x),-p)-1,1/p)
temp_name1 s_y
temp_expr1 (lim_y-thr_y)/pow(pow((1-thr_y)/(lim_y-thr_y),-p)-1,1/p)
temp_name2 s_z
temp_expr2 (lim_z-thr_z)/pow(pow((1-thr_z)/(lim_z-thr_z),-p)-1,1/p)
expr0 r<thr_x||lim_x<1.0001?r:thr_x+s_x*((r-thr_x)/s_x)/(pow(1+pow((r-thr_x)/s_x,p),1/p))
expr1 g<thr_y||lim_y<1.0001?g:thr_y+s_y*((g-thr_y)/s_y)/(pow(1+pow((g-thr_y)/s_y,p),1/p))
expr2 b<thr_z||lim_z<1.0001?b:thr_z+s_z*((b-thr_z)/s_z)/(pow(1+pow((b-thr_z)/s_z,p),1/p))
name compress
xpos -370
ypos -202
addUserKnob {20 Params_tab l Params}
addUserKnob {7 thr_x}
thr_x {{1-parent.threshold.r}}
addUserKnob {7 thr_y}
thr_y {{1-parent.threshold.g}}
addUserKnob {7 thr_z}
thr_z {{1-parent.threshold.b}}
addUserKnob {7 lim_x}
lim_x {{parent.cyan+1}}
addUserKnob {7 lim_y}
lim_y {{parent.magenta+1}}
addUserKnob {7 lim_z}
lim_z {{parent.yellow+1}}
addUserKnob {7 p R 1 5}
p {{parent.power}}
}
Switch {
inputs 2
which {{parent.invert}}
name switch_direction
xpos -260
ypos -154
}
Output {
name Output
xpos -260
ypos -106
}
end_group
Merge2 {
inputs 2
operation multiply
bbox B
Achannels rgb
Bchannels rgb
output rgb
name Merge3
xpos -40
ypos 14
}
Merge2 {
inputs 2
operation minus
bbox B
Achannels rgb
Bchannels rgb
output rgb
name Merge5
xpos -40
ypos 62
}
Output {
name Output
xpos -40
ypos 158
}
end_group