Boost GIL


any_image_view.hpp
Go to the documentation of this file.
1 /*
2  Copyright 2005-2007 Adobe Systems Incorporated
3 
4  Use, modification and distribution are subject to the Boost Software License,
5  Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6  http://www.boost.org/LICENSE_1_0.txt).
7 
8  See http://opensource.adobe.com/gil for most recent version including documentation.
9 */
10 
11 /*************************************************************************************************/
12 
13 #ifndef GIL_DYNAMICIMAGE_ANY_IMAGEVIEW_HPP
14 #define GIL_DYNAMICIMAGE_ANY_IMAGEVIEW_HPP
15 
24 
25 #include "variant.hpp"
26 #include "../../image_view.hpp"
27 #include "../../image.hpp"
28 
29 namespace boost { namespace gil {
30 
31 namespace detail {
32  template <typename View> struct get_const_t { typedef typename View::const_t type; };
33  template <typename Views> struct views_get_const_t : public mpl::transform<Views, get_const_t<mpl::_1> > {};
34 }
35 template <typename View> struct dynamic_xy_step_type;
36 template <typename View> struct dynamic_xy_step_transposed_type;
37 
38 namespace detail {
39  struct any_type_get_num_channels { // works for both image_view and image
40  typedef int result_type;
41  template <typename T> result_type operator()(const T&) const { return num_channels<T>::value; }
42  };
43  struct any_type_get_dimensions { // works for both image_view and image
44  typedef point2<std::ptrdiff_t> result_type;
45  template <typename T> result_type operator()(const T& v) const { return v.dimensions(); }
46  };
47 }
48 
63 template <typename ImageViewTypes>
64 class any_image_view : public variant<ImageViewTypes> {
66 public:
68  typedef std::ptrdiff_t x_coord_t;
69  typedef std::ptrdiff_t y_coord_t;
71 
72  any_image_view() : parent_t() {}
73  template <typename T> explicit any_image_view(const T& obj) : parent_t(obj) {}
74  any_image_view(const any_image_view& v) : parent_t((const parent_t&)v) {}
75  template <typename Types> any_image_view(const any_image_view<Types>& v) : parent_t((const variant<Types>&)v) {}
76 
77  template <typename T> any_image_view& operator=(const T& obj) { parent_t::operator=(obj); return *this; }
78  any_image_view& operator=(const any_image_view& v) { parent_t::operator=((const parent_t&)v); return *this;}
79  template <typename Types> any_image_view& operator=(const any_image_view<Types>& v) { parent_t::operator=((const variant<Types>&)v); return *this;}
80 
81  std::size_t num_channels() const { return apply_operation(*this, detail::any_type_get_num_channels()); }
82  point_t dimensions() const { return apply_operation(*this, detail::any_type_get_dimensions()); }
83  x_coord_t width() const { return dimensions().x; }
84  y_coord_t height() const { return dimensions().y; }
85 };
86 
88 // HasDynamicXStepTypeConcept
90 
91 template <typename IVTypes>
92 struct dynamic_x_step_type<any_image_view<IVTypes> > {
94 };
95 
97 // HasDynamicYStepTypeConcept
99 
100 template <typename IVTypes>
101 struct dynamic_y_step_type<any_image_view<IVTypes> > {
102  typedef any_image_view<typename mpl::transform<IVTypes, dynamic_y_step_type<mpl::_1> >::type> type;
103 };
104 
105 template <typename IVTypes>
106 struct dynamic_xy_step_type<any_image_view<IVTypes> > {
107  typedef any_image_view<typename mpl::transform<IVTypes, dynamic_xy_step_type<mpl::_1> >::type> type;
108 };
109 
110 template <typename IVTypes>
111 struct dynamic_xy_step_transposed_type<any_image_view<IVTypes> > {
112  typedef any_image_view<typename mpl::transform<IVTypes, dynamic_xy_step_transposed_type<mpl::_1> >::type> type;
113 };
114 
115 } } // namespace boost::gil
116 
117 #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:35
Support for run-time instantiated types.
Represents a concrete instance of a run-time specified type from a set of typesA concept is typically...
Definition: variant.hpp:89
Represents a run-time specified image view. Models HasDynamicXStepTypeConcept, HasDynamicYStepTypeCon...
Definition: any_image_view.hpp:64
Returns the number of channels of a pixel-based GIL construct.
Definition: gil_concept.hpp:66