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 
13 #include <boost/gil/image.hpp>
14 
15 #include <boost/config.hpp>
16 
17 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
18 #pragma warning(push)
19 #pragma warning(disable:4512) //assignment operator could not be generated
20 #endif
21 
22 namespace boost { namespace gil {
23 
24 namespace detail {
25  template <typename T> struct get_view_t { typedef typename T::view_t type; };
26  template <typename Images> struct images_get_views_t : public mpl::transform<Images, get_view_t<mpl::_1> > {};
27 
28  template <typename T> struct get_const_view_t { typedef typename T::const_view_t type; };
29  template <typename Images> struct images_get_const_views_t : public mpl::transform<Images, get_const_view_t<mpl::_1> > {};
30 
31  struct recreate_image_fnobj
32  {
33  typedef void result_type;
34  point<std::ptrdiff_t> const& _dimensions;
35  unsigned _alignment;
36 
37  recreate_image_fnobj(point<std::ptrdiff_t> const& dims, unsigned alignment) : _dimensions(dims), _alignment(alignment) {}
38  template <typename Image>
39  result_type operator()(Image& img) const { img.recreate(_dimensions,_alignment); }
40  };
41 
42  template <typename AnyView> // Models AnyViewConcept
43  struct any_image_get_view {
44  typedef AnyView result_type;
45  template <typename Image> result_type operator()( Image& img) const { return result_type(view(img)); }
46  };
47 
48  template <typename AnyConstView> // Models AnyConstViewConcept
49  struct any_image_get_const_view {
50  typedef AnyConstView result_type;
51  template <typename Image> result_type operator()(const Image& img) const { return result_type(const_view(img)); }
52  };
53 }
54 
65 template <typename ImageTypes>
66 class any_image : public variant<ImageTypes> {
68 public:
71  typedef std::ptrdiff_t x_coord_t;
72  typedef std::ptrdiff_t y_coord_t;
74 
75  any_image() : parent_t() {}
76  template <typename T> explicit any_image(const T& obj) : parent_t(obj) {}
77  template <typename T> explicit any_image(T& obj, bool do_swap) : parent_t(obj,do_swap) {}
78  any_image(const any_image& v) : parent_t((const parent_t&)v) {}
79  template <typename Types> any_image(const any_image<Types>& v) : parent_t((const variant<Types>&)v) {}
80 
81  template <typename T> any_image& operator=(const T& obj) { parent_t::operator=(obj); return *this; }
82  any_image& operator=(const any_image& v) { parent_t::operator=((const parent_t&)v); return *this;}
83  template <typename Types> any_image& operator=(const any_image<Types>& v) { parent_t::operator=((const variant<Types>&)v); return *this;}
84 
85  void recreate(const point_t& dims, unsigned alignment=1)
86  {
87  apply_operation(*this,detail::recreate_image_fnobj(dims,alignment));
88  }
89 
90  void recreate(x_coord_t width, y_coord_t height, unsigned alignment=1)
91  {
92  recreate({width, height}, alignment);
93  }
94 
95  std::size_t num_channels() const { return apply_operation(*this, detail::any_type_get_num_channels()); }
96  point_t dimensions() const { return apply_operation(*this, detail::any_type_get_dimensions()); }
97  x_coord_t width() const { return dimensions().x; }
98  y_coord_t height() const { return dimensions().y; }
99 };
100 
104 
106 
108 template <typename Types> BOOST_FORCEINLINE // Models ImageVectorConcept
110  return apply_operation(anyImage, detail::any_image_get_view<typename any_image<Types>::view_t>());
111 }
112 
114 template <typename Types> BOOST_FORCEINLINE // Models ImageVectorConcept
116  return apply_operation(anyImage, detail::any_image_get_const_view<typename any_image<Types>::const_view_t>());
117 }
119 
120 }} // namespace boost::gil
121 
122 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
123 #pragma warning(pop)
124 #endif
125 
126 #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:115
Represents a run-time specified image. Note it does NOT model ImageConcept.
Definition: any_image.hpp:66
BOOST_FORCEINLINE UnaryOp::result_type 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 concrete instance of a run-time specified type from a set of typesA concept is typically...
Definition: variant.hpp:80
Represents a run-time specified image view. Models HasDynamicXStepTypeConcept, HasDynamicYStepTypeCon...
Definition: any_image_view.hpp:60
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:109
Returns the number of channels of a pixel-based GIL construct.
Definition: concepts.hpp:56