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/dynamic_step.hpp>
14 #include <boost/gil/image_view_factory.hpp>
15 #include <boost/gil/point.hpp>
16 
17 namespace boost { namespace gil {
18 
19 // Methods for constructing any image views from other any image views
20 // Extends image view factory to runtime type-specified views (any_image_view)
21 
22 namespace detail {
23 template <typename Result> struct flipped_up_down_view_fn {
24  using result_type = Result;
25  template <typename View> result_type operator()(const View& src) const { return result_type(flipped_up_down_view(src)); }
26 };
27 template <typename Result> struct flipped_left_right_view_fn {
28  using result_type = Result;
29  template <typename View> result_type operator()(const View& src) const { return result_type(flipped_left_right_view(src)); }
30 };
31 template <typename Result> struct rotated90cw_view_fn {
32  using result_type = Result;
33  template <typename View> result_type operator()(const View& src) const { return result_type(rotated90cw_view(src)); }
34 };
35 template <typename Result> struct rotated90ccw_view_fn {
36  using result_type = Result;
37  template <typename View> result_type operator()(const View& src) const { return result_type(rotated90ccw_view(src)); }
38 };
39 template <typename Result> struct tranposed_view_fn {
40  using result_type = Result;
41  template <typename View> result_type operator()(const View& src) const { return result_type(tranposed_view(src)); }
42 };
43 template <typename Result> struct rotated180_view_fn {
44  using result_type = Result;
45  template <typename View> result_type operator()(const View& src) const { return result_type(rotated180_view(src)); }
46 };
47 
48 template <typename Result>
49 struct subimage_view_fn
50 {
51  using result_type = Result;
52  subimage_view_fn(point_t const& topleft, point_t const& dimensions)
53  : _topleft(topleft), _size2(dimensions)
54  {}
55 
56  template <typename View>
57  result_type operator()(const View& src) const
58  {
59  return result_type(subimage_view(src,_topleft,_size2));
60  }
61 
62  point_t _topleft;
63  point_t _size2;
64 };
65 
66 template <typename Result>
67 struct subsampled_view_fn
68 {
69  using result_type = Result;
70  subsampled_view_fn(point_t const& step) : _step(step) {}
71 
72  template <typename View>
73  result_type operator()(const View& src) const
74  {
75  return result_type(subsampled_view(src,_step));
76  }
77 
78  point_t _step;
79 };
80 
81 template <typename Result> struct nth_channel_view_fn {
82  using result_type = Result;
83  nth_channel_view_fn(int n) : _n(n) {}
84  int _n;
85  template <typename View> result_type operator()(const View& src) const { return result_type(nth_channel_view(src,_n)); }
86 };
87 template <typename DstP, typename Result, typename CC = default_color_converter> struct color_converted_view_fn {
88  using result_type = Result;
89  color_converted_view_fn(CC cc = CC()): _cc(cc) {}
90 
91  template <typename View> result_type operator()(const View& src) const { return result_type(color_converted_view<DstP>(src, _cc)); }
92 
93  private:
94  CC _cc;
95 };
96 } // namespace detail
97 
98 
100 template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
101 typename dynamic_y_step_type<any_image_view<ViewTypes> >::type flipped_up_down_view(const any_image_view<ViewTypes>& src) {
102  return apply_operation(src,detail::flipped_up_down_view_fn<typename dynamic_y_step_type<any_image_view<ViewTypes> >::type>());
103 }
104 
106 template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
107 typename dynamic_x_step_type<any_image_view<ViewTypes> >::type flipped_left_right_view(const any_image_view<ViewTypes>& src) {
108  return apply_operation(src,detail::flipped_left_right_view_fn<typename dynamic_x_step_type<any_image_view<ViewTypes> >::type>());
109 }
110 
112 template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
113 typename dynamic_xy_step_transposed_type<any_image_view<ViewTypes> >::type transposed_view(const any_image_view<ViewTypes>& src) {
114  return apply_operation(src,detail::tranposed_view_fn<typename dynamic_xy_step_transposed_type<any_image_view<ViewTypes> >::type>());
115 }
116 
118 template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
119 typename dynamic_xy_step_transposed_type<any_image_view<ViewTypes> >::type rotated90cw_view(const any_image_view<ViewTypes>& src) {
120  return apply_operation(src,detail::rotated90cw_view_fn<typename dynamic_xy_step_transposed_type<any_image_view<ViewTypes> >::type>());
121 }
122 
124 template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
125 typename dynamic_xy_step_transposed_type<any_image_view<ViewTypes> >::type rotated90ccw_view(const any_image_view<ViewTypes>& src) {
126  return apply_operation(src,detail::rotated90ccw_view_fn<typename dynamic_xy_step_transposed_type<any_image_view<ViewTypes> >::type>());
127 }
128 
131 template <typename ViewTypes>
134 {
135  using step_type = typename dynamic_xy_step_type<any_image_view<ViewTypes>>::type;
136  return apply_operation(src, detail::rotated180_view_fn<step_type>());
137 }
138 
141 template <typename ViewTypes>
143  point_t const& topleft, point_t const& dimensions)
145 {
146  using subimage_view_fn = detail::subimage_view_fn<any_image_view<ViewTypes>>;
147  return apply_operation(src, subimage_view_fn(topleft, dimensions));
148 }
149 
152 template <typename ViewTypes>
154  int xMin, int yMin, int width, int height)
156 {
157  using subimage_view_fn = detail::subimage_view_fn<any_image_view<ViewTypes>>;
158  return apply_operation(src, subimage_view_fn(point_t(xMin, yMin),point_t(width, height)));
159 }
160 
163 template <typename ViewTypes>
164 inline auto subsampled_view(any_image_view<ViewTypes> const& src, point_t const& step)
166 {
167  using step_type = typename dynamic_xy_step_type<any_image_view<ViewTypes>>::type;
168  using subsampled_view = detail::subsampled_view_fn<step_type>;
169  return apply_operation(src, subsampled_view(step));
170 }
171 
174 template <typename ViewTypes>
175 inline auto subsampled_view(any_image_view<ViewTypes> const& src, int xStep, int yStep)
177 {
178  using step_type = typename dynamic_xy_step_type<any_image_view<ViewTypes>>::type;
179  using subsampled_view_fn = detail::subsampled_view_fn<step_type>;
180  return apply_operation(src, subsampled_view_fn(point_t(xStep, yStep)));
181 }
182 
183 namespace detail {
184  template <typename View> struct get_nthchannel_type { using type = typename nth_channel_view_type<View>::type; };
185  template <typename Views> struct views_get_nthchannel_type : public mpl::transform<Views, get_nthchannel_type<mpl::_1> > {};
186 }
187 
190 template <typename ViewTypes>
193 };
194 
196 template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
197 typename nth_channel_view_type<any_image_view<ViewTypes> >::type nth_channel_view(const any_image_view<ViewTypes>& src, int n) {
198  return apply_operation(src,detail::nth_channel_view_fn<typename nth_channel_view_type<any_image_view<ViewTypes> >::type>(n));
199 }
200 
201 namespace detail {
202  template <typename View, typename DstP, typename CC> struct get_ccv_type : public color_converted_view_type<View, DstP, CC> {};
203  template <typename Views, typename DstP, typename CC> struct views_get_ccv_type : public mpl::transform<Views, get_ccv_type<mpl::_1,DstP,CC> > {};
204 }
205 
208 template <typename ViewTypes, typename DstP, typename CC>
209 struct color_converted_view_type<any_image_view<ViewTypes>,DstP,CC>
210 {
212 };
213 
216 template <typename DstP, typename ViewTypes, typename CC> inline // Models MPL Random Access Container of models of ImageViewConcept
218  return apply_operation(src,detail::color_converted_view_fn<DstP,typename color_converted_view_type<any_image_view<ViewTypes>, DstP, CC>::type >());
219 }
220 
223 template <typename ViewTypes, typename DstP>
225 {
227 };
228 
231 template <typename DstP, typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
233  return apply_operation(src,detail::color_converted_view_fn<DstP,typename color_converted_view_type<any_image_view<ViewTypes>, DstP>::type >());
234 }
235 
236 
240 template <typename DstP, typename ViewTypes, typename CC> inline // Models MPL Random Access Container of models of ImageViewConcept
242  return apply_operation(src,detail::color_converted_view_fn<DstP,typename color_converted_view_type<any_image_view<ViewTypes>, DstP, CC>::type >());
243 }
244 
248 template <typename DstP, typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
250  return apply_operation(src,detail::color_converted_view_fn<DstP,typename color_converted_view_type<any_image_view<ViewTypes>, DstP>::type >());
251 }
252 
254 
255 } } // namespace boost::gil
256 
257 #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:232
Definition: algorithm.hpp:30
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:132
Returns the type of a view that has a dynamic step along both X and Y.
Definition: dynamic_step.hpp:27
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:387
BOOST_FORCEINLINE auto 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
Returns the type of a view that does color conversion upon dereferencing its pixels.
Definition: image_view_factory.hpp:155
Represents a run-time specified image view. Models HasDynamicXStepTypeConcept, HasDynamicYStepTypeCon...
Definition: any_image_view.hpp:61
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:153
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:175
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:249