-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColorPixel.cpp
More file actions
57 lines (57 loc) · 1.75 KB
/
ColorPixel.cpp
File metadata and controls
57 lines (57 loc) · 1.75 KB
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
#include "ColorPixel.h"
ColorPixel::ColorPixel(unsigned int mC, unsigned int r, unsigned int g, unsigned int b) : MaxColor(mC), red(r), green(g), blue(b) {}
ColorPixel::ColorPixel(const ColorPixel& other) {
MaxColor = other.MaxColor;
red = other.red;
green = other.green;
blue = other.blue;
}
ColorPixel& ColorPixel::operator=(const ColorPixel& other) {
if (this != &other) {
MaxColor = other.MaxColor;
red = other.red;
green = other.green;
blue = other.blue;
}
return *this;
}
void ColorPixel::grayscale() {
red = round(red * 0.299 + green * 0.587 + blue * 0.114);
green = round(red * 0.299 + green * 0.587 + blue * 0.114);
blue = round(red * 0.299 + green * 0.587 + blue * 0.114);
}
void ColorPixel::monochrome() {
grayscale();
if (red <= MaxColor/2) { red = 0; green = 0; blue = 0; }
else { red = MaxColor; green = MaxColor; blue = MaxColor; }
}
void ColorPixel::negative() {
red = MaxColor - red;
green = MaxColor - green;
blue = MaxColor - blue;
}
void ColorPixel::setColors(unsigned int r, unsigned int g, unsigned int b) {
assert(r <= MaxColor && green <= MaxColor && blue <= MaxColor);
red = r; green = g; blue = b;
}
void ColorPixel::setMaxColor(unsigned int mC) {
MaxColor = mC;
}
void ColorPixel::setMaxColorandColors(unsigned int mC) {
setMaxColor(mC);
red = green = blue = MaxColor;
}
void ColorPixel::setMaxColorandColors(unsigned int mC, unsigned int r, unsigned int g, unsigned int b) {
setMaxColor(mC);
setColors(r, g, b);
}
std::ostream& operator<<(std::ostream& out, const ColorPixel& cp) {
out << cp.red << " " << cp.green << " " << cp.blue << " ";
return out;
}
std::istream& operator>>(std::istream& in, ColorPixel& cp) {
in >> cp.red;
in >> cp.green;
in >> cp.blue;
return in;
}