Boost GIL


any_image.hpp
1 //
2 // Copyright 2005-2007 Adobe Systems Incorporated
3 //
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
7 //
8 #ifndef BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ANY_IMAGE_HPP
9 #define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ANY_IMAGE_HPP
10 
11 #include <boost/gil/extension/dynamic_image/any_image_view.hpp>
12 #include <boost/gil/extension/dynamic_image/apply_operation.hpp>
13 
14 #include <boost/gil/image.hpp>
15 
16 #include <boost/config.hpp>
17 
18 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
19 #pragma warning(push)
20 #pragma warning(disable:4512) //assignment operator could not be generated
21 #endif
22 
23 namespace boost { namespace gil {
24 
25 namespace detail {
26  template <typename T> struct get_view_t { using type = typename T::view_t; };
27  template <typename Images> struct images_get_views_t : public mpl::transform<Images, get_view_t<mpl::_1> > {};
28 
29  template <typename T> struct get_const_view_t { using type = typename T::const_view_t; };
30  template <typename Images> struct images_get_const_views_t : public mpl::transform<Images, get_const_view_t<mpl::_1> > {};
31 
32  struct recreate_image_fnobj
33  {
34  using result_type = void;
35  point<std::ptrdiff_t> const& _dimensions;
36  unsigned _alignment;
37 
38  recreate_image_fnobj(point<std::ptrdiff_t> const& dims, unsigned alignment) : _dimensions(dims), _alignment(alignment) {}
39  template <typename Image>
40  result_type operator()(Image& img) const { img.recreate(_dimensions,_alignment); }
41  };
42 
43  template <typename AnyView> // Models AnyViewConcept
44  struct any_image_get_view {
45  using result_type = AnyView;
46  template <typename Image> result_type operator()( Image& img) const { return result_type(view(img)); }
47  };
48 
49  template <typename AnyConstView> // Models AnyConstViewConcept
50  struct any_image_get_const_view {
51  using result_type = AnyConstView;
52  template <typename Image> result_type operator()(const Image& img) const { return result_type(const_view(img)); }
53  };
54 }
55 
66 template <typename ImageTypes>
67 class any_image : public make_variant_over<ImageTypes>::type {
68  using parent_t = typename make_variant_over<ImageTypes>::type;
69 public:
72  using x_coord_t = std::ptrdiff_t;
73  using y_coord_t = std::ptrdiff_t;
75 
76  any_image() : parent_t() {}
77  template <typename T> explicit any_image(const T& obj) : parent_t(obj) {}
78  template <typename T> explicit any_image(T& obj, bool do_swap) : parent_t(obj,do_swap) {}
79  any_image(const any_image& v) : parent_t((const parent_t&)v) {}
80  template <typename Types> any_image(const any_image<Types>& v) : parent_t((const typename make_variant_over<Types>::type&)v) {}
81 
82  template <typename T> any_image& operator=(const T& obj) { parent_t::operator=(obj); return *this; }
83  any_image& operator=(const any_image& v) { parent_t::operator=((const parent_t&)v); return *this;}
84  template <typename Types> any_image& operator=(const any_image<Types>& v) { parent_t::operator=((const typename make_variant_over<Types>::type&)v); return *this;}
85 
86  void recreate(const point_t& dims, unsigned alignment=1)
87  {
88  apply_operation(*this,detail::recreate_image_fnobj(dims,alignment));
89  }
90 
91  void recreate(x_coord_t width, y_coord_t height, unsigned alignment=1)
92  {
93  recreate({width, height}, alignment);
94  }
95 
96  std::size_t num_channels() const { return apply_operation(*this, detail::any_type_get_num_channels()); }
97  point_t dimensions() const { return apply_operation(*this, detail::any_type_get_dimensions()); }
98  x_coord_t width() const { return dimensions().x; }
99  y_coord_t height() const { return dimensions().y; }
100 };
101 
105 
107 
109 template <typename Types> BOOST_FORCEINLINE // Models ImageVectorConcept
111  return apply_operation(anyImage, detail::any_image_get_view<typename any_image<Types>::view_t>());
112 }
113 
115 template <typename Types> BOOST_FORCEINLINE // Models ImageVectorConcept
117  return apply_operation(anyImage, detail::any_image_get_const_view<typename any_image<Types>::const_view_t>());
118 }
120 
121 }} // namespace boost::gil
122 
123 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
124 #pragma warning(pop)
125 #endif
126 
127 #endif
BOOST_FORCEINLINE any_image< Types >::const_view_t const_view(const any_image< Types > &anyImage)
Returns the constant-pixel view of any image. The returned view is any view.
Definition: any_image.hpp:116
Definition: algorithm.hpp:30
Represents a run-time specified image. Note it does NOT model ImageConcept.
Definition: any_image.hpp:67
BOOST_FORCEINLINE auto apply_operation(variant< Types > &arg, UnaryOp op)
Invokes a generic mutable operation (represented as a unary function object) on a variant...
Definition: apply_operation.hpp:31
Represents a run-time specified image view. Models HasDynamicXStepTypeConcept, HasDynamicYStepTypeCon...
Definition: any_image_view.hpp:61
BOOST_FORCEINLINE any_image< Types >::view_t view(any_image< Types > &anyImage)
Returns the non-constant-pixel view of any image. The returned view is any view.
Definition: any_image.hpp:110
Returns the number of channels of a pixel-based GIL construct.
Definition: locator.hpp:38