Boost GIL


any_image_view.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_VIEW_HPP
9 #define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ANY_IMAGE_VIEW_HPP
10 
11 #include <boost/gil/extension/dynamic_image/variant.hpp>
12 
13 #include <boost/gil/image.hpp>
14 #include <boost/gil/image_view.hpp>
15 #include <boost/gil/point.hpp>
16 
17 namespace boost { namespace gil {
18 
19 namespace detail {
20  template <typename View> struct get_const_t { typedef typename View::const_t type; };
21  template <typename Views> struct views_get_const_t : public mpl::transform<Views, get_const_t<mpl::_1> > {};
22 }
23 template <typename View> struct dynamic_xy_step_type;
24 template <typename View> struct dynamic_xy_step_transposed_type;
25 
26 namespace detail {
27 
28  // works for both image_view and image
29  struct any_type_get_num_channels
30  {
31  typedef int result_type;
32  template <typename T>
33  result_type operator()(const T&) const { return num_channels<T>::value; }
34  };
35 
36  // works for both image_view and image
37  struct any_type_get_dimensions
38  {
39  using result_type = point<std::ptrdiff_t>;
40  template <typename T>
41  result_type operator()(const T& v) const { return v.dimensions(); }
42  };
43 }
44 
59 template <typename ImageViewTypes>
60 class any_image_view : public variant<ImageViewTypes> {
62 public:
64  typedef std::ptrdiff_t x_coord_t;
65  typedef std::ptrdiff_t y_coord_t;
67 
68  any_image_view() : parent_t() {}
69  template <typename T> explicit any_image_view(const T& obj) : parent_t(obj) {}
70  any_image_view(const any_image_view& v) : parent_t((const parent_t&)v) {}
71  template <typename Types> any_image_view(const any_image_view<Types>& v) : parent_t((const variant<Types>&)v) {}
72 
73  template <typename T> any_image_view& operator=(const T& obj) { parent_t::operator=(obj); return *this; }
74  any_image_view& operator=(const any_image_view& v) { parent_t::operator=((const parent_t&)v); return *this;}
75  template <typename Types> any_image_view& operator=(const any_image_view<Types>& v) { parent_t::operator=((const variant<Types>&)v); return *this;}
76 
77  std::size_t num_channels() const { return apply_operation(*this, detail::any_type_get_num_channels()); }
78  point_t dimensions() const { return apply_operation(*this, detail::any_type_get_dimensions()); }
79  x_coord_t width() const { return dimensions().x; }
80  y_coord_t height() const { return dimensions().y; }
81 };
82 
84 // HasDynamicXStepTypeConcept
86 
87 template <typename IVTypes>
88 struct dynamic_x_step_type<any_image_view<IVTypes> > {
90 };
91 
93 // HasDynamicYStepTypeConcept
95 
96 template <typename IVTypes>
97 struct dynamic_y_step_type<any_image_view<IVTypes> > {
98  typedef any_image_view<typename mpl::transform<IVTypes, dynamic_y_step_type<mpl::_1> >::type> type;
99 };
100 
101 template <typename IVTypes>
102 struct dynamic_xy_step_type<any_image_view<IVTypes> > {
103  typedef any_image_view<typename mpl::transform<IVTypes, dynamic_xy_step_type<mpl::_1> >::type> type;
104 };
105 
106 template <typename IVTypes>
107 struct dynamic_xy_step_transposed_type<any_image_view<IVTypes> > {
108  typedef any_image_view<typename mpl::transform<IVTypes, dynamic_xy_step_transposed_type<mpl::_1> >::type> type;
109 };
110 
111 }} // namespace boost::gil
112 
113 #endif
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
Returns the number of channels of a pixel-based GIL construct.
Definition: concepts.hpp:56