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 #include <boost/gil/detail/mp11.hpp>
16 
17 #include <boost/variant.hpp>
18 
19 namespace boost { namespace gil {
20 
21 template <typename View>
22 struct dynamic_xy_step_transposed_type;
23 
24 namespace detail {
25 
26 template <typename View>
27 struct get_const_t { using type = typename View::const_t; };
28 
29 template <typename Views>
30 struct views_get_const_t : mp11::mp_transform<get_const_t, Views> {};
31 
32 // works for both image_view and image
33 struct any_type_get_num_channels
34 {
35  using result_type = int;
36  template <typename T>
37  result_type operator()(const T&) const { return num_channels<T>::value; }
38 };
39 
40 // works for both image_view and image
41 struct any_type_get_dimensions
42 {
43  using result_type = point<std::ptrdiff_t>;
44  template <typename T>
45  result_type operator()(const T& v) const { return v.dimensions(); }
46 };
47 
48 // works for image_view
49 struct any_type_get_size
50 {
51  using result_type = std::size_t;
52  template <typename T>
53  result_type operator()(const T& v) const { return v.size(); }
54 };
55 
56 } // namespace detail
57 
72 
73 template <typename Views>
74 class any_image_view : public make_variant_over<Views>::type
75 {
76  using parent_t = typename make_variant_over<Views>::type;
77 public:
79  using x_coord_t = std::ptrdiff_t;
80  using y_coord_t = std::ptrdiff_t;
82  using size_type = std::size_t;
83 
84  any_image_view() = default;
85  any_image_view(any_image_view const& view) : parent_t((parent_t const&)view) {}
86 
87  template <typename View>
88  explicit any_image_view(View const& view) : parent_t(view) {}
89 
90  template <typename OtherViews>
92  : parent_t((typename make_variant_over<OtherViews>::type const&)view)
93  {}
94 
95  any_image_view& operator=(any_image_view const& view)
96  {
97  parent_t::operator=((parent_t const&)view);
98  return *this;
99  }
100 
101  template <typename View>
102  any_image_view& operator=(View const& view)
103  {
104  parent_t::operator=(view);
105  return *this;
106  }
107 
108  template <typename OtherViews>
110  {
111  parent_t::operator=((typename make_variant_over<OtherViews>::type const&)view);
112  return *this;
113  }
114 
115  std::size_t num_channels() const { return apply_operation(*this, detail::any_type_get_num_channels()); }
116  point_t dimensions() const { return apply_operation(*this, detail::any_type_get_dimensions()); }
117  size_type size() const { return apply_operation(*this, detail::any_type_get_size()); }
118  x_coord_t width() const { return dimensions().x; }
119  y_coord_t height() const { return dimensions().y; }
120 };
121 
123 // HasDynamicXStepTypeConcept
125 
126 template <typename Views>
127 struct dynamic_x_step_type<any_image_view<Views>>
128 {
129 private:
130  // FIXME: Remove class name injection with gil:: qualification
131  // Required as workaround for Boost.MP11 issue that treats unqualified metafunction
132  // in the class definition of the same name as the specialization (Peter Dimov):
133  // invalid template argument for template parameter 'F', expected a class template
134  template <typename T>
135  using dynamic_step_view = typename gil::dynamic_x_step_type<T>::type;
136 
137 public:
139 };
140 
142 // HasDynamicYStepTypeConcept
144 
145 template <typename Views>
146 struct dynamic_y_step_type<any_image_view<Views>>
147 {
148 private:
149  // FIXME: Remove class name injection with gil:: qualification
150  // Required as workaround for Boost.MP11 issue that treats unqualified metafunction
151  // in the class definition of the same name as the specialization (Peter Dimov):
152  // invalid template argument for template parameter 'F', expected a class template
153  template <typename T>
154  using dynamic_step_view = typename gil::dynamic_y_step_type<T>::type;
155 
156 public:
157  using type = any_image_view<mp11::mp_transform<dynamic_step_view, Views>>;
158 };
159 
160 template <typename Views>
161 struct dynamic_xy_step_type<any_image_view<Views>>
162 {
163 private:
164  // FIXME: Remove class name injection with gil:: qualification
165  // Required as workaround for Boost.MP11 issue that treats unqualified metafunction
166  // in the class definition of the same name as the specialization (Peter Dimov):
167  // invalid template argument for template parameter 'F', expected a class template
168  template <typename T>
169  using dynamic_step_view = typename gil::dynamic_xy_step_type<T>::type;
170 
171 public:
172  using type = any_image_view<mp11::mp_transform<dynamic_step_view, Views>>;
173 };
174 
175 template <typename Views>
176 struct dynamic_xy_step_transposed_type<any_image_view<Views>>
177 {
178 private:
179  // FIXME: Remove class name injection with gil:: qualification
180  // Required as workaround for Boost.MP11 issue that treats unqualified metafunction
181  // in the class definition of the same name as the specialization (Peter Dimov):
182  // invalid template argument for template parameter 'F', expected a class template
183  template <typename T>
184  using dynamic_step_view = typename gil::dynamic_xy_step_type<T>::type;
185 
186 public:
187  using type = any_image_view<mp11::mp_transform<dynamic_step_view, Views>>;
188 };
189 
190 }} // namespace boost::gil
191 
192 #endif
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:21
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:74
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:535
Returns an integral constant type specifying the number of elements in a color base.
Definition: color_base_algorithm.hpp:42
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