1
1
//
2
2
// Copyright 2005-2007 Adobe Systems Incorporated
3
+ // Copyright 2022 Marco Langer <langer.m86 at gmail dot com>
3
4
//
4
5
// Distributed under the Boost Software License, Version 1.0
5
6
// See accompanying file LICENSE_1_0.txt or copy at
12
13
13
14
#include < boost/gil/algorithm.hpp>
14
15
16
+ #include < boost/variant2/variant.hpp>
17
+
15
18
#include < functional>
19
+ #include < utility>
16
20
17
21
// //////////////////////////////////////////////////////////////////////////////////////
18
22
// / \file
@@ -43,31 +47,31 @@ struct equal_pixels_fn : binary_operation_obj<equal_pixels_fn, bool>
43
47
// / \tparam Types Model Boost.MP11-compatible list of models of ImageViewConcept
44
48
// / \tparam View Model MutableImageViewConcept
45
49
template <typename ...Types, typename View>
46
- bool equal_pixels (any_image_view<Types...> const & src, View const & dst)
50
+ auto equal_pixels (any_image_view<Types...> const & src, View const & dst) -> bool
47
51
{
48
- return apply_operation (
49
- src ,
50
- std::bind ( detail::equal_pixels_fn (), std::placeholders::_1, dst) );
52
+ return variant2::visit (
53
+ std::bind ( detail::equal_pixels_fn (), std::placeholders::_1, dst) ,
54
+ src );
51
55
}
52
56
53
57
// / \ingroup ImageViewSTLAlgorithmsEqualPixels
54
58
// / \tparam View Model ImageViewConcept
55
59
// / \tparam Types Model Boost.MP11-compatible list of models of MutableImageViewConcept
56
60
template <typename View, typename ...Types>
57
- bool equal_pixels (View const & src, any_image_view<Types...> const & dst)
61
+ auto equal_pixels (View const & src, any_image_view<Types...> const & dst) -> bool
58
62
{
59
- return apply_operation (
60
- dst ,
61
- std::bind ( detail::equal_pixels_fn (), src, std::placeholders::_1) );
63
+ return variant2::visit (
64
+ std::bind ( detail::equal_pixels_fn (), src, std::placeholders::_1) ,
65
+ dst );
62
66
}
63
67
64
68
// / \ingroup ImageViewSTLAlgorithmsEqualPixels
65
69
// / \tparam Types1 Model Boost.MP11-compatible list of models of ImageViewConcept
66
70
// / \tparam Types2 Model Boost.MP11-compatible list of models of MutableImageViewConcept
67
71
template <typename ...Types1, typename ...Types2>
68
- bool equal_pixels (any_image_view<Types1...> const & src, any_image_view<Types2...> const & dst)
72
+ auto equal_pixels (any_image_view<Types1...> const & src, any_image_view<Types2...> const & dst) -> bool
69
73
{
70
- return apply_operation (src, dst, detail::equal_pixels_fn ());
74
+ return variant2::visit ( detail::equal_pixels_fn (), src, dst );
71
75
}
72
76
73
77
namespace detail {
@@ -90,7 +94,7 @@ struct copy_pixels_fn : public binary_operation_obj<copy_pixels_fn>
90
94
template <typename ...Types, typename View>
91
95
void copy_pixels (any_image_view<Types...> const & src, View const & dst)
92
96
{
93
- apply_operation (src, std::bind (detail::copy_pixels_fn (), std::placeholders::_1, dst));
97
+ variant2::visit ( std::bind (detail::copy_pixels_fn (), std::placeholders::_1, dst), src );
94
98
}
95
99
96
100
// / \ingroup ImageViewSTLAlgorithmsCopyPixels
@@ -99,7 +103,7 @@ void copy_pixels(any_image_view<Types...> const& src, View const& dst)
99
103
template <typename ...Types, typename View>
100
104
void copy_pixels (View const & src, any_image_view<Types...> const & dst)
101
105
{
102
- apply_operation (dst, std::bind (detail::copy_pixels_fn (), src, std::placeholders::_1));
106
+ variant2::visit ( std::bind (detail::copy_pixels_fn (), src, std::placeholders::_1), dst );
103
107
}
104
108
105
109
// / \ingroup ImageViewSTLAlgorithmsCopyPixels
@@ -108,7 +112,7 @@ void copy_pixels(View const& src, any_image_view<Types...> const& dst)
108
112
template <typename ...Types1, typename ...Types2>
109
113
void copy_pixels (any_image_view<Types1...> const & src, any_image_view<Types2...> const & dst)
110
114
{
111
- apply_operation (src, dst, detail::copy_pixels_fn ());
115
+ variant2::visit ( detail::copy_pixels_fn (), src, dst );
112
116
}
113
117
114
118
// forward declaration for default_color_converter (see full definition in color_convert.hpp)
@@ -122,7 +126,7 @@ template <typename ...Types, typename View, typename CC>
122
126
void copy_and_convert_pixels (any_image_view<Types...> const & src, View const & dst, CC cc)
123
127
{
124
128
using cc_fn = detail::copy_and_convert_pixels_fn<CC>;
125
- apply_operation (src, std::bind (cc_fn{cc}, std::placeholders::_1, dst));
129
+ variant2::visit ( std::bind (cc_fn{cc}, std::placeholders::_1, dst), src );
126
130
}
127
131
128
132
// / \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
@@ -132,7 +136,7 @@ template <typename ...Types, typename View>
132
136
void copy_and_convert_pixels (any_image_view<Types...> const & src, View const & dst)
133
137
{
134
138
using cc_fn = detail::copy_and_convert_pixels_fn<default_color_converter>;
135
- apply_operation (src, std::bind (cc_fn{}, std::placeholders::_1, dst));
139
+ variant2::visit ( std::bind (cc_fn{}, std::placeholders::_1, dst), src );
136
140
}
137
141
138
142
// / \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
@@ -143,7 +147,7 @@ template <typename View, typename ...Types, typename CC>
143
147
void copy_and_convert_pixels (View const & src, any_image_view<Types...> const & dst, CC cc)
144
148
{
145
149
using cc_fn = detail::copy_and_convert_pixels_fn<CC>;
146
- apply_operation (dst, std::bind (cc_fn{cc}, src, std::placeholders::_1));
150
+ variant2::visit ( std::bind (cc_fn{cc}, src, std::placeholders::_1), dst );
147
151
}
148
152
149
153
// / \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
@@ -153,7 +157,7 @@ template <typename View, typename ...Types>
153
157
void copy_and_convert_pixels (View const & src, any_image_view<Types...> const & dst)
154
158
{
155
159
using cc_fn = detail::copy_and_convert_pixels_fn<default_color_converter>;
156
- apply_operation (dst, std::bind (cc_fn{}, src, std::placeholders::_1));
160
+ variant2::visit ( std::bind (cc_fn{}, src, std::placeholders::_1), dst );
157
161
}
158
162
159
163
// / \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
@@ -165,7 +169,7 @@ void copy_and_convert_pixels(
165
169
any_image_view<Types1...> const & src,
166
170
any_image_view<Types2...> const & dst, CC cc)
167
171
{
168
- apply_operation (src, dst, detail::copy_and_convert_pixels_fn<CC>(cc));
172
+ variant2::visit ( detail::copy_and_convert_pixels_fn<CC>(cc), src, dst );
169
173
}
170
174
171
175
// / \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
@@ -176,8 +180,8 @@ void copy_and_convert_pixels(
176
180
any_image_view<Types1...> const & src,
177
181
any_image_view<Types2...> const & dst)
178
182
{
179
- apply_operation (src, dst,
180
- detail::copy_and_convert_pixels_fn<default_color_converter>());
183
+ variant2::visit (
184
+ detail::copy_and_convert_pixels_fn<default_color_converter>(), src, dst );
181
185
}
182
186
183
187
namespace detail {
@@ -186,15 +190,15 @@ template <bool IsCompatible>
186
190
struct fill_pixels_fn1
187
191
{
188
192
template <typename V, typename Value>
189
- static void apply (V const & src, Value const & val) { fill_pixels (src, val); }
193
+ static void apply (V const & src, Value const & val) { fill_pixels (src, val); }
190
194
};
191
195
192
196
// copy_pixels invoked on incompatible images
193
197
template <>
194
198
struct fill_pixels_fn1 <false >
195
199
{
196
200
template <typename V, typename Value>
197
- static void apply (V const &, Value const &) { throw std::bad_cast ();}
201
+ static void apply (V const &, Value const &) { throw std::bad_cast ();}
198
202
};
199
203
200
204
template <typename Value>
@@ -227,7 +231,7 @@ struct fill_pixels_fn
227
231
template <typename ...Types, typename Value>
228
232
void fill_pixels (any_image_view<Types...> const & view, Value const & val)
229
233
{
230
- apply_operation (view, detail::fill_pixels_fn<Value>(val));
234
+ variant2::visit ( detail::fill_pixels_fn<Value>(val), view );
231
235
}
232
236
233
237
namespace detail {
@@ -236,7 +240,7 @@ template <typename F>
236
240
struct for_each_pixel_fn
237
241
{
238
242
for_each_pixel_fn (F&& fun) : fun_(std::move(fun)) {}
239
-
243
+
240
244
template <typename View>
241
245
auto operator ()(View const & view) -> F
242
246
{
0 commit comments