-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor.h
99 lines (79 loc) · 1.89 KB
/
color.h
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
#pragma once
#include "defs.h"
inline float clamp(float val, float minVal, float maxVal) { return Min(Max(val, minVal), maxVal); }
struct Color {
float r, g, b;
Color() {}
Color(float r, float g, float b): r(r), b(b), g(g) {}
Color operator * (float scalar) const {
return Color(r * scalar, g * scalar, b * scalar);
}
Color operator * (const Color& rhs) const {
return Color(r * rhs.r, g * rhs.g, b * rhs.b);
}
Color& operator += (float scalar) {
r += scalar;
g += scalar;
b += scalar;
return *this;
}
Color& operator += (const Color& rhs) {
r += rhs.r;
g += rhs.g;
b += rhs.b;
return *this;
}
Color& operator -= (float scalar) {
r -= scalar;
g -= scalar;
b -= scalar;
return *this;
}
Color& operator -= (const Color& rhs) {
r -= rhs.r;
g -= rhs.g;
b -= rhs.b;
return *this;
}
Color& operator /= (float scalar) {
scalar = 1.0f/scalar;
r *= scalar;
g *= scalar;
b *= scalar;
return *this;
}
Color& operator=(const Color& rhs) {
r = rhs.r;
g = rhs.g;
b = rhs.b;
return *this;
}
Color(const Color& rhs) {
r = rhs.r;
g = rhs.g;
b = rhs.b;
}
Color operator / (float scalar) const {
scalar = 1.0f / scalar;
return Color(r * scalar, g * scalar, b * scalar);
}
Color operator - (const Color& rhs) const {
return Color(r - rhs.r, g - rhs.g, b - rhs.b);
}
Color operator + (const Color& rhs) const {
return Color(r + rhs.r, g + rhs.g, b + rhs.b);
}
Color operator - () const {
return Color(-r, -g, -b);
}
uint8 getRedUINT8() const { return uint8(clamp(r,0.0f,1.0f)*255.0f); }
uint8 getGreenUINT8() const { return uint8(clamp(g,0.0f,1.0f)*255.0f); }
uint8 getBlueUINT8() const { return uint8(clamp(b,0.0f,1.0f)*255.0f); }
float intensity() const { return (r+g+b)/3.0f; }
void makeZero() {
r = g = b = 0.0f;
}
};
//inline Color operator*(const Color &a, const Color &b) {
// return Color(a.r*b.r, a.b*b.b, a.g*b.g);
//}