00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef GIL_PLANAR_REF_H
00014 #define GIL_PLANAR_REF_H
00015
00024
00025 #include <boost/mpl/range_c.hpp>
00026 #include "gil_config.hpp"
00027 #include "gil_concept.hpp"
00028 #include "color_base.hpp"
00029 #include "channel.hpp"
00030 #include "pixel.hpp"
00031 #include "planar_pixel_iterator.hpp"
00032
00033 namespace boost { namespace gil {
00034
00039
00043
00044
00050 template <typename ChannelReference, typename ColorSpace>
00051 struct planar_pixel_reference
00052 : public detail::homogeneous_color_base<ChannelReference,layout<ColorSpace>,mpl::size<ColorSpace>::value> {
00053 typedef detail::homogeneous_color_base<ChannelReference,layout<ColorSpace>,mpl::size<ColorSpace>::value> parent_t;
00054 private:
00055
00056 typedef typename channel_traits<ChannelReference>::value_type channel_t;
00057 typedef typename channel_traits<ChannelReference>::const_reference channel_const_reference;
00058 public:
00059 BOOST_STATIC_CONSTANT(bool, is_mutable = channel_traits<ChannelReference>::is_mutable);
00060 typedef pixel<channel_t,layout<ColorSpace> > value_type;
00061 typedef planar_pixel_reference reference;
00062 typedef planar_pixel_reference<channel_const_reference,ColorSpace> const_reference;
00063
00064 planar_pixel_reference(ChannelReference v0, ChannelReference v1) : parent_t(v0,v1) {}
00065 planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2) : parent_t(v0,v1,v2) {}
00066 planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3) : parent_t(v0,v1,v2,v3) {}
00067 planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3, ChannelReference v4) : parent_t(v0,v1,v2,v3,v4) {}
00068 planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3, ChannelReference v4, ChannelReference v5) : parent_t(v0,v1,v2,v3,v4,v5) {}
00069
00070 template <typename P> planar_pixel_reference(const P& p) : parent_t(p) { check_compatible<P>();}
00071
00072
00073 template <typename ChannelV, typename Mapping>
00074 planar_pixel_reference(pixel<ChannelV,layout<ColorSpace,Mapping> >& p) : parent_t(p) { check_compatible<pixel<ChannelV,layout<ColorSpace,Mapping> > >();}
00075
00076
00077 template <typename ChannelPtr> planar_pixel_reference(const planar_pixel_iterator<ChannelPtr,ColorSpace>& p, std::ptrdiff_t diff) : parent_t(p,diff) {}
00078
00079 const planar_pixel_reference& operator=(const planar_pixel_reference& p) const { static_copy(p,*this); return *this; }
00080 template <typename P> const planar_pixel_reference& operator=(const P& p) const { check_compatible<P>(); static_copy(p,*this); return *this; }
00081
00082 template <typename P> bool operator==(const P& p) const { check_compatible<P>(); return static_equal(*this,p); }
00083 template <typename P> bool operator!=(const P& p) const { return !(*this==p); }
00084
00085 ChannelReference operator[](std::size_t i) const { return this->at_c_dynamic(i); }
00086
00087 const planar_pixel_reference* operator->() const { return this; }
00088 private:
00089 template <typename Pixel> static void check_compatible() { gil_function_requires<PixelsCompatibleConcept<Pixel,planar_pixel_reference> >(); }
00090 };
00091
00093
00095
00096 template <typename ChannelReference, typename ColorSpace, int K>
00097 struct kth_element_type<planar_pixel_reference<ChannelReference,ColorSpace>, K> {
00098 typedef ChannelReference type;
00099 };
00100
00101 template <typename ChannelReference, typename ColorSpace, int K>
00102 struct kth_element_reference_type<planar_pixel_reference<ChannelReference,ColorSpace>, K> {
00103 typedef ChannelReference type;
00104 };
00105
00106 template <typename ChannelReference, typename ColorSpace, int K>
00107 struct kth_element_const_reference_type<planar_pixel_reference<ChannelReference,ColorSpace>, K>
00108 : public add_reference<typename add_const<ChannelReference>::type>
00109 {
00110
00111 };
00112
00114
00116
00119 template <typename ChannelReference, typename ColorSpace>
00120 struct is_pixel< planar_pixel_reference<ChannelReference,ColorSpace> > : public mpl::true_{};
00121
00123
00125
00128 template <typename ChannelReference, typename ColorSpace>
00129 struct color_space_type<planar_pixel_reference<ChannelReference,ColorSpace> > {
00130 typedef ColorSpace type;
00131 };
00132
00135 template <typename ChannelReference, typename ColorSpace>
00136 struct channel_mapping_type<planar_pixel_reference<ChannelReference,ColorSpace> > {
00137 typedef typename layout<ColorSpace>::channel_mapping_t type;
00138 };
00139
00142 template <typename ChannelReference, typename ColorSpace>
00143 struct is_planar<planar_pixel_reference<ChannelReference,ColorSpace> > : mpl::true_ {};
00144
00147 template <typename ChannelReference, typename ColorSpace>
00148 struct channel_type<planar_pixel_reference<ChannelReference,ColorSpace> > {
00149 typedef typename channel_traits<ChannelReference>::value_type type;
00150 };
00151
00152 } }
00153
00154 namespace std {
00155
00156
00157
00158
00159
00160
00161
00164 template <typename CR, typename CS, typename R> inline
00165 void swap(boost::gil::planar_pixel_reference<CR,CS> x, R& y) {
00166 boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y);
00167 }
00168
00169
00172 template <typename CR, typename CS> inline
00173 void swap(typename boost::gil::planar_pixel_reference<CR,CS>::value_type& x, boost::gil::planar_pixel_reference<CR,CS> y) {
00174 boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y);
00175 }
00176
00177
00180 template <typename CR, typename CS> inline
00181 void swap(boost::gil::planar_pixel_reference<CR,CS> x, boost::gil::planar_pixel_reference<CR,CS> y) {
00182 boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y);
00183 }
00184 }
00185
00186 #endif