-
Notifications
You must be signed in to change notification settings - Fork 3
/
color.cpp
154 lines (124 loc) · 4.13 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
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
/***************************************************************************
* Copyright (C) 2014 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. *
***************************************************************************/
#include "color.hpp"
namespace wc3lib
{
Rgb::Rgb(uint8_t red, uint8_t green, uint8_t blue) : m_red(red), m_green(green), m_blue(blue)
{
}
Rgb::Rgb() : m_red(0), m_green(0), m_blue(0)
{
}
Rgb::~Rgb()
{
}
std::streamsize Rgb::read(InputStream &istream)
{
std::streamsize size = 0;
wc3lib::read(istream, m_red, size);
wc3lib::read(istream, m_green, size);
wc3lib::read(istream, m_blue, size);
return size;
}
std::streamsize Rgb::write(OutputStream &ostream) const
{
std::streamsize size = 0;
wc3lib::write(ostream, red(), size);
wc3lib::write(ostream, green(), size);
wc3lib::write(ostream, blue(), size);
return size;
}
uint32_t Rgb::value() const
{
return ((uint32_t)this->red() << 16) + ((uint32_t)this->green() << 8) + this->blue();
}
bool Rgb::operator==(uint32_t value) const
{
return this->value() == value;
}
bool Rgb::operator==(const Rgb &other) const
{
return this->value() == other.value();
}
std::streamsize Bgr::read(InputStream &istream)
{
std::streamsize size = 0;
wc3lib::read(istream, m_blue, size);
wc3lib::read(istream, m_green, size);
wc3lib::read(istream, m_red, size);
return size;
}
std::streamsize Bgr::write(OutputStream &ostream) const
{
std::streamsize size = 0;
wc3lib::write(ostream, blue(), size);
wc3lib::write(ostream, green(), size);
wc3lib::write(ostream, red(), size);
return size;
}
uint32_t Bgr::value() const
{
return ((uint32_t)this->blue() << 16) + ((uint32_t)this->green() << 8) + this->red();
}
Rgba::Rgba(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha) : Rgb(red, green, blue), m_alpha(alpha)
{
}
Rgba::Rgba() : Rgb(), m_alpha(0)
{
}
std::streamsize Rgba::read(InputStream &istream)
{
std::streamsize size = Rgb::read(istream);
wc3lib::read(istream, m_alpha, size);
return size;
}
std::streamsize Rgba::write(OutputStream &ostream) const
{
std::streamsize size = Rgb::write(ostream);
wc3lib::write(ostream, alpha(), size);
return size;
}
uint32_t Rgba::value() const
{
return ((uint32_t)this->red() << 24) + ((uint32_t)this->green() << 16) + ((uint32_t)this->blue() << 8) + this->alpha();
}
std::streamsize Bgra::read(InputStream &istream)
{
std::streamsize size = 0;
wc3lib::read(istream, m_blue, size);
wc3lib::read(istream, m_green, size);
wc3lib::read(istream, m_red, size);
wc3lib::read(istream, m_alpha, size);
return size;
}
std::streamsize Bgra::write(OutputStream &ostream) const
{
std::streamsize size = 0;
wc3lib::write(ostream, blue(), size);
wc3lib::write(ostream, green(), size);
wc3lib::write(ostream, red(), size);
wc3lib::write(ostream, alpha(), size);
return size;
}
uint32_t Bgra::value() const
{
return ((uint32_t)this->blue() << 24) + ((uint32_t)this->green() << 16) + ((uint32_t)this->red() << 8) + this->alpha();
}
}