-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathHSLtoRGB.dctl
executable file
·37 lines (25 loc) · 1.15 KB
/
HSLtoRGB.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
// HSL to RGB
__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 H = p_R;
float S = p_G;
float L = p_B;
float Q = L < 0.5f ? L * (1.0f + S) : L + S - L * S;
float P = 2.0f * L - Q;
float RH = H + 1.0f / 3.0f < 0.0f ? H + 1.0f / 3.0f + 1.0f :
H + 1.0f / 3.0f > 1.0f ? H + 1.0f / 3.0f - 1.0f : H + 1.0f / 3.0f;
float RR = RH < 1.0f / 6.0f ? P + (Q - P) * 6.0f * RH :
RH < 1.0f / 2.0f ? Q : RH < 2.0f / 3.0f ? P + (Q - P) * (2.0f / 3.0f - RH) * 6.0f : P;
float GH = H < 0.0f ? H + 1.0f :
H > 1.0f ? H - 1.0f : H;
float GG = GH < 1.0f / 6.0f ? P + (Q - P) * 6.0f * GH :
GH < 1.0f / 2.0f ? Q : GH < 2.0f / 3.0f ? P + (Q - P) * (2.0f / 3.0f - GH) * 6.0f : P;
float BH = H - 1.0f / 3.0f < 0.0f ? H - 1.0f / 3.0f + 1.0f :
H - 1.0f / 3.0f > 1.0f ? H - 1.0f / 3.0f - 1.0f : H - 1.0f / 3.0f;
float BB = BH < 1.0f / 6.0f ? P + (Q - P) * 6.0f * BH :
BH < 1.0f / 2.0f ? Q : BH < 2.0f / 3.0f ? P + (Q - P) * (2.0f / 3.0f - BH) * 6.0f : P;
const float r = S == 0.0f ? L : RR;
const float g = S == 0.0f ? L : GG;
const float b = S == 0.0f ? L : BB;
return make_float3(r, g, b);
}