CVD 0.8
cvd/la.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_LA_H
00022 #define CVD_LA_H
00023 
00024 #include <iostream>
00025 #include <cvd/internal/is_pod.h>
00026 
00027 namespace CVD {
00028 
00029 
00031   // CVD::La
00032   // Template class to represent luminance and alpha components
00033   //
00037   template <typename T>
00038     class La
00039     {
00040     public:
00042       La() {}
00046     La(T l, T a) : luminance(l), alpha(a) {}
00047 
00048       T luminance; 
00049       T alpha; 
00050 
00053       La<T>& operator=(const La<T>& c)
00054     {luminance = c.luminance; alpha = c.alpha; return *this;}
00055 
00058       template <typename T2>
00059     La<T>& operator=(const La<T2>& c){
00060     luminance = static_cast<T>(c.luminance);
00061     alpha = static_cast<T>(c.alpha); 
00062     return *this;
00063       }
00064    
00067       bool operator==(const La<T>& c) const
00068       {return luminance == c.luminance && alpha == c.alpha;}
00069       
00072       bool operator!=(const La<T>& c) const
00073       {return luminance != c.luminance || alpha != c.alpha;}
00074       
00075     };
00076   
00081   template <typename T>
00082     std::ostream& operator <<(std::ostream& os, const La<T>& x)
00083     {
00084       return os << "(" << x.luminance << "," << x.alpha << ")";
00085     }
00086   
00091   inline std::ostream& operator <<(std::ostream& os, const La<unsigned char>& x)
00092   {
00093     return os << "(" << static_cast<unsigned int>(x.luminance) << ","
00094           << static_cast<unsigned int>(x.alpha) << ")";
00095   }
00096   
00097 #ifndef DOXYGEN_IGNORE_INTERNAL
00098   namespace Internal
00099   {
00100     template<class C> struct is_POD<La<C> >
00101       {
00102     enum { is_pod = is_POD<C>::is_pod };
00103       };
00104   }
00105 #endif
00106   
00107   
00108   
00109 } // end namespace 
00110 #endif
00111