-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRec2020_ST2084_to_Rec709_Linear.dctl
More file actions
36 lines (29 loc) · 1.25 KB
/
Rec2020_ST2084_to_Rec709_Linear.dctl
File metadata and controls
36 lines (29 loc) · 1.25 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
// Rec.2020 ST2084 to Rec.709 Linear (EOTF)
__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 xyz[9] = {0.636958048f, 0.144616904f, 0.168880975f, 0.262700212f, 0.677998072f, 0.0593017165f, 0.0f, 0.028072693f, 1.06098506f};
const float rec709[9] = {3.2404542f, -1.5371385f, -0.4985314f, -0.9692660f, 1.8760108f, 0.0415560f, 0.0556434f, -0.2040259f, 1.0572252f};
float r1 = eotf(p_R);
float g1 = eotf(p_G);
float b1 = eotf(p_B);
float r2 = r1 * xyz[0] + g1 * xyz[1] + b1 * xyz[2];
float g2 = r1 * xyz[3] + g1 * xyz[4] + b1 * xyz[5];
float b2 = r1 * xyz[6] + g1 * xyz[7] + b1 * xyz[8];
float r3 = r2 * rec709[0] + g2 * rec709[1] + b2 * rec709[2];
float g3 = r2 * rec709[3] + g2 * rec709[4] + b2 * rec709[5];
float b3 = r2 * rec709[6] + g2 * rec709[7] + b2 * rec709[8];
return make_float3(r3, g3, b3);
}