cvd/rgb.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 */
00022 //                                                                      //
00023 //  rgb.h                                                               //
00024 //                                                                      //
00025 //  Contains definitions of Rgb template class                          //
00026 //                                                                      //
00027 //  derived from IPRS_* developed by Tom Drummond                       //
00028 //                                                                      //
00030 #ifndef CVD_RGB_H
00031 #define CVD_RGB_H
00032 
00033 #include <iostream>
00034 
00035 #include <cvd/byte.h>
00036 
00037 #include <cvd/internal/is_pod.h>
00038 
00039 namespace CVD {
00040 
00045 template <class T>
00046 class Rgb
00047 {
00048 public:
00050   Rgb() {}
00055   inline Rgb(T r, T g, T b) : red(r),green(g),blue(b) {}
00056     template <class S> inline explicit Rgb(const Rgb<S>& rgb) : red(static_cast<T>(rgb.red)), green(static_cast<T>(rgb.green)), blue(static_cast<T>(rgb.blue)) {}
00057       
00058   T red;   
00059   T green; 
00060   T blue;  
00061    
00064     inline Rgb<T>& operator=(const Rgb<T>& c)
00065     {red = c.red; green = c.green; blue = c.blue; return *this;}
00066         
00069   inline bool operator==(const Rgb<T>& c) const
00070   {return red == c.red && green == c.green && blue == c.blue;}
00071           
00074   inline bool operator!=(const Rgb<T>& c) const
00075   {return red != c.red || green != c.green || blue != c.blue;}
00076         
00079     template <class T2>
00080       inline Rgb<T>& operator=(const Rgb<T2>& c){ red = c.red; green=c.green;  blue=c.blue; return *this;}
00081           
00082   //   T to_grey() {return 0.3*red + 0.6*green + 0.1*blue;}
00083 };
00084   
00089 template <class T>
00090 std::ostream& operator <<(std::ostream& os, const Rgb<T>& x)
00091 {
00092   return os << "(" << x.red << "," << x.green << ","
00093         << x.blue << ")";
00094 }
00095 
00100 inline std::ostream& operator <<(std::ostream& os, const Rgb<char>& x)
00101 {
00102   return os << "(" << (int)(unsigned char)x.red << ","
00103         << (int)(unsigned char)x.green << ","
00104         << (int)(unsigned char)x.blue << ")";
00105 }
00106 
00111 inline std::ostream& operator <<(std::ostream& os, const Rgb<byte>& x)
00112 {
00113   return os << "(" << static_cast<int>(x.red) << ","
00114         << static_cast<int>(x.green) << ","
00115         << static_cast<int>(x.blue) << ")";
00116 }
00117 
00118 #ifndef DOXYGEN_IGNORE_INTERNAL
00119 namespace Internal
00120 {
00121   template<class C> struct is_POD<Rgb<C> >
00122   {
00123     enum { is_pod = is_POD<C>::is_pod };
00124   };
00125 }
00126 #endif
00127 
00128 
00129 } // end namespace
00130 #endif

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