color.hpp
Go to the documentation of this file.
1 /*
2 ** TP CPE Lyon
3 ** Copyright (C) 2013 Damien Rohmer
4 **
5 ** This program is free software: you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation, either version 3 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 
20 #ifndef COLOR_HPP
21 #define COLOR_HPP
22 
23 #include <iostream>
24 #include <exception_cpe.hpp>
25 
26 
27 namespace cpe
28 {
29 class vec3;
30 typedef float color_component;
31 
33  class color
34  {
35  public:
36 
37 
38  // ********************************************* //
39  // ********************************************* //
40  // CONSTRUCTORS
41  // ********************************************* //
42  // ********************************************* //
43 
45  color();
47  color(color_component gray);
50  color(const vec3& c);
51 
52  // ********************************************* //
53  // ********************************************* //
54  // ACCESS COLOR VALUE
55  // ********************************************* //
56  // ********************************************* //
57 
59  color_component r() const;
61  color_component& r();
63  color_component g() const;
65  color_component& g();
67  color_component b() const;
69  color_component& b();
70 
71  // ********************************************* //
72  // ********************************************* //
73  // COLOR MANIPULATION
74  // ********************************************* //
75  // ********************************************* //
76 
77 
79  void clamp();
80 
81 
82 
83  private:
84 
85  // ********************************************* //
86  // ********************************************* //
87  // INTERNAL STORAGE
88  // ********************************************* //
89  // ********************************************* //
90 
97 
98  };
99 
100  color& operator+=(color& c0,const color& c1);
101  color& operator-=(color& c0,const color& c1);
102  color operator+(const color& c0,const color& c1);
103  color operator-(const color& c0,const color& c1);
104  color& operator*=(color& c0,float alpha);
105  color& operator/=(color& c0,float alpha);
106  color operator*(const color& c0,float alpha);
107  color operator*(float alpha,const color& c0);
108  color operator/(const color& c0,float alpha);
109 
110 
111  // ********************************************* //
112  // ********************************************* //
113  // I/O
114  // ********************************************* //
115  // ********************************************* //
116 
118  std::ostream& operator<<(std::ostream& stream,const color& c);
119 
120 
121 
124  {
125  public:
129  exception_color(const std::string& msg_param,const std::string& file_param,const std::string& caller_param,const int& line_param):exception_cpe(msg_param,file_param,caller_param,line_param){}
130  };
131 }
132 
133 #endif