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

source code of boost/boost/gil/metafunctions.hpp