-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColor.hh
124 lines (99 loc) · 2.87 KB
/
Color.hh
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
Author: Daniel Knutsen
Desc: This is the header file for the color class
*/
#ifndef Color_hh
#define Color_hh
#include "Vector.hh"
#include <iostream>
using std::ostream;
class Color
{
private:
float c[3];
public:
/*--------------------- Constructors --------------------*/
Color(float r, float g, float b){
c[0] = r;
c[1] = g;
c[2] = b;
}
Color(const Color& color){
c[0] = color.r();
c[1] = color.g();
c[2] = color.b();
}
Color(){
c[0] = 0;
c[1] = 0;
c[2] = 0;
}
/*------------------- Accessors -----------------------*/
float r()const{return c[0];}
float g()const{return c[1];}
float b()const{return c[2];}
float& r(){return c[0];}
float& g(){return c[1];}
float& b(){return c[2];}
/*----------------- Operators ------------------------------*/
float operator[](int i) const{
return c[i%3];
}
float operator[](int i){
return c[i%3];
}
Color operator+(const Color& color)const{
return Color(c[0] + color.r(), c[1] + color.g(), c[2] + color.b());
}
Color operator-(const Color& color)const{
return Color(c[0] - color.r(), c[1] - color.g(), c[2] - color.b());
}
Color operator*(const Color& color)const{
return Color(color.r()*c[0], color.g()*c[1], color.b()*c[2]);
}
Color operator*(const Vector& v)const{
return Color(v.x()*c[0], v.y()*c[1], v.z()*c[2]);
}
Color operator*(float d)const{
return Color(c[0]*d, c[1]*d, c[2]*d);
}
Color& operator+=(const Color& color){
c[0] = c[0] + color.r();
c[1] = c[1] + color.g();
c[2] = c[2] + color.b();
return *this;
}
Color& operator-=(const Color& color){
c[0] = c[0] - color.r();
c[1] = c[1] - color.g();
c[2] = c[2] - color.b();
return *this;
}
friend Color operator*(float x, const Color& color){
return Color(x*color.r(), x*color.g(), x*color.b());
}
/*friend operator<<(ostream& o, const Color& color){
o << color.r() << "," << color.g() << "," << color.b();
return o;
}*/
/*-------------------------------- Color Functions -----------------*/
// rename this something better
/* void crustualize(){
float max=0.f;
for(int i=0; i<3; i++)
if(c[i]>max) max = c[i];
float dmax = 1.f/max;
for(int i=0; i<3; i++)
c[i] *= dmax;
}
*/
// Move this to new Post Processing library
Color PsuedoPhotoExposure(Color& color)
{
float exposure = -1.00f; // random exposure value. TODO : determine a good value automatically
color.b() = (1.0f - expf(color.b() * exposure));
color.r() = (1.0f - expf(color.r() * exposure));
color.g() = (1.0f - expf(color.g() * exposure));
}
};
#endif