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  typedef void result_type;
33  const point2<std::ptrdiff_t>& _dimensions;
34  unsigned _alignment;
35 
36  recreate_image_fnobj(const point2<std::ptrdiff_t>& dims, unsigned alignment) : _dimensions(dims), _alignment(alignment) {}
37  template <typename Image> result_type operator()(Image& img) const { img.recreate(_dimensions,_alignment); }
38  };
39 
40  template <typename AnyView> // Models AnyViewConcept
41  struct any_image_get_view {
42  typedef AnyView result_type;
43  template <typename Image> result_type operator()( Image& img) const { return result_type(view(img)); }
44  };
45 
46  template <typename AnyConstView> // Models AnyConstViewConcept
47  struct any_image_get_const_view {
48  typedef AnyConstView result_type;
49  template <typename Image> result_type operator()(const Image& img) const { return result_type(const_view(img)); }
50  };
51 }
52 
63 template <typename ImageTypes>
64 class any_image : public variant<ImageTypes> {
66 public:
69  typedef std::ptrdiff_t x_coord_t;
70  typedef std::ptrdiff_t y_coord_t;
72 
73  any_image() : parent_t() {}
74  template <typename T> explicit any_image(const T& obj) : parent_t(obj) {}
75  template <typename T> explicit any_image(T& obj, bool do_swap) : parent_t(obj,do_swap) {}
76  any_image(const any_image& v) : parent_t((const parent_t&)v) {}
77  template <typename Types> any_image(const any_image<Types>& v) : parent_t((const variant<Types>&)v) {}
78 
79  template <typename T> any_image& operator=(const T& obj) { parent_t::operator=(obj); return *this; }
80  any_image& operator=(const any_image& v) { parent_t::operator=((const parent_t&)v); return *this;}
81  template <typename Types> any_image& operator=(const any_image<Types>& v) { parent_t::operator=((const variant<Types>&)v); return *this;}
82 
83  void recreate(const point_t& dims, unsigned alignment=1) { apply_operation(*this,detail::recreate_image_fnobj(dims,alignment)); }
84  void recreate(x_coord_t width, y_coord_t height, unsigned alignment=1) { recreate(point2<std::ptrdiff_t>(width,height),alignment); }
85 
86  std::size_t num_channels() const { return apply_operation(*this, detail::any_type_get_num_channels()); }
87  point_t dimensions() const { return apply_operation(*this, detail::any_type_get_dimensions()); }
88  x_coord_t width() const { return dimensions().x; }
89  y_coord_t height() const { return dimensions().y; }
90 };
91 
95 
97 
99 template <typename Types> BOOST_FORCEINLINE // Models ImageVectorConcept
101  return apply_operation(anyImage, detail::any_image_get_view<typename any_image<Types>::view_t>());
102 }
103 
105 template <typename Types> BOOST_FORCEINLINE // Models ImageVectorConcept
107  return apply_operation(anyImage, detail::any_image_get_const_view<typename any_image<Types>::const_view_t>());
108 }
110 
111 }} // namespace boost::gil
112 
113 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
114 #pragma warning(pop)
115 #endif
116 
117 #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:106
Represents a run-time specified image. Note it does NOT model ImageConcept.
Definition: any_image.hpp:64
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:51
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:100
Returns the number of channels of a pixel-based GIL construct.
Definition: concepts.hpp:56