-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgamutcompress.ctl
More file actions
67 lines (56 loc) · 2.44 KB
/
gamutcompress.ctl
File metadata and controls
67 lines (56 loc) · 2.44 KB
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
// ACES-style gamut compression
//
// @ART-colorspace: "rec2020"
// @ART-label: "$CTL_GAMUT_COMPRESSION;Gamut compression"
import "_artlib";
const float to_p3[3][3] = transpose_f33(mult_f33_f33(invert_f33(xyz_p3),
xyz_rec2020));
const float from_p3[3][3] = invert_f33(to_p3);
const float to_rec709[3][3] = transpose_f33(mult_f33_f33(invert_f33(xyz_rec709),
xyz_rec2020));
const float from_rec709[3][3] = invert_f33(to_rec709);
const float to_ap1[3][3] = transpose_f33(mult_f33_f33(invert_f33(xyz_ap1),
xyz_rec2020));
const float from_ap1[3][3] = invert_f33(to_ap1);
// @ART-param: ["colorspace", "$CTL_TARGET_GAMUT;Target gamut", ["Rec.2020", "Rec.709 / sRGB", "DCI-P3", "ACES AP1"], 3]
// @ART-param: ["th_c", "$CTL_CYAN;Cyan", 0.0, 1, 0.815, 0.001, "$CTL_THRESHOLD;Threshold"]
// @ART-param: ["th_m", "$CTL_MAGENTA;Magenta", 0.0, 1, 0.803, 0.001, "$CTL_THRESHOLD;Threshold"]
// @ART-param: ["th_y", "$CTL_YELLOW;Yellow", 0.0, 1, 0.880, 0.001, "$CTL_THRESHOLD;Threshold"]
// @ART-param: ["d_c", "$CTL_CYAN;Cyan", 1.001, 2, 1.147, 0.001, "$CTL_LIMIT;Limit"]
// @ART-param: ["d_m", "$CTL_MAGENTA;Magenta", 1.001, 2, 1.264, 0.001, "$CTL_LIMIT;Limit"]
// @ART-param: ["d_y", "$CTL_YELLOW;Yellow", 1.001, 2, 1.312, 0.001, "$CTL_LIMIT;Limit"]
// @ART-param: ["pwr", "$CTL_ROLL_OFF;Roll-off", 0.5, 2.0, 1.2, 0.01]
void ART_main(varying float r, varying float g, varying float b,
output varying float rout,
output varying float gout,
output varying float bout,
int colorspace,
float th_c, float th_m, float th_y,
float d_c, float d_m, float d_y,
float pwr)
{
float rgb[3] = {r, g, b};
float to_out[3][3] = {
{1, 0, 0},
{0, 1, 0},
{0, 0, 1}
};
float from_out[3][3] = to_out;
if (colorspace == 1) { // rec709
to_out = to_rec709;
from_out = from_rec709;
} else if (colorspace == 2) { // DCI P3
to_out = to_p3;
from_out = from_p3;
} else if (colorspace == 3) { // ACES AP1
to_out = to_ap1;
from_out = from_ap1;
}
float th[3] = { th_c, th_m, th_y };
float dl[3] = { d_c, d_m, d_y };
rgb = gamut_compress(rgb, th, dl, to_out, from_out, pwr);
// Return output RGB
rout = rgb[0];
gout = rgb[1];
bout = rgb[2];
}