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_HPP
0010 #define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ANY_IMAGE_HPP
0011 
0012 #include <boost/gil/extension/dynamic_image/any_image_view.hpp>
0013 
0014 #include <boost/gil/image.hpp>
0015 #include <boost/gil/detail/mp11.hpp>
0016 
0017 #include <boost/config.hpp>
0018 #include <boost/variant2/variant.hpp>
0019 
0020 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
0021 #pragma warning(push)
0022 #pragma warning(disable:4512) //assignment operator could not be generated
0023 #endif
0024 
0025 namespace boost { namespace gil {
0026 
0027 namespace detail {
0028 
0029 template <typename T>
0030 using get_view_t = typename T::view_t;
0031 
0032 template <typename Images>
0033 using images_get_views_t = mp11::mp_transform<get_view_t, Images>;
0034 
0035 template <typename T>
0036 using get_const_view_t = typename T::const_view_t;
0037 
0038 template <typename Images>
0039 using images_get_const_views_t = mp11::mp_transform<get_const_view_t, Images>;
0040 
0041 struct recreate_image_fnobj
0042 {
0043     using result_type = void;
0044     point<std::ptrdiff_t> const& _dimensions;
0045     unsigned _alignment;
0046 
0047     recreate_image_fnobj(point<std::ptrdiff_t> const& dims, unsigned alignment)
0048         : _dimensions(dims), _alignment(alignment)
0049     {}
0050 
0051     template <typename Image>
0052     result_type operator()(Image& img) const { img.recreate(_dimensions,_alignment); }
0053 };
0054 
0055 template <typename AnyView>  // Models AnyViewConcept
0056 struct any_image_get_view
0057 {
0058     using result_type = AnyView;
0059     template <typename Image>
0060     result_type operator()(Image& img) const
0061     {
0062         return result_type(view(img));
0063     }
0064 };
0065 
0066 template <typename AnyConstView>  // Models AnyConstViewConcept
0067 struct any_image_get_const_view
0068 {
0069     using result_type = AnyConstView;
0070     template <typename Image>
0071     result_type operator()(Image const& img) const { return result_type{const_view(img)}; }
0072 };
0073 
0074 } // namespce detail
0075 
0076 ////////////////////////////////////////////////////////////////////////////////////////
0077 /// \ingroup ImageModel
0078 /// \brief Represents a run-time specified image. Note it does NOT model ImageConcept
0079 ///
0080 /// Represents an image whose type (color space, layout, planar/interleaved organization, etc) can be specified at run time.
0081 /// It is the runtime equivalent of \p image.
0082 /// Some of the requirements of ImageConcept, such as the \p value_type alias cannot be fulfilled, since the language does not allow runtime type specification.
0083 /// Other requirements, such as access to the pixels, would be inefficient to provide. Thus \p any_image does not fully model ImageConcept.
0084 /// 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.
0085 ////////////////////////////////////////////////////////////////////////////////////////
0086 
0087 template <typename ...Images>
0088 class any_image : public variant2::variant<Images...>
0089 {
0090     using parent_t = variant2::variant<Images...>;
0091 
0092 public:
0093     using view_t = mp11::mp_rename<detail::images_get_views_t<any_image>, any_image_view>;
0094     using const_view_t = mp11::mp_rename<detail::images_get_const_views_t<any_image>, any_image_view>;
0095     using x_coord_t = std::ptrdiff_t;
0096     using y_coord_t = std::ptrdiff_t;
0097     using point_t = point<std::ptrdiff_t>;
0098 
0099     using parent_t::parent_t;
0100 
0101     any_image& operator=(any_image const& img)
0102     {
0103         parent_t::operator=((parent_t const&)img);
0104         return *this;
0105     }
0106 
0107     template <typename Image>
0108     any_image& operator=(Image const& img)
0109     {
0110         parent_t::operator=(img);
0111         return *this;
0112     }
0113 
0114     template <typename ...OtherImages>
0115     any_image& operator=(any_image<OtherImages...> const& img)
0116     {
0117             parent_t::operator=((typename variant2::variant<OtherImages...> const&)img);
0118             return *this;
0119     }
0120 
0121     void recreate(point_t const& dims, unsigned alignment=1)
0122     {
0123         variant2::visit(detail::recreate_image_fnobj(dims, alignment), *this);
0124     }
0125 
0126     void recreate(x_coord_t width, y_coord_t height, unsigned alignment=1)
0127     {
0128         recreate({ width, height }, alignment);
0129     }
0130 
0131     std::size_t num_channels() const
0132     {
0133         return variant2::visit(detail::any_type_get_num_channels(), *this);
0134     }
0135 
0136     point_t dimensions() const
0137     {
0138         return variant2::visit(detail::any_type_get_dimensions(), *this);
0139     }
0140 
0141     x_coord_t width()  const { return dimensions().x; }
0142     y_coord_t height() const { return dimensions().y; }
0143 };
0144 
0145 ///@{
0146 /// \name view, const_view
0147 /// \brief Get an image view from a run-time instantiated image
0148 
0149 /// \ingroup ImageModel
0150 
0151 /// \brief Returns the non-constant-pixel view of any image. The returned view is any view.
0152 /// \tparam Images Models ImageVectorConcept
0153 template <typename ...Images>
0154 BOOST_FORCEINLINE
0155 auto view(any_image<Images...>& img) -> typename any_image<Images...>::view_t
0156 {
0157     using view_t = typename any_image<Images...>::view_t;
0158     return variant2::visit(detail::any_image_get_view<view_t>(), img);
0159 }
0160 
0161 /// \brief Returns the constant-pixel view of any image. The returned view is any view.
0162 /// \tparam Types Models ImageVectorConcept
0163 template <typename ...Images>
0164 BOOST_FORCEINLINE
0165 auto const_view(any_image<Images...> const& img) -> typename any_image<Images...>::const_view_t
0166 {
0167     using view_t = typename any_image<Images...>::const_view_t;
0168     return variant2::visit(detail::any_image_get_const_view<view_t>(), img);
0169 }
0170 ///@}
0171 
0172 }}  // namespace boost::gil
0173 
0174 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
0175 #pragma warning(pop)
0176 #endif
0177 
0178 #endif