1 | #include <iostream>
|
---|
2 | #include <boost/gil/gil_all.hpp>
|
---|
3 | using namespace boost;
|
---|
4 | using namespace gil;
|
---|
5 |
|
---|
6 | //
|
---|
7 | // Do-nothing dereference adaptor
|
---|
8 | //
|
---|
9 | template <typename View>
|
---|
10 | struct deref_fn {
|
---|
11 | BOOST_STATIC_CONSTANT(bool, is_mutable=false);
|
---|
12 | typedef deref_fn<typename View::const_t> const_t;
|
---|
13 | typedef typename View::value_type value_type;
|
---|
14 | typedef typename View::reference reference;
|
---|
15 | typedef typename View::point_t argument_type;
|
---|
16 | typedef reference result_type;
|
---|
17 |
|
---|
18 | deref_fn() {;}
|
---|
19 | deref_fn(const View& v) : mView(v) { ; }
|
---|
20 | result_type operator()(const argument_type& p) const {
|
---|
21 | return mView(p);
|
---|
22 | }
|
---|
23 |
|
---|
24 | View mView;
|
---|
25 | };
|
---|
26 |
|
---|
27 | typedef rgb8_planar_image_t image_t;
|
---|
28 | typedef image_t::view_t view_t;
|
---|
29 | typedef deref_fn<view_t> fn_t;
|
---|
30 | typedef virtual_2d_locator<fn_t, false> loc_t;
|
---|
31 | typedef image_view<loc_t> virt_view_t;
|
---|
32 | typedef kth_channel_view_type<0, virt_view_t>::type chan0_view_t;
|
---|
33 |
|
---|
34 | int main(int argc, char **argv) {
|
---|
35 | image_t img(4,4,rgb8_pixel_t(1,2,3),0);
|
---|
36 | view_t v(view(img));
|
---|
37 |
|
---|
38 | fn_t fn(v);
|
---|
39 | loc_t loc(view_t::point_t(0,0), view_t::point_t(1,1), fn);
|
---|
40 | virt_view_t virtView(v.dimensions(), loc);
|
---|
41 |
|
---|
42 | //
|
---|
43 | // Here detail::kth_channel_deref_fn<K,SrcP> is instantiated with
|
---|
44 | // SrcP = 'planar_pixel_reference<bits8&, rgb_t>'. The
|
---|
45 | // kth_channel_deref_fn then declares its result_type (and thereby
|
---|
46 | // the chan0_view_t:reference) to be a
|
---|
47 | // 'pixel<bits8&, gray_layout_t>&'
|
---|
48 | //
|
---|
49 | chan0_view_t chan0View(kth_channel_view<0,virt_view_t>(virtView));
|
---|
50 |
|
---|
51 | assert((is_same<chan0_view_t::reference,
|
---|
52 | pixel<bits8&, gray_layout_t>& >::value));
|
---|
53 |
|
---|
54 | //
|
---|
55 | // This will typically cause a bus error because the result_type
|
---|
56 | // of the deref adaptor is a 'pixel<bits8&, gray_layout_t>&'
|
---|
57 | // which gets initialized in the deref function by a
|
---|
58 | // 'pixel<bits8, gray_layout_t>&'
|
---|
59 | //
|
---|
60 | assert(chan0View(0,0) == gray8_pixel_t(1));
|
---|
61 | return 0;
|
---|
62 | }
|
---|