Boost GIL


concepts/image_view.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_CONCEPTS_IMAGE_VIEW_HPP
9 #define BOOST_GIL_CONCEPTS_IMAGE_VIEW_HPP
10 
11 #include <boost/gil/concepts/basic.hpp>
12 #include <boost/gil/concepts/concept_check.hpp>
13 #include <boost/gil/concepts/fwd.hpp>
14 #include <boost/gil/concepts/pixel.hpp>
15 #include <boost/gil/concepts/pixel_dereference.hpp>
16 #include <boost/gil/concepts/pixel_iterator.hpp>
17 #include <boost/gil/concepts/pixel_locator.hpp>
18 #include <boost/gil/concepts/point.hpp>
19 #include <boost/gil/concepts/detail/utility.hpp>
20 
21 #include <cstddef>
22 #include <iterator>
23 
24 #if defined(BOOST_CLANG)
25 #pragma clang diagnostic push
26 #pragma clang diagnostic ignored "-Wunused-local-typedefs"
27 #endif
28 
29 #if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
30 #pragma GCC diagnostic push
31 #pragma GCC diagnostic ignored "-Wunused-local-typedefs"
32 #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
33 #endif
34 
35 namespace boost { namespace gil {
36 
40 
44 
48 
100 template <typename View>
102 {
103  void constraints()
104  {
105  gil_function_requires<Regular<View>>();
106 
107  using value_type = typename View::value_type;
108  using reference = typename View::reference; // result of dereferencing
109  using pointer = typename View::pointer;
110  using difference_type = typename View::difference_type; // result of operator-(1d_iterator,1d_iterator)
111  using const_t = typename View::const_t; // same as this type, but over const values
112  using point_t = typename View::point_t; // N-dimensional point
113  using locator = typename View::locator; // N-dimensional locator
114  using iterator = typename View::iterator;
115  using const_iterator = typename View::const_iterator;
116  using reverse_iterator = typename View::reverse_iterator;
117  using size_type = typename View::size_type;
118  static const std::size_t N=View::num_dimensions;
119 
120  gil_function_requires<RandomAccessNDLocatorConcept<locator>>();
121  gil_function_requires<boost_concepts::RandomAccessTraversalConcept<iterator>>();
122  gil_function_requires<boost_concepts::RandomAccessTraversalConcept<reverse_iterator>>();
123 
124  using first_it_type = typename View::template axis<0>::iterator;
125  using last_it_type = typename View::template axis<N-1>::iterator;
126  gil_function_requires<boost_concepts::RandomAccessTraversalConcept<first_it_type>>();
127  gil_function_requires<boost_concepts::RandomAccessTraversalConcept<last_it_type>>();
128 
129 // static_assert(typename std::iterator_traits<first_it_type>::difference_type, typename point_t::template axis<0>::coord_t>::value, "");
130 // static_assert(typename std::iterator_traits<last_it_type>::difference_type, typename point_t::template axis<N-1>::coord_t>::value, "");
131 
132  // point_t must be an N-dimensional point, each dimension of which must have the same type as difference_type of the corresponding iterator
133  gil_function_requires<PointNDConcept<point_t>>();
134  static_assert(point_t::num_dimensions == N, "");
135  static_assert(is_same
136  <
137  typename std::iterator_traits<first_it_type>::difference_type,
138  typename point_t::template axis<0>::coord_t
139  >::value, "");
140  static_assert(is_same
141  <
142  typename std::iterator_traits<last_it_type>::difference_type,
143  typename point_t::template axis<N-1>::coord_t
144  >::value, "");
145 
146  point_t p;
147  locator lc;
148  iterator it;
149  reverse_iterator rit;
150  difference_type d; detail::initialize_it(d); ignore_unused_variable_warning(d);
151 
152  View(p,lc); // view must be constructible from a locator and a point
153 
154  p = view.dimensions();
155  lc = view.pixels();
156  size_type sz = view.size(); ignore_unused_variable_warning(sz);
157  bool is_contiguous = view.is_1d_traversable();
158  ignore_unused_variable_warning(is_contiguous);
159 
160  it = view.begin();
161  it = view.end();
162  rit = view.rbegin();
163  rit = view.rend();
164 
165  reference r1 = view[d]; ignore_unused_variable_warning(r1); // 1D access
166  reference r2 = view(p); ignore_unused_variable_warning(r2); // 2D access
167 
168  // get 1-D iterator of any dimension at a given pixel location
169  first_it_type fi = view.template axis_iterator<0>(p);
170  ignore_unused_variable_warning(fi);
171  last_it_type li = view.template axis_iterator<N-1>(p);
172  ignore_unused_variable_warning(li);
173 
174  using deref_t = PixelDereferenceAdaptorArchetype<typename View::value_type>;
175  using dtype = typename View::template add_deref<deref_t>::type;
176  }
177  View view;
178 };
179 
218 template <typename View>
220 {
221  void constraints()
222  {
223  gil_function_requires<RandomAccessNDImageViewConcept<View>>();
224  static_assert(View::num_dimensions == 2, "");
225 
226  // TODO: This executes the requirements for RandomAccessNDLocatorConcept again. Fix it to improve compile time
227  gil_function_requires<RandomAccess2DLocatorConcept<typename View::locator>>();
228 
229  using dynamic_x_step_t = typename dynamic_x_step_type<View>::type;
230  using dynamic_y_step_t = typename dynamic_y_step_type<View>::type;
231  using transposed_t = typename transposed_type<View>::type;
232  using x_iterator = typename View::x_iterator;
233  using y_iterator = typename View::y_iterator;
234  using x_coord_t = typename View::x_coord_t;
235  using y_coord_t = typename View::y_coord_t;
236  using xy_locator = typename View::xy_locator;
237 
238  x_coord_t xd = 0; ignore_unused_variable_warning(xd);
239  y_coord_t yd = 0; ignore_unused_variable_warning(yd);
240  x_iterator xit;
241  y_iterator yit;
242  typename View::point_t d;
243 
244  View(xd, yd, xy_locator()); // constructible with width, height, 2d_locator
245 
246  xy_locator lc = view.xy_at(xd, yd);
247  lc = view.xy_at(d);
248 
249  typename View::reference r = view(xd, yd);
250  ignore_unused_variable_warning(r);
251  xd = view.width();
252  yd = view.height();
253 
254  xit = view.x_at(d);
255  xit = view.x_at(xd,yd);
256  xit = view.row_begin(xd);
257  xit = view.row_end(xd);
258 
259  yit = view.y_at(d);
260  yit = view.y_at(xd,yd);
261  yit = view.col_begin(xd);
262  yit = view.col_end(xd);
263  }
264  View view;
265 };
266 
271 template <typename View>
273 {
274  void constraints()
275  {
276  using value_type = typename View::value_type;
277  using iterator = typename View::iterator;
278  using const_iterator = typename View::const_iterator;
279  using reference = typename View::reference;
280  using const_reference = typename View::const_reference;
281  using pointer = typename View::pointer;
282  using difference_type = typename View::difference_type;
283  using size_type= typename View::size_type;
284 
285  iterator i;
286  i = view1.begin();
287  i = view2.end();
288 
289  const_iterator ci;
290  ci = view1.begin();
291  ci = view2.end();
292 
293  size_type s;
294  s = view1.size();
295  s = view2.size();
296  ignore_unused_variable_warning(s);
297 
298  view1.empty();
299 
300  view1.swap(view2);
301  }
302  View view1;
303  View view2;
304 };
305 
310 template <typename View>
312 {
313  void constraints()
314  {
315  gil_function_requires<CollectionImageViewConcept<View>>();
316 
317  using reference = typename View::reference;
318  using const_reference = typename View::const_reference;
319 
320  reference r = view.front();
321  ignore_unused_variable_warning(r);
322 
323  const_reference cr = view.front();
324  ignore_unused_variable_warning(cr);
325  }
326  View view;
327 };
328 
333 template <typename View>
335 {
336  void constraints()
337  {
338  gil_function_requires<CollectionImageViewConcept<View>>();
339 
340  using reverse_iterator = typename View::reverse_iterator;
341  using reference = typename View::reference;
342  using const_reference = typename View::const_reference;
343 
344  reverse_iterator i;
345  i = view.rbegin();
346  i = view.rend();
347 
348  reference r = view.back();
349  ignore_unused_variable_warning(r);
350 
351  const_reference cr = view.back();
352  ignore_unused_variable_warning(cr);
353  }
354  View view;
355 };
356 
372 template <typename View>
374 {
375  void constraints()
376  {
377  gil_function_requires<RandomAccess2DImageViewConcept<View>>();
378 
379  // TODO: This executes the requirements for RandomAccess2DLocatorConcept again. Fix it to improve compile time
380  gil_function_requires<PixelLocatorConcept<typename View::xy_locator>>();
381 
382  static_assert(is_same<typename View::x_coord_t, typename View::y_coord_t>::value, "");
383 
384  using coord_t = typename View::coord_t; // 1D difference type (same for all dimensions)
385  std::size_t num_chan = view.num_channels(); ignore_unused_variable_warning(num_chan);
386  }
387  View view;
388 };
389 
390 namespace detail {
391 
393 template <typename View>
395 {
396  void constraints()
397  {
398  gil_function_requires<detail::RandomAccessNDLocatorIsMutableConcept<typename View::locator>>();
399 
400  gil_function_requires<detail::RandomAccessIteratorIsMutableConcept<typename View::iterator>>();
401 
402  gil_function_requires<detail::RandomAccessIteratorIsMutableConcept
403  <
404  typename View::reverse_iterator
405  >>();
406 
407  gil_function_requires<detail::RandomAccessIteratorIsMutableConcept
408  <
409  typename View::template axis<0>::iterator
410  >>();
411 
412  gil_function_requires<detail::RandomAccessIteratorIsMutableConcept
413  <
414  typename View::template axis<View::num_dimensions - 1>::iterator
415  >>();
416 
417  typename View::difference_type diff;
418  initialize_it(diff);
419  ignore_unused_variable_warning(diff);
420 
421  typename View::point_t pt;
422  typename View::value_type v;
423  initialize_it(v);
424 
425  view[diff] = v;
426  view(pt) = v;
427  }
428  View view;
429 };
430 
432 template <typename View>
434 {
435  void constraints()
436  {
437  gil_function_requires<detail::RandomAccessNDImageViewIsMutableConcept<View>>();
438  typename View::x_coord_t xd = 0; ignore_unused_variable_warning(xd);
439  typename View::y_coord_t yd = 0; ignore_unused_variable_warning(yd);
440  typename View::value_type v; initialize_it(v);
441  view(xd, yd) = v;
442  }
443  View view;
444 };
445 
447 template <typename View>
449 {
450  void constraints()
451  {
452  gil_function_requires<detail::RandomAccess2DImageViewIsMutableConcept<View>>();
453  }
454 };
455 
456 } // namespace detail
457 
467 template <typename View>
469 {
470  void constraints()
471  {
472  gil_function_requires<RandomAccessNDImageViewConcept<View>>();
473  gil_function_requires<detail::RandomAccessNDImageViewIsMutableConcept<View>>();
474  }
475 };
476 
484 template <typename View>
486 {
487  void constraints()
488  {
489  gil_function_requires<RandomAccess2DImageViewConcept<View>>();
490  gil_function_requires<detail::RandomAccess2DImageViewIsMutableConcept<View>>();
491  }
492 };
493 
501 template <typename View>
503 {
504  void constraints()
505  {
506  gil_function_requires<ImageViewConcept<View>>();
507  gil_function_requires<detail::PixelImageViewIsMutableConcept<View>>();
508  }
509 };
510 
519 template <typename V1, typename V2>
521  : pixels_are_compatible<typename V1::value_type, typename V2::value_type>
522 {
523 };
524 
536 template <typename V1, typename V2>
538 {
539  void constraints()
540  {
541  static_assert(views_are_compatible<V1, V2>::value, "");
542  }
543 };
544 
545 }} // namespace boost::gil
546 
547 #if defined(BOOST_CLANG)
548 #pragma clang diagnostic pop
549 #endif
550 
551 #if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
552 #pragma GCC diagnostic pop
553 #endif
554 
555 #endif
2-dimensional view over mutable values
Definition: concepts/image_view.hpp:485
Definition: algorithm.hpp:30
N-dimensional view over mutable values.
Definition: concepts/image_view.hpp:468
GIL view as Collection.
Definition: concepts/image_view.hpp:272
Returns whether two views are compatible.
Definition: concepts/image_view.hpp:520
GIL view as ReversibleCollection.
Definition: concepts/image_view.hpp:334
Base template for types that model HasDynamicYStepTypeConcept.
Definition: dynamic_step.hpp:21
GIL&#39;s 2-dimensional view over mutable GIL pixels.
Definition: concepts/image_view.hpp:502
Returns whether two pixels are compatible Pixels are compatible if their channels and color space typ...
Definition: concepts/pixel.hpp:231
GIL&#39;s 2-dimensional view over immutable GIL pixels.
Definition: concepts/image_view.hpp:373
const image< Pixel, IsPlanar, Alloc >::view_t & view(image< Pixel, IsPlanar, Alloc > &img)
Returns the non-constant-pixel view of an image.
Definition: image.hpp:460
2-dimensional view over immutable values
Definition: concepts/image_view.hpp:219
GIL view as ForwardCollection.
Definition: concepts/image_view.hpp:311
Views are compatible if they have the same color spaces and compatible channel values.
Definition: concepts/image_view.hpp:537
N-dimensional view over immutable values.
Definition: concepts/image_view.hpp:101
Definition: concepts/image_view.hpp:448
Base template for types that model HasDynamicXStepTypeConcept.
Definition: dynamic_step.hpp:17