Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:36:55

0001 //
0002 // Copyright 2005-2007 Adobe Systems Incorporated
0003 // Copyright 2020 Samuel Debionne
0004 //
0005 // Distributed under the Boost Software License, Version 1.0
0006 // See accompanying file LICENSE_1_0.txt or copy at
0007 // http://www.boost.org/LICENSE_1_0.txt
0008 //
0009 #ifndef BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ANY_IMAGE_VIEW_HPP
0010 #define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ANY_IMAGE_VIEW_HPP
0011 
0012 #include <boost/gil/dynamic_step.hpp>
0013 #include <boost/gil/image.hpp>
0014 #include <boost/gil/image_view.hpp>
0015 #include <boost/gil/point.hpp>
0016 #include <boost/gil/detail/mp11.hpp>
0017 
0018 #include <boost/variant2/variant.hpp>
0019 
0020 namespace boost { namespace gil {
0021 
0022 template <typename View>
0023 struct dynamic_xy_step_transposed_type;
0024 
0025 namespace detail {
0026 
0027 template <typename View>
0028 using get_const_t = typename View::const_t;
0029 
0030 template <typename Views>
0031 using views_get_const_t = mp11::mp_transform<get_const_t, Views>;
0032 
0033 // works for both image_view and image
0034 struct any_type_get_num_channels
0035 {
0036     using result_type = int;
0037     template <typename T>
0038     result_type operator()(const T&) const { return num_channels<T>::value; }
0039 };
0040 
0041 // works for both image_view and image
0042 struct any_type_get_dimensions
0043 {
0044     using result_type = point<std::ptrdiff_t>;
0045     template <typename T>
0046     result_type operator()(const T& v) const { return v.dimensions(); }
0047 };
0048 
0049 // works for image_view
0050 struct any_type_get_size
0051 {
0052     using result_type = std::size_t;
0053     template <typename T>
0054     result_type operator()(const T& v) const { return v.size(); }
0055 };
0056 
0057 } // namespace detail
0058 
0059 ////////////////////////////////////////////////////////////////////////////////////////
0060 /// CLASS any_image_view
0061 ///
0062 /// \ingroup ImageViewModel
0063 /// \brief Represents a run-time specified image view. Models HasDynamicXStepTypeConcept, HasDynamicYStepTypeConcept, Note that this class does NOT model ImageViewConcept
0064 ///
0065 /// Represents a view whose type (color space, layout, planar/interleaved organization, etc) can be specified at run time.
0066 /// It is the runtime equivalent of \p image_view.
0067 /// 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.
0068 /// Other requirements, such as access to the pixels, would be inefficient to provide. Thus \p any_image_view does not fully model ImageViewConcept.
0069 /// 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.
0070 ///
0071 /// 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);
0072 ////////////////////////////////////////////////////////////////////////////////////////
0073 
0074 template <typename ...Views>
0075 class any_image_view : public variant2::variant<Views...>
0076 {
0077     using parent_t = variant2::variant<Views...>;
0078 
0079 public:
0080     using const_t = detail::views_get_const_t<any_image_view>;
0081     using x_coord_t = std::ptrdiff_t;
0082     using y_coord_t = std::ptrdiff_t;
0083     using point_t = point<std::ptrdiff_t>;
0084     using size_type = std::size_t;
0085 
0086     using parent_t::parent_t;
0087 
0088     any_image_view& operator=(any_image_view const& view)
0089     {
0090         parent_t::operator=((parent_t const&)view);
0091         return *this;
0092     }
0093 
0094     template <typename View>
0095     any_image_view& operator=(View const& view)
0096     {
0097         parent_t::operator=(view);
0098         return *this;
0099     }
0100 
0101     template <typename ...OtherViews>
0102     any_image_view& operator=(any_image_view<OtherViews...> const& view)
0103     {
0104         parent_t::operator=((variant2::variant<OtherViews...> const&)view);
0105         return *this;
0106     }
0107 
0108     std::size_t num_channels()  const { return variant2::visit(detail::any_type_get_num_channels(), *this); }
0109     point_t     dimensions()    const { return variant2::visit(detail::any_type_get_dimensions(), *this); }
0110     size_type   size()          const { return variant2::visit(detail::any_type_get_size(), *this); }
0111     x_coord_t   width()         const { return dimensions().x; }
0112     y_coord_t   height()        const { return dimensions().y; }
0113 };
0114 
0115 /////////////////////////////
0116 //  HasDynamicXStepTypeConcept
0117 /////////////////////////////
0118 
0119 template <typename ...Views>
0120 struct dynamic_x_step_type<any_image_view<Views...>>
0121 {
0122 private:
0123     // FIXME: Remove class name injection with gil:: qualification
0124     // Required as workaround for Boost.MP11 issue that treats unqualified metafunction
0125     // in the class definition of the same name as the specialization (Peter Dimov):
0126     //    invalid template argument for template parameter 'F', expected a class template
0127     template <typename T>
0128     using dynamic_step_view = typename gil::dynamic_x_step_type<T>::type;
0129 
0130 public:
0131     using type = mp11::mp_transform<dynamic_step_view, any_image_view<Views...>>;
0132 };
0133 
0134 /////////////////////////////
0135 //  HasDynamicYStepTypeConcept
0136 /////////////////////////////
0137 
0138 template <typename ...Views>
0139 struct dynamic_y_step_type<any_image_view<Views...>>
0140 {
0141 private:
0142     // FIXME: Remove class name injection with gil:: qualification
0143     // Required as workaround for Boost.MP11 issue that treats unqualified metafunction
0144     // in the class definition of the same name as the specialization (Peter Dimov):
0145     //    invalid template argument for template parameter 'F', expected a class template
0146     template <typename T>
0147     using dynamic_step_view = typename gil::dynamic_y_step_type<T>::type;
0148 
0149 public:
0150     using type = mp11::mp_transform<dynamic_step_view, any_image_view<Views...>>;
0151 };
0152 
0153 template <typename ...Views>
0154 struct dynamic_xy_step_type<any_image_view<Views...>>
0155 {
0156 private:
0157     // FIXME: Remove class name injection with gil:: qualification
0158     // Required as workaround for Boost.MP11 issue that treats unqualified metafunction
0159     // in the class definition of the same name as the specialization (Peter Dimov):
0160     //    invalid template argument for template parameter 'F', expected a class template
0161     template <typename T>
0162     using dynamic_step_view = typename gil::dynamic_xy_step_type<T>::type;
0163 
0164 public:
0165     using type = mp11::mp_transform<dynamic_step_view, any_image_view<Views...>>;
0166 };
0167 
0168 template <typename ...Views>
0169 struct dynamic_xy_step_transposed_type<any_image_view<Views...>>
0170 {
0171 private:
0172     // FIXME: Remove class name injection with gil:: qualification
0173     // Required as workaround for Boost.MP11 issue that treats unqualified metafunction
0174     // in the class definition of the same name as the specialization (Peter Dimov):
0175     //    invalid template argument for template parameter 'F', expected a class template
0176     template <typename T>
0177     using dynamic_step_view = typename gil::dynamic_xy_step_type<T>::type;
0178 
0179 public:
0180     using type = mp11::mp_transform<dynamic_step_view, any_image_view<Views...>>;
0181 };
0182 
0183 }}  // namespace boost::gil
0184 
0185 #endif