###

#

any_image.hpp
//
// Copyright 2005-2007 Adobe Systems Incorporated
// Copyright 2020 Samuel Debionne
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
#ifndef BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ANY_IMAGE_HPP
#define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ANY_IMAGE_HPP
#include <boost/gil/extension/dynamic_image/any_image_view.hpp>
#include <boost/gil/image.hpp>
#include <boost/gil/detail/mp11.hpp>
#include <boost/config.hpp>
#include <boost/variant2/variant.hpp>
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
#pragma warning(push)
#pragma warning(disable:4512) //assignment operator could not be generated
#endif
namespace boost { namespace gil {
namespace detail {
template <typename T>
using get_view_t = typename T::view_t;
template <typename Images>
using images_get_views_t = mp11::mp_transform<get_view_t, Images>;
template <typename T>
using get_const_view_t = typename T::const_view_t;
template <typename Images>
using images_get_const_views_t = mp11::mp_transform<get_const_view_t, Images>;
struct recreate_image_fnobj
{
using result_type = void;
point<std::ptrdiff_t> const& _dimensions;
unsigned _alignment;
recreate_image_fnobj(point<std::ptrdiff_t> const& dims, unsigned alignment)
: _dimensions(dims), _alignment(alignment)
{}
template <typename Image>
result_type operator()(Image& img) const { img.recreate(_dimensions,_alignment); }
};
template <typename AnyView> // Models AnyViewConcept
struct any_image_get_view
{
using result_type = AnyView;
template <typename Image>
result_type operator()(Image& img) const
{
return result_type(view(img));
}
};
template <typename AnyConstView> // Models AnyConstViewConcept
struct any_image_get_const_view
{
using result_type = AnyConstView;
template <typename Image>
result_type operator()(Image const& img) const { return result_type{const_view(img)}; }
};
} // namespce detail
template <typename ...Images>
class any_image : public variant2::variant<Images...>
{
using parent_t = variant2::variant<Images...>;
public:
using view_t = mp11::mp_rename<detail::images_get_views_t<any_image>, any_image_view>;
using const_view_t = mp11::mp_rename<detail::images_get_const_views_t<any_image>, any_image_view>;
using x_coord_t = std::ptrdiff_t;
using y_coord_t = std::ptrdiff_t;
using point_t = point<std::ptrdiff_t>;
using parent_t::parent_t;
any_image& operator=(any_image const& img)
{
parent_t::operator=((parent_t const&)img);
return *this;
}
template <typename Image>
any_image& operator=(Image const& img)
{
parent_t::operator=(img);
return *this;
}
template <typename ...OtherImages>
any_image& operator=(any_image<OtherImages...> const& img)
{
parent_t::operator=((typename variant2::variant<OtherImages...> const&)img);
return *this;
}
void recreate(point_t const& dims, unsigned alignment=1)
{
variant2::visit(detail::recreate_image_fnobj(dims, alignment), *this);
}
void recreate(x_coord_t width, y_coord_t height, unsigned alignment=1)
{
recreate({ width, height }, alignment);
}
std::size_t num_channels() const
{
return variant2::visit(detail::any_type_get_num_channels(), *this);
}
point_t dimensions() const
{
return variant2::visit(detail::any_type_get_dimensions(), *this);
}
x_coord_t width() const { return dimensions().x; }
y_coord_t height() const { return dimensions().y; }
};
template <typename ...Images>
BOOST_FORCEINLINE
auto view(any_image<Images...>& img) -> typename any_image<Images...>::view_t
{
using view_t = typename any_image<Images...>::view_t;
return variant2::visit(detail::any_image_get_view<view_t>(), img);
}
template <typename ...Images>
BOOST_FORCEINLINE
auto const_view(any_image<Images...> const& img) -> typename any_image<Images...>::const_view_t
{
using view_t = typename any_image<Images...>::const_view_t;
return variant2::visit(detail::any_image_get_const_view<view_t>(), img);
}
}} // namespace boost::gil
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
#pragma warning(pop)
#endif
#endif
boost::gil::any_image_view
Represents a run-time specified image view. Models HasDynamicXStepTypeConcept, HasDynamicYStepTypeCon...
Definition: any_image_view.hpp:76
boost::gil::any_image
Represents a run-time specified image. Note it does NOT model ImageConcept.
Definition: any_image.hpp:89
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::gil::const_view
auto const_view(const image< Pixel, IsPlanar, Alloc > &img) -> typename image< Pixel, IsPlanar, Alloc >::const_view_t const
Returns the constant-pixel view of an image.
Definition: image.hpp:573
boost
defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
Definition: algorithm.hpp:36
boost::gil::num_channels
Returns the number of channels of a pixel-based GIL construct.
Definition: pixel.hpp:54