-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColorMaskRemove_V04.dctl
110 lines (90 loc) · 3.23 KB
/
ColorMaskRemove_V04.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
//Remove Color Mask Ver.04
//2020-06-22 19:00
//By HikariDragon
//https://github.com/OwenYou/DavinciResolveDCTL_RemoveColorMask/
//Release Notes
//----Ver.04----
//- fix: new color mask removal algorithm, easier to control and more precise.
//----Ver.03----
//- fix: wrong exposure adjustment algorithm.
//- !be noticed: the exposure equation in this version is not based on the same cineon log curve used by Davinci Resolve, this may lead to unexpected result. I may fix this in later versions.
//----Ver.02----
//- add function: adjust exposure
//----Ver.01----
//- add function: RGB channel black & white point
//- add function: Negative invert
//--------UI Components--------
//isNegative
DEFINE_UI_PARAMS(isNegative, IsNegative, DCTLUI_CHECK_BOX, 0)
//exposure
DEFINE_UI_PARAMS(expo, Exposure, DCTLUI_SLIDER_FLOAT, 0.0, -3.0, 3.0, 1.0)
//Red channel
DEFINE_UI_PARAMS(RL, Red Low Point, DCTLUI_SLIDER_FLOAT, 0.0, 0.0, 1.0, 0.005)
DEFINE_UI_PARAMS(RH, Red High Point, DCTLUI_SLIDER_FLOAT, 1.0, 0.0, 1.0, 0.005)
//Green channel
DEFINE_UI_PARAMS(GL, Green Low Point, DCTLUI_SLIDER_FLOAT, 0.0, 0.0, 1.0, 0.005)
DEFINE_UI_PARAMS(GH, Green High Point, DCTLUI_SLIDER_FLOAT, 1.0, 0.0, 1.0, 0.005)
//Blue channel
DEFINE_UI_PARAMS(BL, Blue Low Point, DCTLUI_SLIDER_FLOAT, 0.0, 0.0, 1.0, 0.005)
DEFINE_UI_PARAMS(BH, Blue High Point, DCTLUI_SLIDER_FLOAT, 1.0, 0.0, 1.0, 0.005)
//--------UI Components--------
//--------Log2linear function--------
__DEVICE__ inline float Log_to_linear(float inv)
{
float outv;
outv = (powf(10.0f , ((1023.0f * inv - 685.0f) / 300.0f)) - 0.010797752f) / (1.0f - 0.010797752f);
return outv;
}
//--------linear2Log function--------
__DEVICE__ inline float linear_to_log(float inv)
{
float outv;
outv = ((685.0f + 300.0f * _log10f(inv * (1.0f - 0.010797752f) + 0.010797752f)) / 1023.0f);
return outv;
}
__DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, float p_R, float p_G, float p_B)
{
expo = _powf(2.0f, expo);
//Positive
if (isNegative == 0)
{
float r = p_R;
float g = p_G;
float b = p_B;
float r2 = (r-RL)/(RH-RL);
float g2 = (g-GL)/(GH-GL);
float b2 = (b-BL)/(BH-BL);
//--------adjust exposure--------
r2 = Log_to_linear(r2);
g2 = Log_to_linear(g2);
b2 = Log_to_linear(b2);
r2 = expo*r2;
g2 = expo*g2;
b2 = expo*b2;
r2 = linear_to_log(r2);
g2 = linear_to_log(g2);
b2 = linear_to_log(b2);
return make_float3(r2, g2, b2);
}
//Negative
else
{
float r = (-1.0f * p_R)+1.0f;
float g = (-1.0f * p_G)+1.0f;
float b = (-1.0f * p_B)+1.0f;
float r2 = (r-RL)/(RH-RL);
float g2 = (g-GL)/(GH-GL);
float b2 = (b-BL)/(BH-BL);
//--------adjust exposure--------
r2 = Log_to_linear(r2);
g2 = Log_to_linear(g2);
b2 = Log_to_linear(b2);
r2 = expo*r2;
g2 = expo*g2;
b2 = expo*b2;
r2 = linear_to_log(r2);
g2 = linear_to_log(g2);
b2 = linear_to_log(b2);
return make_float3(r2, g2, b2);
}
}