color.hpp

Go to the documentation of this file.
00001 /*
00002 **    TP 4ETI CPE Lyon
00003 **    Copyright (C) 2011 Damien Rohmer
00004 **
00005 **    This program is free software: you can redistribute it and/or modify
00006 **    it under the terms of the GNU General Public License as published by
00007 **    the Free Software Foundation, either version 3 of the License, or
00008 **    (at your option) any later version.
00009 **
00010 **   This program is distributed in the hope that it will be useful,
00011 **    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 **    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 **    GNU General Public License for more details.
00014 **
00015 **    You should have received a copy of the GNU General Public License
00016 **    along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 */
00018 
00019 #ifndef _COLOR_RGB_HPP_
00020 #define _COLOR_RGB_HPP_
00021 
00022 #include <iostream>
00023 #include <exception_cpe.hpp>
00024 
00025 #include <vector>
00026 
00027 namespace cpe
00028 {
00030     class color
00031     {
00032     public:
00033 
00034 
00035         // ********************************************* //
00036         // ********************************************* //
00037         //  CONSTRUCTORS
00038         // ********************************************* //
00039         // ********************************************* //
00040 
00042         color();
00044         color(const unsigned char& gray);
00046         color(const unsigned char& r,const unsigned char& g,const unsigned char& b);
00047 
00048         // ********************************************* //
00049         // ********************************************* //
00050         //  ACCESS COLOR VALUE
00051         // ********************************************* //
00052         // ********************************************* //
00053 
00055         void set(const unsigned char& r,const unsigned char& g,const unsigned char& b);
00057         void get(unsigned char* r,unsigned char* g,unsigned char *b) const;
00058 
00060         const unsigned char& r() const;
00062         unsigned char& r();
00064         const unsigned char& g() const;
00066         unsigned char& g();
00068         const unsigned char& b() const;
00070         unsigned char& b();
00071 
00072         // ********************************************* //
00073         // ********************************************* //
00074         //  COLOR INTERPOLATION
00075         // ********************************************* //
00076         // ********************************************* //
00077 
00079         static color interpolate_linear(const color& c1,const color& c2,double alpha);
00080 
00086         static color interpolate_linear(const std::vector<color>& v_color,const std::vector<double>& weights);
00087 
00088 
00089         // ********************************************* //
00090         // ********************************************* //
00091         //  MATH OPERATOR
00092         // ********************************************* //
00093         // ********************************************* //
00094 
00096         friend color operator+(const color& c0,const color& c1);
00098         color& operator+=(const color& c);
00099 
00101         friend color operator*(const double& alpha,const color& c);
00103         friend color operator*(const color& c,const double& alpha);
00105         color& operator*=(const double& alpha);
00106 
00107 
00108 
00109         // ********************************************* //
00110         // ********************************************* //
00111         //  I/O
00112         // ********************************************* //
00113         // ********************************************* //
00114 
00116         friend std::ostream& operator<<(std::ostream& stream,const color& c);
00117 
00118 
00119     private:
00120 
00121         // ********************************************* //
00122         // ********************************************* //
00123         //  INTERNAL STORAGE
00124         // ********************************************* //
00125         // ********************************************* //
00126 
00128         unsigned char internal_r;
00130         unsigned char internal_g;
00132         unsigned char internal_b;
00133 
00134     };
00135 
00137     class exception_color: public exception_cpe
00138     {
00139     public:
00141         exception_color():exception_cpe(){}
00143         exception_color(const std::string& msg,const std::string& file,const std::string& caller,const int& line):exception_cpe(msg,file,caller,line){}
00144     };
00145 }
00146 
00147 #endif
Generated on Mon Apr 18 16:13:40 2011 by  doxygen 1.6.3