CVD 0.8
|
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 explicit Rgb() : red(0), green(0), blue(0) {} 00051 00056 explicit inline Rgb(T r, T g, T b) : red(r),green(g),blue(b) {} 00057 00058 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)) {} 00059 00060 T red; 00061 T green; 00062 T blue; 00063 00066 inline Rgb<T>& operator=(const Rgb<T>& c) 00067 {red = c.red; green = c.green; blue = c.blue; return *this;} 00068 00071 inline bool operator==(const Rgb<T>& c) const 00072 {return red == c.red && green == c.green && blue == c.blue;} 00073 00076 inline bool operator!=(const Rgb<T>& c) const 00077 {return red != c.red || green != c.green || blue != c.blue;} 00078 00081 template <class T2> 00082 inline Rgb<T>& operator=(const Rgb<T2>& c){ 00083 red = static_cast<T>(c.red); 00084 green = static_cast<T>(c.green); 00085 blue = static_cast<T>(c.blue); 00086 return *this; 00087 } 00088 00089 // T to_grey() {return 0.3*red + 0.6*green + 0.1*blue;} 00090 }; 00091 00096 template <class T> 00097 std::ostream& operator <<(std::ostream& os, const Rgb<T>& x) 00098 { 00099 return os << "(" << x.red << "," << x.green << "," 00100 << x.blue << ")"; 00101 } 00102 00107 inline std::ostream& operator <<(std::ostream& os, const Rgb<char>& x) 00108 { 00109 return os << "(" << (int)(unsigned char)x.red << "," 00110 << (int)(unsigned char)x.green << "," 00111 << (int)(unsigned char)x.blue << ")"; 00112 } 00113 00118 inline std::ostream& operator <<(std::ostream& os, const Rgb<byte>& x) 00119 { 00120 return os << "(" << static_cast<int>(x.red) << "," 00121 << static_cast<int>(x.green) << "," 00122 << static_cast<int>(x.blue) << ")"; 00123 } 00124 00125 #ifndef DOXYGEN_IGNORE_INTERNAL 00126 namespace Internal 00127 { 00128 template<class C> struct is_POD<Rgb<C> > 00129 { 00130 enum { is_pod = is_POD<C>::is_pod }; 00131 }; 00132 } 00133 #endif 00134 00135 00136 } // end namespace 00137 #endif