-
Notifications
You must be signed in to change notification settings - Fork 0
/
rgbapixel.cpp
54 lines (47 loc) · 1.17 KB
/
rgbapixel.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
/**
* @file rgbapixel.cpp
* Implementation of the RGBAPixel class for the EasyPNG library.
*
* @author Chase Geigle
* @date Spring 2012
*/
#include "rgbapixel.h"
RGBAPixel::RGBAPixel() : red(255.0), green(255.0), blue(255.0), alpha(255.0)
{
/* nothing */
}
RGBAPixel::RGBAPixel(double r, double g, double b)
: red(r), green(g), blue(b), alpha(255.0)
{
/* nothing */
}
RGBAPixel::RGBAPixel(double r, double g, double b,
double a) : red(r), green(g), blue(b), alpha(a)
{
/* nothing */
}
bool RGBAPixel::operator==(RGBAPixel const & other) const
{
return red == other.red && green == other.green && blue == other.blue &&
alpha == other.alpha;
}
bool RGBAPixel::operator!=(RGBAPixel const & other) const
{
return !(*this == other);
}
bool RGBAPixel::operator<(RGBAPixel const & other) const
{
if (red != other.red)
return red < other.red;
if (green != other.green)
return green < other.green;
return blue < other.blue;
}
std::ostream & operator<<(std::ostream & out, RGBAPixel const & pixel)
{
out << "(" << (int) pixel.red << "," << (int) pixel.green << ","
<< (int) pixel.blue << ")";
if (pixel.alpha != 255)
out << " a:" << pixel.alpha;
return out;
}