]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/gil/include/boost/gil/extension/dynamic_image/image_view_factory.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / gil / include / boost / gil / extension / dynamic_image / image_view_factory.hpp
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_IMAGE_VIEWS_HPP
14 #define GIL_DYNAMICIMAGE_IMAGE_VIEWS_HPP
15
16 /*!
17 /// \file
18 /// \brief Methods for constructing any image views from other any image views
19 /// \author Lubomir Bourdev and Hailin Jin \n
20 /// Adobe Systems Incorporated
21 /// \date 2005-2007 \n Last updated on January 31, 2007
22 /// Extends image view factory to runtime type-specified views (any_image_view)
23 */
24
25 #include "any_image_view.hpp"
26 #include "../../image_view_factory.hpp"
27
28 namespace boost { namespace gil {
29
30 namespace detail {
31 template <typename Result> struct flipped_up_down_view_fn {
32 typedef Result result_type;
33 template <typename View> result_type operator()(const View& src) const { return result_type(flipped_up_down_view(src)); }
34 };
35 template <typename Result> struct flipped_left_right_view_fn {
36 typedef Result result_type;
37 template <typename View> result_type operator()(const View& src) const { return result_type(flipped_left_right_view(src)); }
38 };
39 template <typename Result> struct rotated90cw_view_fn {
40 typedef Result result_type;
41 template <typename View> result_type operator()(const View& src) const { return result_type(rotated90cw_view(src)); }
42 };
43 template <typename Result> struct rotated90ccw_view_fn {
44 typedef Result result_type;
45 template <typename View> result_type operator()(const View& src) const { return result_type(rotated90ccw_view(src)); }
46 };
47 template <typename Result> struct tranposed_view_fn {
48 typedef Result result_type;
49 template <typename View> result_type operator()(const View& src) const { return result_type(tranposed_view(src)); }
50 };
51 template <typename Result> struct rotated180_view_fn {
52 typedef Result result_type;
53 template <typename View> result_type operator()(const View& src) const { return result_type(rotated180_view(src)); }
54 };
55 template <typename Result> struct subimage_view_fn {
56 typedef Result result_type;
57 subimage_view_fn(const point2<std::ptrdiff_t>& topleft, const point2<std::ptrdiff_t>& dimensions) : _topleft(topleft), _size2(dimensions) {}
58 point2<std::ptrdiff_t> _topleft,_size2;
59 template <typename View> result_type operator()(const View& src) const { return result_type(subimage_view(src,_topleft,_size2)); }
60 };
61 template <typename Result> struct subsampled_view_fn {
62 typedef Result result_type;
63 subsampled_view_fn(const point2<std::ptrdiff_t>& step) : _step(step) {}
64 point2<std::ptrdiff_t> _step;
65 template <typename View> result_type operator()(const View& src) const { return result_type(subsampled_view(src,_step)); }
66 };
67 template <typename Result> struct nth_channel_view_fn {
68 typedef Result result_type;
69 nth_channel_view_fn(int n) : _n(n) {}
70 int _n;
71 template <typename View> result_type operator()(const View& src) const { return result_type(nth_channel_view(src,_n)); }
72 };
73 template <typename DstP, typename Result, typename CC = default_color_converter> struct color_converted_view_fn {
74 typedef Result result_type;
75 color_converted_view_fn(CC cc = CC()): _cc(cc) {}
76
77 template <typename View> result_type operator()(const View& src) const { return result_type(color_converted_view<DstP>(src, _cc)); }
78
79 private:
80 CC _cc;
81 };
82 } // namespace detail
83
84
85 /// \ingroup ImageViewTransformationsFlipUD
86 template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
87 typename dynamic_y_step_type<any_image_view<ViewTypes> >::type flipped_up_down_view(const any_image_view<ViewTypes>& src) {
88 return apply_operation(src,detail::flipped_up_down_view_fn<typename dynamic_y_step_type<any_image_view<ViewTypes> >::type>());
89 }
90
91 /// \ingroup ImageViewTransformationsFlipLR
92 template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
93 typename dynamic_x_step_type<any_image_view<ViewTypes> >::type flipped_left_right_view(const any_image_view<ViewTypes>& src) {
94 return apply_operation(src,detail::flipped_left_right_view_fn<typename dynamic_x_step_type<any_image_view<ViewTypes> >::type>());
95 }
96
97 /// \ingroup ImageViewTransformationsTransposed
98 template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
99 typename dynamic_xy_step_transposed_type<any_image_view<ViewTypes> >::type transposed_view(const any_image_view<ViewTypes>& src) {
100 return apply_operation(src,detail::tranposed_view_fn<typename dynamic_xy_step_transposed_type<any_image_view<ViewTypes> >::type>());
101 }
102
103 /// \ingroup ImageViewTransformations90CW
104 template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
105 typename dynamic_xy_step_transposed_type<any_image_view<ViewTypes> >::type rotated90cw_view(const any_image_view<ViewTypes>& src) {
106 return apply_operation(src,detail::rotated90cw_view_fn<typename dynamic_xy_step_transposed_type<any_image_view<ViewTypes> >::type>());
107 }
108
109 /// \ingroup ImageViewTransformations90CCW
110 template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
111 typename dynamic_xy_step_transposed_type<any_image_view<ViewTypes> >::type rotated90ccw_view(const any_image_view<ViewTypes>& src) {
112 return apply_operation(src,detail::rotated90ccw_view_fn<typename dynamic_xy_step_transposed_type<any_image_view<ViewTypes> >::type>());
113 }
114
115 /// \ingroup ImageViewTransformations180
116 template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
117 typename dynamic_xy_step_type<any_image_view<ViewTypes> >::type rotated180_view(const any_image_view<ViewTypes>& src) {
118 return apply_operation(src,detail::rotated180_view_fn<typename dynamic_xy_step_type<any_image_view<ViewTypes> >::type>());
119 }
120
121 /// \ingroup ImageViewTransformationsSubimage
122 template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
123 any_image_view<ViewTypes> subimage_view(const any_image_view<ViewTypes>& src, const point2<std::ptrdiff_t>& topleft, const point2<std::ptrdiff_t>& dimensions) {
124 return apply_operation(src,detail::subimage_view_fn<any_image_view<ViewTypes> >(topleft,dimensions));
125 }
126
127 /// \ingroup ImageViewTransformationsSubimage
128 template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
129 any_image_view<ViewTypes> subimage_view(const any_image_view<ViewTypes>& src, int xMin, int yMin, int width, int height) {
130 return apply_operation(src,detail::subimage_view_fn<any_image_view<ViewTypes> >(point2<std::ptrdiff_t>(xMin,yMin),point2<std::ptrdiff_t>(width,height)));
131 }
132
133 /// \ingroup ImageViewTransformationsSubsampled
134 template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
135 typename dynamic_xy_step_type<any_image_view<ViewTypes> >::type subsampled_view(const any_image_view<ViewTypes>& src, const point2<std::ptrdiff_t>& step) {
136 return apply_operation(src,detail::subsampled_view_fn<typename dynamic_xy_step_type<any_image_view<ViewTypes> >::type>(step));
137 }
138
139 /// \ingroup ImageViewTransformationsSubsampled
140 template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
141 typename dynamic_xy_step_type<any_image_view<ViewTypes> >::type subsampled_view(const any_image_view<ViewTypes>& src, int xStep, int yStep) {
142 return apply_operation(src,detail::subsampled_view_fn<typename dynamic_xy_step_type<any_image_view<ViewTypes> >::type>(point2<std::ptrdiff_t>(xStep,yStep)));
143 }
144
145 namespace detail {
146 template <typename View> struct get_nthchannel_type { typedef typename nth_channel_view_type<View>::type type; };
147 template <typename Views> struct views_get_nthchannel_type : public mpl::transform<Views, get_nthchannel_type<mpl::_1> > {};
148 }
149
150 /// \ingroup ImageViewTransformationsNthChannel
151 /// \brief Given a runtime source image view, returns the type of a runtime image view over a single channel of the source view
152 template <typename ViewTypes>
153 struct nth_channel_view_type<any_image_view<ViewTypes> > {
154 typedef any_image_view<typename detail::views_get_nthchannel_type<ViewTypes>::type> type;
155 };
156
157 /// \ingroup ImageViewTransformationsNthChannel
158 template <typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
159 typename nth_channel_view_type<any_image_view<ViewTypes> >::type nth_channel_view(const any_image_view<ViewTypes>& src, int n) {
160 return apply_operation(src,detail::nth_channel_view_fn<typename nth_channel_view_type<any_image_view<ViewTypes> >::type>(n));
161 }
162
163 namespace detail {
164 template <typename View, typename DstP, typename CC> struct get_ccv_type : public color_converted_view_type<View, DstP, CC> {};
165 template <typename Views, typename DstP, typename CC> struct views_get_ccv_type : public mpl::transform<Views, get_ccv_type<mpl::_1,DstP,CC> > {};
166 }
167
168 /// \ingroup ImageViewTransformationsColorConvert
169 /// \brief Returns the type of a runtime-specified view, color-converted to a given pixel type with user specified color converter
170 template <typename ViewTypes, typename DstP, typename CC>
171 struct color_converted_view_type<any_image_view<ViewTypes>,DstP,CC> {
172 typedef any_image_view<typename detail::views_get_ccv_type<ViewTypes, DstP, CC>::type> type;
173 };
174
175 /// \ingroup ImageViewTransformationsColorConvert
176 /// \brief overload of generic color_converted_view with user defined color-converter
177 template <typename DstP, typename ViewTypes, typename CC> inline // Models MPL Random Access Container of models of ImageViewConcept
178 typename color_converted_view_type<any_image_view<ViewTypes>, DstP, CC>::type color_converted_view(const any_image_view<ViewTypes>& src,CC cc) {
179 return apply_operation(src,detail::color_converted_view_fn<DstP,typename color_converted_view_type<any_image_view<ViewTypes>, DstP, CC>::type >());
180 }
181
182 /// \ingroup ImageViewTransformationsColorConvert
183 /// \brief Returns the type of a runtime-specified view, color-converted to a given pixel type with the default coor converter
184 template <typename ViewTypes, typename DstP>
185 struct color_converted_view_type<any_image_view<ViewTypes>,DstP> {
186 typedef any_image_view<typename detail::views_get_ccv_type<ViewTypes, DstP, default_color_converter>::type> type;
187 };
188
189 /// \ingroup ImageViewTransformationsColorConvert
190 /// \brief overload of generic color_converted_view with the default color-converter
191 template <typename DstP, typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
192 typename color_converted_view_type<any_image_view<ViewTypes>, DstP>::type color_converted_view(const any_image_view<ViewTypes>& src) {
193 return apply_operation(src,detail::color_converted_view_fn<DstP,typename color_converted_view_type<any_image_view<ViewTypes>, DstP>::type >());
194 }
195
196
197 /// \ingroup ImageViewTransformationsColorConvert
198 /// \brief overload of generic color_converted_view with user defined color-converter
199 /// These are workarounds for GCC 3.4, which thinks color_converted_view is ambiguous with the same method for templated views (in gil/image_view_factory.hpp)
200 template <typename DstP, typename ViewTypes, typename CC> inline // Models MPL Random Access Container of models of ImageViewConcept
201 typename color_converted_view_type<any_image_view<ViewTypes>, DstP, CC>::type any_color_converted_view(const any_image_view<ViewTypes>& src,CC cc) {
202 return apply_operation(src,detail::color_converted_view_fn<DstP,typename color_converted_view_type<any_image_view<ViewTypes>, DstP, CC>::type >());
203 }
204
205 /// \ingroup ImageViewTransformationsColorConvert
206 /// \brief overload of generic color_converted_view with the default color-converter
207 /// These are workarounds for GCC 3.4, which thinks color_converted_view is ambiguous with the same method for templated views (in gil/image_view_factory.hpp)
208 template <typename DstP, typename ViewTypes> inline // Models MPL Random Access Container of models of ImageViewConcept
209 typename color_converted_view_type<any_image_view<ViewTypes>, DstP>::type any_color_converted_view(const any_image_view<ViewTypes>& src) {
210 return apply_operation(src,detail::color_converted_view_fn<DstP,typename color_converted_view_type<any_image_view<ViewTypes>, DstP>::type >());
211 }
212
213 /// \}
214
215 } } // namespace boost::gil
216
217 #endif