Boost GIL


extension/dynamic_image/image_view_factory.hpp
1 //
2 // Copyright 2005-2007 Adobe Systems Incorporated
3 //
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
7 //
8 #ifndef BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_IMAGE_VIEW_FACTORY_HPP
9 #define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_IMAGE_VIEW_FACTORY_HPP
10 
11 #include <boost/gil/extension/dynamic_image/any_image_view.hpp>
12 
13 #include <boost/gil/image_view_factory.hpp>
14 #include <boost/gil/point.hpp>
15 
16 namespace boost { namespace gil {
17 
18 // Methods for constructing any image views from other any image views
19 // Extends image view factory to runtime type-specified views (any_image_view)
20 
21 namespace detail {
22 template <typename Result> struct flipped_up_down_view_fn {
23  typedef Result result_type;
24  template <typename View> result_type operator()(const View& src) const { return result_type(flipped_up_down_view(src)); }
25 };
26 template <typename Result> struct flipped_left_right_view_fn {
27  typedef Result result_type;
28  template <typename View> result_type operator()(const View& src) const { return result_type(flipped_left_right_view(src)); }
29 };
30 template <typename Result> struct rotated90cw_view_fn {
31  typedef Result result_type;
32  template <typename View> result_type operator()(const View& src) const { return result_type(rotated90cw_view(src)); }
33 };
34 template <typename Result> struct rotated90ccw_view_fn {
35  typedef Result result_type;
36  template <typename View> result_type operator()(const View& src) const { return result_type(rotated90ccw_view(src)); }
37 };
38 template <typename Result> struct tranposed_view_fn {
39  typedef Result result_type;
40  template <typename View> result_type operator()(const View& src) const { return result_type(tranposed_view(src)); }
41 };
42 template <typename Result> struct rotated180_view_fn {
43  typedef Result result_type;
44  template <typename View> result_type operator()(const View& src) const { return result_type(rotated180_view(src)); }
45 };
46 
47 template <typename Result>
48 struct subimage_view_fn
49 {
50  typedef Result result_type;
51  subimage_view_fn(point_t const& topleft, point_t const& dimensions)
52  : _topleft(topleft), _size2(dimensions)
53  {}
54 
55  template <typename View>
56  result_type operator()(const View& src) const
57  {
58  return result_type(subimage_view(src,_topleft,_size2));
59  }
60 
61  point_t _topleft;
62  point_t _size2;
63 };
64 
65 template <typename Result>
66 struct subsampled_view_fn
67 {
68  typedef Result result_type;
69  subsampled_view_fn(point_t const& step) : _step(step) {}
70 
71  template <typename View>
72  result_type operator()(const View& src) const
73  {
74  return result_type(subsampled_view(src,_step));
75  }
76 
77  point_t _step;
78 };
79 
80 template <typename Result> struct nth_channel_view_fn {
81  typedef Result result_type;
82  nth_channel_view_fn(int n) : _n(n) {}
83  int _n;
84  template <typename View> result_type operator()(const View& src) const { return result_type(nth_channel_view(src,_n)); }
85 };
86 template <typename DstP, typename Result, typename CC = default_color_converter> struct color_converted_view_fn {
87  typedef Result result_type;
88  color_converted_view_fn(CC cc = CC()): _cc(cc) {}
89 
90  template <typename View> result_type operator()(const View& src) const { return result_type(color_converted_view<DstP>(src, _cc)); }
91 
92  private:
93  CC _cc;
94 };
95 } // namespace detail
96 
97 
99 template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
100 typename dynamic_y_step_type<any_image_view<ViewTypes> >::type flipped_up_down_view(const any_image_view<ViewTypes>& src) {
101  return apply_operation(src,detail::flipped_up_down_view_fn<typename dynamic_y_step_type<any_image_view<ViewTypes> >::type>());
102 }
103 
105 template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
106 typename dynamic_x_step_type<any_image_view<ViewTypes> >::type flipped_left_right_view(const any_image_view<ViewTypes>& src) {
107  return apply_operation(src,detail::flipped_left_right_view_fn<typename dynamic_x_step_type<any_image_view<ViewTypes> >::type>());
108 }
109 
111 template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
112 typename dynamic_xy_step_transposed_type<any_image_view<ViewTypes> >::type transposed_view(const any_image_view<ViewTypes>& src) {
113  return apply_operation(src,detail::tranposed_view_fn<typename dynamic_xy_step_transposed_type<any_image_view<ViewTypes> >::type>());
114 }
115 
117 template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
118 typename dynamic_xy_step_transposed_type<any_image_view<ViewTypes> >::type rotated90cw_view(const any_image_view<ViewTypes>& src) {
119  return apply_operation(src,detail::rotated90cw_view_fn<typename dynamic_xy_step_transposed_type<any_image_view<ViewTypes> >::type>());
120 }
121 
123 template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
124 typename dynamic_xy_step_transposed_type<any_image_view<ViewTypes> >::type rotated90ccw_view(const any_image_view<ViewTypes>& src) {
125  return apply_operation(src,detail::rotated90ccw_view_fn<typename dynamic_xy_step_transposed_type<any_image_view<ViewTypes> >::type>());
126 }
127 
130 template <typename ViewTypes>
133 {
134  using step_type = typename dynamic_xy_step_type<any_image_view<ViewTypes>>::type;
135  return apply_operation(src, detail::rotated180_view_fn<step_type>());
136 }
137 
140 template <typename ViewTypes>
142  point_t const& topleft, point_t const& dimensions)
144 {
145  using subimage_view_fn = detail::subimage_view_fn<any_image_view<ViewTypes>>;
146  return apply_operation(src, subimage_view_fn(topleft, dimensions));
147 }
148 
151 template <typename ViewTypes>
153  int xMin, int yMin, int width, int height)
155 {
156  using subimage_view_fn = detail::subimage_view_fn<any_image_view<ViewTypes>>;
157  return apply_operation(src, subimage_view_fn(point_t(xMin, yMin),point_t(width, height)));
158 }
159 
162 template <typename ViewTypes>
163 inline auto subsampled_view(any_image_view<ViewTypes> const& src, point_t const& step)
165 {
166  using step_type = typename dynamic_xy_step_type<any_image_view<ViewTypes>>::type;
167  using subsampled_view = detail::subsampled_view_fn<step_type>;
168  return apply_operation(src, subsampled_view(step));
169 }
170 
173 template <typename ViewTypes>
174 inline auto subsampled_view(any_image_view<ViewTypes> const& src, int xStep, int yStep)
176 {
177  using step_type = typename dynamic_xy_step_type<any_image_view<ViewTypes>>::type;
178  using subsampled_view_fn = detail::subsampled_view_fn<step_type>;
179  return apply_operation(src, subsampled_view_fn(point_t(xStep, yStep)));
180 }
181 
182 namespace detail {
183  template <typename View> struct get_nthchannel_type { typedef typename nth_channel_view_type<View>::type type; };
184  template <typename Views> struct views_get_nthchannel_type : public mpl::transform<Views, get_nthchannel_type<mpl::_1> > {};
185 }
186 
189 template <typename ViewTypes>
192 };
193 
195 template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
196 typename nth_channel_view_type<any_image_view<ViewTypes> >::type nth_channel_view(const any_image_view<ViewTypes>& src, int n) {
197  return apply_operation(src,detail::nth_channel_view_fn<typename nth_channel_view_type<any_image_view<ViewTypes> >::type>(n));
198 }
199 
200 namespace detail {
201  template <typename View, typename DstP, typename CC> struct get_ccv_type : public color_converted_view_type<View, DstP, CC> {};
202  template <typename Views, typename DstP, typename CC> struct views_get_ccv_type : public mpl::transform<Views, get_ccv_type<mpl::_1,DstP,CC> > {};
203 }
204 
207 template <typename ViewTypes, typename DstP, typename CC>
208 struct color_converted_view_type<any_image_view<ViewTypes>,DstP,CC> {
210 };
211 
214 template <typename DstP, typename ViewTypes, typename CC> inline // Models MPL Random Access Container of models of ImageViewConcept
216  return apply_operation(src,detail::color_converted_view_fn<DstP,typename color_converted_view_type<any_image_view<ViewTypes>, DstP, CC>::type >());
217 }
218 
221 template <typename ViewTypes, typename DstP>
222 struct color_converted_view_type<any_image_view<ViewTypes>,DstP> {
224 };
225 
228 template <typename DstP, typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
230  return apply_operation(src,detail::color_converted_view_fn<DstP,typename color_converted_view_type<any_image_view<ViewTypes>, DstP>::type >());
231 }
232 
233 
237 template <typename DstP, typename ViewTypes, typename CC> inline // Models MPL Random Access Container of models of ImageViewConcept
239  return apply_operation(src,detail::color_converted_view_fn<DstP,typename color_converted_view_type<any_image_view<ViewTypes>, DstP, CC>::type >());
240 }
241 
245 template <typename DstP, typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
247  return apply_operation(src,detail::color_converted_view_fn<DstP,typename color_converted_view_type<any_image_view<ViewTypes>, DstP>::type >());
248 }
249 
251 
252 } } // namespace boost::gil
253 
254 #endif
color_converted_view_type< any_image_view< ViewTypes >, DstP >::type color_converted_view(const any_image_view< ViewTypes > &src)
overload of generic color_converted_view with the default color-converter
Definition: extension/dynamic_image/image_view_factory.hpp:229
auto rotated180_view(const any_image_view< ViewTypes > &src) -> typename dynamic_xy_step_type< any_image_view< ViewTypes >>::type
Definition: extension/dynamic_image/image_view_factory.hpp:131
Returns the type of a view that has a dynamic step along both X and Y.
Definition: image_view_factory.hpp:41
Given a source image view type View, returns the type of an image view over a single channel of ViewI...
Definition: image_view_factory.hpp:381
Returns the type of a view that does color conversion upon dereferencing its pixels.
Definition: image_view_factory.hpp:154
BOOST_FORCEINLINE UnaryOp::result_type apply_operation(variant< Types > &arg, UnaryOp op)
Invokes a generic mutable operation (represented as a unary function object) on a variant...
Definition: apply_operation.hpp:31
Represents a run-time specified image view. Models HasDynamicXStepTypeConcept, HasDynamicYStepTypeCon...
Definition: any_image_view.hpp:60
auto subimage_view(any_image_view< ViewTypes > const &src, int xMin, int yMin, int width, int height) -> any_image_view< ViewTypes >
Definition: extension/dynamic_image/image_view_factory.hpp:152
auto subsampled_view(any_image_view< ViewTypes > const &src, int xStep, int yStep) -> typename dynamic_xy_step_type< any_image_view< ViewTypes >>::type
Definition: extension/dynamic_image/image_view_factory.hpp:174
color_converted_view_type< any_image_view< ViewTypes >, DstP >::type any_color_converted_view(const any_image_view< ViewTypes > &src)
overload of generic color_converted_view with the default color-converter These are workarounds for G...
Definition: extension/dynamic_image/image_view_factory.hpp:246