CVD 0.8
cvd/argb.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_QT_ARGB_H
00022 #define CVD_QT_ARGB_H
00023 
00024 #include <iostream>
00025 #include <cvd/internal/is_pod.h>
00026 
00027 namespace CVD {
00028 
00029 
00031 // CVD::Argb
00032 // Template class to represent red, green, blue and alpha components
00033 //
00037 template <typename T>
00038 class Argb
00039 {
00040 public:
00042     explicit Argb() : red(0), green(0), blue(0), alpha(0) {}
00043 
00049     explicit Argb(T a, T r, T g, T b) : red(r), green(g), blue(b), alpha(a) {}
00050 
00051    T blue; 
00052    T green; 
00053    T red; 
00054    T alpha; 
00055 
00058    template <typename T2>
00059      Argb<T>& operator=(const Argb<T2>& c){
00060      red = static_cast<T>(c.red);
00061      green = static_cast<T>(c.green); 
00062      blue = static_cast<T>(c.blue); 
00063      alpha = static_cast<T>(c.alpha); 
00064      return *this;
00065    }
00066 
00069     bool operator==(const Argb<T>& c) const
00070       {return red == c.red && green == c.green && blue == c.blue && alpha == c.alpha;}
00071 
00074     bool operator!=(const Argb<T>& c) const
00075       {return red != c.red || green != c.green || blue != c.blue || alpha != c.alpha;}
00076 
00077 //   T to_grey() const {return 0.3*red + 0.6*green + 0.1*blue;}
00078 };
00079 
00084 template <typename T>
00085 std::ostream& operator <<(std::ostream& os, const Argb<T>& x)
00086 {
00087    return os << "(" << x.alpha << "," << x.red << ","
00088              << x.green << "," << x.blue << ")";
00089 }
00090 
00095 inline std::ostream& operator <<(std::ostream& os, const Argb<unsigned char>& x)
00096 {
00097    return os << "(" << static_cast<unsigned int>(x.alpha) << ","
00098              << static_cast<unsigned int>(x.red) << ","
00099              << static_cast<unsigned int>(x.green) << ","
00100              << static_cast<unsigned int>(x.blue) << ")";
00101 }
00102 
00103 #ifndef DOXYGEN_IGNORE_INTERNAL
00104 namespace Internal
00105 {
00106   template<class C> struct is_POD<Argb<C> >
00107   {
00108     enum { is_pod = is_POD<C>::is_pod };
00109   };
00110 }
00111 #endif
00112 
00113 
00114 
00115 } // end namespace 
00116 #endif
00117