// // 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_VIEW_HPP #define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ANY_IMAGE_VIEW_HPP #include #include #include #include #include #include namespace boost { namespace gil { template struct dynamic_xy_step_transposed_type; namespace detail { template using get_const_t = typename View::const_t; template using views_get_const_t = mp11::mp_transform; // works for both image_view and image struct any_type_get_num_channels { using result_type = int; template result_type operator()(const T&) const { return num_channels::value; } }; // works for both image_view and image struct any_type_get_dimensions { using result_type = point; template result_type operator()(const T& v) const { return v.dimensions(); } }; // works for image_view struct any_type_get_size { using result_type = std::size_t; template result_type operator()(const T& v) const { return v.size(); } }; } // namespace detail //////////////////////////////////////////////////////////////////////////////////////// /// CLASS any_image_view /// /// \ingroup ImageViewModel /// \brief Represents a run-time specified image view. Models HasDynamicXStepTypeConcept, HasDynamicYStepTypeConcept, Note that this class does NOT model ImageViewConcept /// /// Represents a view whose type (color space, layout, planar/interleaved organization, etc) can be specified at run time. /// It is the runtime equivalent of \p image_view. /// Some of the requirements of ImageViewConcept, such as the \p value_type alias cannot be fulfilled, since the language does not allow runtime type specification. /// Other requirements, such as access to the pixels, would be inefficient to provide. Thus \p any_image_view does not fully model ImageViewConcept. /// However, many algorithms provide overloads taking runtime specified views and thus in many cases \p any_image_view can be used in places taking a view. /// /// To perform an algorithm on any_image_view, put the algorithm in a function object and invoke it by calling \p variant2::visit(algorithm_fn, runtime_view); //////////////////////////////////////////////////////////////////////////////////////// template class any_image_view : public variant2::variant { using parent_t = variant2::variant; public: using const_t = detail::views_get_const_t; using x_coord_t = std::ptrdiff_t; using y_coord_t = std::ptrdiff_t; using point_t = point; using size_type = std::size_t; using parent_t::parent_t; any_image_view& operator=(any_image_view const& view) { parent_t::operator=((parent_t const&)view); return *this; } template any_image_view& operator=(View const& view) { parent_t::operator=(view); return *this; } template any_image_view& operator=(any_image_view const& view) { parent_t::operator=((variant2::variant const&)view); return *this; } 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); } size_type size() const { return variant2::visit(detail::any_type_get_size(), *this); } x_coord_t width() const { return dimensions().x; } y_coord_t height() const { return dimensions().y; } }; ///////////////////////////// // HasDynamicXStepTypeConcept ///////////////////////////// template struct dynamic_x_step_type> { private: // FIXME: Remove class name injection with gil:: qualification // Required as workaround for Boost.MP11 issue that treats unqualified metafunction // in the class definition of the same name as the specialization (Peter Dimov): // invalid template argument for template parameter 'F', expected a class template template using dynamic_step_view = typename gil::dynamic_x_step_type::type; public: using type = mp11::mp_transform>; }; ///////////////////////////// // HasDynamicYStepTypeConcept ///////////////////////////// template struct dynamic_y_step_type> { private: // FIXME: Remove class name injection with gil:: qualification // Required as workaround for Boost.MP11 issue that treats unqualified metafunction // in the class definition of the same name as the specialization (Peter Dimov): // invalid template argument for template parameter 'F', expected a class template template using dynamic_step_view = typename gil::dynamic_y_step_type::type; public: using type = mp11::mp_transform>; }; template struct dynamic_xy_step_type> { private: // FIXME: Remove class name injection with gil:: qualification // Required as workaround for Boost.MP11 issue that treats unqualified metafunction // in the class definition of the same name as the specialization (Peter Dimov): // invalid template argument for template parameter 'F', expected a class template template using dynamic_step_view = typename gil::dynamic_xy_step_type::type; public: using type = mp11::mp_transform>; }; template struct dynamic_xy_step_transposed_type> { private: // FIXME: Remove class name injection with gil:: qualification // Required as workaround for Boost.MP11 issue that treats unqualified metafunction // in the class definition of the same name as the specialization (Peter Dimov): // invalid template argument for template parameter 'F', expected a class template template using dynamic_step_view = typename gil::dynamic_xy_step_type::type; public: using type = mp11::mp_transform>; }; }} // namespace boost::gil #endif