]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/gil/extension/dynamic_image/any_image_view.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / gil / extension / dynamic_image / any_image_view.hpp
CommitLineData
92f5a8d4
TL
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>
7c673cae 18
92f5a8d4 19namespace boost { namespace gil {
7c673cae 20
92f5a8d4
TL
21template <typename View>
22struct dynamic_xy_step_transposed_type;
7c673cae 23
92f5a8d4 24namespace detail {
7c673cae 25
92f5a8d4
TL
26template <typename View>
27struct get_const_t { using type = typename View::const_t; };
7c673cae 28
92f5a8d4
TL
29template <typename Views>
30struct views_get_const_t : mp11::mp_transform<get_const_t, Views> {};
7c673cae 31
92f5a8d4
TL
32// works for both image_view and image
33struct 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};
7c673cae 39
92f5a8d4
TL
40// works for both image_view and image
41struct 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};
7c673cae 47
92f5a8d4 48} // namespace detail
7c673cae
FG
49
50////////////////////////////////////////////////////////////////////////////////////////
51/// CLASS any_image_view
52///
53/// \ingroup ImageViewModel
54/// \brief Represents a run-time specified image view. Models HasDynamicXStepTypeConcept, HasDynamicYStepTypeConcept, Note that this class does NOT model ImageViewConcept
55///
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.
92f5a8d4 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.
7c673cae
FG
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.
61///
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////////////////////////////////////////////////////////////////////////////////////////
7c673cae 64
92f5a8d4
TL
65template <typename Views>
66class any_image_view : public make_variant_over<Views>::type
67{
68 using parent_t = typename make_variant_over<Views>::type;
69public:
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>;
74
75 any_image_view() = default;
76 any_image_view(any_image_view const& view) : parent_t((parent_t const&)view) {}
77
78 template <typename View>
79 explicit any_image_view(View const& view) : parent_t(view) {}
80
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)
84 {}
85
86 any_image_view& operator=(any_image_view const& view)
87 {
88 parent_t::operator=((parent_t const&)view);
89 return *this;
90 }
91
92 template <typename View>
93 any_image_view& operator=(View const& view)
94 {
95 parent_t::operator=(view);
96 return *this;
97 }
98
99 template <typename OtherViews>
100 any_image_view& operator=(any_image_view<OtherViews> const& view)
101 {
102 parent_t::operator=((typename make_variant_over<OtherViews>::type const&)view);
103 return *this;
104 }
7c673cae
FG
105
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; }
110};
111
112/////////////////////////////
113// HasDynamicXStepTypeConcept
114/////////////////////////////
115
92f5a8d4
TL
116template <typename Views>
117struct dynamic_x_step_type<any_image_view<Views>>
118{
119private:
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;
126
127public:
128 using type = any_image_view<mp11::mp_transform<dynamic_step_view, Views>>;
7c673cae
FG
129};
130
131/////////////////////////////
132// HasDynamicYStepTypeConcept
133/////////////////////////////
134
92f5a8d4
TL
135template <typename Views>
136struct dynamic_y_step_type<any_image_view<Views>>
137{
138private:
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;
145
146public:
147 using type = any_image_view<mp11::mp_transform<dynamic_step_view, Views>>;
7c673cae
FG
148};
149
92f5a8d4
TL
150template <typename Views>
151struct dynamic_xy_step_type<any_image_view<Views>>
152{
153private:
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;
160
161public:
162 using type = any_image_view<mp11::mp_transform<dynamic_step_view, Views>>;
7c673cae
FG
163};
164
92f5a8d4
TL
165template <typename Views>
166struct dynamic_xy_step_transposed_type<any_image_view<Views>>
167{
168private:
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;
175
176public:
177 using type = any_image_view<mp11::mp_transform<dynamic_step_view, Views>>;
7c673cae
FG
178};
179
92f5a8d4 180}} // namespace boost::gil
7c673cae
FG
181
182#endif