Generic Image Library: any_image_view.hpp Source File

###  | #  |

any_image_view.hpp
1//
2// Copyright 2005-2007 Adobe Systems Incorporated
3// Copyright 2020 Samuel Debionne
4//
5// Distributed under the Boost Software License, Version 1.0
6// See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt
8//
9#ifndef BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ANY_IMAGE_VIEW_HPP
10#define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ANY_IMAGE_VIEW_HPP
11
12#include <boost/gil/dynamic_step.hpp>
13#include <boost/gil/image.hpp>
14#include <boost/gil/image_view.hpp>
15#include <boost/gil/point.hpp>
16#include <boost/gil/detail/mp11.hpp>
17
18#include <boost/variant2/variant.hpp>
19
20namespace boost { namespace gil {
21
22template <typename View>
23 struct dynamic_xy_step_transposed_type;
24
25namespace detail {
26
27template <typename View>
28using get_const_t = typename View::const_t;
29
30template <typename Views>
31using views_get_const_t = mp11::mp_transform<get_const_t, Views>;
32
33// works for both image_view and image
34struct any_type_get_num_channels
35{
36 using result_type = int;
37 template <typename T>
38 result_type operator()(const T&) const { return num_channels<T>::value; }
39};
40
41// works for both image_view and image
42struct any_type_get_dimensions
43{
44 using result_type = point<std::ptrdiff_t>;
45 template <typename T>
46 result_type operator()(const T& v) const { return v.dimensions(); }
47};
48
49// works for image_view
50struct any_type_get_size
51{
52 using result_type = std::size_t;
53 template <typename T>
54 result_type operator()(const T& v) const { return v.size(); }
55};
56
57} // namespace detail
58
73
74template <typename ...Views>
75 class any_image_view : public variant2::variant<Views...>
76{
77 using parent_t = variant2::variant<Views...>;
78
79public:
80 using const_t = detail::views_get_const_t<any_image_view>;
81 using x_coord_t = std::ptrdiff_t;
82 using y_coord_t = std::ptrdiff_t;
83 using point_t = point<std::ptrdiff_t>;
84 using size_type = std::size_t;
85
86 using parent_t::parent_t;
87
88 any_image_view& operator=(any_image_view const& view)
89 {
90 parent_t::operator=((parent_t const&)view);
91 return *this;
92 }
93
94 template <typename View>
95 any_image_view& operator=(View const& view)
96 {
97 parent_t::operator=(view);
98 return *this;
99 }
100
101 template <typename ...OtherViews>
102 any_image_view& operator=(any_image_view<OtherViews...> const& view)
103 {
104 parent_t::operator=((variant2::variant<OtherViews...> const&)view);
105 return *this;
106 }
107
108 std::size_t num_channels() const { return variant2::visit(detail::any_type_get_num_channels(), *this); }
109 point_t dimensions() const { return variant2::visit(detail::any_type_get_dimensions(), *this); }
110 size_type size() const { return variant2::visit(detail::any_type_get_size(), *this); }
111 x_coord_t width() const { return dimensions().x; }
112 y_coord_t height() const { return dimensions().y; }
113};
114
116// HasDynamicXStepTypeConcept
118
119template <typename ...Views>
120struct dynamic_x_step_type<any_image_view<Views...>>
121{
122private:
123 // FIXME: Remove class name injection with gil:: qualification
124 // Required as workaround for Boost.MP11 issue that treats unqualified metafunction
125 // in the class definition of the same name as the specialization (Peter Dimov):
126 // invalid template argument for template parameter 'F', expected a class template
127 template <typename T>
128 using dynamic_step_view = typename gil::dynamic_x_step_type<T>::type;
129
130public:
131 using type = mp11::mp_transform<dynamic_step_view, any_image_view<Views...>>;
132};
133
135// HasDynamicYStepTypeConcept
137
138template <typename ...Views>
139struct dynamic_y_step_type<any_image_view<Views...>>
140{
141private:
142 // FIXME: Remove class name injection with gil:: qualification
143 // Required as workaround for Boost.MP11 issue that treats unqualified metafunction
144 // in the class definition of the same name as the specialization (Peter Dimov):
145 // invalid template argument for template parameter 'F', expected a class template
146 template <typename T>
147 using dynamic_step_view = typename gil::dynamic_y_step_type<T>::type;
148
149public:
150 using type = mp11::mp_transform<dynamic_step_view, any_image_view<Views...>>;
151};
152
153template <typename ...Views>
154struct dynamic_xy_step_type<any_image_view<Views...>>
155{
156private:
157 // FIXME: Remove class name injection with gil:: qualification
158 // Required as workaround for Boost.MP11 issue that treats unqualified metafunction
159 // in the class definition of the same name as the specialization (Peter Dimov):
160 // invalid template argument for template parameter 'F', expected a class template
161 template <typename T>
162 using dynamic_step_view = typename gil::dynamic_xy_step_type<T>::type;
163
164public:
165 using type = mp11::mp_transform<dynamic_step_view, any_image_view<Views...>>;
166};
167
168template <typename ...Views>
169struct dynamic_xy_step_transposed_type<any_image_view<Views...>>
170{
171private:
172 // FIXME: Remove class name injection with gil:: qualification
173 // Required as workaround for Boost.MP11 issue that treats unqualified metafunction
174 // in the class definition of the same name as the specialization (Peter Dimov):
175 // invalid template argument for template parameter 'F', expected a class template
176 template <typename T>
177 using dynamic_step_view = typename gil::dynamic_xy_step_type<T>::type;
178
179public:
180 using type = mp11::mp_transform<dynamic_step_view, any_image_view<Views...>>;
181};
182
183}} // namespace boost::gil
184
185#endif
boost::gil::any_image_view
Represents a run-time specified image view. Models HasDynamicXStepTypeConcept, HasDynamicYStepTypeCon...
Definition any_image_view.hpp:76
boost::gil::point< std::ptrdiff_t >
boost::gil::view
auto view(image< Pixel, IsPlanar, Alloc > &img) -> typename image< Pixel, IsPlanar, Alloc >::view_t const &
Returns the non-constant-pixel view of an image.
Definition image.hpp:565
boost
defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
Definition algorithm.hpp:36
boost::gil::dynamic_x_step_type
Base template for types that model HasDynamicXStepTypeConcept.
Definition fwd.hpp:30
boost::gil::dynamic_xy_step_transposed_type
Returns the type of a transposed view that has a dynamic step along both X and Y.
Definition any_image_view.hpp:23
boost::gil::dynamic_y_step_type
Base template for types that model HasDynamicYStepTypeConcept.
Definition fwd.hpp:31
boost::gil::num_channels
Returns the number of channels of a pixel-based GIL construct.
Definition fwd.hpp:28
boost::gil::size
Returns an integral constant type specifying the number of elements in a color base.
Definition fwd.hpp:20