#include #include using namespace boost; using namespace gil; // // Do-nothing dereference adaptor // template struct deref_fn { BOOST_STATIC_CONSTANT(bool, is_mutable=false); typedef deref_fn const_t; typedef typename View::value_type value_type; typedef typename View::reference reference; typedef typename View::point_t argument_type; typedef reference result_type; deref_fn() {;} deref_fn(const View& v) : mView(v) { ; } result_type operator()(const argument_type& p) const { return mView(p); } View mView; }; typedef rgb8_planar_image_t image_t; typedef image_t::view_t view_t; typedef deref_fn fn_t; typedef virtual_2d_locator loc_t; typedef image_view virt_view_t; typedef kth_channel_view_type<0, virt_view_t>::type chan0_view_t; int main(int argc, char **argv) { image_t img(4,4,rgb8_pixel_t(1,2,3),0); view_t v(view(img)); fn_t fn(v); loc_t loc(view_t::point_t(0,0), view_t::point_t(1,1), fn); virt_view_t virtView(v.dimensions(), loc); // // Here detail::kth_channel_deref_fn is instantiated with // SrcP = 'planar_pixel_reference'. The // kth_channel_deref_fn then declares its result_type (and thereby // the chan0_view_t:reference) to be a // 'pixel&' // chan0_view_t chan0View(kth_channel_view<0,virt_view_t>(virtView)); assert((is_same& >::value)); // // This will typically cause a bus error because the result_type // of the deref adaptor is a 'pixel&' // which gets initialized in the deref function by a // 'pixel&' // assert(chan0View(0,0) == gray8_pixel_t(1)); return 0; }