Skip to content

Commit 104a589

Browse files
committed
Merge remote-tracking branch 'origin/develop' into stl-interfaces
2 parents bb63229 + adddbec commit 104a589

40 files changed

+899
-221
lines changed

RELEASES.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
2828
support at least C++14 are considered unsupported as of now.
2929
- BREAKING: `any_color_converted_view()` is deprecated and will be removed in the next release.
3030
Use `color_converted_view()` instead, which provides the same feature.
31+
- BREAKING: `apply_operation` for `any_image` is deprecated and will be removed in the next release.
32+
Use `variant2::visit` instead, which provides the same feature.
3133
- documentation: Display that GIL is a header-only library
3234
- Moved numeric extension to core ([PR #573](https://github.com/boostorg/gil/pull/573))
3335
- Added support for C++17's `<filesystem>` ([PR #636](https://github.com/boostorg/gil/pull/636)).
@@ -327,18 +329,18 @@ linked PDF documents with detailed changes.
327329

328330
### Changed
329331
- Updated the design guide and tutorial, updated syntax of concepts to the latest concepts proposal.
330-
- In `image`, `image_view`, `any_image`, `any_image_view`:
332+
- In `image`, `image_view`, `any_image`, `any_image_view`:
331333
There are no longer global functions `get_width()`, `get_height()`, `get_dimensions()`, `num_channels()`.
332334
Use methods `width()`, `height()`, `dimensions()` instead.
333-
- In models of pixel, pixel iterator, pixel locator, image view and image:
335+
- In models of pixel, pixel iterator, pixel locator, image view and image:
334336
There used to be different ways of getting to a pixel, channel, color space, etc. of an image view,
335337
pixel, locator, iterator and image (e.g. traits, member typedefs).
336338
Now all pixel-based GIL constructs (pixels, pixel iterators, locators, image views and images) model
337339
`PixelBasedConcept`, which means they provide the following metafunctions: `color_space_type`, `channel_mapping_type`, `is_planar`, `num_channels`
338340
and for homogeneous constructs we also have: `channel_type`.
339341
To get the pixel type or pixel reference/const reference type of an image, image view, locator
340342
and pixel, use member typedefs `value_type`, `reference` and `const_reference`.
341-
- In `locator`, `image`, `image_view`, `any_image` and `any_image_view`:
343+
- In `locator`, `image`, `image_view`, `any_image` and `any_image_view`:
342344
Removed `dynamic_x_step_t`, `dynamic_y_step_t`, `dynamic_xy_step_t` and `dynamic_xy_step_transposed_t`
343345
as member typedefs of locators and image views.
344346
Instead, there are separate concepts `HasDynamicXStepTypeConcept`, `HasDynamicYStepTypeConcept`,

doc/design/dynamic_image.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ GIL ``any_image_view`` and ``any_image`` are subclasses of ``variant``:
103103
y_coord_t height() const;
104104
};
105105
106-
Operations are invoked on variants via ``apply_operation`` passing a
106+
Operations are invoked on variants via ``variant2::visit`` passing a
107107
function object to perform the operation. The code for every allowed
108108
type in the variant is instantiated and the appropriate instantiation
109109
is selected via a switch statement. Since image view algorithms
@@ -129,7 +129,7 @@ pixels. There is no "any_pixel" or "any_pixel_iterator" in GIL. Such
129129
constructs could be provided via the ``variant`` mechanism, but doing
130130
so would result in inefficient algorithms, since the type resolution
131131
would have to be performed per pixel. Image-level algorithms should be
132-
implemented via ``apply_operation``. That said, many common operations
132+
implemented via ``variant2::visit``. That said, many common operations
133133
are shared between the static and dynamic types. In addition, all of
134134
the image view transformations and many STL-like image view algorithms
135135
have overloads operating on ``any_image_view``, as illustrated with
@@ -180,25 +180,25 @@ implemented:
180180
template <typename View>
181181
typename dynamic_xy_step_type<View>::type rotated180_view(const View& src) { ... }
182182
183-
namespace detail
184-
{
183+
namespace detail {
185184
// the function, wrapped inside a function object
186185
template <typename Result> struct rotated180_view_fn
187186
{
188187
typedef Result result_type;
189188
template <typename View> result_type operator()(const View& src) const
190-
{
189+
{
191190
return result_type(rotated180_view(src));
192191
}
193192
};
194193
}
195194
196195
// overloading of the function using variant. Takes and returns run-time bound view.
197196
// The returned view has a dynamic step
198-
template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
199-
typename dynamic_xy_step_type<any_image_view<ViewTypes> >::type rotated180_view(const any_image_view<ViewTypes>& src)
197+
template <typename ...ViewTypes> inline
198+
typename dynamic_xy_step_type<any_image_view<ViewTypes...>>::type rotated180_view(const any_image_view<ViewTypes...>& src)
200199
{
201-
return apply_operation(src,detail::rotated180_view_fn<typename dynamic_xy_step_type<any_image_view<ViewTypes> >::type>());
200+
using result_view_t = typename dynamic_xy_step_type<any_image_view<ViewTypes...>>::type;
201+
return variant2::visit(detail::rotated180_view_fn<result_view_t>(), src);
202202
}
203203
204204
Variants should be used with caution (especially algorithms that take

doc/tutorial/gradient.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -870,22 +870,22 @@ source view:
870870
};
871871
872872
The second step is to provide an overload of ``x_luminosity_gradient`` that
873-
takes image view variant and calls GIL's ``apply_operation`` passing it the
873+
takes image view variant and calls ``variant2::visit`` passing it the
874874
function object:
875875

876876
.. code-block:: cpp
877877
878-
template <typename SrcViews, typename DstView>
879-
void x_luminosity_gradient(const any_image_view<SrcViews>& src, const DstView& dst)
878+
template <typename ...SrcViews, typename DstView>
879+
void x_luminosity_gradient(const any_image_view<SrcViews...>& src, const DstView& dst)
880880
{
881-
apply_operation(src, x_gradient_obj<DstView>(dst));
881+
variant2::visit(x_gradient_obj<DstView>(dst), src);
882882
}
883883
884-
``any_image_view<SrcViews>`` is the image view variant. It is
885-
templated over ``SrcViews``, an enumeration of all possible view types
884+
``any_image_view<SrcViews...>`` is the image view variant. It is
885+
templated over ``SrcViews...``, an enumeration of all possible view types
886886
the variant can take. ``src`` contains inside an index of the
887887
currently instantiated type, as well as a block of memory containing
888-
the instance. ``apply_operation`` goes through a switch statement
888+
the instance. ``variant2::visit`` goes through a switch statement
889889
over the index, each case of which casts the memory to the correct
890890
view type and invokes the function object with it. Invoking an
891891
algorithm on a variant has the overhead of one switch

example/rasterizer_circle.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88

99
#include <boost/gil.hpp>
1010
#include <boost/gil/extension/io/png.hpp>
11+
1112
#include <cmath>
1213
#include <limits>
1314
#include <vector>
1415

1516
namespace gil = boost::gil;
1617

1718
// Demonstrates the use of a rasterizer to generate an image of a circle
18-
// The various rasterizers available are defined in include/boost/gil/rasterization/circle.hpp,
19-
// include/boost/gil/rasterization/ellipse.hpp and include/boost/gil/rasterization/line.hpp
19+
// The various rasterizers available are defined in include/boost/gil/extension/rasterization/circle.hpp,
20+
// include/boost/gil/extension/rasterization/ellipse.hpp and include/boost/gil/extension/rasterization/line.hpp
2021
// This example uses a trigonometric rasterizer; GIL also offers the rasterizer midpoint_circle_rasterizer,
2122
// which implements the Midpoint algorithm.
2223
// See also:

example/rasterizer_ellipse.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
// http://www.boost.org/LICENSE_1_0.txt)
77
//
88

9-
#include <boost/gil/extension/io/jpeg.hpp>
109
#include <boost/gil.hpp>
10+
#include <boost/gil/extension/io/jpeg.hpp>
1111

1212
namespace gil = boost::gil;
1313

1414
// Demonstrates the use of a rasterizer to generate an image of an ellipse
15-
// The various rasterizers available are defined in include/boost/gil/rasterization/circle.hpp,
16-
// include/boost/gil/rasterization/ellipse.hpp and include/boost/gil/rasterization/line.hpp
15+
// The various rasterizers available are defined in include/boost/gil/extension/rasterization/circle.hpp,
16+
// include/boost/gil/extension/rasterization/ellipse.hpp and include/boost/gil/extension/rasterization/line.hpp
1717
// The rasterizer used is a generalisation of the midpoint algorithm often used for drawing circle.
1818
// This examples also shows how to create images with various pixel depth, as well as the behaviour
1919
// in case of the rasterization of a curve that doesn't fit in a view.
@@ -25,28 +25,28 @@ namespace gil = boost::gil;
2525
int main()
2626
{
2727
// Syntax for usage :-
28-
// auto rasterizer = gil::midpoint_elliptical_rasterizer{};
29-
// rasterizer(img_view, colour, center, semi-axes_length);
28+
// auto rasterizer = gil::midpoint_ellipse_rasterizer{};
29+
// rasterizer(img_view, pixel, center, semi-axes_length);
3030
// Where
3131
// img_view : gil view of the image on which ellipse is to be drawn.
32-
// colour : Vector containing channel intensity values for img_view. Number of colours
33-
// provided must be equal to the number of channels present in img_view.
34-
// center : Array containing positive integer x co-ordinate and y co-ordinate of the center
32+
// pixel : Pixel value for the elliptical curve to be drawn. Pixel's type must be compatible to the
33+
// pixel type of the image view.
34+
// center : Point containing positive integer x co-ordinate and y co-ordinate of the center
3535
// respectively.
36-
// semi-axes_length : Array containing positive integer lengths of horizontal semi-axis
36+
// semi-axes_length : Point containing positive integer lengths of horizontal semi-axis
3737
// and vertical semi-axis respectively.
3838

3939
gil::gray8_image_t gray_buffer_image(256, 256);
40-
auto gray_elliptical_rasterizer = gil::midpoint_elliptical_rasterizer{};
41-
gray_elliptical_rasterizer(view(gray_buffer_image), {128}, {128, 128}, {100, 50});
40+
auto gray_ellipse_rasterizer = gil::midpoint_ellipse_rasterizer{};
41+
gray_ellipse_rasterizer(view(gray_buffer_image), gil::gray8_pixel_t{128}, {128, 128}, {100, 50});
4242

4343
gil::rgb8_image_t rgb_buffer_image(256, 256);
44-
auto rgb_elliptical_rasterizer = gil::midpoint_elliptical_rasterizer{};
45-
rgb_elliptical_rasterizer(view(rgb_buffer_image), {0, 0, 255}, {128, 128}, {50, 100});
44+
auto rgb_ellipse_rasterizer = gil::midpoint_ellipse_rasterizer{};
45+
rgb_ellipse_rasterizer(view(rgb_buffer_image), gil::rgb8_pixel_t{0, 0, 255}, {128, 128}, {50, 100});
4646

4747
gil::rgb8_image_t rgb_buffer_image_out_of_bound(256, 256);
48-
auto rgb_elliptical_rasterizer_out_of_bound = gil::midpoint_elliptical_rasterizer{};
49-
rgb_elliptical_rasterizer_out_of_bound(view(rgb_buffer_image_out_of_bound), {255, 0, 0},
48+
auto rgb_ellipse_rasterizer_out_of_bound = gil::midpoint_ellipse_rasterizer{};
49+
rgb_ellipse_rasterizer_out_of_bound(view(rgb_buffer_image_out_of_bound), gil::rgb8_pixel_t{255, 0, 0},
5050
{100, 100}, {160, 160});
5151

5252
gil::write_view("rasterized_ellipse_gray.jpg", view(gray_buffer_image), gil::jpeg_tag{});

example/rasterizer_line.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
namespace gil = boost::gil;
1616

1717
// Demonstrates the use of a rasterizer to generate an image of a line
18-
// The various rasterizers available are defined in include/boost/gil/rasterization/circle.hpp,
19-
// include/boost/gil/rasterization/ellipse.hpp and include/boost/gil/rasterization/line.hpp
18+
// The various rasterizers available are defined in include/boost/gil/extension/rasterization/circle.hpp,
19+
// include/boost/gil/extension/rasterization/ellipse.hpp and include/boost/gil/extension/rasterization/line.hpp
2020
// The rasterizer used implements the Bresenham's line algorithm.
2121
// Multiple images are created, all of the same size, but with areas of different sizes passed to the rasterizer, resulting in different lines.
2222
// See also:

include/boost/gil/extension/dynamic_image/algorithm.hpp

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//
22
// Copyright 2005-2007 Adobe Systems Incorporated
3+
// Copyright 2022 Marco Langer <langer.m86 at gmail dot com>
34
//
45
// Distributed under the Boost Software License, Version 1.0
56
// See accompanying file LICENSE_1_0.txt or copy at
@@ -12,7 +13,10 @@
1213

1314
#include <boost/gil/algorithm.hpp>
1415

16+
#include <boost/variant2/variant.hpp>
17+
1518
#include <functional>
19+
#include <utility>
1620

1721
////////////////////////////////////////////////////////////////////////////////////////
1822
/// \file
@@ -43,31 +47,31 @@ struct equal_pixels_fn : binary_operation_obj<equal_pixels_fn, bool>
4347
/// \tparam Types Model Boost.MP11-compatible list of models of ImageViewConcept
4448
/// \tparam View Model MutableImageViewConcept
4549
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
4751
{
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);
5155
}
5256

5357
/// \ingroup ImageViewSTLAlgorithmsEqualPixels
5458
/// \tparam View Model ImageViewConcept
5559
/// \tparam Types Model Boost.MP11-compatible list of models of MutableImageViewConcept
5660
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
5862
{
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);
6266
}
6367

6468
/// \ingroup ImageViewSTLAlgorithmsEqualPixels
6569
/// \tparam Types1 Model Boost.MP11-compatible list of models of ImageViewConcept
6670
/// \tparam Types2 Model Boost.MP11-compatible list of models of MutableImageViewConcept
6771
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
6973
{
70-
return apply_operation(src, dst, detail::equal_pixels_fn());
74+
return variant2::visit(detail::equal_pixels_fn(), src, dst);
7175
}
7276

7377
namespace detail {
@@ -90,7 +94,7 @@ struct copy_pixels_fn : public binary_operation_obj<copy_pixels_fn>
9094
template <typename ...Types, typename View>
9195
void copy_pixels(any_image_view<Types...> const& src, View const& dst)
9296
{
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);
9498
}
9599

96100
/// \ingroup ImageViewSTLAlgorithmsCopyPixels
@@ -99,7 +103,7 @@ void copy_pixels(any_image_view<Types...> const& src, View const& dst)
99103
template <typename ...Types, typename View>
100104
void copy_pixels(View const& src, any_image_view<Types...> const& dst)
101105
{
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);
103107
}
104108

105109
/// \ingroup ImageViewSTLAlgorithmsCopyPixels
@@ -108,7 +112,7 @@ void copy_pixels(View const& src, any_image_view<Types...> const& dst)
108112
template <typename ...Types1, typename ...Types2>
109113
void copy_pixels(any_image_view<Types1...> const& src, any_image_view<Types2...> const& dst)
110114
{
111-
apply_operation(src, dst, detail::copy_pixels_fn());
115+
variant2::visit(detail::copy_pixels_fn(), src, dst);
112116
}
113117

114118
//forward declaration for default_color_converter (see full definition in color_convert.hpp)
@@ -122,7 +126,7 @@ template <typename ...Types, typename View, typename CC>
122126
void copy_and_convert_pixels(any_image_view<Types...> const& src, View const& dst, CC cc)
123127
{
124128
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);
126130
}
127131

128132
/// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
@@ -132,7 +136,7 @@ template <typename ...Types, typename View>
132136
void copy_and_convert_pixels(any_image_view<Types...> const& src, View const& dst)
133137
{
134138
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);
136140
}
137141

138142
/// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
@@ -143,7 +147,7 @@ template <typename View, typename ...Types, typename CC>
143147
void copy_and_convert_pixels(View const& src, any_image_view<Types...> const& dst, CC cc)
144148
{
145149
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);
147151
}
148152

149153
/// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
@@ -153,7 +157,7 @@ template <typename View, typename ...Types>
153157
void copy_and_convert_pixels(View const& src, any_image_view<Types...> const& dst)
154158
{
155159
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);
157161
}
158162

159163
/// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
@@ -165,7 +169,7 @@ void copy_and_convert_pixels(
165169
any_image_view<Types1...> const& src,
166170
any_image_view<Types2...> const& dst, CC cc)
167171
{
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);
169173
}
170174

171175
/// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
@@ -176,8 +180,8 @@ void copy_and_convert_pixels(
176180
any_image_view<Types1...> const& src,
177181
any_image_view<Types2...> const& dst)
178182
{
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);
181185
}
182186

183187
namespace detail {
@@ -186,15 +190,15 @@ template <bool IsCompatible>
186190
struct fill_pixels_fn1
187191
{
188192
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); }
190194
};
191195

192196
// copy_pixels invoked on incompatible images
193197
template <>
194198
struct fill_pixels_fn1<false>
195199
{
196200
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();}
198202
};
199203

200204
template <typename Value>
@@ -227,7 +231,7 @@ struct fill_pixels_fn
227231
template <typename ...Types, typename Value>
228232
void fill_pixels(any_image_view<Types...> const& view, Value const& val)
229233
{
230-
apply_operation(view, detail::fill_pixels_fn<Value>(val));
234+
variant2::visit(detail::fill_pixels_fn<Value>(val), view);
231235
}
232236

233237
namespace detail {
@@ -236,7 +240,7 @@ template <typename F>
236240
struct for_each_pixel_fn
237241
{
238242
for_each_pixel_fn(F&& fun) : fun_(std::move(fun)) {}
239-
243+
240244
template <typename View>
241245
auto operator()(View const& view) -> F
242246
{

0 commit comments

Comments
 (0)