#include <boost/gil/extension/dynamic_image/apply_operation.hpp>
#include <boost/gil/image.hpp>
+#include <boost/gil/detail/mp11.hpp>
#include <boost/config.hpp>
+#include <boost/variant.hpp>
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
#pragma warning(push)
namespace boost { namespace gil {
namespace detail {
- template <typename T> struct get_view_t { using type = typename T::view_t; };
- template <typename Images> struct images_get_views_t : public mpl::transform<Images, get_view_t<mpl::_1> > {};
- template <typename T> struct get_const_view_t { using type = typename T::const_view_t; };
- template <typename Images> struct images_get_const_views_t : public mpl::transform<Images, get_const_view_t<mpl::_1> > {};
+template <typename T>
+using get_view_t = typename T::view_t;
- struct recreate_image_fnobj
+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
{
- 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()(const Image& img) const { return result_type(const_view(img)); }
- };
-}
+ 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
////////////////////////////////////////////////////////////////////////////////////////
/// \ingroup ImageModel
/// Other requirements, such as access to the pixels, would be inefficient to provide. Thus \p any_image does not fully model ImageConcept.
/// In particular, its \p view and \p const_view methods return \p any_image_view, which does not fully model ImageViewConcept. See \p any_image_view for more.
////////////////////////////////////////////////////////////////////////////////////////
-template <typename ImageTypes>
-class any_image : public make_variant_over<ImageTypes>::type {
- using parent_t = typename make_variant_over<ImageTypes>::type;
+
+template <typename Images>
+class any_image : public make_variant_over<Images>::type
+{
+ using parent_t = typename make_variant_over<Images>::type;
public:
- using const_view_t = any_image_view<typename detail::images_get_const_views_t<ImageTypes>::type>;
- using view_t = any_image_view<typename detail::images_get_views_t<ImageTypes>::type>;
+ using view_t = any_image_view<detail::images_get_views_t<Images>>;
+ using const_view_t = any_image_view<detail::images_get_const_views_t<Images>>;
using x_coord_t = std::ptrdiff_t;
using y_coord_t = std::ptrdiff_t;
using point_t = point<std::ptrdiff_t>;
- any_image() : parent_t() {}
- template <typename T> explicit any_image(const T& obj) : parent_t(obj) {}
- template <typename T> explicit any_image(T& obj, bool do_swap) : parent_t(obj,do_swap) {}
- any_image(const any_image& v) : parent_t((const parent_t&)v) {}
- template <typename Types> any_image(const any_image<Types>& v) : parent_t((const typename make_variant_over<Types>::type&)v) {}
+ any_image() = default;
+ any_image(any_image const& img) : parent_t((parent_t const&)img) {}
+
+ template <typename Image>
+ explicit any_image(Image const& img) : parent_t(img) {}
+
+ template <typename Image>
+ explicit any_image(Image& img, bool do_swap) : parent_t(img, do_swap) {}
- template <typename T> any_image& operator=(const T& obj) { parent_t::operator=(obj); return *this; }
- any_image& operator=(const any_image& v) { parent_t::operator=((const parent_t&)v); return *this;}
- template <typename Types> any_image& operator=(const any_image<Types>& v) { parent_t::operator=((const typename make_variant_over<Types>::type&)v); return *this;}
+ template <typename OtherImages>
+ any_image(any_image<OtherImages> const& img)
+ : parent_t((typename make_variant_over<OtherImages>::type const&)img)
+ {}
+
+ 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 make_variant_over<OtherImages>::type const&)img);
+ return *this;
+ }
void recreate(const point_t& dims, unsigned alignment=1)
{
- apply_operation(*this,detail::recreate_image_fnobj(dims,alignment));
+ apply_operation(*this, detail::recreate_image_fnobj(dims, alignment));
}
void recreate(x_coord_t width, y_coord_t height, unsigned alignment=1)
{
- recreate({width, height}, alignment);
+ recreate({ width, height }, alignment);
+ }
+
+ std::size_t num_channels() const
+ {
+ return apply_operation(*this, detail::any_type_get_num_channels());
+ }
+
+ point_t dimensions() const
+ {
+ return apply_operation(*this, detail::any_type_get_dimensions());
}
- std::size_t num_channels() const { return apply_operation(*this, detail::any_type_get_num_channels()); }
- point_t dimensions() const { return apply_operation(*this, detail::any_type_get_dimensions()); }
- x_coord_t width() const { return dimensions().x; }
- y_coord_t height() const { return dimensions().y; }
+ x_coord_t width() const { return dimensions().x; }
+ y_coord_t height() const { return dimensions().y; }
};
///@{
/// \ingroup ImageModel
/// \brief Returns the non-constant-pixel view of any image. The returned view is any view.
-template <typename Types> BOOST_FORCEINLINE // Models ImageVectorConcept
-typename any_image<Types>::view_t view(any_image<Types>& anyImage) {
- return apply_operation(anyImage, detail::any_image_get_view<typename any_image<Types>::view_t>());
+/// \tparam Types Models ImageVectorConcept
+template <typename Types>
+BOOST_FORCEINLINE
+auto view(any_image<Types>& img) -> typename any_image<Types>::view_t
+{
+ using view_t = typename any_image<Types>::view_t;
+ return apply_operation(img, detail::any_image_get_view<view_t>());
}
/// \brief Returns the constant-pixel view of any image. The returned view is any view.
-template <typename Types> BOOST_FORCEINLINE // Models ImageVectorConcept
-typename any_image<Types>::const_view_t const_view(const any_image<Types>& anyImage) {
- return apply_operation(anyImage, detail::any_image_get_const_view<typename any_image<Types>::const_view_t>());
+/// \tparam Types Models ImageVectorConcept
+template <typename Types>
+BOOST_FORCEINLINE
+auto const_view(any_image<Types> const& img) -> typename any_image<Types>::const_view_t
+{
+ using view_t = typename any_image<Types>::const_view_t;
+ return apply_operation(img, detail::any_image_get_const_view<view_t>());
}
///@}