// // Copyright 2005-2007 Adobe Systems Incorporated // // 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 struct get_const_t { using type = typename View::const_t; }; template struct 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(); } }; } // 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 apply_operation(runtime_view, algorithm_fn); //////////////////////////////////////////////////////////////////////////////////////// template class any_image_view : public make_variant_over::type { using parent_t = typename make_variant_over::type; public: using const_t = any_image_view>; using x_coord_t = std::ptrdiff_t; using y_coord_t = std::ptrdiff_t; using point_t = point; any_image_view() = default; any_image_view(any_image_view const& view) : parent_t((parent_t const&)view) {} template explicit any_image_view(View const& view) : parent_t(view) {} template any_image_view(any_image_view const& view) : parent_t((typename make_variant_over::type const&)view) {} 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=((typename make_variant_over::type const&)view); return *this; } 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; } }; ///////////////////////////// // 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 = any_image_view>; }; ///////////////////////////// // 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 = any_image_view>; }; 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 = any_image_view>; }; 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 = any_image_view>; }; }} // namespace boost::gil #endif