00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef GIL_METAFUNCTIONS_H
00010 #define GIL_METAFUNCTIONS_H
00011
00020
00021 #include <iterator>
00022 #include "gil_config.hpp"
00023 #include "gil_concept.hpp"
00024 #include <boost/mpl/if.hpp>
00025 #include <boost/type_traits.hpp>
00026
00027 ADOBE_GIL_NAMESPACE_BEGIN
00028
00029
00030 template <typename T, typename C> struct pixel;
00031 template <typename T, typename C> struct planar_ref;
00032 template <typename IC, typename C> struct planar_ptr;
00033 template <typename I> class pixel_step_iterator;
00034 template <typename I> class pixel_2d_locator;
00035 template <typename L> class image_view;
00036 template <typename V, typename ALLOC> class image;
00037 template <typename PIT> struct pixel_iterator_traits;
00038
00039
00042 template <typename T, typename C, bool IS_PLANAR=false, bool IS_STEP=false, bool IS_MUTABLE=true> struct iterator_type {};
00044 template <typename T, typename C> struct iterator_type<T,C,false,false,true > { typedef pixel<T,C>* type; };
00046 template <typename T, typename C> struct iterator_type<T,C,false,false,false> { typedef const pixel<T,C>* type; };
00048 template <typename T, typename C> struct iterator_type<T,C,true,false,true> { typedef planar_ptr<T*,C> type; };
00050 template <typename T, typename C> struct iterator_type<T,C,true,false,false> { typedef planar_ptr<const T*,C> type; };
00052 template <typename T, typename C, bool IS_PLANAR, bool IS_MUTABLE> struct iterator_type<T,C,IS_PLANAR,true,IS_MUTABLE> {
00053 typedef pixel_step_iterator<typename iterator_type<T,C,IS_PLANAR,false,IS_MUTABLE>::type> type;
00054 };
00055
00058 template <typename X_IT>
00059 struct type_from_x_iterator {
00060 typedef pixel_step_iterator<X_IT> step_iterator_t;
00061 typedef pixel_2d_locator<step_iterator_t> xy_locator_t;
00062 typedef image_view<xy_locator_t> view_t;
00063 };
00064
00067 template <typename T, typename C, bool IS_PLANAR=false, bool IS_STEP=false, bool IS_MUTABLE=true>
00068 struct pixel_2d_locator_type {
00069 typedef typename type_from_x_iterator<typename iterator_type<T,C,IS_PLANAR,IS_STEP,IS_MUTABLE>::type>::xy_locator_type type;
00070 };
00071
00074 template <typename T, typename C, bool IS_PLANAR=false, bool IS_STEP=false, bool IS_MUTABLE=true>
00075 struct view_type {
00076 typedef typename type_from_x_iterator<typename iterator_type<T,C,IS_PLANAR,IS_STEP,IS_MUTABLE>::type>::view_t type;
00077 };
00078
00081 template <typename T, typename C, bool IS_PLANAR=false, typename ALLOC=std::allocator<unsigned char> >
00082 struct image_type {
00083 typedef typename type_from_x_iterator<typename iterator_type<T,C,IS_PLANAR,false,true>::type>::view_t view_t;
00084 typedef image<view_t, ALLOC> type;
00085 };
00086
00087
00088
00095
00099 template <typename IT>
00100 struct iterator_is_basic { static const bool value=false; };
00102 template <typename T, typename CS>
00103 struct iterator_is_basic< pixel<T,CS>* > { static const bool value=true; };
00105 template <typename T, typename CS>
00106 struct iterator_is_basic<const pixel<T,CS>* > { static const bool value=true; };
00108 template <typename T, typename CS>
00109 struct iterator_is_basic<planar_ptr< T*,CS> > { static const bool value=true; };
00111 template <typename T, typename CS>
00112 struct iterator_is_basic<planar_ptr<const T*,CS> > { static const bool value=true; };
00114 template <typename T, typename CS>
00115 struct iterator_is_basic<pixel_step_iterator< pixel<T,CS>*> > { static const bool value=true; };
00117 template <typename T, typename CS>
00118 struct iterator_is_basic<pixel_step_iterator<const pixel<T,CS>*> > { static const bool value=true; };
00120 template <typename T, typename CS>
00121 struct iterator_is_basic<pixel_step_iterator<planar_ptr< T*,CS> > > { static const bool value=true; };
00123 template <typename T, typename CS>
00124 struct iterator_is_basic<pixel_step_iterator<planar_ptr<const T*,CS> > > { static const bool value=true; };
00125
00126
00128 template <typename LOC> struct locator_is_basic { static const bool value=false; };
00131 template <typename IT> struct locator_is_basic<pixel_2d_locator<pixel_step_iterator<IT> > > : public iterator_is_basic<IT> {};
00132
00134 template <typename VIEW> struct view_is_basic { static const bool value=false; };
00137 template <typename LOC> struct view_is_basic<image_view<LOC> > : public locator_is_basic<LOC> {};
00138
00140 template <typename IMG> struct image_is_basic { static const bool value=false; };
00143 template <typename VIEW> struct image_is_basic<image<VIEW, std::allocator<unsigned char> > > : public view_is_basic<VIEW> {};
00144
00145
00149
00151 template <typename I> struct iterator_is_planar { static const bool value = pixel_iterator_traits<I>::is_planar; };
00153 template <typename L> struct locator_is_planar : public iterator_is_planar<typename L::x_iterator> {};
00155 template <typename V> struct view_is_planar : public iterator_is_planar<typename V::x_iterator> {};
00157 template <typename I> struct image_is_planar : public view_is_planar<typename I::view_t> {};
00158
00159
00163
00165 template <typename I> struct iterator_is_step {
00166 static const bool value = boost::is_same<I,typename pixel_iterator_traits<I>::dynamic_step_t>::value;
00167 };
00169 template <typename L> struct locator_is_step {
00170 static const bool value = iterator_is_step<typename L::x_iterator>::value;
00171 };
00173 template <typename V> struct view_is_step {
00174 static const bool value = iterator_is_step<typename V::x_iterator>::value;
00175 };
00176
00177
00181
00183 template <typename I> struct iterator_is_mutable { static const bool value = pixel_iterator_traits<I>::is_mutable; };
00185 template <typename L> struct locator_is_mutable : public iterator_is_mutable<typename L::x_iterator> {};
00187 template <typename V> struct view_is_mutable : public iterator_is_mutable<typename V::x_iterator> {};
00188
00189
00190 struct use_default {};
00191
00195 template <typename VIEW, typename T=use_default, typename CS=use_default, typename PLANAR=use_default, typename STEP=use_default, typename MUTABLE=use_default>
00196 struct derived_view_type {
00197 typedef typename boost::mpl::if_<boost::is_same<T ,use_default>, typename VIEW::channel_t, T >::type channel_t;
00198 typedef typename boost::mpl::if_<boost::is_same<CS,use_default>, typename VIEW::color_space_t, CS>::type color_space_t;
00199 static const bool mut =boost::mpl::if_<boost::is_same<MUTABLE,use_default>, view_is_mutable<VIEW>, MUTABLE>::type::value;
00200 static const bool planar=boost::mpl::if_<boost::is_same<PLANAR,use_default>, view_is_planar<VIEW>, PLANAR>::type::value;
00201 static const bool step =boost::mpl::if_<boost::is_same<STEP ,use_default>, view_is_step<VIEW>, STEP>::type::value;
00202 public:
00203 typedef typename view_type<channel_t, color_space_t, planar, step, mut>::type type;
00204 };
00205
00209 template <typename IMAGE, typename T=use_default, typename CS=use_default, typename PLANAR=use_default>
00210 struct derived_image_type {
00211 typedef typename boost::mpl::if_<boost::is_same<T ,use_default>, typename IMAGE::channel_t, T >::type channel_t;
00212 typedef typename boost::mpl::if_<boost::is_same<CS,use_default>, typename IMAGE::color_space_t, CS>::type color_space_t;
00213 static const bool planar=boost::mpl::if_<boost::is_same<PLANAR,use_default>, image_is_planar<IMAGE>, PLANAR>::type::value;
00214 public:
00215 typedef typename image_type<channel_t, color_space_t, planar>::type type;
00216 };
00217
00220 template <typename CS> struct color_space_is_base {
00221 static const bool value = boost::is_same<CS, typename CS::base>::value;
00222 };
00223
00224
00245
00248 template <typename I> typename pixel_iterator_traits<I>::dynamic_step_t make_step_iterator(const I& it, std::ptrdiff_t step) {
00249 return make_step_iterator(it.base(), step);
00250 }
00251
00254 template <typename T, typename C> pixel_step_iterator<pixel<T,C>*> make_step_iterator(pixel<T,C>* it, std::ptrdiff_t step) {
00255 return pixel_step_iterator<pixel<T,C>*>(it, step);
00256 }
00257
00260 template <typename T, typename C> pixel_step_iterator<const pixel<T,C>*> make_step_iterator(const pixel<T,C>* it, std::ptrdiff_t step) {
00261 return pixel_step_iterator<const pixel<T,C>*>(it, step);
00262 }
00263
00266 template <typename IC, typename C> pixel_step_iterator<planar_ptr<IC,C> > make_step_iterator(const planar_ptr<IC,C>& it, std::ptrdiff_t step) {
00267 return pixel_step_iterator<planar_ptr<IC,C> >(it, step);
00268 }
00269
00272 template <typename I> typename pixel_iterator_traits<I>::dynamic_step_t make_step_iterator(const pixel_step_iterator<I>& it, std::ptrdiff_t step) {
00273 return typename pixel_iterator_traits< I >::dynamic_step_t(it.base(), step);
00274 }
00276
00277 ADOBE_GIL_NAMESPACE_END
00278
00279 #endif