-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtinteq.ctl
More file actions
145 lines (123 loc) · 4.34 KB
/
tinteq.ctl
File metadata and controls
145 lines (123 loc) · 4.34 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
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
/**
* Tint by luminance ART CTL script.
*
* Copyright 2023 Alberto Griggio <alberto.griggio@gmail.com>
*
* ART is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ART is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ART. If not, see <http://www.gnu.org/licenses/>.
*/
// @ART-label: "$CTL_TINT_BY_LUMINANCE;Tint by luminance"
// @ART-colorspace: "rec2020"
import "_artlib";
float lum(float rgb[3])
{
float Y = luminance(rgb[0], rgb[1], rgb[2]);
return clamp(Y, 1e-5, 32.0);
}
const float centers[12] = {
-16.0, -14.0, -12.0, -10.0, -8.0, -6.0, -4.0, -2.0, 0.0, 2.0, 4.0, 6.0
};
float gauss_sum()
{
float res = 0;
for (int i = 0; i < 12; i = i+1) {
res = res + gauss(centers[i], 2, 0);
}
return res;
}
const float w_sum = gauss_sum();
const float luma_lo = -14.0;
const float luma_hi = 4.0;
float[12] get_factors(float bands[5])
{
float res[12] = {
bands[0],
bands[0],
bands[0],
bands[0],
bands[0],
bands[1],
bands[2],
bands[3],
bands[4],
bands[4],
bands[4],
bands[4]
};
return res;
}
float get_gain(float y, float factors[12])
{
float luma = clamp(log2(y), luma_lo, luma_hi);
float correction = 0;
for (int c = 0; c < 12; c = c+1) {
correction = correction + gauss(centers[c], 2, luma) * factors[c];
}
return correction / w_sum;
}
void hs2uv(float h, float s, output float u, output float v)
{
float a = h / 180.0 * M_PI;
float f = s * 1.5;
u = f * sin(a);
v = f * cos(a);
}
// @ART-param: ["blacks_h", "$CTL_HUE;Hue", 0, 360, 0, 0.1, "$TP_TONE_EQUALIZER_BAND_0"]
// @ART-param: ["blacks_s", "$CTL_STRENGTH;Strength", 0, 1, 0, 0.01, "$TP_TONE_EQUALIZER_BAND_0"]
// @ART-param: ["shadows_h", "$CTL_HUE;Hue", 0, 360, 0, 0.1, "$TP_TONE_EQUALIZER_BAND_1"]
// @ART-param: ["shadows_s", "$CTL_STRENGTH;Strength", 0, 1, 0, 0.01, "$TP_TONE_EQUALIZER_BAND_1"]
// @ART-param: ["midtones_h", "$CTL_HUE;Hue", 0, 360, 0, 0.1, "$TP_TONE_EQUALIZER_BAND_2"]
// @ART-param: ["midtones_s", "$CTL_STRENGTH;Strength", 0, 1, 0, 0.01, "$TP_TONE_EQUALIZER_BAND_2"]
// @ART-param: ["highlights_h", "$CTL_HUE;Hue", 0, 360, 0, 0.1, "$TP_TONE_EQUALIZER_BAND_3"]
// @ART-param: ["highlights_s", "$CTL_STRENGTH;Strength", 0, 1, 0, 0.01, "$TP_TONE_EQUALIZER_BAND_3"]
// @ART-param: ["whites_h", "$CTL_HUE;Hue", 0, 360, 0, 0.1, "$TP_TONE_EQUALIZER_BAND_4"]
// @ART-param: ["whites_s", "$CTL_STRENGTH;Strength", 0, 1, 0, 0.01, "$TP_TONE_EQUALIZER_BAND_4"]
// @ART-param: ["pivot", "$TP_TONE_EQUALIZER_PIVOT", -4, 4, 0, 0.05]
void ART_main(varying float r, varying float g, varying float b,
output varying float rout,
output varying float gout,
output varying float bout,
float blacks_h,
float blacks_s,
float shadows_h,
float shadows_s,
float midtones_h,
float midtones_s,
float highlights_h,
float highlights_s,
float whites_h,
float whites_s,
float pivot)
{
const float gain = 1.0 / pow(2, -pivot);
const float bands_h[5] =
{ blacks_h, shadows_h, midtones_h, highlights_h, whites_h };
const float bands_s[5] =
{ blacks_s, shadows_s, midtones_s, highlights_s, whites_s };
float bands_u[5];
float bands_v[5];
for (int i = 0; i < 5; i = i+1) {
hs2uv(bands_h[i], bands_s[i], bands_u[i], bands_v[i]);
}
const float u_factors[12] = get_factors(bands_u);
const float v_factors[12] = get_factors(bands_v);
float rgb[3] = { r * gain, g * gain, b * gain };
float Y = lum(rgb);
float v_f = get_gain(Y, v_factors);
float u_f = get_gain(Y, u_factors);
float luv[3] = rgb2luv(r, g, b);
rgb = luv2rgb(luv[0], luv[1] + u_f * luv[0], luv[2] + v_f * luv[0]);
rout = rgb[0];
gout = rgb[1];
bout = rgb[2];
}