-
Notifications
You must be signed in to change notification settings - Fork 1
/
C_Analyze.dctl
134 lines (112 loc) · 3.68 KB
/
C_Analyze.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
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
/*
C_Analyze
This DCTL works togeher with C_Mark. C_Mark places information on the top line and bottom left corner of the video.
C_Analyzes describes the changes made between the C_Mark and C_Analyze nodes.
Version 010
ToDo
- Rec2100 support
- Optimize code
*/
__CONSTANT__ int LEVEL = 12;
__CONSTANT__ int PERCEPTUAL_CURVE = 0;
__DEVICE__ inline float h2r(float v1, float v2, float h)
{
if (h < 0)
h += 1;
if (h > 1)
h -= 1;
if (6 * h < 1)
return v1 + (v2 - v1) * 6 * h;
if (2 * h < 1)
return v2;
if (3 * h < 2)
return v1 + (v2 - v1) * (2 / 3.0f - h) * 6;
return v1;
}
__DEVICE__ float3 compute(int p_X, int p_Y)
{
struct hsl {
float h;
float s;
float l;
};
struct float3 p;
hsl g;
// Generate HSL model
g.h = _fmod(p_X, LEVEL) / LEVEL;
g.l = _fmod(p_Y / 3 / LEVEL, LEVEL) / LEVEL;
g.s = _fmod(p_Y / (LEVEL*LEVEL), LEVEL) / LEVEL;
// Limit the range
g.l = g.l*0.6 + 0.2;
g.s = g.s*0.7 + 0.15;
if (g.s == 0)
p.x = p.y = p.z = g.l;
else
{
float v2 = g.l < 0.5 ? g.l*(1 + g.s) : (g.l + g.s) - (g.s*g.l);
float v1 = 2 * g.l - v2;
p.x = h2r(v1, v2, g.h + 1 / 3.0f);
p.y = h2r(v1, v2, g.h);
p.z = h2r(v1, v2, g.h - 1 / 3.0f);
}
return p;
}
__DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, __TEXTURE__ p_TexR, __TEXTURE__ p_TexG, __TEXTURE__ p_TexB)
{
const int right = p_X >= p_Width / 2 ? p_Width / 2 : 0;
const int bottom = p_Y >= p_Height / 2 ? p_Height / 2 : 0;
if (!right && !bottom)
return make_float3(
_tex2D(p_TexR, 2 * (p_X - right), 2 * (p_Y - bottom)),
_tex2D(p_TexG, 2 * (p_X - right), 2 * (p_Y - bottom)),
_tex2D(p_TexB, 2 * (p_X - right), 2 * (p_Y - bottom)));
if (!right)
{
float xval = p_X * 2;
float val = xval / p_Width;
float d = 0.002;
// Scope
if (!(p_Y % (p_Height / 20)))
return make_float3(0.3, 0.6, 0.7);
float scope = 1 - (p_Y + 1 - p_Height / 2.0f) / (p_Height / 2.0f);
float postR = _tex2D(p_TexR, xval, 0);
float postG = _tex2D(p_TexG, xval, 0);
float postB = _tex2D(p_TexB, xval, 0);
// Relative luminance
float lumR = postR <= 0.081f ? postR / 4.5f : _powf((postR + 0.099f) / 1.099f, 1.0f / 0.45f);
float lumG = postG <= 0.081f ? postG / 4.5f : _powf((postG + 0.099f) / 1.099f, 1.0f / 0.45f);
float lumB = postB <= 0.081f ? postB / 4.5f : _powf((postB + 0.099f) / 1.099f, 1.0f / 0.45f);
float luminance = lumR * 0.2126f + lumG * 0.7152f + lumB * 0.0722f;
if (PERCEPTUAL_CURVE && luminance >= scope - d && luminance <= scope + d && !(p_X % 4))
return make_float3(1, 1, 1);
// Green first for tinting the overlappings
if (postG >= scope - d && postG <= scope + d)
return make_float3((postG == postR) ? 0.9 : 0, 1, (postG == postB) ? 0.9 : 0);
if (postR >= scope - d && postR <= scope + d)
return make_float3(1, (postR == postG) ? 0.9 : 0, (postR == postB) ? 0.9 : 0);
if (postB >= scope - d && postB <= scope + d)
return make_float3((postB == postR) ? 0.9 : 0, (postB == postG) ? 0.9 : 0, 1);
else
return make_float3(
_tex2D(p_TexR, xval, 0),
_tex2D(p_TexG, xval, 0),
_tex2D(p_TexB, xval, 0));
}
if (right)
{
int p_Xs = ((p_X - right) / (right / LEVEL));
int p_Ys = (p_Y / ((float) p_Height / (LEVEL*LEVEL)));
if ((float) p_X / (right / LEVEL) - (p_X / (right / LEVEL)) > 0.5f)
return compute(p_Xs, (int) (LEVEL*LEVEL*LEVEL / (float) p_Height * p_Y));
else
{
// Scale the X and Y values
int height = p_Ys*LEVEL;
int x = height + p_Xs;
return make_float3(
_tex2D(p_TexR, x, p_Height - 1),
_tex2D(p_TexG, x, p_Height - 1),
_tex2D(p_TexB, x, p_Height - 1));
}
}
}