-
Notifications
You must be signed in to change notification settings - Fork 6
/
Camera-AgX.dctl
310 lines (277 loc) · 10.1 KB
/
Camera-AgX.dctl
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
DEFINE_UI_PARAMS(rc, Red Attenuation Rate, DCTLUI_SLIDER_FLOAT, 0.25, 0.001, 0.999, 0.001)
DEFINE_UI_PARAMS(gc, Green Attenuation Rate, DCTLUI_SLIDER_FLOAT, 0.25, 0.001, 0.999, 0.001)
DEFINE_UI_PARAMS(bc,Blue Attenuation Rate, DCTLUI_SLIDER_FLOAT, 0.25, 0.001, 0.999, 0.001)
DEFINE_UI_PARAMS(ored, Red Hue Flight, DCTLUI_SLIDER_FLOAT, 4.0, -25.0, 25.0, 0.5)
DEFINE_UI_PARAMS(og, Green Hue Flight, DCTLUI_SLIDER_FLOAT, -0.50, -25.0, 25.0, 0.5)
DEFINE_UI_PARAMS(ob, Blue Hue Flight, DCTLUI_SLIDER_FLOAT, -4.0, -25.0, 25.0, 0.5)
DEFINE_UI_PARAMS(r_restore, Red Purity, DCTLUI_SLIDER_FLOAT, 0.25, -5.0, 0.999, 0.1)
DEFINE_UI_PARAMS(g_restore, Green Purity, DCTLUI_SLIDER_FLOAT, 0.25, -5.0, 0.999, 0.1)
DEFINE_UI_PARAMS(b_restore, Blue Purity, DCTLUI_SLIDER_FLOAT, 0.25, -5.0, 0.999, 0.1)
DEFINE_UI_PARAMS(tp, Toe Contrast Power, DCTLUI_SLIDER_FLOAT, 1.45, 0.05, 10, 0.1)
DEFINE_UI_PARAMS(sp, Shoulder Contrast Power, DCTLUI_SLIDER_FLOAT, 1.5, 0.05, 10, 0.1)
DEFINE_UI_PARAMS(slope, General Contrast Power, DCTLUI_SLIDER_FLOAT, 2.4, 0.001, 5.0, 0.1)
DEFINE_UI_PARAMS(in_gamut, Input Primaries, DCTLUI_COMBO_BOX, 6, {ap0, ap1, p3d65,p3d60, rec2020, rec709, awg3, awg4,rwg, sgamut3,sgamut3cine, blackmagicwg, canoncinema, davinciwg,egamut}, {ACES, ACEScg, P3D65,P3D60, Rec.2020, Rec.709, Alexa Wide Gamut 3,Alexa Wide Gamut 4, Red Wide Gamut RGB, Sony SGamut3,Sony SGamut3Cine, Blackmagic Wide Gamut, Canon Cinema - Gamut, DaVinci Wide Gamut,Filmlight E - Gamut})
DEFINE_UI_PARAMS(in_transfer, Input Transfer Characteristic Encoding, DCTLUI_COMBO_BOX, 2, {in_linear, in_acescct, in_arri_logc, in_arri_logc4, in_red_log3g10, in_sony_slog3, in_blackmagic_film_gen5, in_canonlog3, in_davinci_intermediate, in_filmlight_tlog, in_AgX_Log_Kraken}, {Linear, ACEScct, Arri V3LogC,Arri LogCV4, Red Log3G10, Sony SLog3, Blackmagic Film Gen5, Canon Log3, DaVinci Intermediate,Filmlight TLog, AgX Log Kraken})
DEFINE_UI_PARAMS(in_curve, Working Log Encoding, DCTLUI_COMBO_BOX, 2, {linear, acescct, arri_logc,arri_logc4, red_log3g10, sony_slog3, blackmagic_film_gen5, canonlog3, davinci_intermediate,filmlight_tlog,AgX_Log_Kraken}, {Linear, ACEScct, Arri V3LogC,Arri LogCV4, Red Log3G10, Sony SLog3, Blackmagic Film Gen5, Canon Log3, DaVinci Intermediate,Filmlight TLog, AgX Log Kraken})
DEFINE_UI_PARAMS(wmg, Working Middle Grey, DCTLUI_SLIDER_FLOAT, 0.391, 0.01, 2.0, 0.01)
DEFINE_UI_PARAMS(out_gamut, Output Primaries, DCTLUI_COMBO_BOX, 5, {outap0, outap1, outp3d65, outp3d60, outrec2020, outrec709, outawg3, outawg4, outrwg, outsgamut3, outsgamut3cine, outblackmagicwg, outcanoncinema, outdavinciwg, outegamut}, {ACES, ACEScg, P3D65,P3D60, Rec.2020, Rec.709, Alexa Wide Gamut 3,Alexa Wide Gamut 4, Red Wide Gamut RGB, Sony SGamut3,Sony SGamut3Cine, Blackmagic Wide Gamut, Canon Cinema - Gamut, DaVinci Wide Gamut,Filmlight E - Gamut})
DEFINE_UI_PARAMS(out_transfer, Output Transfer, DCTLUI_COMBO_BOX, 1, {out_linear, out_sRGB_inverse_EOTF, out_BT1886_inverse_EOTF}, { Linear, sRGB Inverse EOTF 2.2, BT.1886 Inverse EOTF 2.4})
DEFINE_UI_PARAMS(logoutput, Log Encoded Output, DCTLUI_CHECK_BOX, 0)
#include "Camera-AgX-Lib.h"
// title: Camera-AgX.dctl
// version: 2023-03-01 18:15:32
__DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, float p_R, float p_G, float p_B)
{
float3x3 in_to_xyz;
float3x3 out_to_xyz;
Chromaticities in_chromaticities = {{0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0}};
Chromaticities out_chromaticities = {{0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0}};
float out_transfer_function = 0.0;
if (in_gamut == ap0) {
in_to_xyz = matrix_ap0_to_xyz;
in_chromaticities = AP0;
}
else if (in_gamut == ap1) {
in_to_xyz = matrix_ap1_to_xyz;
in_chromaticities = AP1;
}
else if (in_gamut == p3d65){
in_to_xyz = matrix_p3d65_to_xyz;
in_chromaticities = P3D65_PRI;
}
else if (in_gamut == p3d60){
in_to_xyz = RGBtoXYZ(P3D60_PRI);
in_chromaticities = P3D60_PRI;
}
else if (in_gamut == rec2020){
in_to_xyz = matrix_rec2020_to_xyz;
in_chromaticities = REC2020_PRI;
}
else if (in_gamut == rec709){
in_to_xyz = matrix_rec709_to_xyz;
in_chromaticities = REC709_PRI;
}
else if (in_gamut == awg3){
in_to_xyz = matrix_arriwg_to_xyz;
in_chromaticities = ARRI_ALEXA_WG_PRI;
}
else if (in_gamut == rwg){
in_to_xyz = matrix_redwg_to_xyz;
in_chromaticities = REDWG_PRI;
}
else if (in_gamut == sgamut3){
in_to_xyz = matrix_sonysgamut3;
in_chromaticities = SGAMUT3_PRI;
}
else if (in_gamut == blackmagicwg){
in_to_xyz = matrix_blackmagicwg_to_xyz;
in_chromaticities = BLACKMAGICWG_PRI;
}
else if (in_gamut == canoncinema){
in_to_xyz = matrix_canoncinema_to_xyz;
in_chromaticities = CANONCINEMA_PRI;
}
else if (in_gamut == davinciwg){
in_to_xyz = matrix_davinciwg_to_xyz;
in_chromaticities = DWGINT_PRI;
}
else if (in_gamut == egamut){
in_to_xyz = matrix_egamut_to_xyz;
in_chromaticities = EGAMUT_PRI;
}
else if (in_gamut == awg4){
in_to_xyz = RGBtoXYZ(ARRI_ALEXA_WG4_PRI);
in_chromaticities = ARRI_ALEXA_WG4_PRI;
}
else if (in_gamut == sgamut3cine){
in_to_xyz = RGBtoXYZ(SGAMUT3cine_PRI);
in_chromaticities = SGAMUT3cine_PRI;
}
if (out_gamut == outap0) {
out_to_xyz = matrix_ap0_to_xyz;
out_chromaticities = AP0;
}
else if (out_gamut == outap1) {
out_to_xyz = matrix_ap1_to_xyz;
out_chromaticities = AP1;
}
else if (out_gamut == outp3d65){
out_to_xyz = matrix_p3d65_to_xyz;
out_chromaticities = P3D65_PRI;
}
else if (out_gamut == outp3d60){
out_to_xyz = RGBtoXYZ(P3D60_PRI);
out_chromaticities = P3D60_PRI;
}
else if (out_gamut == outrec2020){
out_to_xyz = matrix_rec2020_to_xyz;
out_chromaticities = REC2020_PRI;
}
else if (out_gamut == outrec709){
out_to_xyz = matrix_rec709_to_xyz;
out_chromaticities = REC709_PRI;
}
else if (out_gamut == outawg3){
out_to_xyz = matrix_arriwg_to_xyz;
out_chromaticities = ARRI_ALEXA_WG_PRI;
}
else if (out_gamut == outrwg){
out_to_xyz = matrix_redwg_to_xyz;
out_chromaticities = REDWG_PRI;
}
else if (out_gamut == outsgamut3){
out_to_xyz = matrix_sonysgamut3;
out_chromaticities = SGAMUT3_PRI;
}
else if (out_gamut == outblackmagicwg){
out_to_xyz = matrix_blackmagicwg_to_xyz;
out_chromaticities = BLACKMAGICWG_PRI;
}
else if (out_gamut == outcanoncinema){
out_to_xyz = matrix_canoncinema_to_xyz;
out_chromaticities = CANONCINEMA_PRI;
}
else if (out_gamut == outdavinciwg){
out_to_xyz = matrix_davinciwg_to_xyz;
out_chromaticities = DWGINT_PRI;
}
else if (out_gamut == outegamut){
out_to_xyz = matrix_egamut_to_xyz;
out_chromaticities = EGAMUT_PRI;
}
else if (out_gamut == outawg4){
out_to_xyz = RGBtoXYZ(ARRI_ALEXA_WG4_PRI);
out_chromaticities = ARRI_ALEXA_WG4_PRI;
}
else if (out_gamut == outsgamut3cine){
out_to_xyz = RGBtoXYZ(SGAMUT3cine_PRI);
out_chromaticities = SGAMUT3cine_PRI;
}
if (out_transfer == out_linear) {
out_transfer_function = 1.0;
}
else if (out_transfer == out_sRGB_inverse_EOTF) {
out_transfer_function = 2.2;
}
else if (out_transfer == out_BT1886_inverse_EOTF) {
out_transfer_function = 2.4;
}
// const float3x3 xyz_to_in = inv_f33(in_to_xyz);
int in_tf = 0;
if (in_transfer == in_linear) {
in_tf = 0;
}
else if (in_transfer == in_acescct) {
in_tf = 1;
}
else if (in_transfer == in_arri_logc) {
in_tf = 2;
}
else if (in_transfer == in_red_log3g10) {
in_tf = 3;
}
else if (in_transfer == in_sony_slog3) {
in_tf = 4;
}
else if (in_transfer == in_filmlight_tlog) {
in_tf = 5;
}
else if (in_transfer == in_davinci_intermediate) {
in_tf = 6;
}
else if (in_transfer == in_blackmagic_film_gen5) {
in_tf = 7;
}
else if (in_transfer == in_canonlog3) {
in_tf = 8;
}
else if (in_transfer == in_arri_logc4) {
in_tf = 9;
}
else if (in_transfer == in_AgX_Log_Kraken) {
in_tf = 10;
}
int tf = 0;
if (in_curve == linear) {
tf = 0;
}
else if (in_curve == acescct) {
tf = 1;
}
else if (in_curve == arri_logc) {
tf = 2;
}
else if (in_curve == red_log3g10) {
tf = 3;
}
else if (in_curve == sony_slog3) {
tf = 4;
}
else if (in_curve == filmlight_tlog) {
tf = 5;
}
else if (in_curve == davinci_intermediate) {
tf = 6;
}
else if (in_curve == blackmagic_film_gen5) {
tf = 7;
}
else if (in_curve == canonlog3) {
tf = 8;
}
else if (in_curve == arri_logc4) {
tf = 9;
}
else if (in_curve == AgX_Log_Kraken) {
tf = 10;
}
//Pre calculate parameters
//SB2383 scale parameters
Chromaticities inset_chromaticities = InsetPrimaries(in_chromaticities,rc,gc,bc,ored,og,ob);
Chromaticities outset_chromaticities = InsetPrimaries(
in_chromaticities, r_restore, g_restore, b_restore, ored, og, ob
);
float3x3 outsetmat= RGBtoRGB(in_chromaticities, outset_chromaticities);
float3x3 insetmat= RGBtoRGB(inset_chromaticities, in_chromaticities);
// float3x3 insetmat= inv_f33(outsetmat);
float mg = _powf(0.18,1/2.2);
float lmg = wmg;
//Calculate Matrices
float3x3 in_to_out = RGBtoRGB(in_chromaticities, out_chromaticities);
//Input
float3 rgb = make_float3(p_R, p_G, p_B);
float3 agx = rgb;
rgb = log2lin(rgb, in_tf);
// float3 xyz = mult_f3_f33(rgb, in_to_xyz);
// rgb = mult_f3_f33(xyz, xyz_to_rec709);
float3 uniform_logfloor = log2lin(make_float3(0.0, 0.0, 0.0), in_tf);
rgb = maxf3(uniform_logfloor.x, rgb);
//apply inset matrix
rgb = mult_f3_f33(rgb, insetmat);
rgb = lin2log(rgb, tf);
float3 log = rgb;
if (logoutput == 1)
rgb=agx;
rgb.x = tonescale(rgb.x, sp, tp, slope, lmg, mg,1,0);
rgb.y = tonescale(rgb.y, sp, tp, slope, lmg, mg,1,0);
rgb.z = tonescale(rgb.z, sp, tp, slope, lmg, mg,1,0);
//rgb = clampf3(rgb,0,1);
float3 img = rgb;
img = spowf3(img,2.2);
img = mult_f3_f33(img, outsetmat);
img = mult_f3_f33(img, in_to_out);
//img = clampf3(img,0,1);
switch (logoutput) {
case 0:
img = encode_inverse_EOTF(img, out_transfer_function);
img = maxf3(0.0,img);
//img.x = _fabs(img.x);
//img.y = _fabs(img.y);
//img.z = _fabs(img.z);
break;
case 1:
img=log;
break;
}
return img;
}