-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtcolor.cpp
110 lines (88 loc) · 2.02 KB
/
rtcolor.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
#include "rtcolor.h"
RTColor::RTColor(unsigned int r, unsigned int g, unsigned int b)
{
unsigned int rr=(r>255)?255:r;
unsigned int rg=(g>255)?255:g;
unsigned int rb=(b>255)?255:b;
this->_r=rr;
this->_g=rg;
this->_b=rb;
}
RTColor::RTColor(const RTColor &c)
{
unsigned int r = (c.getR()>255?255:c.getR());
unsigned int g = (c.getG()>255?255:c.getG());
unsigned int b = (c.getB()>255?255:c.getB());
this->_r=r;
this->_g=g;
this->_b=b;
}
RTColor::RTColor()
{
this->_r = 0;
this->_g = 0;
this->_b = 0;
}
void RTColor::setR(unsigned int r)
{
unsigned int rx=(r>255)?255:r;
this->_r = rx;
}
void RTColor::setG(unsigned int g)
{
unsigned int gx=(g>255)?255:g;
this->_g = gx;
}
void RTColor::setB(unsigned int b)
{
unsigned int bx=(b>255)?255:b;
this->_b = bx;
}
unsigned int RTColor::getR() const
{
return this->_r;
}
unsigned int RTColor::getG() const
{
return this->_g;
}
unsigned int RTColor::getB() const
{
return this->_b;
}
RTColor RTColor::operator+(RTColor color)
{
RTColor newColor( this->_r + color.getR(),
this->_g + color.getG(),
this->_b + color.getB());
return newColor;
}
RTColor RTColor::operator-(RTColor color)
{
RTColor newColor( this->_r - color.getR(),
this->_g - color.getG(),
this->_b - color.getB());
return newColor;
}
RTColor RTColor::operator*(double value)
{
RTColor newColor( this->_r * value,
this->_g * value,
this->_b * value);
return newColor;
}
RTColor RTColor::operator *(RTColor c)
{
RTColor newColor( this->_r * c.getR(),
this->_g * c.getG(),
this->_b * c.getB());
return newColor;
}
RTColor RTColor::operator/(double value)
{
double r = ((double)this->_r) / value;
double g = ((double)this->_g) / value;
double b = ((double)this->_b) / value;
RTColor newColor( r, g, b);
return newColor;
}