forked from mapsme/omim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor.cpp
102 lines (80 loc) · 1.58 KB
/
color.cpp
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
#include "drape/color.hpp"
namespace dp
{
namespace
{
static const uint8_t MaxChannelValue = 255;
} // namespace
#define EXTRACT_BYTE(x, n) (((x) >> 8 * (n)) & 0xFF);
#define CHANNEL_TO_FLOAT(x) ((x) / static_cast<float>(MaxChannelValue))
Color::Color()
: m_rgba(MaxChannelValue)
{
}
Color::Color(uint8_t red, uint8_t green, uint8_t blue, uint8_t alfa)
{
m_rgba = red << 24 | green << 16 | blue << 8 | alfa;
}
uint8_t Color::GetRed() const
{
return EXTRACT_BYTE(m_rgba, 3);
}
uint8_t Color::GetGreen() const
{
return EXTRACT_BYTE(m_rgba, 2);
}
uint8_t Color::GetBlue() const
{
return EXTRACT_BYTE(m_rgba, 1);
}
uint8_t Color::GetAlfa() const
{
return EXTRACT_BYTE(m_rgba, 0);
}
float Color::GetRedF() const
{
return CHANNEL_TO_FLOAT(GetRed());
}
float Color::GetGreenF() const
{
return CHANNEL_TO_FLOAT(GetGreen());
}
float Color::GetBlueF() const
{
return CHANNEL_TO_FLOAT(GetBlue());
}
float Color::GetAlfaF() const
{
return CHANNEL_TO_FLOAT(GetAlfa());
}
uint8_t ExtractRed(uint32_t argb)
{
return (argb >> 16) & 0xFF;
}
uint8_t ExtractGreen(uint32_t argb)
{
return (argb >> 8) & 0xFF;
}
uint8_t ExtractBlue(uint32_t argb)
{
return argb & 0xFF;
}
uint8_t ExtractAlfa(uint32_t argb)
{
return (argb >> 24) & 0xFF;
}
Color Extract(uint32_t argb)
{
return Color(ExtractRed(argb),
ExtractGreen(argb),
ExtractBlue(argb),
ExtractAlfa(argb));
}
Color Extract(uint32_t xrgb, uint8_t a)
{
return Color(ExtractRed(xrgb),
ExtractGreen(xrgb),
ExtractBlue(xrgb),
a);
}
} // namespace dp