9 #ifndef BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ANY_IMAGE_HPP
10 #define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ANY_IMAGE_HPP
12 #include <boost/gil/extension/dynamic_image/any_image_view.hpp>
14 #include <boost/gil/image.hpp>
15 #include <boost/gil/detail/mp11.hpp>
17 #include <boost/config.hpp>
18 #include <boost/variant2/variant.hpp>
20 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
22 #pragma warning(disable:4512)
25 namespace boost {
namespace gil {
30 using get_view_t =
typename T::view_t;
32 template <
typename Images>
33 using images_get_views_t = mp11::mp_transform<get_view_t, Images>;
36 using get_const_view_t =
typename T::const_view_t;
38 template <
typename Images>
39 using images_get_const_views_t = mp11::mp_transform<get_const_view_t, Images>;
41 struct recreate_image_fnobj
43 using result_type = void;
44 point<std::ptrdiff_t>
const& _dimensions;
47 recreate_image_fnobj(point<std::ptrdiff_t>
const& dims,
unsigned alignment)
48 : _dimensions(dims), _alignment(alignment)
51 template <
typename Image>
52 result_type operator()(Image& img)
const { img.recreate(_dimensions,_alignment); }
55 template <
typename AnyView>
56 struct any_image_get_view
58 using result_type = AnyView;
59 template <
typename Image>
60 result_type operator()(Image& img)
const
62 return result_type(
view(img));
66 template <
typename AnyConstView>
67 struct any_image_get_const_view
69 using result_type = AnyConstView;
70 template <
typename Image>
71 result_type operator()(Image
const& img)
const {
return result_type{
const_view(img)}; }
87 template <
typename ...Images>
88 class any_image :
public variant2::variant<Images...>
90 using parent_t = variant2::variant<Images...>;
93 using view_t = mp11::mp_rename<detail::images_get_views_t<any_image>,
any_image_view>;
94 using const_view_t = mp11::mp_rename<detail::images_get_const_views_t<any_image>,
any_image_view>;
95 using x_coord_t = std::ptrdiff_t;
96 using y_coord_t = std::ptrdiff_t;
99 using parent_t::parent_t;
103 parent_t::operator=((parent_t
const&)img);
107 template <
typename Image>
110 parent_t::operator=(img);
114 template <
typename ...OtherImages>
117 parent_t::operator=((
typename variant2::variant<OtherImages...>
const&)img);
121 void recreate(
point_t const& dims,
unsigned alignment=1)
123 variant2::visit(detail::recreate_image_fnobj(dims, alignment), *
this);
126 void recreate(x_coord_t width, y_coord_t height,
unsigned alignment=1)
128 recreate({ width, height }, alignment);
133 return variant2::visit(detail::any_type_get_num_channels(), *
this);
138 return variant2::visit(detail::any_type_get_dimensions(), *
this);
141 x_coord_t width()
const {
return dimensions().x; }
142 y_coord_t height()
const {
return dimensions().y; }
153 template <
typename ...Images>
157 using view_t =
typename any_image<Images...>::view_t;
158 return variant2::visit(detail::any_image_get_view<view_t>(), img);
163 template <
typename ...Images>
167 using view_t =
typename any_image<Images...>::const_view_t;
168 return variant2::visit(detail::any_image_get_const_view<view_t>(), img);
174 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
Represents a run-time specified image view. Models HasDynamicXStepTypeConcept, HasDynamicYStepTypeCon...
Definition: any_image_view.hpp:76
Represents a run-time specified image. Note it does NOT model ImageConcept.
Definition: any_image.hpp:89
BOOST_FORCEINLINE auto view(any_image< Images... > &img) -> typename any_image< Images... >::view_t
Returns the non-constant-pixel view of any image. The returned view is any view.
Definition: any_image.hpp:155
BOOST_FORCEINLINE auto const_view(any_image< Images... > const &img) -> typename any_image< Images... >::const_view_t
Returns the constant-pixel view of any image. The returned view is any view.
Definition: any_image.hpp:165
defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
Definition: algorithm.hpp:36
Returns the number of channels of a pixel-based GIL construct.
Definition: pixel.hpp:54