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 #include <boost/gil/detail/mp11.hpp>
17 
18 #include <cstdint>
19 
20 namespace boost { namespace gil {
21 
22 // Methods for constructing any image views from other any image views
23 // Extends image view factory to runtime type-specified views (any_image_view)
24 
25 namespace detail {
26 
27 template <typename ResultView>
28 struct flipped_up_down_view_fn
29 {
30  using result_type = ResultView;
31 
32  template <typename View>
33  auto operator()(View const& src) const -> result_type
34  {
35  return result_type{flipped_up_down_view(src)};
36  }
37 };
38 
39 template <typename ResultView>
40 struct flipped_left_right_view_fn
41 {
42  using result_type = ResultView;
43 
44  template <typename View>
45  auto operator()(View const& src) const -> result_type
46  {
47  return result_type{flipped_left_right_view(src)};
48  }
49 };
50 
51 template <typename ResultView>
52 struct rotated90cw_view_fn
53 {
54  using result_type = ResultView;
55 
56  template <typename View>
57  auto operator()(View const& src) const -> result_type
58  {
59  return result_type{rotated90cw_view(src)};
60  }
61 };
62 
63 template <typename ResultView>
64 struct rotated90ccw_view_fn
65 {
66  using result_type = ResultView;
67 
68  template <typename View>
69  auto operator()(View const& src) const -> result_type
70  {
71  return result_type{rotated90ccw_view(src)};
72  }
73 };
74 
75 template <typename ResultView>
76 struct transposed_view_fn
77 {
78  using result_type = ResultView;
79 
80  template <typename View>
81  auto operator()(View const& src) const -> result_type
82  {
83  return result_type{transposed_view(src)};
84  }
85 };
86 
87 template <typename ResultView>
88 struct rotated180_view_fn
89 {
90  using result_type = ResultView;
91 
92  template <typename View>
93  auto operator()(View const& src) const -> result_type
94  {
95  return result_type{rotated180_view(src)};
96  }
97 };
98 
99 template <typename ResultView>
100 struct subimage_view_fn
101 {
102  using result_type = ResultView;
103 
104  subimage_view_fn(point_t const& topleft, point_t const& dimensions)
105  : _topleft(topleft), _size2(dimensions)
106  {}
107 
108  template <typename View>
109  auto operator()(View const& src) const -> result_type
110  {
111  return result_type{subimage_view(src,_topleft,_size2)};
112  }
113 
114  point_t _topleft;
115  point_t _size2;
116 };
117 
118 template <typename ResultView>
119 struct subsampled_view_fn
120 {
121  using result_type = ResultView;
122 
123  subsampled_view_fn(point_t const& step) : _step(step) {}
124 
125  template <typename View>
126  auto operator()(View const& src) const -> result_type
127  {
128  return result_type{subsampled_view(src,_step)};
129  }
130 
131  point_t _step;
132 };
133 
134 template <typename ResultView>
135 struct nth_channel_view_fn
136 {
137  using result_type = ResultView;
138 
139  nth_channel_view_fn(int n) : _n(n) {}
140 
141  template <typename View>
142  auto operator()(View const& src) const -> result_type
143  {
144  return result_type(nth_channel_view(src,_n));
145  }
146 
147  int _n;
148 };
149 
150 template <typename DstP, typename ResultView, typename CC = default_color_converter>
151 struct color_converted_view_fn
152 {
153  using result_type = ResultView;
154 
155  color_converted_view_fn(CC cc = CC()): _cc(cc) {}
156 
157  template <typename View>
158  auto operator()(View const& src) const -> result_type
159  {
160  return result_type{color_converted_view<DstP>(src, _cc)};
161  }
162 
163 private:
164  CC _cc;
165 };
166 
167 } // namespace detail
168 
171 template <typename ...Views>
172 inline
174  -> typename dynamic_y_step_type<any_image_view<Views...>>::type
175 {
176  using result_view_t = typename dynamic_y_step_type<any_image_view<Views...>>::type;
177  return variant2::visit(detail::flipped_up_down_view_fn<result_view_t>(), src);
178 }
179 
182 template <typename ...Views>
183 inline
185  -> typename dynamic_x_step_type<any_image_view<Views...>>::type
186 {
187  using result_view_t = typename dynamic_x_step_type<any_image_view<Views...>>::type;
188  return variant2::visit(detail::flipped_left_right_view_fn<result_view_t>(), src);
189 }
190 
193 template <typename ...Views>
194 inline
196  -> typename dynamic_xy_step_transposed_type<any_image_view<Views...>>::type
197 {
198  using result_view_t = typename dynamic_xy_step_transposed_type<any_image_view<Views...>>::type;
199  return variant2::visit(detail::transposed_view_fn<result_view_t>(), src);
200 }
201 
204 template <typename ...Views>
205 inline
207  -> typename dynamic_xy_step_transposed_type<any_image_view<Views...>>::type
208 {
209  using result_view_t = typename dynamic_xy_step_transposed_type<any_image_view<Views...>>::type;
210  return variant2::visit(detail::rotated90cw_view_fn<result_view_t>(), src);
211 }
212 
215 template <typename ...Views>
216 inline
218  -> typename dynamic_xy_step_transposed_type<any_image_view<Views...>>::type
219 {
220  using result_view_t = typename dynamic_xy_step_transposed_type<any_image_view<Views...>>::type;
221  return variant2::visit(detail::rotated90ccw_view_fn<result_view_t>(), src);
222 }
223 
226 template <typename ...Views>
227 inline
229  -> typename dynamic_xy_step_type<any_image_view<Views...>>::type
230 {
231  using result_view_t = typename dynamic_xy_step_type<any_image_view<Views...>>::type;
232  return variant2::visit(detail::rotated180_view_fn<result_view_t>(), src);
233 }
234 
237 template <typename ...Views>
238 inline
240  any_image_view<Views...> const& src,
241  point_t const& topleft,
242  point_t const& dimensions)
243  -> any_image_view<Views...>
244 {
245  using subimage_view_fn = detail::subimage_view_fn<any_image_view<Views...>>;
246  return variant2::visit(subimage_view_fn(topleft, dimensions), src);
247 }
248 
251 template <typename ...Views>
252 inline
254  any_image_view<Views...> const& src,
255  std::ptrdiff_t x_min, std::ptrdiff_t y_min, std::ptrdiff_t width, std::ptrdiff_t height)
256  -> any_image_view<Views...>
257 {
258  using subimage_view_fn = detail::subimage_view_fn<any_image_view<Views...>>;
259  return variant2::visit(subimage_view_fn(point_t(x_min, y_min),point_t(width, height)), src);
260 }
261 
264 template <typename ...Views>
265 inline
266 auto subsampled_view(any_image_view<Views...> const& src, point_t const& step)
267  -> typename dynamic_xy_step_type<any_image_view<Views...>>::type
268 {
269  using step_type = typename dynamic_xy_step_type<any_image_view<Views...>>::type;
270  using subsampled_view = detail::subsampled_view_fn<step_type>;
271  return variant2::visit(subsampled_view(step), src);
272 }
273 
276 template <typename ...Views>
277 inline
278 auto subsampled_view(any_image_view<Views...> const& src, std::ptrdiff_t x_step, std::ptrdiff_t y_step)
279  -> typename dynamic_xy_step_type<any_image_view<Views...>>::type
280 {
281  using step_type = typename dynamic_xy_step_type<any_image_view<Views...>>::type;
282  using subsampled_view_fn = detail::subsampled_view_fn<step_type>;
283  return variant2::visit(subsampled_view_fn(point_t(x_step, y_step)), src);
284 }
285 
286 namespace detail {
287 
288 template <typename View>
289 struct get_nthchannel_type { using type = typename nth_channel_view_type<View>::type; };
290 
291 template <typename Views>
292 struct views_get_nthchannel_type : mp11::mp_transform<get_nthchannel_type, Views> {};
293 
294 } // namespace detail
295 
298 template <typename ...Views>
300 {
301  using type = typename detail::views_get_nthchannel_type<any_image_view<Views...>>;
302 };
303 
306 template <typename ...Views>
307 inline
309  -> typename nth_channel_view_type<any_image_view<Views...>>::type
310 {
311  using result_view_t = typename nth_channel_view_type<any_image_view<Views...>>::type;
312  return variant2::visit(detail::nth_channel_view_fn<result_view_t>(n), src);
313 }
314 
315 namespace detail {
316 
317 template <typename Views, typename DstP, typename CC>
318 struct views_get_ccv_type
319 {
320 private:
321  template <typename T>
322  using ccvt = typename color_converted_view_type<T, DstP, CC>::type;
323 public:
324  using type = mp11::mp_transform<ccvt, Views>;
325 };
326 
327 } // namespace detail
328 
331 template <typename ...Views, typename DstP, typename CC>
332 struct color_converted_view_type<any_image_view<Views...>,DstP,CC>
333 {
334  //using type = any_image_view<typename detail::views_get_ccv_type<Views, DstP, CC>::type>;
335  using type = typename detail::views_get_ccv_type<any_image_view<Views...>, DstP, CC>::type;
336 };
337 
341 template <typename DstP, typename ...Views, typename CC>
342 inline
344  -> typename color_converted_view_type<any_image_view<Views...>, DstP, CC>::type
345 {
346  using cc_view_t = typename color_converted_view_type<any_image_view<Views...>, DstP, CC>::type;
347  return variant2::visit(detail::color_converted_view_fn<DstP, cc_view_t, CC>(cc), src);
348 }
349 
352 template <typename ...Views, typename DstP>
354 {
355  using type = typename detail::views_get_ccv_type<any_image_view<Views...>, DstP, default_color_converter>::type;
356 };
357 
361 template <typename DstP, typename ...Views>
362 inline
364  -> typename color_converted_view_type<any_image_view<Views...>, DstP>::type
365 {
366  using cc_view_t = typename color_converted_view_type<any_image_view<Views...>, DstP>::type;
367  return variant2::visit(detail::color_converted_view_fn<DstP, cc_view_t>(), src);
368 }
369 
374 template <typename DstP, typename ...Views, typename CC>
375 [[deprecated("Use color_converted_view(const any_image_view<Views...>& src, CC) instead.")]]
376 inline
378  -> typename color_converted_view_type<any_image_view<Views...>, DstP, CC>::type
379 {
380  return color_converted_view(src, cc);
381 }
382 
387 template <typename DstP, typename ...Views>
388 [[deprecated("Use color_converted_view(any_image_view<Views...> const& src) instead.")]]
389 inline
391  -> typename color_converted_view_type<any_image_view<Views...>, DstP>::type
392 {
393  return color_converted_view(src);
394 }
395 
397 
398 }} // namespace boost::gil
399 
400 #endif
Represents a run-time specified image view. Models HasDynamicXStepTypeConcept, HasDynamicYStepTypeCon...
Definition: any_image_view.hpp:76
auto rotated180_view(any_image_view< Views... > const &src) -> typename dynamic_xy_step_type< any_image_view< Views... >>::type
Definition: extension/dynamic_image/image_view_factory.hpp:228
auto rotated90ccw_view(any_image_view< Views... > const &src) -> typename dynamic_xy_step_transposed_type< any_image_view< Views... >>::type
Definition: extension/dynamic_image/image_view_factory.hpp:217
auto rotated90cw_view(any_image_view< Views... > const &src) -> typename dynamic_xy_step_transposed_type< any_image_view< Views... >>::type
Definition: extension/dynamic_image/image_view_factory.hpp:206
auto any_color_converted_view(const any_image_view< Views... > &src) -> typename color_converted_view_type< any_image_view< Views... >, DstP >::type
overload of generic color_converted_view with the default color-converter These are workarounds for G...
Definition: extension/dynamic_image/image_view_factory.hpp:390
auto color_converted_view(any_image_view< Views... > const &src) -> typename color_converted_view_type< any_image_view< Views... >, DstP >::type
overload of generic color_converted_view with the default color-converter
Definition: extension/dynamic_image/image_view_factory.hpp:363
auto flipped_left_right_view(any_image_view< Views... > const &src) -> typename dynamic_x_step_type< any_image_view< Views... >>::type
Definition: extension/dynamic_image/image_view_factory.hpp:184
auto flipped_up_down_view(any_image_view< Views... > const &src) -> typename dynamic_y_step_type< any_image_view< Views... >>::type
Definition: extension/dynamic_image/image_view_factory.hpp:173
auto nth_channel_view(any_image_view< Views... > const &src, int n) -> typename nth_channel_view_type< any_image_view< Views... >>::type
Definition: extension/dynamic_image/image_view_factory.hpp:308
auto subimage_view(any_image_view< Views... > const &src, std::ptrdiff_t x_min, std::ptrdiff_t y_min, std::ptrdiff_t width, std::ptrdiff_t height) -> any_image_view< Views... >
Definition: extension/dynamic_image/image_view_factory.hpp:253
auto subsampled_view(any_image_view< Views... > const &src, std::ptrdiff_t x_step, std::ptrdiff_t y_step) -> typename dynamic_xy_step_type< any_image_view< Views... >>::type
Definition: extension/dynamic_image/image_view_factory.hpp:278
auto transposed_view(any_image_view< Views... > const &src) -> typename dynamic_xy_step_transposed_type< any_image_view< Views... >>::type
Definition: extension/dynamic_image/image_view_factory.hpp:195
defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
Definition: algorithm.hpp:36
Returns the type of a view that does color conversion upon dereferencing its pixels.
Definition: image_view_factory.hpp:176
class for color-converting one pixel to another
Definition: color_convert.hpp:328
Base template for types that model HasDynamicXStepTypeConcept.
Definition: dynamic_step.hpp:17
Returns the type of a transposed view that has a dynamic step along both X and Y.
Definition: image_view_factory.hpp:52
Returns the type of a view that has a dynamic step along both X and Y.
Definition: image_view_factory.hpp:46
Base template for types that model HasDynamicYStepTypeConcept.
Definition: dynamic_step.hpp:21
Given a source image view type View, returns the type of an image view over a single channel of View.
Definition: image_view_factory.hpp:437