-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColour.cpp
42 lines (34 loc) · 1.33 KB
/
Colour.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
#include "Colour.h"
namespace A6 {
ostream& operator<<(ostream& os, Colour c) {
os << "(" << +c.red << ", " << +c.green << ", " << +c.blue << ")" << endl;
return os;
}
bool operator==(const Colour &a, const Colour &b)
{
return (a.red == b.red && a.green == b.green && a.blue == b.blue && a.alpha == b.alpha);
}
bool operator!=(const Colour &a, const Colour &b)
{
return !(a == b);
}
Colour operator+(const Colour& left, const Colour& right)
{
return Colour{ static_cast<uint8_t>(min(left.red + right.red, 255)),
static_cast<uint8_t>(min(left.green + right.green, 255)),
static_cast<uint8_t>(min(left.blue + right.blue, 255)),
static_cast<uint8_t>(min(left.alpha + right.alpha, 255)) };
}
Colour operator-(const Colour& left, const Colour& right)
{
return Colour{ static_cast<uint8_t>(min(left.red - right.red, 255)),
static_cast<uint8_t>(min(left.green - right.green, 255)),
static_cast<uint8_t>(min(left.blue - right.blue, 255)),
static_cast<uint8_t>(min(left.alpha - right.alpha, 255)) };
}
const Colour Colour::Black{0, 0, 0, 255};
const Colour Colour::White{255, 255, 255, 255};
const Colour Colour::Red{255, 0, 0, 255};
const Colour Colour::Green{0, 255, 0, 255};
const Colour Colour::Blue{0, 0, 255, 255};
};