Generic Image Library: any_image.hpp Source File

###  | #  |

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

any_image.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 #ifndef GIL_DYNAMICIMAGE_ANY_IMAGE_HPP
13 #define GIL_DYNAMICIMAGE_ANY_IMAGE_HPP
14
23
24 #include "any_image_view.hpp"
25 #include "../../image.hpp"
26
27 //#ifdef _MSC_VER
28 //#pragma warning(push)
29 //#pragma warning(disable : 4244) // conversion from 'std::ptrdiff_t' to 'int', possible loss of data. even if we static-assert the two types are the same (on visual studio 8)
30 //#endif
31
32 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
33 #pragma warning(push)
34 #pragma warning(disable:4512) //assignment operator could not be generated
35 #endif
36
37 namespace boost { namespace gil {
38
39 namespace detail {
40 template <typename T> struct get_view_t { typedef typename T::view_t type; };
41 template <typename Images> struct images_get_views_t : public mpl::transform<Images, get_view_t<mpl::_1> > {};
42
43 template <typename T> struct get_const_view_t { typedef typename T::const_view_t type; };
44 template <typename Images> struct images_get_const_views_t : public mpl::transform<Images, get_const_view_t<mpl::_1> > {};
45
46 struct recreate_image_fnobj {
47 typedef void result_type;
48 const point2<std::ptrdiff_t>& _dimensions;
49 unsigned _alignment;
50
51 recreate_image_fnobj(const point2<std::ptrdiff_t>& dims, unsigned alignment) : _dimensions(dims), _alignment(alignment) {}
52 template <typename Image> result_type operator()(Image& img) const { img.recreate(_dimensions,_alignment); }
53 };
54
55 template <typename AnyView> // Models AnyViewConcept
56 struct any_image_get_view {
57 typedef AnyView result_type;
58 template <typename Image> result_type operator()( Image& img) const { return result_type(view(img)); }
59 };
60
61 template <typename AnyConstView> // Models AnyConstViewConcept
62 struct any_image_get_const_view {
63 typedef AnyConstView result_type;
64 template <typename Image> result_type operator()(const Image& img) const { return result_type(const_view(img)); }
65 };
66 }
67
78 template <typename ImageTypes>
79 class any_image : public variant<ImageTypes> {
80 typedef variant<ImageTypes> parent_t;
81 public:
82 typedef any_image_view<typename detail::images_get_const_views_t<ImageTypes>::type> const_view_t;
83 typedef any_image_view<typename detail::images_get_views_t<ImageTypes>::type> view_t;
84 typedef std::ptrdiff_t x_coord_t;
85 typedef std::ptrdiff_t y_coord_t;
86 typedef point2<std::ptrdiff_t> point_t;
87
88 any_image() : parent_t() {}
89 template <typename T> explicit any_image(const T& obj) : parent_t(obj) {}
90 template <typename T> explicit any_image(T& obj, bool do_swap) : parent_t(obj,do_swap) {}
91 any_image(const any_image& v) : parent_t((const parent_t&)v) {}
92 template <typename Types> any_image(const any_image<Types>& v) : parent_t((const variant<Types>&)v) {}
93
94 template <typename T> any_image& operator=(const T& obj) { parent_t::operator=(obj); return *this; }
95 any_image& operator=(const any_image& v) { parent_t::operator=((const parent_t&)v); return *this;}
96 template <typename Types> any_image& operator=(const any_image<Types>& v) { parent_t::operator=((const variant<Types>&)v); return *this;}
97
98 void recreate(const point_t& dims, unsigned alignment=1) { apply_operation(*this,detail::recreate_image_fnobj(dims,alignment)); }
99 void recreate(x_coord_t width, y_coord_t height, unsigned alignment=1) { recreate(point2<std::ptrdiff_t>(width,height),alignment); }
100
101 std::size_t num_channels() const { return apply_operation(*this, detail::any_type_get_num_channels()); }
102 point_t dimensions() const { return apply_operation(*this, detail::any_type_get_dimensions()); }
103 x_coord_t width() const { return dimensions().x; }
104 y_coord_t height() const { return dimensions().y; }
105 };
106
110
112
114 template <typename Types> BOOST_FORCEINLINE // Models ImageVectorConcept
115 typename any_image<Types>::view_t view(any_image<Types>& anyImage) {
116 return apply_operation(anyImage, detail::any_image_get_view<typename any_image<Types>::view_t>());
117 }
118
120 template <typename Types> BOOST_FORCEINLINE // Models ImageVectorConcept
121 typename any_image<Types>::const_view_t const_view(const any_image<Types>& anyImage) {
122 return apply_operation(anyImage, detail::any_image_get_const_view<typename any_image<Types>::const_view_t>());
123 }
125
126 } } // namespace boost::gil
127
128 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
129 #pragma warning(pop)
130 #endif
131
132 //#ifdef _MSC_VER
133 //#pragma warning(pop)
134 //#endif
135
136 #endif
boost::gil::const_view
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:121
boost::gil::any_image
Represents a run-time specified image. Note it does NOT model ImageConcept.
Definition: any_image.hpp:79
boost::gil::apply_operation
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
boost::gil::variant
Represents a concrete instance of a run-time specified type from a set of typesA concept is typically...
Definition: variant.hpp:89
boost::gil::any_image_view
Represents a run-time specified image view. Models HasDynamicXStepTypeConcept, HasDynamicYStepTypeCon...
Definition: any_image_view.hpp:64
boost::gil::view
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:115
boost::gil::point2< std::ptrdiff_t >
boost::gil::num_channels
Returns the number of channels of a pixel-based GIL construct.
Definition: gil_concept.hpp:66
any_image_view.hpp
Support for run-time instantiated image view.