forked from rodrigomas/DCTLs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Linear_Rec2020_to_ICTCP.dctl
38 lines (30 loc) · 1.21 KB
/
Linear_Rec2020_to_ICTCP.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
// Linear Rec.2020 to ICTCP
// (Rec.2020 to LMS, then LMS to L'M'S' (via PQ OETF), then L'M'S' to ICTCP)
__DEVICE__ float oetf(float x) {
float ST2084_M1 = 0.1593017578125f;
float ST2084_M2 = 78.84375f;
float ST2084_C1 = 0.8359375f;
float ST2084_C2 = 18.8515625f;
float ST2084_C3 = 18.6875f;
float peak = 100.0f;
float x1 = x / peak;
float X = _powf(x1, ST2084_M1);
float X1 = (ST2084_C1 + ST2084_C2 * X) / (1.0f + ST2084_C3 * X);
float X2 = _powf(X1, ST2084_M2);
return X2;
}
__DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, float p_R, float p_G, float p_B)
{
const int lms[9] = {1688, 2146, 262, 683, 2951, 462, 99, 309, 3688};
const int ictcp[9] = {2048, 2048, 0, 6610, -13613, 7003, 17933, -17390, -543};
float r1 = (p_R * lms[0] + p_G * lms[1] + p_B * lms[2]) / 4096;
float g1 = (p_R * lms[3] + p_G * lms[4] + p_B * lms[5]) / 4096;
float b1 = (p_R * lms[6] + p_G * lms[7] + p_B * lms[8]) / 4096;
float r2 = oetf(r1);
float g2 = oetf(g1);
float b2 = oetf(b1);
float r3 = (r2 * ictcp[0] + g2 * ictcp[1] + b2 * ictcp[2]) / 4096;
float g3 = (r2 * ictcp[3] + g2 * ictcp[4] + b2 * ictcp[5]) / 4096;
float b3 = (r2 * ictcp[6] + g2 * ictcp[7] + b2 * ictcp[8]) / 4096;
return make_float3(r3, g3, b3);
}