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 */ 00021 #ifndef CVD_INCLUDE_BGRX_H 00022 #define CVD_INCLUDE_BGRX_H 00023 00024 #include <iostream> 00025 #include <cvd/internal/is_pod.h> 00026 00027 namespace CVD { 00028 00029 00031 // CVD::Bgrx 00036 template <typename T> 00037 class Bgrx 00038 { 00039 public: 00041 explicit Bgrx() : blue(0), green(0), red(0), dummy(0) {} 00042 00047 explicit Bgrx(T b, T g, T r) : blue(b), green(g), red(r), dummy(0) {} 00048 00049 T blue; 00050 T green; 00051 T red; 00052 T dummy; 00053 00056 template <typename T2> 00057 Bgrx<T>& operator=(const Bgrx<T2>& c){ 00058 blue = static_cast<T>(c.blue); 00059 green = static_cast<T>(c.green); 00060 red = static_cast<T>(c.red); 00061 return *this; 00062 } 00063 00066 bool operator==(const Bgrx<T>& c) const 00067 {return red == c.red && green == c.green && blue == c.blue;} 00068 00071 bool operator!=(const Bgrx<T>& c) const 00072 {return red != c.red || green != c.green || blue != c.blue;} 00073 00074 // T to_grey() const {return 0.3*red + 0.6*green + 0.1*blue;} 00075 }; 00076 00081 template <typename T> 00082 std::ostream& operator <<(std::ostream& os, const Bgrx<T>& x) 00083 { 00084 return os << "(" << x.blue << "," 00085 << x.green << "," << x.red << ")"; 00086 } 00087 00092 inline std::ostream& operator <<(std::ostream& os, const Bgrx<unsigned char>& x) 00093 { 00094 return os << "(" 00095 << static_cast<unsigned int>(x.blue) << ")" 00096 << static_cast<unsigned int>(x.green) << "," 00097 << static_cast<unsigned int>(x.red) << ","; 00098 } 00099 00100 #ifndef DOXYGEN_IGNORE_INTERNAL 00101 namespace Internal 00102 { 00103 template<class C> struct is_POD<Bgrx<C> > 00104 { 00105 enum { is_pod = is_POD<C>::is_pod }; 00106 }; 00107 } 00108 #endif 00109 00110 00111 00112 } // end namespace 00113 #endif 00114