-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcolor.cpp
More file actions
executable file
·46 lines (40 loc) · 1.38 KB
/
color.cpp
File metadata and controls
executable file
·46 lines (40 loc) · 1.38 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
#include "color.h"
#include "point3d.h"
color::color(unsigned char p_r, unsigned char p_g, unsigned char p_b):B(p_b),G(p_g),R(p_r){
}
color operator+(const color &p_a, const color &p_b){
int R = static_cast<int>(p_a.R + p_b.R);
int G = static_cast<int>(p_a.G + p_b.G);
int B = static_cast<int>(p_a.B + p_b.B);
R = R<0 ? 0 : (R>255 ? 255 : R);
G = G<0 ? 0 : (G>255 ? 255 : G);
B = B<0 ? 0 : (B>255 ? 255 : B);
return color(R, G, B);
}
color operator*(const color &p_a, const color &p_b){
int R = static_cast<int>((p_a.R * p_b.R) / 255);
int G = static_cast<int>((p_a.G * p_b.G) / 255);
int B = static_cast<int>((p_a.B * p_b.B) / 255);
R = R<0 ? 0 : (R>255 ? 255 : R);
G = G<0 ? 0 : (G>255 ? 255 : G);
B = B<0 ? 0 : (B>255 ? 255 : B);
return color(R, G, B);
}
color operator*(const color &p_a, const double b){
int R = static_cast<int>(p_a.R * b);
int G = static_cast<int>(p_a.G * b);
int B = static_cast<int>(p_a.B * b);
R = R<0 ? 0 : (R>255 ? 255 : R);
G = G<0 ? 0 : (G>255 ? 255 : G);
B = B<0 ? 0 : (B>255 ? 255 : B);
return color(R, G, B);
}
color operator*(const color &p_a, const point3d &b){
int R = static_cast<int>(p_a.R * b.x);
int G = static_cast<int>(p_a.G * b.y);
int B = static_cast<int>(p_a.B * b.z);
R = R<0 ? 0 : (R>255 ? 255 : R);
G = G<0 ? 0 : (G>255 ? 255 : G);
B = B<0 ? 0 : (B>255 ? 255 : B);
return color(R, G, B);
}