Boost GIL


any_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_EXTENSION_DYNAMIC_IMAGE_ANY_IMAGE_VIEW_HPP
9 #define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ANY_IMAGE_VIEW_HPP
10 
11 #include <boost/gil/dynamic_step.hpp>
12 #include <boost/gil/image.hpp>
13 #include <boost/gil/image_view.hpp>
14 #include <boost/gil/point.hpp>
15 
16 #include <boost/variant.hpp>
17 
18 namespace boost { namespace gil {
19 
20 namespace detail {
21  template <typename View> struct get_const_t { using type = typename View::const_t; };
22  template <typename Views> struct views_get_const_t : public mpl::transform<Views, get_const_t<mpl::_1> > {};
23 }
24 
25 template <typename View> struct dynamic_xy_step_transposed_type;
26 
27 namespace detail {
28 
29  // works for both image_view and image
30  struct any_type_get_num_channels
31  {
32  using result_type = int;
33  template <typename T>
34  result_type operator()(const T&) const { return num_channels<T>::value; }
35  };
36 
37  // works for both image_view and image
38  struct any_type_get_dimensions
39  {
40  using result_type = point<std::ptrdiff_t>;
41  template <typename T>
42  result_type operator()(const T& v) const { return v.dimensions(); }
43  };
44 }
45 
60 template <typename ImageViewTypes>
61 class any_image_view : public make_variant_over<ImageViewTypes>::type {
62  using parent_t = typename make_variant_over<ImageViewTypes>::type;
63 public:
65  using x_coord_t = std::ptrdiff_t;
66  using y_coord_t = std::ptrdiff_t;
68 
69  any_image_view() : parent_t() {}
70  template <typename T> explicit any_image_view(const T& obj) : parent_t(obj) {}
71  any_image_view(const any_image_view& v) : parent_t((const parent_t&)v) {}
72  template <typename Types> any_image_view(const any_image_view<Types>& v) : parent_t((const typename make_variant_over<Types>::type&)v) {}
73 
74  template <typename T> any_image_view& operator=(const T& obj) { parent_t::operator=(obj); return *this; }
75  any_image_view& operator=(const any_image_view& v) { parent_t::operator=((const parent_t&)v); return *this;}
76  template <typename Types> any_image_view& operator=(const any_image_view<Types>& v) { parent_t::operator=((const typename make_variant_over<Types>::type&)v); return *this;}
77 
78  std::size_t num_channels() const { return apply_operation(*this, detail::any_type_get_num_channels()); }
79  point_t dimensions() const { return apply_operation(*this, detail::any_type_get_dimensions()); }
80  x_coord_t width() const { return dimensions().x; }
81  y_coord_t height() const { return dimensions().y; }
82 };
83 
85 // HasDynamicXStepTypeConcept
87 
88 template <typename IVTypes>
89 struct dynamic_x_step_type<any_image_view<IVTypes>>
90 {
92 };
93 
95 // HasDynamicYStepTypeConcept
97 
98 template <typename IVTypes>
99 struct dynamic_y_step_type<any_image_view<IVTypes>>
100 {
102 };
103 
104 template <typename IVTypes>
105 struct dynamic_xy_step_type<any_image_view<IVTypes>>
106 {
108 };
109 
110 template <typename IVTypes>
111 struct dynamic_xy_step_transposed_type<any_image_view<IVTypes>>
112 {
114 };
115 
116 }} // namespace boost::gil
117 
118 #endif
Returns the type of a transposed view that has a dynamic step along both X and Y. ...
Definition: image_view_factory.hpp:47
Definition: algorithm.hpp:30
Returns the type of a view that has a dynamic step along both X and Y.
Definition: dynamic_step.hpp:27
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
Base template for types that model HasDynamicYStepTypeConcept.
Definition: dynamic_step.hpp:21
Represents a run-time specified image view. Models HasDynamicXStepTypeConcept, HasDynamicYStepTypeCon...
Definition: any_image_view.hpp:61
Returns the number of channels of a pixel-based GIL construct.
Definition: locator.hpp:38
Base template for types that model HasDynamicXStepTypeConcept.
Definition: dynamic_step.hpp:17