-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrgb.cpp
More file actions
60 lines (49 loc) · 831 Bytes
/
rgb.cpp
File metadata and controls
60 lines (49 loc) · 831 Bytes
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
#include "rgb.h"
rgb::rgb(u8 r, u8 g, u8 b) : r{r}, g{g}, b{b}
{
}
rgb::rgb()
{
r = 0;
g = 0;
b = 0;
}
rgb& rgb::operator + (const rgb &color)
{
if (r + color.r > 255) r = 255;
else r += color.r;
if (g + color.g > 255) g = 255;
else g += color.g;
if (b + color.b > 255) b = 255;
else b += color.b;
return *this;
}
rgb& rgb::operator = (const rgb &source)
{
r = source.r;
g = source.g;
b = source.b;
return *this;
}
rgb& rgb::operator * (const float &f)
{
r *= f;
g *= f;
b *= f;
return *this;
}
void rgb::add(rgb color)
{
if (r + color.r > 255) r = 255;
else r += color.r;
if (g + color.g > 255) g = 255;
else g += color.g;
if (b + color.b > 255) b = 255;
else b += color.b;
}
void rgb::scale(double f)
{
r *= f;
g *= f;
b *= f;
}