2 // Copyright 2005-2007 Adobe Systems Incorporated
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
8 #ifndef BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ANY_IMAGE_VIEW_HPP
9 #define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ANY_IMAGE_VIEW_HPP
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>
17 #include <boost/variant.hpp>
19 namespace boost { namespace gil {
21 template <typename View>
22 struct dynamic_xy_step_transposed_type;
26 template <typename View>
27 struct get_const_t { using type = typename View::const_t; };
29 template <typename Views>
30 struct views_get_const_t : mp11::mp_transform<get_const_t, Views> {};
32 // works for both image_view and image
33 struct any_type_get_num_channels
35 using result_type = int;
37 result_type operator()(const T&) const { return num_channels<T>::value; }
40 // works for both image_view and image
41 struct any_type_get_dimensions
43 using result_type = point<std::ptrdiff_t>;
45 result_type operator()(const T& v) const { return v.dimensions(); }
50 ////////////////////////////////////////////////////////////////////////////////////////
51 /// CLASS any_image_view
53 /// \ingroup ImageViewModel
54 /// \brief Represents a run-time specified image view. Models HasDynamicXStepTypeConcept, HasDynamicYStepTypeConcept, Note that this class does NOT model ImageViewConcept
56 /// Represents a view whose type (color space, layout, planar/interleaved organization, etc) can be specified at run time.
57 /// It is the runtime equivalent of \p image_view.
58 /// Some of the requirements of ImageViewConcept, such as the \p value_type alias cannot be fulfilled, since the language does not allow runtime type specification.
59 /// Other requirements, such as access to the pixels, would be inefficient to provide. Thus \p any_image_view does not fully model ImageViewConcept.
60 /// However, many algorithms provide overloads taking runtime specified views and thus in many cases \p any_image_view can be used in places taking a view.
62 /// To perform an algorithm on any_image_view, put the algorithm in a function object and invoke it by calling \p apply_operation(runtime_view, algorithm_fn);
63 ////////////////////////////////////////////////////////////////////////////////////////
65 template <typename Views>
66 class any_image_view : public make_variant_over<Views>::type
68 using parent_t = typename make_variant_over<Views>::type;
70 using const_t = any_image_view<detail::views_get_const_t<Views>>;
71 using x_coord_t = std::ptrdiff_t;
72 using y_coord_t = std::ptrdiff_t;
73 using point_t = point<std::ptrdiff_t>;
75 any_image_view() = default;
76 any_image_view(any_image_view const& view) : parent_t((parent_t const&)view) {}
78 template <typename View>
79 explicit any_image_view(View const& view) : parent_t(view) {}
81 template <typename OtherViews>
82 any_image_view(any_image_view<OtherViews> const& view)
83 : parent_t((typename make_variant_over<OtherViews>::type const&)view)
86 any_image_view& operator=(any_image_view const& view)
88 parent_t::operator=((parent_t const&)view);
92 template <typename View>
93 any_image_view& operator=(View const& view)
95 parent_t::operator=(view);
99 template <typename OtherViews>
100 any_image_view& operator=(any_image_view<OtherViews> const& view)
102 parent_t::operator=((typename make_variant_over<OtherViews>::type const&)view);
106 std::size_t num_channels() const { return apply_operation(*this, detail::any_type_get_num_channels()); }
107 point_t dimensions() const { return apply_operation(*this, detail::any_type_get_dimensions()); }
108 x_coord_t width() const { return dimensions().x; }
109 y_coord_t height() const { return dimensions().y; }
112 /////////////////////////////
113 // HasDynamicXStepTypeConcept
114 /////////////////////////////
116 template <typename Views>
117 struct dynamic_x_step_type<any_image_view<Views>>
120 // FIXME: Remove class name injection with gil:: qualification
121 // Required as workaround for Boost.MP11 issue that treats unqualified metafunction
122 // in the class definition of the same name as the specialization (Peter Dimov):
123 // invalid template argument for template parameter 'F', expected a class template
124 template <typename T>
125 using dynamic_step_view = typename gil::dynamic_x_step_type<T>::type;
128 using type = any_image_view<mp11::mp_transform<dynamic_step_view, Views>>;
131 /////////////////////////////
132 // HasDynamicYStepTypeConcept
133 /////////////////////////////
135 template <typename Views>
136 struct dynamic_y_step_type<any_image_view<Views>>
139 // FIXME: Remove class name injection with gil:: qualification
140 // Required as workaround for Boost.MP11 issue that treats unqualified metafunction
141 // in the class definition of the same name as the specialization (Peter Dimov):
142 // invalid template argument for template parameter 'F', expected a class template
143 template <typename T>
144 using dynamic_step_view = typename gil::dynamic_y_step_type<T>::type;
147 using type = any_image_view<mp11::mp_transform<dynamic_step_view, Views>>;
150 template <typename Views>
151 struct dynamic_xy_step_type<any_image_view<Views>>
154 // FIXME: Remove class name injection with gil:: qualification
155 // Required as workaround for Boost.MP11 issue that treats unqualified metafunction
156 // in the class definition of the same name as the specialization (Peter Dimov):
157 // invalid template argument for template parameter 'F', expected a class template
158 template <typename T>
159 using dynamic_step_view = typename gil::dynamic_xy_step_type<T>::type;
162 using type = any_image_view<mp11::mp_transform<dynamic_step_view, Views>>;
165 template <typename Views>
166 struct dynamic_xy_step_transposed_type<any_image_view<Views>>
169 // FIXME: Remove class name injection with gil:: qualification
170 // Required as workaround for Boost.MP11 issue that treats unqualified metafunction
171 // in the class definition of the same name as the specialization (Peter Dimov):
172 // invalid template argument for template parameter 'F', expected a class template
173 template <typename T>
174 using dynamic_step_view = typename gil::dynamic_xy_step_type<T>::type;
177 using type = any_image_view<mp11::mp_transform<dynamic_step_view, Views>>;
180 }} // namespace boost::gil