Chris@16
|
1 /*
|
Chris@16
|
2 Copyright 2005-2007 Adobe Systems Incorporated
|
Chris@16
|
3
|
Chris@16
|
4 Use, modification and distribution are subject to the Boost Software License,
|
Chris@16
|
5 Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
6 http://www.boost.org/LICENSE_1_0.txt).
|
Chris@16
|
7
|
Chris@16
|
8 See http://opensource.adobe.com/gil for most recent version including documentation.
|
Chris@16
|
9 */
|
Chris@16
|
10
|
Chris@16
|
11 /*************************************************************************************************/
|
Chris@16
|
12
|
Chris@16
|
13 #ifndef GIL_METAFUNCTIONS_HPP
|
Chris@16
|
14 #define GIL_METAFUNCTIONS_HPP
|
Chris@16
|
15
|
Chris@16
|
16 ////////////////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
17 /// \file
|
Chris@16
|
18 /// \brief metafunctions that construct types or return type properties
|
Chris@16
|
19 /// \author Lubomir Bourdev and Hailin Jin \n
|
Chris@16
|
20 /// Adobe Systems Incorporated
|
Chris@16
|
21 ///
|
Chris@16
|
22 /// \date 2005-2007 \n Last updated on February 6, 2007
|
Chris@16
|
23 ///
|
Chris@16
|
24 ////////////////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
25
|
Chris@16
|
26 #include <iterator>
|
Chris@16
|
27 #include <boost/mpl/accumulate.hpp>
|
Chris@16
|
28 #include <boost/mpl/back.hpp>
|
Chris@16
|
29 #include <boost/mpl/bool.hpp>
|
Chris@16
|
30 #include <boost/mpl/if.hpp>
|
Chris@16
|
31 #include <boost/mpl/pop_back.hpp>
|
Chris@16
|
32 #include <boost/mpl/push_back.hpp>
|
Chris@16
|
33 #include <boost/mpl/transform.hpp>
|
Chris@16
|
34 #include <boost/mpl/vector.hpp>
|
Chris@16
|
35 #include <boost/type_traits.hpp>
|
Chris@16
|
36 #include "gil_config.hpp"
|
Chris@16
|
37 #include "gil_concept.hpp"
|
Chris@16
|
38 #include "channel.hpp"
|
Chris@16
|
39
|
Chris@16
|
40 namespace boost { namespace gil {
|
Chris@16
|
41
|
Chris@16
|
42 // forward declarations
|
Chris@16
|
43 template <typename T, typename L> struct pixel;
|
Chris@16
|
44 template <typename BitField,typename ChannelRefVec,typename Layout> struct packed_pixel;
|
Chris@16
|
45 template <typename T, typename C> struct planar_pixel_reference;
|
Chris@16
|
46 template <typename IC, typename C> struct planar_pixel_iterator;
|
Chris@16
|
47 template <typename I> class memory_based_step_iterator;
|
Chris@16
|
48 template <typename I> class memory_based_2d_locator;
|
Chris@16
|
49 template <typename L> class image_view;
|
Chris@16
|
50 template <typename Pixel, bool IsPlanar, typename Alloc> class image;
|
Chris@16
|
51 template <typename T> struct channel_type;
|
Chris@16
|
52 template <typename T> struct color_space_type;
|
Chris@16
|
53 template <typename T> struct channel_mapping_type;
|
Chris@16
|
54 template <typename It> struct is_iterator_adaptor;
|
Chris@16
|
55 template <typename It> struct iterator_adaptor_get_base;
|
Chris@16
|
56 template <typename BitField, typename ChannelBitSizes, typename Layout, bool IsMutable> struct bit_aligned_pixel_reference;
|
Chris@16
|
57
|
Chris@16
|
58 //////////////////////////////////////////////////
|
Chris@16
|
59 ///
|
Chris@16
|
60 /// TYPE ANALYSIS METAFUNCTIONS
|
Chris@16
|
61 /// Predicate metafunctions determining properties of GIL types
|
Chris@16
|
62 ///
|
Chris@16
|
63 //////////////////////////////////////////////////
|
Chris@16
|
64
|
Chris@16
|
65
|
Chris@16
|
66 /// \defgroup GILIsBasic xxx_is_basic
|
Chris@16
|
67 /// \ingroup TypeAnalysis
|
Chris@16
|
68 /// \brief Determines if GIL constructs are basic.
|
Chris@16
|
69 /// Basic constructs are the ones that can be generated with the type
|
Chris@16
|
70 /// factory methods pixel_reference_type, iterator_type, locator_type, view_type and image_type
|
Chris@16
|
71 /// They can be mutable/immutable, planar/interleaved, step/nonstep. They must use GIL-provided models.
|
Chris@16
|
72
|
Chris@16
|
73 /// \brief Determines if a given pixel reference is basic
|
Chris@16
|
74 /// Basic references must use gil::pixel& (if interleaved), gil::planar_pixel_reference (if planar). They must use the standard constness rules.
|
Chris@16
|
75 /// \ingroup GILIsBasic
|
Chris@16
|
76 template <typename PixelRef> struct pixel_reference_is_basic : public mpl::false_ {};
|
Chris@16
|
77 template <typename T, typename L> struct pixel_reference_is_basic< pixel<T,L>&> : public mpl::true_ {};
|
Chris@16
|
78 template <typename T, typename L> struct pixel_reference_is_basic<const pixel<T,L>&> : public mpl::true_ {};
|
Chris@16
|
79 template <typename TR, typename Cs> struct pixel_reference_is_basic<planar_pixel_reference<TR,Cs> > : public mpl::true_ {};
|
Chris@16
|
80 template <typename TR, typename Cs> struct pixel_reference_is_basic<const planar_pixel_reference<TR,Cs> > : public mpl::true_ {};
|
Chris@16
|
81
|
Chris@16
|
82
|
Chris@16
|
83 /// \brief Determines if a given pixel iterator is basic
|
Chris@16
|
84 /// Basic iterators must use gil::pixel (if interleaved), gil::planar_pixel_iterator (if planar) and gil::memory_based_step_iterator (if step). They must use the standard constness rules.
|
Chris@16
|
85 /// \ingroup GILIsBasic
|
Chris@16
|
86 template <typename Iterator>
|
Chris@16
|
87 struct iterator_is_basic : public mpl::false_ {};
|
Chris@16
|
88 template <typename T, typename L> // mutable interleaved
|
Chris@16
|
89 struct iterator_is_basic< pixel<T,L>* > : public mpl::true_ {};
|
Chris@16
|
90 template <typename T, typename L> // immutable interleaved
|
Chris@16
|
91 struct iterator_is_basic<const pixel<T,L>* > : public mpl::true_ {};
|
Chris@16
|
92 template <typename T, typename Cs> // mutable planar
|
Chris@16
|
93 struct iterator_is_basic<planar_pixel_iterator< T*,Cs> > : public mpl::true_ {};
|
Chris@16
|
94 template <typename T, typename Cs> // immutable planar
|
Chris@16
|
95 struct iterator_is_basic<planar_pixel_iterator<const T*,Cs> > : public mpl::true_ {};
|
Chris@16
|
96 template <typename T, typename L> // mutable interleaved step
|
Chris@16
|
97 struct iterator_is_basic<memory_based_step_iterator< pixel<T,L>*> > : public mpl::true_ {};
|
Chris@16
|
98 template <typename T, typename L> // immutable interleaved step
|
Chris@16
|
99 struct iterator_is_basic<memory_based_step_iterator<const pixel<T,L>*> > : public mpl::true_ {};
|
Chris@16
|
100 template <typename T, typename Cs> // mutable planar step
|
Chris@16
|
101 struct iterator_is_basic<memory_based_step_iterator<planar_pixel_iterator< T*,Cs> > > : public mpl::true_ {};
|
Chris@16
|
102 template <typename T, typename Cs> // immutable planar step
|
Chris@16
|
103 struct iterator_is_basic<memory_based_step_iterator<planar_pixel_iterator<const T*,Cs> > > : public mpl::true_ {};
|
Chris@16
|
104
|
Chris@16
|
105
|
Chris@16
|
106 /// \ingroup GILIsBasic
|
Chris@16
|
107 /// \brief Determines if a given locator is basic. A basic locator is memory-based and has basic x_iterator and y_iterator
|
Chris@16
|
108 template <typename Loc> struct locator_is_basic : public mpl::false_ {};
|
Chris@16
|
109 template <typename Iterator> struct locator_is_basic<memory_based_2d_locator<memory_based_step_iterator<Iterator> > > : public iterator_is_basic<Iterator> {};
|
Chris@16
|
110
|
Chris@16
|
111 /// \ingroup GILIsBasic
|
Chris@16
|
112 /// \brief Basic views must be over basic locators
|
Chris@16
|
113 template <typename View> struct view_is_basic : public mpl::false_ {};
|
Chris@16
|
114 template <typename Loc> struct view_is_basic<image_view<Loc> > : public locator_is_basic<Loc> {};
|
Chris@16
|
115
|
Chris@16
|
116 /// \ingroup GILIsBasic
|
Chris@16
|
117 /// \brief Basic images must use basic views and std::allocator of char
|
Chris@16
|
118 template <typename Img> struct image_is_basic : public mpl::false_ {};
|
Chris@16
|
119 template <typename Pixel, bool IsPlanar, typename Alloc> struct image_is_basic<image<Pixel,IsPlanar,Alloc> > : public mpl::true_ {};
|
Chris@16
|
120
|
Chris@16
|
121
|
Chris@16
|
122 /// \defgroup GILIsStep xxx_is_step
|
Chris@16
|
123 /// \ingroup TypeAnalysis
|
Chris@16
|
124 /// \brief Determines if the given iterator/locator/view has a step that could be set dynamically
|
Chris@16
|
125
|
Chris@16
|
126 template <typename I> struct iterator_is_step;
|
Chris@16
|
127 namespace detail {
|
Chris@16
|
128 template <typename It, bool IsBase, bool EqualsStepType> struct iterator_is_step_impl;
|
Chris@16
|
129 // iterator that has the same type as its dynamic_x_step_type must be a step iterator
|
Chris@16
|
130 template <typename It, bool IsBase> struct iterator_is_step_impl<It,IsBase,true> : public mpl::true_{};
|
Chris@16
|
131
|
Chris@16
|
132 // base iterator can never be a step iterator
|
Chris@16
|
133 template <typename It> struct iterator_is_step_impl<It,true,false> : public mpl::false_{};
|
Chris@16
|
134
|
Chris@16
|
135 // for an iterator adaptor, see if its base is step
|
Chris@16
|
136 template <typename It> struct iterator_is_step_impl<It,false,false>
|
Chris@16
|
137 : public iterator_is_step<typename iterator_adaptor_get_base<It>::type>{};
|
Chris@16
|
138 }
|
Chris@16
|
139
|
Chris@16
|
140 /// \ingroup GILIsStep
|
Chris@16
|
141 /// \brief Determines if the given iterator has a step that could be set dynamically
|
Chris@16
|
142 template <typename I> struct iterator_is_step
|
Chris@16
|
143 : public detail::iterator_is_step_impl<I,
|
Chris@16
|
144 !is_iterator_adaptor<I>::type::value,
|
Chris@16
|
145 is_same<I,typename dynamic_x_step_type<I>::type>::value >{};
|
Chris@16
|
146
|
Chris@16
|
147 /// \ingroup GILIsStep
|
Chris@16
|
148 /// \brief Determines if the given locator has a horizontal step that could be set dynamically
|
Chris@16
|
149 template <typename L> struct locator_is_step_in_x : public iterator_is_step<typename L::x_iterator> {};
|
Chris@16
|
150
|
Chris@16
|
151 /// \ingroup GILIsStep
|
Chris@16
|
152 /// \brief Determines if the given locator has a vertical step that could be set dynamically
|
Chris@16
|
153 template <typename L> struct locator_is_step_in_y : public iterator_is_step<typename L::y_iterator> {};
|
Chris@16
|
154
|
Chris@16
|
155 /// \ingroup GILIsStep
|
Chris@16
|
156 /// \brief Determines if the given view has a horizontal step that could be set dynamically
|
Chris@16
|
157 template <typename V> struct view_is_step_in_x : public locator_is_step_in_x<typename V::xy_locator> {};
|
Chris@16
|
158
|
Chris@16
|
159 /// \ingroup GILIsStep
|
Chris@16
|
160 /// \brief Determines if the given view has a vertical step that could be set dynamically
|
Chris@16
|
161 template <typename V> struct view_is_step_in_y : public locator_is_step_in_y<typename V::xy_locator> {};
|
Chris@16
|
162
|
Chris@16
|
163 /// \brief Determines whether the given pixel reference is a proxy class or a native C++ reference
|
Chris@16
|
164 /// \ingroup TypeAnalysis
|
Chris@16
|
165 template <typename PixelReference>
|
Chris@16
|
166 struct pixel_reference_is_proxy
|
Chris@16
|
167 : public mpl::not_<is_same<typename remove_const_and_reference<PixelReference>::type,
|
Chris@16
|
168 typename remove_const_and_reference<PixelReference>::type::value_type> > {};
|
Chris@16
|
169
|
Chris@16
|
170 /// \brief Given a model of a pixel, determines whether the model represents a pixel reference (as opposed to pixel value)
|
Chris@16
|
171 /// \ingroup TypeAnalysis
|
Chris@16
|
172 template <typename Pixel>
|
Chris@16
|
173 struct pixel_is_reference : public mpl::or_<is_reference<Pixel>, pixel_reference_is_proxy<Pixel> > {};
|
Chris@16
|
174
|
Chris@16
|
175 /// \defgroup GILIsMutable xxx_is_mutable
|
Chris@16
|
176 /// \ingroup TypeAnalysis
|
Chris@16
|
177 /// \brief Determines if the given pixel reference/iterator/locator/view is mutable (i.e. its pixels can be changed)
|
Chris@16
|
178
|
Chris@16
|
179 /// \ingroup GILIsMutable
|
Chris@16
|
180 /// \brief Determines if the given pixel reference is mutable (i.e. its channels can be changed)
|
Chris@16
|
181 ///
|
Chris@16
|
182 /// Note that built-in C++ references obey the const qualifier but reference proxy classes do not.
|
Chris@16
|
183 template <typename R> struct pixel_reference_is_mutable : public mpl::bool_<remove_reference<R>::type::is_mutable> {};
|
Chris@16
|
184 template <typename R> struct pixel_reference_is_mutable<const R&>
|
Chris@16
|
185 : public mpl::and_<pixel_reference_is_proxy<R>, pixel_reference_is_mutable<R> > {};
|
Chris@16
|
186
|
Chris@16
|
187 /// \ingroup GILIsMutable
|
Chris@16
|
188 /// \brief Determines if the given locator is mutable (i.e. its pixels can be changed)
|
Chris@16
|
189 template <typename L> struct locator_is_mutable : public iterator_is_mutable<typename L::x_iterator> {};
|
Chris@16
|
190 /// \ingroup GILIsMutable
|
Chris@16
|
191 /// \brief Determines if the given view is mutable (i.e. its pixels can be changed)
|
Chris@16
|
192 template <typename V> struct view_is_mutable : public iterator_is_mutable<typename V::x_iterator> {};
|
Chris@16
|
193
|
Chris@16
|
194
|
Chris@16
|
195 //////////////////////////////////////////////////
|
Chris@16
|
196 ///
|
Chris@16
|
197 /// TYPE FACTORY METAFUNCTIONS
|
Chris@16
|
198 /// Metafunctions returning GIL types from other GIL types
|
Chris@16
|
199 ///
|
Chris@16
|
200 //////////////////////////////////////////////////
|
Chris@16
|
201
|
Chris@16
|
202 /// \defgroup TypeFactoryFromElements xxx_type
|
Chris@16
|
203 /// \ingroup TypeFactory
|
Chris@16
|
204 /// \brief Returns the type of a homogeneous GIL construct given its elements (channel, layout, whether it is planar, step, mutable, etc.)
|
Chris@16
|
205
|
Chris@16
|
206 /// \defgroup TypeFactoryFromPixel xxx_type_from_pixel
|
Chris@16
|
207 /// \ingroup TypeFactory
|
Chris@16
|
208 /// \brief Returns the type of a GIL construct given its pixel type, whether it is planar, step, mutable, etc.
|
Chris@16
|
209
|
Chris@16
|
210 /// \defgroup TypeFactoryDerived derived_xxx_type
|
Chris@16
|
211 /// \ingroup TypeFactory
|
Chris@16
|
212 /// \brief Returns the type of a homogeneous GIL construct given a related construct by changing some of its properties
|
Chris@16
|
213
|
Chris@16
|
214 /// \ingroup TypeFactoryFromElements
|
Chris@16
|
215 /// \brief Returns the type of a homogeneous pixel reference given the channel type, layout, whether it operates on planar data and whether it is mutable
|
Chris@16
|
216 template <typename T, typename L, bool IsPlanar=false, bool IsMutable=true> struct pixel_reference_type{};
|
Chris@16
|
217 template <typename T, typename L> struct pixel_reference_type<T,L,false,true > { typedef pixel<T,L>& type; };
|
Chris@16
|
218 template <typename T, typename L> struct pixel_reference_type<T,L,false,false> { typedef const pixel<T,L>& type; };
|
Chris@16
|
219 template <typename T, typename L> struct pixel_reference_type<T,L,true,true> { typedef const planar_pixel_reference<typename channel_traits<T>::reference,typename color_space_type<L>::type> type; }; // TODO: Assert M=identity
|
Chris@16
|
220 template <typename T, typename L> struct pixel_reference_type<T,L,true,false> { typedef const planar_pixel_reference<typename channel_traits<T>::const_reference,typename color_space_type<L>::type> type; };// TODO: Assert M=identity
|
Chris@16
|
221
|
Chris@16
|
222 /// \ingroup TypeFactoryFromPixel
|
Chris@16
|
223 /// \brief Returns the type of a pixel iterator given the pixel type, whether it operates on planar data, whether it is a step iterator, and whether it is mutable
|
Chris@16
|
224 template <typename Pixel, bool IsPlanar=false, bool IsStep=false, bool IsMutable=true> struct iterator_type_from_pixel{};
|
Chris@16
|
225 template <typename Pixel> struct iterator_type_from_pixel<Pixel,false,false,true > { typedef Pixel* type; };
|
Chris@16
|
226 template <typename Pixel> struct iterator_type_from_pixel<Pixel,false,false,false> { typedef const Pixel* type; };
|
Chris@16
|
227 template <typename Pixel> struct iterator_type_from_pixel<Pixel,true,false,true> {
|
Chris@16
|
228 typedef planar_pixel_iterator<typename channel_traits<typename channel_type<Pixel>::type>::pointer,typename color_space_type<Pixel>::type> type;
|
Chris@16
|
229 };
|
Chris@16
|
230 template <typename Pixel> struct iterator_type_from_pixel<Pixel,true,false,false> {
|
Chris@16
|
231 typedef planar_pixel_iterator<typename channel_traits<typename channel_type<Pixel>::type>::const_pointer,typename color_space_type<Pixel>::type> type;
|
Chris@16
|
232 };
|
Chris@16
|
233 template <typename Pixel, bool IsPlanar, bool IsMutable> struct iterator_type_from_pixel<Pixel,IsPlanar,true,IsMutable> {
|
Chris@16
|
234 typedef memory_based_step_iterator<typename iterator_type_from_pixel<Pixel,IsPlanar,false,IsMutable>::type> type;
|
Chris@16
|
235 };
|
Chris@16
|
236
|
Chris@16
|
237 /// \ingroup TypeFactoryFromElements
|
Chris@16
|
238 /// \brief Returns the type of a homogeneous iterator given the channel type, layout, whether it operates on planar data, whether it is a step iterator, and whether it is mutable
|
Chris@16
|
239 template <typename T, typename L, bool IsPlanar=false, bool IsStep=false, bool IsMutable=true> struct iterator_type{};
|
Chris@16
|
240 template <typename T, typename L> struct iterator_type<T,L,false,false,true > { typedef pixel<T,L>* type; };
|
Chris@16
|
241 template <typename T, typename L> struct iterator_type<T,L,false,false,false> { typedef const pixel<T,L>* type; };
|
Chris@16
|
242 template <typename T, typename L> struct iterator_type<T,L,true,false,true> { typedef planar_pixel_iterator<T*,typename L::color_space_t> type; }; // TODO: Assert M=identity
|
Chris@16
|
243 template <typename T, typename L> struct iterator_type<T,L,true,false,false> { typedef planar_pixel_iterator<const T*,typename L::color_space_t> type; }; // TODO: Assert M=identity
|
Chris@16
|
244 template <typename T, typename L, bool IsPlanar, bool IsMutable> struct iterator_type<T,L,IsPlanar,true,IsMutable> {
|
Chris@16
|
245 typedef memory_based_step_iterator<typename iterator_type<T,L,IsPlanar,false,IsMutable>::type> type;
|
Chris@16
|
246 };
|
Chris@16
|
247
|
Chris@16
|
248 /// \brief Given a pixel iterator defining access to pixels along a row, returns the types of the corresponding built-in step_iterator, xy_locator, image_view
|
Chris@16
|
249 /// \ingroup TypeFactory
|
Chris@16
|
250 template <typename XIterator>
|
Chris@16
|
251 struct type_from_x_iterator {
|
Chris@16
|
252 typedef memory_based_step_iterator<XIterator> step_iterator_t;
|
Chris@16
|
253 typedef memory_based_2d_locator<step_iterator_t> xy_locator_t;
|
Chris@16
|
254 typedef image_view<xy_locator_t> view_t;
|
Chris@16
|
255 };
|
Chris@16
|
256
|
Chris@16
|
257 namespace detail {
|
Chris@16
|
258 template <typename BitField, typename FirstBit, typename NumBits>
|
Chris@16
|
259 struct packed_channel_reference_type {
|
Chris@16
|
260 typedef const packed_channel_reference<BitField,FirstBit::value,NumBits::value,true> type;
|
Chris@16
|
261 };
|
Chris@16
|
262
|
Chris@16
|
263 template <typename BitField, typename ChannelBitSizesVector>
|
Chris@16
|
264 class packed_channel_references_vector_type {
|
Chris@16
|
265 // If ChannelBitSizesVector is mpl::vector<int,7,7,2>
|
Chris@16
|
266 // Then first_bits_vector will be mpl::vector<int,0,7,14,16>
|
Chris@16
|
267 typedef typename mpl::accumulate<ChannelBitSizesVector, mpl::vector1<mpl::int_<0> >,
|
Chris@16
|
268 mpl::push_back<mpl::_1, mpl::plus<mpl::back<mpl::_1>, mpl::_2> > >::type first_bits_vector;
|
Chris@16
|
269 public:
|
Chris@16
|
270 typedef typename mpl::transform<typename mpl::pop_back<first_bits_vector>::type, ChannelBitSizesVector,
|
Chris@16
|
271 packed_channel_reference_type<BitField, mpl::_1,mpl::_2> >::type type;
|
Chris@16
|
272 };
|
Chris@16
|
273
|
Chris@16
|
274 }
|
Chris@16
|
275
|
Chris@16
|
276 /// \ingroup TypeFactoryFromElements
|
Chris@16
|
277 /// \brief Returns the type of a packed pixel given its bitfield type, the bit size of its channels and its layout.
|
Chris@16
|
278 ///
|
Chris@16
|
279 /// A packed pixel has channels that cover bit ranges but itself is byte aligned. RGB565 pixel is an example.
|
Chris@16
|
280 ///
|
Chris@16
|
281 /// The size of ChannelBitSizeVector must equal the number of channels in the given layout
|
Chris@16
|
282 /// The sum of bit sizes for all channels must be less than or equal to the number of bits in BitField (and cannot exceed 64).
|
Chris@16
|
283 /// If it is less than the number of bits in BitField, the last bits will be unused.
|
Chris@16
|
284 template <typename BitField, typename ChannelBitSizeVector, typename Layout>
|
Chris@16
|
285 struct packed_pixel_type {
|
Chris@16
|
286 typedef packed_pixel<BitField, typename detail::packed_channel_references_vector_type<BitField,ChannelBitSizeVector>::type, Layout> type;
|
Chris@16
|
287 };
|
Chris@16
|
288
|
Chris@16
|
289 /// \defgroup TypeFactoryPacked packed_image_type,bit_aligned_image_type
|
Chris@16
|
290 /// \ingroup TypeFactoryFromElements
|
Chris@16
|
291 /// \brief Returns the type of an image whose channels are not byte-aligned.
|
Chris@16
|
292 ///
|
Chris@16
|
293 /// A packed image is an image whose pixels are byte aligned, such as "rgb565". <br>
|
Chris@16
|
294 /// A bit-aligned image is an image whose pixels are not byte aligned, such as "rgb222". <br>
|
Chris@16
|
295 ///
|
Chris@16
|
296 /// The sum of the bit sizes of all channels cannot exceed 64.
|
Chris@16
|
297
|
Chris@16
|
298 /// \ingroup TypeFactoryPacked
|
Chris@16
|
299 /// \brief Returns the type of an interleaved packed image: an image whose channels may not be byte-aligned, but whose pixels are byte aligned.
|
Chris@16
|
300 template <typename BitField, typename ChannelBitSizeVector, typename Layout, typename Alloc=std::allocator<unsigned char> >
|
Chris@16
|
301 struct packed_image_type {
|
Chris@16
|
302 typedef image<typename packed_pixel_type<BitField,ChannelBitSizeVector,Layout>::type,false,Alloc> type;
|
Chris@16
|
303 };
|
Chris@16
|
304
|
Chris@16
|
305 /// \ingroup TypeFactoryPacked
|
Chris@16
|
306 /// \brief Returns the type of a single-channel image given its bitfield type, the bit size of its channel and its layout
|
Chris@16
|
307 template <typename BitField, unsigned Size1, typename Layout, typename Alloc=std::allocator<unsigned char> >
|
Chris@16
|
308 struct packed_image1_type : public packed_image_type<BitField, mpl::vector1_c<unsigned, Size1>, Layout, Alloc> {};
|
Chris@16
|
309
|
Chris@16
|
310 /// \ingroup TypeFactoryPacked
|
Chris@16
|
311 /// \brief Returns the type of a two channel image given its bitfield type, the bit size of its channels and its layout
|
Chris@16
|
312 template <typename BitField, unsigned Size1, unsigned Size2, typename Layout, typename Alloc=std::allocator<unsigned char> >
|
Chris@16
|
313 struct packed_image2_type : public packed_image_type<BitField, mpl::vector2_c<unsigned, Size1, Size2>, Layout, Alloc> {};
|
Chris@16
|
314
|
Chris@16
|
315 /// \ingroup TypeFactoryPacked
|
Chris@16
|
316 /// \brief Returns the type of a three channel image given its bitfield type, the bit size of its channels and its layout
|
Chris@16
|
317 template <typename BitField, unsigned Size1, unsigned Size2, unsigned Size3, typename Layout, typename Alloc=std::allocator<unsigned char> >
|
Chris@16
|
318 struct packed_image3_type : public packed_image_type<BitField, mpl::vector3_c<unsigned, Size1, Size2, Size3>, Layout, Alloc> {};
|
Chris@16
|
319
|
Chris@16
|
320 /// \ingroup TypeFactoryPacked
|
Chris@16
|
321 /// \brief Returns the type of a four channel image given its bitfield type, the bit size of its channels and its layout
|
Chris@16
|
322 template <typename BitField, unsigned Size1, unsigned Size2, unsigned Size3, unsigned Size4, typename Layout, typename Alloc=std::allocator<unsigned char> >
|
Chris@16
|
323 struct packed_image4_type : public packed_image_type<BitField, mpl::vector4_c<unsigned, Size1, Size2, Size3, Size4>, Layout, Alloc> {};
|
Chris@16
|
324
|
Chris@16
|
325 /// \ingroup TypeFactoryPacked
|
Chris@16
|
326 /// \brief Returns the type of a five channel image given its bitfield type, the bit size of its channels and its layout
|
Chris@16
|
327 template <typename BitField, unsigned Size1, unsigned Size2, unsigned Size3, unsigned Size4, unsigned Size5, typename Layout, typename Alloc=std::allocator<unsigned char> >
|
Chris@16
|
328 struct packed_image5_type : public packed_image_type<BitField, mpl::vector5_c<unsigned, Size1, Size2, Size3, Size4, Size5>, Layout, Alloc> {};
|
Chris@16
|
329
|
Chris@16
|
330
|
Chris@16
|
331 /// \ingroup TypeFactoryPacked
|
Chris@16
|
332 /// \brief Returns the type of a packed image whose pixels may not be byte aligned. For example, an "rgb222" image is bit-aligned because its pixel spans six bits.
|
Chris@16
|
333 ///
|
Chris@16
|
334 /// Note that the alignment parameter in the constructor of bit-aligned images is in bit units. For example, if you want to construct a bit-aligned
|
Chris@16
|
335 /// image whose rows are byte-aligned, use 8 as the alignment parameter, not 1.
|
Chris@16
|
336
|
Chris@16
|
337 template <typename ChannelBitSizeVector, typename Layout, typename Alloc=std::allocator<unsigned char> >
|
Chris@16
|
338 struct bit_aligned_image_type {
|
Chris@16
|
339 private:
|
Chris@16
|
340 BOOST_STATIC_CONSTANT(int, bit_size = (mpl::accumulate<ChannelBitSizeVector, mpl::int_<0>, mpl::plus<mpl::_1, mpl::_2> >::type::value));
|
Chris@16
|
341 typedef typename detail::min_fast_uint<bit_size+7>::type bitfield_t;
|
Chris@16
|
342 typedef const bit_aligned_pixel_reference<bitfield_t, ChannelBitSizeVector, Layout, true> bit_alignedref_t;
|
Chris@16
|
343 public:
|
Chris@16
|
344 typedef image<bit_alignedref_t,false,Alloc> type;
|
Chris@16
|
345 };
|
Chris@16
|
346
|
Chris@16
|
347 /// \ingroup TypeFactoryPacked
|
Chris@16
|
348 /// \brief Returns the type of a single-channel bit-aligned image given the bit size of its channel and its layout
|
Chris@16
|
349 template <unsigned Size1, typename Layout, typename Alloc=std::allocator<unsigned char> >
|
Chris@16
|
350 struct bit_aligned_image1_type : public bit_aligned_image_type<mpl::vector1_c<unsigned, Size1>, Layout, Alloc> {};
|
Chris@16
|
351
|
Chris@16
|
352 /// \ingroup TypeFactoryPacked
|
Chris@16
|
353 /// \brief Returns the type of a two channel bit-aligned image given the bit size of its channels and its layout
|
Chris@16
|
354 template <unsigned Size1, unsigned Size2, typename Layout, typename Alloc=std::allocator<unsigned char> >
|
Chris@16
|
355 struct bit_aligned_image2_type : public bit_aligned_image_type<mpl::vector2_c<unsigned, Size1, Size2>, Layout, Alloc> {};
|
Chris@16
|
356
|
Chris@16
|
357 /// \ingroup TypeFactoryPacked
|
Chris@16
|
358 /// \brief Returns the type of a three channel bit-aligned image given the bit size of its channels and its layout
|
Chris@16
|
359 template <unsigned Size1, unsigned Size2, unsigned Size3, typename Layout, typename Alloc=std::allocator<unsigned char> >
|
Chris@16
|
360 struct bit_aligned_image3_type : public bit_aligned_image_type<mpl::vector3_c<unsigned, Size1, Size2, Size3>, Layout, Alloc> {};
|
Chris@16
|
361
|
Chris@16
|
362 /// \ingroup TypeFactoryPacked
|
Chris@16
|
363 /// \brief Returns the type of a four channel bit-aligned image given the bit size of its channels and its layout
|
Chris@16
|
364 template <unsigned Size1, unsigned Size2, unsigned Size3, unsigned Size4, typename Layout, typename Alloc=std::allocator<unsigned char> >
|
Chris@16
|
365 struct bit_aligned_image4_type : public bit_aligned_image_type<mpl::vector4_c<unsigned, Size1, Size2, Size3, Size4>, Layout, Alloc> {};
|
Chris@16
|
366
|
Chris@16
|
367 /// \ingroup TypeFactoryPacked
|
Chris@16
|
368 /// \brief Returns the type of a five channel bit-aligned image given the bit size of its channels and its layout
|
Chris@16
|
369 template <unsigned Size1, unsigned Size2, unsigned Size3, unsigned Size4, unsigned Size5, typename Layout, typename Alloc=std::allocator<unsigned char> >
|
Chris@16
|
370 struct bit_aligned_image5_type : public bit_aligned_image_type<mpl::vector5_c<unsigned, Size1, Size2, Size3, Size4, Size5>, Layout, Alloc> {};
|
Chris@16
|
371
|
Chris@16
|
372
|
Chris@16
|
373
|
Chris@16
|
374 /// \ingroup TypeFactoryFromElements
|
Chris@16
|
375 /// \brief Returns the type of a homogeneous pixel given the channel type and layout
|
Chris@16
|
376 template <typename Channel, typename Layout>
|
Chris@16
|
377 struct pixel_value_type {
|
Chris@16
|
378 typedef pixel<Channel,Layout> type; // by default use gil::pixel. Specializations are provided for
|
Chris@16
|
379 };
|
Chris@16
|
380
|
Chris@16
|
381 // Specializations for packed channels
|
Chris@16
|
382 template <typename BitField, int NumBits, bool IsMutable, typename Layout>
|
Chris@16
|
383 struct pixel_value_type< packed_dynamic_channel_reference<BitField,NumBits,IsMutable>,Layout> :
|
Chris@16
|
384 public packed_pixel_type<BitField, mpl::vector1_c<unsigned,NumBits>, Layout> {};
|
Chris@16
|
385 template <typename BitField, int NumBits, bool IsMutable, typename Layout>
|
Chris@16
|
386 struct pixel_value_type<const packed_dynamic_channel_reference<BitField,NumBits,IsMutable>,Layout> :
|
Chris@16
|
387 public packed_pixel_type<BitField, mpl::vector1_c<unsigned,NumBits>, Layout> {};
|
Chris@16
|
388
|
Chris@16
|
389 template <typename BitField, int FirstBit, int NumBits, bool IsMutable, typename Layout>
|
Chris@16
|
390 struct pixel_value_type< packed_channel_reference<BitField,FirstBit,NumBits,IsMutable>,Layout> :
|
Chris@16
|
391 public packed_pixel_type<BitField, mpl::vector1_c<unsigned,NumBits>, Layout> {};
|
Chris@16
|
392 template <typename BitField, int FirstBit, int NumBits, bool IsMutable, typename Layout>
|
Chris@16
|
393 struct pixel_value_type<const packed_channel_reference<BitField,FirstBit,NumBits,IsMutable>,Layout> :
|
Chris@16
|
394 public packed_pixel_type<BitField, mpl::vector1_c<unsigned,NumBits>, Layout> {};
|
Chris@16
|
395
|
Chris@16
|
396 template <int NumBits, typename Layout>
|
Chris@16
|
397 struct pixel_value_type<packed_channel_value<NumBits>,Layout> :
|
Chris@16
|
398 public packed_pixel_type<typename detail::min_fast_uint<NumBits>::type, mpl::vector1_c<unsigned,NumBits>, Layout> {};
|
Chris@16
|
399
|
Chris@16
|
400
|
Chris@16
|
401 /// \ingroup TypeFactoryFromElements
|
Chris@16
|
402 /// \brief Returns the type of a homogeneous locator given the channel type, layout, whether it operates on planar data and whether it has a step horizontally
|
Chris@16
|
403 template <typename T, typename L, bool IsPlanar=false, bool IsStepX=false, bool IsMutable=true>
|
Chris@16
|
404 struct locator_type {
|
Chris@16
|
405 typedef typename type_from_x_iterator<typename iterator_type<T,L,IsPlanar,IsStepX,IsMutable>::type>::xy_locator_type type;
|
Chris@16
|
406 };
|
Chris@16
|
407
|
Chris@16
|
408 /// \ingroup TypeFactoryFromElements
|
Chris@16
|
409 /// \brief Returns the type of a homogeneous view given the channel type, layout, whether it operates on planar data and whether it has a step horizontally
|
Chris@16
|
410 template <typename T, typename L, bool IsPlanar=false, bool IsStepX=false, bool IsMutable=true>
|
Chris@16
|
411 struct view_type {
|
Chris@16
|
412 typedef typename type_from_x_iterator<typename iterator_type<T,L,IsPlanar,IsStepX,IsMutable>::type>::view_t type;
|
Chris@16
|
413 };
|
Chris@16
|
414
|
Chris@16
|
415 /// \ingroup TypeFactoryFromElements
|
Chris@16
|
416 /// \brief Returns the type of a homogeneous image given the channel type, layout, and whether it operates on planar data
|
Chris@16
|
417 template <typename T, typename L, bool IsPlanar=false, typename Alloc=std::allocator<unsigned char> >
|
Chris@16
|
418 struct image_type {
|
Chris@16
|
419 typedef image<pixel<T,L>, IsPlanar, Alloc> type;
|
Chris@16
|
420 };
|
Chris@16
|
421
|
Chris@16
|
422 /// \ingroup TypeFactoryFromPixel
|
Chris@16
|
423 /// \brief Returns the type of a view the pixel type, whether it operates on planar data and whether it has a step horizontally
|
Chris@16
|
424 template <typename Pixel, bool IsPlanar=false, bool IsStepX=false, bool IsMutable=true>
|
Chris@16
|
425 struct view_type_from_pixel {
|
Chris@16
|
426 typedef typename type_from_x_iterator<typename iterator_type_from_pixel<Pixel,IsPlanar,IsStepX,IsMutable>::type>::view_t type;
|
Chris@16
|
427 };
|
Chris@16
|
428
|
Chris@16
|
429
|
Chris@16
|
430 /// \brief Constructs a pixel reference type from a source pixel reference type by changing some of the properties.
|
Chris@16
|
431 /// \ingroup TypeFactoryDerived
|
Chris@16
|
432 /// Use use_default for the properties of the source view that you want to keep
|
Chris@16
|
433 template <typename Ref, typename T=use_default, typename L=use_default, typename IsPlanar=use_default, typename IsMutable=use_default>
|
Chris@16
|
434 class derived_pixel_reference_type {
|
Chris@16
|
435 typedef typename remove_reference<Ref>::type pixel_t;
|
Chris@16
|
436 typedef typename mpl::if_<is_same<T, use_default>, typename channel_type<pixel_t>::type, T >::type channel_t;
|
Chris@16
|
437 typedef typename mpl::if_<is_same<L, use_default>,
|
Chris@16
|
438 layout<typename color_space_type<pixel_t>::type, typename channel_mapping_type<pixel_t>::type>, L>::type layout_t;
|
Chris@16
|
439 static const bool mut =mpl::if_<is_same<IsMutable,use_default>, pixel_reference_is_mutable<Ref>, IsMutable>::type::value;
|
Chris@16
|
440 static const bool planar=mpl::if_<is_same<IsPlanar,use_default>, is_planar<pixel_t>, IsPlanar>::type::value;
|
Chris@16
|
441 public:
|
Chris@16
|
442 typedef typename pixel_reference_type<channel_t, layout_t, planar, mut>::type type;
|
Chris@16
|
443 };
|
Chris@16
|
444
|
Chris@16
|
445 /// \brief Constructs a pixel iterator type from a source pixel iterator type by changing some of the properties.
|
Chris@16
|
446 /// \ingroup TypeFactoryDerived
|
Chris@16
|
447 /// Use use_default for the properties of the source view that you want to keep
|
Chris@16
|
448 template <typename Iterator, typename T=use_default, typename L=use_default, typename IsPlanar=use_default, typename IsStep=use_default, typename IsMutable=use_default>
|
Chris@16
|
449 class derived_iterator_type {
|
Chris@16
|
450 typedef typename mpl::if_<is_same<T ,use_default>, typename channel_type<Iterator>::type, T >::type channel_t;
|
Chris@16
|
451 typedef typename mpl::if_<is_same<L,use_default>,
|
Chris@16
|
452 layout<typename color_space_type<Iterator>::type, typename channel_mapping_type<Iterator>::type>, L>::type layout_t;
|
Chris@16
|
453
|
Chris@16
|
454 static const bool mut =mpl::if_<is_same<IsMutable,use_default>, iterator_is_mutable<Iterator>, IsMutable>::type::value;
|
Chris@16
|
455 static const bool planar=mpl::if_<is_same<IsPlanar,use_default>, is_planar<Iterator>, IsPlanar>::type::value;
|
Chris@16
|
456 static const bool step =mpl::if_<is_same<IsStep ,use_default>, iterator_is_step<Iterator>, IsStep>::type::value;
|
Chris@16
|
457 public:
|
Chris@16
|
458 typedef typename iterator_type<channel_t, layout_t, planar, step, mut>::type type;
|
Chris@16
|
459 };
|
Chris@16
|
460
|
Chris@16
|
461 /// \brief Constructs an image view type from a source view type by changing some of the properties.
|
Chris@16
|
462 /// \ingroup TypeFactoryDerived
|
Chris@16
|
463 /// Use use_default for the properties of the source view that you want to keep
|
Chris@16
|
464 template <typename View, typename T=use_default, typename L=use_default, typename IsPlanar=use_default, typename StepX=use_default, typename IsMutable=use_default>
|
Chris@16
|
465 class derived_view_type {
|
Chris@16
|
466 typedef typename mpl::if_<is_same<T ,use_default>, typename channel_type<View>::type, T>::type channel_t;
|
Chris@16
|
467 typedef typename mpl::if_<is_same<L,use_default>,
|
Chris@16
|
468 layout<typename color_space_type<View>::type, typename channel_mapping_type<View>::type>, L>::type layout_t;
|
Chris@16
|
469 static const bool mut =mpl::if_<is_same<IsMutable,use_default>, view_is_mutable<View>, IsMutable>::type::value;
|
Chris@16
|
470 static const bool planar=mpl::if_<is_same<IsPlanar,use_default>, is_planar<View>, IsPlanar>::type::value;
|
Chris@16
|
471 static const bool step =mpl::if_<is_same<StepX ,use_default>, view_is_step_in_x<View>,StepX>::type::value;
|
Chris@16
|
472 public:
|
Chris@16
|
473 typedef typename view_type<channel_t, layout_t, planar, step, mut>::type type;
|
Chris@16
|
474 };
|
Chris@16
|
475
|
Chris@16
|
476 /// \brief Constructs a homogeneous image type from a source image type by changing some of the properties.
|
Chris@16
|
477 /// \ingroup TypeFactoryDerived
|
Chris@16
|
478 /// Use use_default for the properties of the source image that you want to keep
|
Chris@16
|
479 template <typename Image, typename T=use_default, typename L=use_default, typename IsPlanar=use_default>
|
Chris@16
|
480 class derived_image_type {
|
Chris@16
|
481 typedef typename mpl::if_<is_same<T ,use_default>, typename channel_type<Image>::type, T >::type channel_t;
|
Chris@16
|
482 typedef typename mpl::if_<is_same<L,use_default>,
|
Chris@16
|
483 layout<typename color_space_type<Image>::type, typename channel_mapping_type<Image>::type>, L>::type layout_t;
|
Chris@16
|
484 static const bool planar=mpl::if_<is_same<IsPlanar,use_default>, is_planar<Image>, IsPlanar>::type::value;
|
Chris@16
|
485 public:
|
Chris@16
|
486 typedef typename image_type<channel_t, layout_t, planar>::type type;
|
Chris@16
|
487 };
|
Chris@16
|
488
|
Chris@16
|
489
|
Chris@16
|
490
|
Chris@16
|
491
|
Chris@16
|
492 } } // namespace boost::gil
|
Chris@16
|
493
|
Chris@16
|
494 #endif
|