Welcome to mirror list, hosted at ThFree Co, Russian Federation.

color.cpp « drape - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 437326d2e82738ae3f1cb22c7fc97b4d2db94140 (plain)
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
#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(uint32_t rgba)
  : m_rgba(rgba)
{}

Color::Color(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
{
  m_rgba = red << 24 | green << 16 | blue << 8 | alpha;
}

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::GetAlpha() 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::GetAlphaF() const
{
  return CHANNEL_TO_FLOAT(GetAlpha());
}

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 ExtractAlpha(uint32_t argb)
{
  return (argb >> 24) & 0xFF;
}

Color Extract(uint32_t argb)
{
  return Color(ExtractRed(argb),
               ExtractGreen(argb),
               ExtractBlue(argb),
               ExtractAlpha(argb));
}

Color Extract(uint32_t xrgb, uint8_t a)
{
  return Color(ExtractRed(xrgb),
               ExtractGreen(xrgb),
               ExtractBlue(xrgb),
               a);
}

} // namespace dp