forked from rodrigomas/DCTLs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathICTCP_to_Linear_Rec2020.dctl
38 lines (30 loc) · 1.26 KB
/
ICTCP_to_Linear_Rec2020.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
// ICTCP to Linear Rec.2020
// (ICTCP to L'M'S', then L'M'S' to LMS (via PQ EOTF), then LMS to Rec.2020)
__DEVICE__ float eotf(float x) {
float ST2084_M1_d = 1 / 0.1593017578125f;
float ST2084_M2_d = 1 / 78.84375f;
float ST2084_C1 = 0.8359375f;
float ST2084_C2 = 18.8515625f;
float ST2084_C3 = 18.6875f;
float peak = 100.0f;
float x1 = _powf(x, ST2084_M2_d);
float x2 = _fmaxf(x1 - ST2084_C1, 0.0f);
float x3 = _powf(x2 / (ST2084_C2 - ST2084_C3 * x1), ST2084_M1_d);
float x4 = peak * x3;
return x4;
}
__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 float lms[9] = {1.0f, 0.009f, 0.111f, 1.0f, -0.009f, -0.111, 1.0f, 0.56f, -0.321f};
const float rec2020[9] = {3.436607f, -2.506452f, 0.069845f, -0.791330f, 1.983600f, -0.192271f, -0.025950f, -0.098914f, 1.124864f};
float r1 = p_R * lms[0] + p_G * lms[1] + p_B * lms[2];
float g1 = p_R * lms[3] + p_G * lms[4] + p_B * lms[5];
float b1 = p_R * lms[6] + p_G * lms[7] + p_B * lms[8];
float r2 = eotf(r1);
float g2 = eotf(g1);
float b2 = eotf(b1);
float r3 = r2 * rec2020[0] + g2 * rec2020[1] + b2 * rec2020[2];
float g3 = r2 * rec2020[3] + g2 * rec2020[4] + b2 * rec2020[5];
float b3 = r2 * rec2020[6] + g2 * rec2020[7] + b2 * rec2020[8];
return make_float3(r3, g3, b3);
}