-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathposterize.ctl
More file actions
35 lines (30 loc) · 856 Bytes
/
posterize.ctl
File metadata and controls
35 lines (30 loc) · 856 Bytes
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
// @ART-label: "$CTL_POSTERIZATION;Posterization"
// @ART-colorspace: "rec709"
import "_artlib";
float lim(float a, float f)
{
float res = a * f;
if (res >= f) {
res = f-1;
}
return res;
}
// @ART-param: ["bits", "$CTL_BITS_PER_CHANNEL;Bits per channel", 1, 16, 8]
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 bits)
{
float f = pow(2, bits);
const float gamma = 2.2;
const float igamma = 1 / gamma;
int rgb[3] = {
lim(pow(fmax(r, 0), igamma), f),
lim(pow(fmax(g, 0), igamma), f),
lim(pow(fmax(b, 0), igamma), f)
};
rout = pow(rgb[0] / f, gamma);
gout = pow(rgb[1] / f, gamma);
bout = pow(rgb[2] / f, gamma);
}