-
Notifications
You must be signed in to change notification settings - Fork 3
/
color.hpp
163 lines (134 loc) · 4.19 KB
/
color.hpp
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/***************************************************************************
* Copyright (C) 2012 by Tamino Dauth *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef WC3LIB_COLOR_HPP
#define WC3LIB_COLOR_HPP
/**
* \file
* Provides basic color classes supporting I/O operations and color channels used by
* Warcraft III formats.
*
* \ingroup colors
*
* \defgroup colors Colors
* \brief Everything about colors in Warcraft III.
*/
#include "config.h"
#include "utilities.hpp"
#include "platform.hpp"
#include "format.hpp"
namespace wc3lib
{
/**
* \brief Basic RGB color with storage and serialization support of three color channels.
*
* \ingroup colors
*/
class Rgb : public Format
{
public:
Rgb(uint8_t red, uint8_t green, uint8_t blue);
Rgb();
virtual ~Rgb();
virtual std::streamsize read(InputStream &istream) override;
virtual std::streamsize write(OutputStream &ostream) const override;
void setRed(uint8_t red);
uint8_t red() const;
void setGreen(uint8_t green);
uint8_t green() const;
void setBlue(uint8_t blue);
uint8_t blue() const;
/**
* Computes an integer value representation containing values of all color channels.
* The channel values can be extracting using binary operations like AND.
*
* The first 8 bits are not used (usually alpha value for argb or red value for rgba).
*/
virtual uint32_t value() const;
bool operator==(uint32_t value) const;
bool operator==(const Rgb &other) const;
protected:
uint8_t m_red;
uint8_t m_green;
uint8_t m_blue;
};
class Bgr : public Rgb
{
public:
virtual std::streamsize read(InputStream &istream) override;
virtual std::streamsize write(OutputStream &ostream) const override;
/**
* The first 8 bits are not used (usually alpha value for argb or red value for rgba).
*/
virtual uint32_t value() const override;
};
class Rgba : public Rgb
{
public:
Rgba(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha);
Rgba();
virtual std::streamsize read(InputStream &istream) override;
virtual std::streamsize write(OutputStream &ostream) const override;
void setAlpha(uint8_t alpha);
uint8_t alpha() const;
virtual uint32_t value() const override;
protected:
uint8_t m_alpha;
};
class Bgra : public Rgba
{
public:
virtual std::streamsize read(InputStream &istream) override;
virtual std::streamsize write(OutputStream &ostream) const override;
virtual uint32_t value() const override;
};
inline void Rgb::setRed(uint8_t red)
{
this->m_red = red;
}
inline uint8_t Rgb::red() const
{
return this->m_red;
}
inline void Rgb::setGreen(uint8_t green)
{
this->m_green = green;
}
inline uint8_t Rgb::green() const
{
return this->m_green;
}
inline void Rgb::setBlue(uint8_t blue)
{
this->m_blue = blue;
}
inline uint8_t Rgb::blue() const
{
return this->m_blue;
}
inline void Rgba::setAlpha(uint8_t alpha)
{
this->m_alpha = alpha;
}
inline uint8_t Rgba::alpha() const
{
return this->m_alpha;
}
}
#endif