forked from rodrigomas/DCTLs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RGBtoHSL.dctl
30 lines (19 loc) · 913 Bytes
/
RGBtoHSL.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
// RGB to HSL
__DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, float p_R, float p_G, float p_B)
{
float Mx = _fmaxf(p_R, _fmaxf(p_G, p_B));
float mn = _fminf(p_R, _fminf(p_G, p_B));
float del_Mx = Mx - mn;
float L = 0.5f * (Mx + mn);
float S = L <= 0.5f ? del_Mx / (Mx + mn) : del_Mx / (2.0f - del_Mx);
float del_R = ((Mx - p_R) / 6.0f + del_Mx / 2.0f) / del_Mx;
float del_G = ((Mx - p_G) / 6.0f + del_Mx / 2.0f) / del_Mx;
float del_B = ((Mx - p_B) / 6.0f + del_Mx / 2.0f) / del_Mx;
float h = del_Mx == 0.0f ? 0.0f : p_R == Mx ? del_B - del_G : p_G == Mx ? 1.0f / 3.0f + del_R - del_B :
2.0f / 3.0f + del_G - del_R;
float H = h < 0.0f ? h + 1.0f : h > 1.0f ? h - 1.0f : h;
const float r = H;
const float g = S;
const float b = L;
return make_float3(r, g, b);
}