-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypes.cpp
More file actions
90 lines (78 loc) · 2.03 KB
/
Types.cpp
File metadata and controls
90 lines (78 loc) · 2.03 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
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
#include "Types.h"
const ColorRGBA8 ColorHSVA8::ConvertToRGBA8()
{
unsigned char A = a * 255;
float C = v * s;
float X = C * (1.0 - std::abs(std::fmod((h / 60.0), 2.0) - 1.0));
float m = v - C;
if (0 <= h && h < 60) {
return ColorRGBA8(
(C + m) * 255,
(X + m) * 255,
m * 255,
A);
}
else if (60 <= h && h < 120) {
return ColorRGBA8(
(X + m) * 255,
(C + m) * 255,
m * 255,
A);
}
else if (120 <= h && h < 180) {
return ColorRGBA8(
m * 255,
(C + m) * 255,
(X + m) * 255,
A);
}
else if (180 <= h && h < 240) {
return ColorRGBA8(
m * 255,
(X + m) * 255,
(C + m) * 255,
A);
}
else if (240 <= h && h < 300) {
return ColorRGBA8(
(X + m) * 255,
m * 255,
(C + m) * 255,
A);
}
else {
return ColorRGBA8(
(C + m) * 255,
m * 255,
(X + m) * 255,
A);
}
}
const ColorHSVA8 ColorRGBA8::ConvertToHSVA8()
{
float Rprime = (float)r / 255;
float Gprime = (float)g / 255;
float Bprime = (float)b / 255;
float A = (float)a / 255;
float Cmax = std::fmax(std::fmax(Rprime, Gprime), Bprime);
float Cmin = std::fmin(std::fmin(Rprime, Gprime), Bprime);
float delta = Cmax - Cmin;
int H = 0;
if (delta != 0) {
if (Cmax == Rprime)
H = 60 * std::fmod(((Gprime - Bprime) / delta), 6);
else if (Cmax == Gprime)
H = 60 * (((Bprime - Rprime) / delta) + 2);
else if (Cmax == Bprime)
H = 60 * (((Rprime - Gprime) / delta) + 4);
}
if (H < 0)
H = 360 + H;
float S;
if (Cmax == 0)
S = 0;
else
S = delta / Cmax;
float V = Cmax;
return ColorHSVA8(H, S, V, A);
}