cvd/rgba.h

00001 /*                       
00002     This file is part of the CVD Library.
00003 
00004     Copyright (C) 2005 The Authors
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Lesser General Public
00008     License as published by the Free Software Foundation; either
00009     version 2.1 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Lesser General Public License for more details.
00015 
00016     You should have received a copy of the GNU Lesser General Public
00017     License along with this library; if not, write to the Free Software
00018     Foundation, Inc., 
00019     51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 */
00021 #ifndef CVD_RGBA_H
00022 #define CVD_RGBA_H
00023 
00024 #include <iostream>
00025 #include <cvd/internal/is_pod.h>
00026 
00027 namespace CVD {
00028 
00029 
00031 // CVD::Rgba
00032 // Template class to represent red, green, blue and alpha components
00033 //
00037 template <typename T>
00038 class Rgba
00039 {
00040 public:
00042     Rgba() {}
00048     Rgba(T r, T g, T b, T a) : red(r), green(g), blue(b), alpha(a) {}
00049 
00050    T red; 
00051    T green; 
00052    T blue; 
00053    T alpha; 
00054 
00057    Rgba<T>& operator=(const Rgba<T>& c)
00058       {red = c.red; green = c.green; blue = c.blue; alpha = c.alpha; return *this;}
00059 
00062    template <typename T2>
00063      Rgba<T>& operator=(const Rgba<T2>& c){
00064      red = static_cast<T>(c.red);
00065      green = static_cast<T>(c.green); 
00066      blue = static_cast<T>(c.blue); 
00067      alpha = static_cast<T>(c.alpha); 
00068      return *this;
00069    }
00070 
00073     bool operator==(const Rgba<T>& c) const
00074       {return red == c.red && green == c.green && blue == c.blue && alpha == c.alpha;}
00075 
00078     bool operator!=(const Rgba<T>& c) const
00079       {return red != c.red || green != c.green || blue != c.blue || alpha != c.alpha;}
00080 
00081 //   T to_grey() const {return 0.3*red + 0.6*green + 0.1*blue;}
00082 };
00083 
00088 template <typename T>
00089 std::ostream& operator <<(std::ostream& os, const Rgba<T>& x)
00090 {
00091    return os << "(" << x.red << "," << x.green << ","
00092              << x.blue << "," << x.alpha << ")";
00093 }
00094 
00099 inline std::ostream& operator <<(std::ostream& os, const Rgba<unsigned char>& x)
00100 {
00101    return os << "(" << static_cast<unsigned int>(x.red) << ","
00102              << static_cast<unsigned int>(x.green) << ","
00103              << static_cast<unsigned int>(x.blue) << ","
00104              << static_cast<unsigned int>(x.alpha) << ")";
00105 }
00106 
00107 #ifndef DOXYGEN_IGNORE_INTERNAL
00108 namespace Internal
00109 {
00110   template<class C> struct is_POD<Rgba<C> >
00111   {
00112     enum { is_pod = is_POD<C>::is_pod };
00113   };
00114 }
00115 #endif
00116 
00117 
00118 
00119 } // end namespace 
00120 #endif
00121 

Generated on Wed Feb 18 10:23:01 2009 for CVD by  doxygen 1.5.3