00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef GIL_RGB_H
00010 #define GIL_RGB_H
00011
00019
00020 #include "gil_config.hpp"
00021 #include <boost/type_traits.hpp>
00022
00023 ADOBE_GIL_NAMESPACE_BEGIN
00024
00025
00026 template <typename T, typename C> struct pixel;
00027 namespace detail { template <typename T, typename C> struct color_base; }
00028 template <typename IC, typename C> struct planar_ptr;
00029 template <typename IC, typename C> struct planar_ptr_base;
00030
00034
00037 struct rgb_t {
00038 typedef rgb_t base;
00039 BOOST_STATIC_CONSTANT(int, num_channels=3);
00040 };
00043 struct bgr_t : public rgb_t {};
00044
00045
00046 namespace detail {
00056 template <typename T>
00057 struct color_base<T,rgb_t> : public homogeneous_color_base<T> {
00058 T red,green,blue;
00059
00060 color_base() {}
00061 color_base(T v0, T v1, T v2) : red(v0), green(v1), blue(v2) {}
00062 template <typename T1, typename C1> color_base(const color_base<T1,C1>& c) : red(c.red), green(c.green), blue(c.blue) {}
00063 template <typename T1, typename C1> color_base( color_base<T1,C1>& c) : red(c.red), green(c.green), blue(c.blue) {}
00064 };
00065
00074 template <typename T>
00075 struct color_base<T,bgr_t> : public homogeneous_color_base<T> {
00076 T blue,green,red;
00077
00078 color_base() {}
00079 color_base(T v0, T v1, T v2) : blue(v0),green(v1),red(v2) {}
00080 template <typename T1, typename C1> color_base(const color_base<T1,C1>& c) : blue(c.blue),green(c.green),red(c.red) {}
00081 };
00082 }
00083 ADOBE_GIL_NAMESPACE_END
00084
00085 #include "pixel_iterator.hpp"
00086
00087
00088 ADOBE_GIL_NAMESPACE_BEGIN
00089
00090
00094
00101 template <typename IC>
00102 struct planar_ptr<IC,rgb_t> : public planar_ptr_base<IC,rgb_t> {
00103 typedef planar_ptr_base<IC,rgb_t> parent_t;
00104 typedef typename parent_t::value_type value_type;
00105 typedef typename parent_t::reference reference;
00106 typedef typename parent_t::color_space_t color_space_t;
00107
00108 planar_ptr() : parent_t(0,0,0) {}
00109 planar_ptr(const IC& ir, const IC& ig, const IC& ib) : parent_t(ir,ig,ib) {}
00110
00111 template <typename T1,typename C1> planar_ptr(const planar_ptr<T1,C1>& ptr) : parent_t(ptr) {}
00112 template <typename T1,typename C1> planar_ptr& operator=(const planar_ptr<T1,C1>& ptr) { parent_t::operator=(ptr); return *this; }
00113
00117 template <typename P> planar_ptr(P* pix) :
00118 parent_t(&pix->template semantic_channel<0>(),&pix->template semantic_channel<1>(), &pix->template semantic_channel<2>()) {
00119 boost::function_requires<PixelsCompatibleConcept<P,value_type> >();
00120 }
00121
00122 template <typename P> planar_ptr& operator=(P* pix) {
00123 boost::function_requires<PixelsCompatibleConcept<P,value_type> >();
00124 this->template semantic_channel<0>()=&pix->template semantic_channel<0>();
00125 this->template semantic_channel<1>()=&pix->template semantic_channel<1>();
00126 this->template semantic_channel<2>()=&pix->template semantic_channel<2>();
00127 return *this;
00128 }
00129
00130 reference dereference() const { return reference(*(this->template semantic_channel<0>()),
00131 *(this->template semantic_channel<1>()),
00132 *(this->template semantic_channel<2>())); }
00133 };
00134
00135
00138 template <typename IC>
00139 inline planar_ref<typename std::iterator_traits<IC>::reference,rgb_t> byte_advanced_ref(const planar_ptr_base<IC,rgb_t>& p, std::ptrdiff_t byteDiff) {
00140 return planar_ref<typename std::iterator_traits<IC>::reference,rgb_t>(*byte_advanced(p.red, byteDiff), *byte_advanced(p.green, byteDiff), *byte_advanced(p.blue, byteDiff));
00141 }
00142
00143 namespace detail {
00144 template <typename CS,int N> struct channel_accessor;
00145
00147 template <>
00148 struct channel_accessor<rgb_t,0> {
00149 template <typename P> typename P::template kth_element_t<0>::reference operator()( P& p) const {return p.red;}
00150 template <typename P> typename P::template kth_element_t<0>::const_reference operator()(const P& p) const {return p.red;}
00151 };
00152
00154 template <>
00155 struct channel_accessor<rgb_t,1> {
00156 template <typename P> typename P::template kth_element_t<1>::reference operator()( P& p) const {return p.green;}
00157 template <typename P> typename P::template kth_element_t<1>::const_reference operator()(const P& p) const {return p.green;}
00158 };
00159
00161 template <>
00162 struct channel_accessor<rgb_t,2> {
00163 template <typename P> typename P::template kth_element_t<2>::reference operator()( P& p) const {return p.blue;}
00164 template <typename P> typename P::template kth_element_t<2>::const_reference operator()(const P& p) const {return p.blue;}
00165 };
00166
00167
00168
00169
00171 template <>
00172 struct channel_accessor<bgr_t,0> {
00173 template <typename P> typename P::template kth_element_t<0>::reference operator()( P& p) const {return p.blue;}
00174 template <typename P> typename P::template kth_element_t<0>::const_reference operator()(const P& p) const {return p.blue;}
00175 };
00176
00178 template <>
00179 struct channel_accessor<bgr_t,1> {
00180 template <typename P> typename P::template kth_element_t<1>::reference operator()( P& p) const {return p.green;}
00181 template <typename P> typename P::template kth_element_t<1>::const_reference operator()(const P& p) const {return p.green;}
00182 };
00183
00185 template <>
00186 struct channel_accessor<bgr_t,2> {
00187 template <typename P> typename P::template kth_element_t<2>::reference operator()( P& p) const {return p.red;}
00188 template <typename P> typename P::template kth_element_t<2>::const_reference operator()(const P& p) const {return p.red;}
00189 };
00190 }
00191
00192 ADOBE_GIL_NAMESPACE_END
00193
00194 #endif