Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/gil/metafunctions.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //
0002 // Copyright 2005-2007 Adobe Systems Incorporated
0003 // Copyright 2021 Pranam Lashkari <plashkari628@gmail.com>
0004 //
0005 // Distributed under the Boost Software License, Version 1.0
0006 // See accompanying file LICENSE_1_0.txt or copy at
0007 // http://www.boost.org/LICENSE_1_0.txt
0008 //
0009 #ifndef BOOST_GIL_METAFUNCTIONS_HPP
0010 #define BOOST_GIL_METAFUNCTIONS_HPP
0011 
0012 #include <boost/gil/channel.hpp>
0013 #include <boost/gil/dynamic_step.hpp>
0014 #include <boost/gil/concepts.hpp>
0015 #include <boost/gil/concepts/detail/type_traits.hpp>
0016 #include <boost/gil/detail/mp11.hpp>
0017 
0018 #include <iterator>
0019 #include <type_traits>
0020 
0021 namespace boost { namespace gil {
0022 
0023 // forward declarations
0024 template <typename T, typename L> struct pixel;
0025 template <typename BitField,typename ChannelRefs,typename Layout> struct packed_pixel;
0026 template <typename T, typename C> struct planar_pixel_reference;
0027 template <typename IC, typename C> struct planar_pixel_iterator;
0028 template <typename I> class memory_based_step_iterator;
0029 template <typename I> class memory_based_2d_locator;
0030 template <typename L> class image_view;
0031 template <typename Pixel, bool IsPlanar = false, typename Alloc=std::allocator<unsigned char> > class image;
0032 template <typename T> struct channel_type;
0033 template <typename T> struct color_space_type;
0034 template <typename T> struct channel_mapping_type;
0035 template <typename It> struct is_iterator_adaptor;
0036 template <typename It> struct iterator_adaptor_get_base;
0037 template <typename BitField, typename ChannelBitSizes, typename Layout, bool IsMutable> struct bit_aligned_pixel_reference;
0038 
0039 //////////////////////////////////////////////////
0040 ///
0041 ///  TYPE ANALYSIS METAFUNCTIONS
0042 ///  Predicate metafunctions determining properties of GIL types
0043 ///
0044 //////////////////////////////////////////////////
0045 
0046 
0047 /// \defgroup GILIsBasic xxx_is_basic
0048 /// \ingroup TypeAnalysis
0049 /// \brief Determines if GIL constructs are basic.
0050 ///    Basic constructs are the ones that can be generated with the type
0051 ///    factory methods pixel_reference_type, iterator_type, locator_type, view_type and image_type
0052 ///    They can be mutable/immutable, planar/interleaved, step/nonstep. They must use GIL-provided models.
0053 
0054 /// \brief Determines if a given pixel reference is basic
0055 ///    Basic references must use gil::pixel& (if interleaved), gil::planar_pixel_reference (if planar). They must use the standard constness rules.
0056 /// \ingroup GILIsBasic
0057 template <typename PixelRef>
0058 struct pixel_reference_is_basic : public std::false_type {};
0059 
0060 template <typename T, typename L>
0061 struct pixel_reference_is_basic<pixel<T, L>&> : std::true_type {};
0062 
0063 template <typename T, typename L>
0064 struct pixel_reference_is_basic<const pixel<T, L>&> : std::true_type {};
0065 
0066 template <typename TR, typename CS>
0067 struct pixel_reference_is_basic<planar_pixel_reference<TR, CS>> : std::true_type {};
0068 
0069 template <typename TR, typename CS>
0070 struct pixel_reference_is_basic<const planar_pixel_reference<TR, CS>> : std::true_type {};
0071 
0072 /// \brief Determines if a given pixel iterator is basic
0073 ///    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.
0074 /// \ingroup GILIsBasic
0075 template <typename Iterator>
0076 struct iterator_is_basic : std::false_type {};
0077 
0078 /// \tparam T mutable interleaved pixel type
0079 template <typename T, typename L>
0080 struct iterator_is_basic<pixel<T, L>*> : std::true_type {};
0081 
0082 /// \tparam T immutable interleaved pixel type
0083 template <typename T, typename L>
0084 struct iterator_is_basic<pixel<T, L> const*> : std::true_type {};
0085 
0086 /// \tparam T mutable planar pixel type
0087 template <typename T, typename CS>
0088 struct iterator_is_basic<planar_pixel_iterator<T*, CS>> : std::true_type {};
0089 
0090 /// \tparam T immutable planar pixel type
0091 template <typename T, typename CS>
0092 struct iterator_is_basic<planar_pixel_iterator<T const*, CS>> : std::true_type {};
0093 
0094 /// \tparam T mutable interleaved step
0095 template <typename T, typename L>
0096 struct iterator_is_basic<memory_based_step_iterator<pixel<T, L>*>> : std::true_type {};
0097 
0098 /// \tparam T immutable interleaved step
0099 template <typename T, typename L>
0100 struct iterator_is_basic<memory_based_step_iterator<pixel<T, L> const*>> : std::true_type {};
0101 
0102 /// \tparam T mutable planar step
0103 template <typename T, typename CS>
0104 struct iterator_is_basic<memory_based_step_iterator<planar_pixel_iterator<T*, CS>>>
0105     : std::true_type
0106 {};
0107 
0108 /// \tparam T immutable planar step
0109 template <typename T, typename CS>
0110 struct iterator_is_basic<memory_based_step_iterator<planar_pixel_iterator<T const*, CS>>>
0111     : std::true_type
0112 {};
0113 
0114 
0115 /// \ingroup GILIsBasic
0116 /// \brief Determines if a given locator is basic. A basic locator is memory-based and has basic x_iterator and y_iterator
0117 template <typename Loc>
0118 struct locator_is_basic : std::false_type {};
0119 
0120 template <typename Iterator>
0121 struct locator_is_basic
0122     <
0123         memory_based_2d_locator<memory_based_step_iterator<Iterator>>
0124     > : iterator_is_basic<Iterator>
0125 {};
0126 
0127 /// \ingroup GILIsBasic
0128 /// \brief Basic views must be over basic locators
0129 template <typename View>
0130 struct view_is_basic : std::false_type {};
0131 
0132 template <typename Loc>
0133 struct view_is_basic<image_view<Loc>> : locator_is_basic<Loc> {};
0134 
0135 /// \ingroup GILIsBasic
0136 /// \brief Basic images must use basic views and std::allocator
0137 template <typename Img>
0138 struct image_is_basic : std::false_type {};
0139 
0140 template <typename Pixel, bool IsPlanar, typename Alloc>
0141 struct image_is_basic<image<Pixel, IsPlanar, Alloc>> : std::true_type {};
0142 
0143 
0144 /// \defgroup GILIsStep xxx_is_step
0145 /// \ingroup TypeAnalysis
0146 /// \brief Determines if the given iterator/locator/view has a step that could be set dynamically
0147 
0148 template <typename I>
0149 struct iterator_is_step;
0150 
0151 namespace detail {
0152 
0153 template <typename It, bool IsBase, bool EqualsStepType>
0154 struct iterator_is_step_impl;
0155 
0156 // iterator that has the same type as its dynamic_x_step_type must be a step iterator
0157 template <typename It, bool IsBase>
0158 struct iterator_is_step_impl<It, IsBase, true> : std::true_type {};
0159 
0160 // base iterator can never be a step iterator
0161 template <typename It>
0162 struct iterator_is_step_impl<It, true, false> : std::false_type {};
0163 
0164 // for an iterator adaptor, see if its base is step
0165 template <typename It>
0166 struct iterator_is_step_impl<It, false, false>
0167     : public iterator_is_step<typename iterator_adaptor_get_base<It>::type> {};
0168 
0169 } // namespace detail
0170 
0171 /// \ingroup GILIsStep
0172 /// \brief Determines if the given iterator has a step that could be set dynamically
0173 template <typename I>
0174 struct iterator_is_step
0175     : detail::iterator_is_step_impl
0176     <
0177         I,
0178         !is_iterator_adaptor<I>::value,
0179         std::is_same<I, typename dynamic_x_step_type<I>::type
0180     >::value
0181 >
0182 {};
0183 
0184 /// \ingroup GILIsStep
0185 /// \brief Determines if the given locator has a horizontal step that could be set dynamically
0186 template <typename L> struct locator_is_step_in_x : public iterator_is_step<typename L::x_iterator> {};
0187 
0188 /// \ingroup GILIsStep
0189 /// \brief Determines if the given locator has a vertical step that could be set dynamically
0190 template <typename L> struct locator_is_step_in_y : public iterator_is_step<typename L::y_iterator> {};
0191 
0192 /// \ingroup GILIsStep
0193 /// \brief Determines if the given view has a horizontal step that could be set dynamically
0194 template <typename V> struct view_is_step_in_x : public locator_is_step_in_x<typename V::xy_locator> {};
0195 
0196 /// \ingroup GILIsStep
0197 /// \brief Determines if the given view has a vertical step that could be set dynamically
0198 template <typename V> struct view_is_step_in_y : public locator_is_step_in_y<typename V::xy_locator> {};
0199 
0200 /// \brief Determines whether the given pixel reference is a proxy class or a native C++ reference
0201 /// \ingroup TypeAnalysis
0202 template <typename PixelReference>
0203 struct pixel_reference_is_proxy
0204     : mp11::mp_not
0205     <
0206         std::is_same
0207         <
0208             typename detail::remove_const_and_reference<PixelReference>::type,
0209             typename detail::remove_const_and_reference<PixelReference>::type::value_type
0210         >
0211     >
0212 {};
0213 
0214 /// \brief Given a model of a pixel, determines whether the model represents a pixel reference (as opposed to pixel value)
0215 /// \ingroup TypeAnalysis
0216 template <typename Pixel>
0217 struct pixel_is_reference
0218     : mp11::mp_or<is_reference<Pixel>, pixel_reference_is_proxy<Pixel>> {};
0219 
0220 /// \defgroup GILIsMutable xxx_is_mutable
0221 /// \ingroup TypeAnalysis
0222 /// \brief Determines if the given pixel reference/iterator/locator/view is mutable (i.e. its pixels can be changed)
0223 
0224 /// \ingroup GILIsMutable
0225 /// \brief Determines if the given pixel reference is mutable (i.e. its channels can be changed)
0226 ///
0227 /// Note that built-in C++ references obey the const qualifier but reference proxy classes do not.
0228 template <typename R>
0229 struct pixel_reference_is_mutable
0230     : std::integral_constant<bool, std::remove_reference<R>::type::is_mutable>
0231 {};
0232 
0233 template <typename R>
0234 struct pixel_reference_is_mutable<R const&>
0235     : mp11::mp_and<pixel_reference_is_proxy<R>, pixel_reference_is_mutable<R>>
0236 {};
0237 
0238 /// \ingroup GILIsMutable
0239 /// \brief Determines if the given locator is mutable (i.e. its pixels can be changed)
0240 template <typename L> struct locator_is_mutable : public iterator_is_mutable<typename L::x_iterator> {};
0241 /// \ingroup GILIsMutable
0242 /// \brief Determines if the given view is mutable (i.e. its pixels can be changed)
0243 template <typename V> struct view_is_mutable : public iterator_is_mutable<typename V::x_iterator> {};
0244 
0245 
0246 //////////////////////////////////////////////////
0247 ///
0248 ///  TYPE FACTORY METAFUNCTIONS
0249 ///  Metafunctions returning GIL types from other GIL types
0250 ///
0251 //////////////////////////////////////////////////
0252 
0253 /// \defgroup TypeFactoryFromElements xxx_type
0254 /// \ingroup TypeFactory
0255 /// \brief Returns the type of a homogeneous GIL construct given its elements (channel, layout, whether it is planar, step, mutable, etc.)
0256 
0257 /// \defgroup TypeFactoryFromPixel xxx_type_from_pixel
0258 /// \ingroup TypeFactory
0259 /// \brief Returns the type of a GIL construct given its pixel type, whether it is planar, step, mutable, etc.
0260 
0261 /// \defgroup TypeFactoryDerived derived_xxx_type
0262 /// \ingroup TypeFactory
0263 /// \brief Returns the type of a homogeneous GIL construct given a related construct by changing some of its properties
0264 
0265 /// \ingroup TypeFactoryFromElements
0266 /// \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
0267 template <typename T, typename L, bool IsPlanar=false, bool IsMutable=true> struct pixel_reference_type{};
0268 template <typename T, typename L> struct pixel_reference_type<T,L,false,true > { using type = pixel<T,L>&; };
0269 template <typename T, typename L> struct pixel_reference_type<T,L,false,false> { using type = pixel<T,L> const&; };
0270 template <typename T, typename L> struct pixel_reference_type<T,L,true,true> { using type = planar_pixel_reference<typename channel_traits<T>::reference,typename color_space_type<L>::type> const; };       // TODO: Assert M=identity
0271 template <typename T, typename L> struct pixel_reference_type<T,L,true,false> { using type = planar_pixel_reference<typename channel_traits<T>::const_reference,typename color_space_type<L>::type> const; };// TODO: Assert M=identity
0272 
0273 /// \ingroup TypeFactoryFromPixel
0274 /// \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
0275 template <typename Pixel, bool IsPlanar=false, bool IsStep=false, bool IsMutable=true> struct iterator_type_from_pixel{};
0276 template <typename Pixel> struct iterator_type_from_pixel<Pixel,false,false,true > { using type = Pixel *; };
0277 template <typename Pixel> struct iterator_type_from_pixel<Pixel,false,false,false> { using type = const Pixel *; };
0278 template <typename Pixel> struct iterator_type_from_pixel<Pixel,true,false,true> {
0279     using type = planar_pixel_iterator<typename channel_traits<typename channel_type<Pixel>::type>::pointer,typename color_space_type<Pixel>::type>;
0280 };
0281 template <typename Pixel> struct iterator_type_from_pixel<Pixel,true,false,false> {
0282     using type = planar_pixel_iterator<typename channel_traits<typename channel_type<Pixel>::type>::const_pointer,typename color_space_type<Pixel>::type>;
0283 };
0284 template <typename Pixel, bool IsPlanar, bool IsMutable> struct iterator_type_from_pixel<Pixel,IsPlanar,true,IsMutable> {
0285     using type = memory_based_step_iterator<typename iterator_type_from_pixel<Pixel,IsPlanar,false,IsMutable>::type>;
0286 };
0287 
0288 /// \ingroup TypeFactoryFromElements
0289 /// \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
0290 template <typename T, typename L, bool IsPlanar=false, bool IsStep=false, bool IsMutable=true> struct iterator_type{};
0291 template <typename T, typename L> struct iterator_type<T,L,false,false,true > { using type = pixel<T,L>*; };
0292 template <typename T, typename L> struct iterator_type<T,L,false,false,false> { using type = pixel<T,L> const*; };
0293 template <typename T, typename L> struct iterator_type<T,L,true,false,true> { using type = planar_pixel_iterator<T*,typename L::color_space_t>; };               // TODO: Assert M=identity
0294 template <typename T, typename L> struct iterator_type<T,L,true,false,false> { using type = planar_pixel_iterator<const T*,typename L::color_space_t>; };        // TODO: Assert M=identity
0295 template <typename T, typename L, bool IsPlanar, bool IsMutable> struct iterator_type<T,L,IsPlanar,true,IsMutable> {
0296     using type = memory_based_step_iterator<typename iterator_type<T,L,IsPlanar,false,IsMutable>::type>;
0297 };
0298 
0299 /// \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
0300 /// \ingroup TypeFactory
0301 template <typename XIterator>
0302 struct type_from_x_iterator
0303 {
0304     using step_iterator_t = memory_based_step_iterator<XIterator>;
0305     using xy_locator_t = memory_based_2d_locator<step_iterator_t>;
0306     using view_t = image_view<xy_locator_t>;
0307 };
0308 
0309 namespace detail {
0310 
0311 template <typename BitField, typename FirstBit, typename NumBits>
0312 struct packed_channel_reference_type
0313 {
0314     using type = packed_channel_reference
0315         <
0316             BitField, FirstBit::value, NumBits::value, true
0317         > const;
0318 };
0319 
0320 template <typename BitField, typename ChannelBitSizes>
0321 class packed_channel_references_vector_type
0322 {
0323     template <typename FirstBit, typename NumBits>
0324     using reference_type = typename packed_channel_reference_type<BitField, FirstBit, NumBits>::type;
0325 
0326     // If ChannelBitSizesVector is mp11::mp_list_c<int,7,7,2>
0327     // Then first_bits_vector will be mp11::mp_list_c<int,0,7,14,16>
0328     using first_bit_list = mp11::mp_fold_q
0329         <
0330             ChannelBitSizes,
0331             mp11::mp_list<std::integral_constant<int, 0>>,
0332             mp11::mp_bind
0333             <
0334                 mp11::mp_push_back,
0335                 mp11::_1,
0336                 mp11::mp_bind
0337                 <
0338                     mp11::mp_plus,
0339                     mp11::mp_bind<mp_back, mp11::_1>,
0340                     mp11::_2
0341                 >
0342             >
0343         >;
0344 
0345     static_assert(mp11::mp_at_c<first_bit_list, 0>::value == 0, "packed channel first bit must be 0");
0346 
0347 public:
0348     using type = mp11::mp_transform
0349         <
0350             reference_type,
0351             mp_pop_back<first_bit_list>,
0352             ChannelBitSizes
0353         >;
0354 };
0355 
0356 } // namespace detail
0357 
0358 /// \ingroup TypeFactoryFromElements
0359 /// \brief Returns the type of a packed pixel given its bitfield type, the bit size of its channels and its layout.
0360 ///
0361 /// A packed pixel has channels that cover bit ranges but itself is byte aligned. RGB565 pixel is an example.
0362 ///
0363 /// The size of ChannelBitSizes must equal the number of channels in the given layout
0364 /// 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).
0365 ///  If it is less than the number of bits in BitField, the last bits will be unused.
0366 template <typename BitField, typename ChannelBitSizes, typename Layout>
0367 struct packed_pixel_type
0368 {
0369     using type = packed_pixel
0370         <
0371             BitField,
0372             typename detail::packed_channel_references_vector_type
0373             <
0374                 BitField,
0375                 ChannelBitSizes
0376             >::type,
0377         Layout>;
0378 };
0379 
0380 /// \defgroup TypeFactoryPacked packed_image_type,bit_aligned_image_type
0381 /// \ingroup TypeFactoryFromElements
0382 /// \brief Returns the type of an image whose channels are not byte-aligned.
0383 ///
0384 /// A packed image is an image whose pixels are byte aligned, such as "rgb565". <br>
0385 /// A bit-aligned image is an image whose pixels are not byte aligned, such as "rgb222". <br>
0386 ///
0387 /// The sum of the bit sizes of all channels cannot exceed 64.
0388 
0389 /// \ingroup TypeFactoryPacked
0390 /// \brief Returns the type of an interleaved packed image: an image whose channels may not be byte-aligned, but whose pixels are byte aligned.
0391 template <typename BitField, typename ChannelBitSizes, typename Layout, typename Alloc=std::allocator<unsigned char>>
0392 struct packed_image_type
0393 {
0394     using type = image<typename packed_pixel_type<BitField,ChannelBitSizes,Layout>::type,false,Alloc>;
0395 };
0396 
0397 /// \ingroup TypeFactoryPacked
0398 /// \brief Returns the type of a single-channel image given its bitfield type, the bit size of its channel and its layout
0399 template <typename BitField, unsigned Size1, typename Layout, typename Alloc = std::allocator<unsigned char>>
0400 struct packed_image1_type
0401     : packed_image_type<BitField, mp11::mp_list_c<unsigned, Size1>, Layout, Alloc>
0402 {};
0403 
0404 /// \ingroup TypeFactoryPacked
0405 /// \brief Returns the type of a two channel image given its bitfield type, the bit size of its channels and its layout
0406 template <typename BitField, unsigned Size1, unsigned Size2, typename Layout, typename Alloc = std::allocator<unsigned char>>
0407 struct packed_image2_type
0408     : packed_image_type<BitField, mp11::mp_list_c<unsigned, Size1, Size2>, Layout, Alloc>
0409 {};
0410 
0411 /// \ingroup TypeFactoryPacked
0412 /// \brief Returns the type of a three channel image given its bitfield type, the bit size of its channels and its layout
0413 template <typename BitField, unsigned Size1, unsigned Size2, unsigned Size3, typename Layout, typename Alloc = std::allocator<unsigned char>>
0414 struct packed_image3_type
0415     : packed_image_type<BitField, mp11::mp_list_c<unsigned, Size1, Size2, Size3>, Layout, Alloc>
0416 {};
0417 
0418 /// \ingroup TypeFactoryPacked
0419 /// \brief Returns the type of a four channel image given its bitfield type, the bit size of its channels and its layout
0420 template <typename BitField, unsigned Size1, unsigned Size2, unsigned Size3, unsigned Size4, typename Layout, typename Alloc = std::allocator<unsigned char>>
0421 struct packed_image4_type
0422     : packed_image_type<BitField, mp11::mp_list_c<unsigned, Size1, Size2, Size3, Size4>, Layout, Alloc>
0423 {};
0424 
0425 /// \ingroup TypeFactoryPacked
0426 /// \brief Returns the type of a five channel image given its bitfield type, the bit size of its channels and its layout
0427 template <typename BitField, unsigned Size1, unsigned Size2, unsigned Size3, unsigned Size4, unsigned Size5, typename Layout, typename Alloc = std::allocator<unsigned char>>
0428 struct packed_image5_type
0429     : packed_image_type<BitField, mp11::mp_list_c<unsigned, Size1, Size2, Size3, Size4, Size5>, Layout, Alloc> {};
0430 
0431 
0432 /// \ingroup TypeFactoryPacked
0433 /// \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.
0434 ///
0435 /// 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
0436 /// image whose rows are byte-aligned, use 8 as the alignment parameter, not 1.
0437 ///
0438 template
0439 <
0440     typename ChannelBitSizes,
0441     typename Layout,
0442     typename Alloc = std::allocator<unsigned char>
0443 >
0444 struct bit_aligned_image_type
0445 {
0446 private:
0447 
0448     static constexpr int bit_size =
0449         mp11::mp_fold
0450         <
0451             ChannelBitSizes,
0452             std::integral_constant<int, 0>,
0453             mp11::mp_plus
0454         >::value;
0455 
0456     using bitfield_t = typename detail::min_fast_uint<bit_size + 7>::type;
0457     using bit_alignedref_t = bit_aligned_pixel_reference<bitfield_t, ChannelBitSizes, Layout, true> const;
0458 
0459 public:
0460     using type = image<bit_alignedref_t,false,Alloc>;
0461 };
0462 
0463 /// \ingroup TypeFactoryPacked
0464 /// \brief Returns the type of a single-channel bit-aligned image given the bit size of its channel and its layout
0465 template <unsigned Size1, typename Layout, typename Alloc = std::allocator<unsigned char>>
0466 struct bit_aligned_image1_type : bit_aligned_image_type<mp11::mp_list_c<unsigned, Size1>, Layout, Alloc> {};
0467 
0468 /// \ingroup TypeFactoryPacked
0469 /// \brief Returns the type of a two channel bit-aligned image given the bit size of its channels and its layout
0470 template <unsigned Size1, unsigned Size2, typename Layout, typename Alloc = std::allocator<unsigned char>>
0471 struct bit_aligned_image2_type : bit_aligned_image_type<mp11::mp_list_c<unsigned, Size1, Size2>, Layout, Alloc> {};
0472 
0473 /// \ingroup TypeFactoryPacked
0474 /// \brief Returns the type of a three channel bit-aligned image given the bit size of its channels and its layout
0475 template <unsigned Size1, unsigned Size2, unsigned Size3, typename Layout, typename Alloc = std::allocator<unsigned char>>
0476 struct bit_aligned_image3_type : bit_aligned_image_type<mp11::mp_list_c<unsigned, Size1, Size2, Size3>, Layout, Alloc> {};
0477 
0478 /// \ingroup TypeFactoryPacked
0479 /// \brief Returns the type of a four channel bit-aligned image given the bit size of its channels and its layout
0480 template <unsigned Size1, unsigned Size2, unsigned Size3, unsigned Size4, typename Layout, typename Alloc = std::allocator<unsigned char>>
0481 struct bit_aligned_image4_type : bit_aligned_image_type<mp11::mp_list_c<unsigned, Size1, Size2, Size3, Size4>, Layout, Alloc> {};
0482 
0483 /// \ingroup TypeFactoryPacked
0484 /// \brief Returns the type of a five channel bit-aligned image given the bit size of its channels and its layout
0485 template <unsigned Size1, unsigned Size2, unsigned Size3, unsigned Size4, unsigned Size5, typename Layout, typename Alloc = std::allocator<unsigned char>>
0486 struct bit_aligned_image5_type : bit_aligned_image_type<mp11::mp_list_c<unsigned, Size1, Size2, Size3, Size4, Size5>, Layout, Alloc> {};
0487 
0488 
0489 /// \ingroup TypeFactoryFromElements
0490 /// \brief Returns the type of a homogeneous pixel given the channel type and layout
0491 template <typename Channel, typename Layout>
0492 struct pixel_value_type
0493 {
0494     // by default use gil::pixel. Specializations are provided for
0495     using type = pixel<Channel, Layout>;
0496 };
0497 
0498 // Specializations for packed channels
0499 template <typename BitField, int NumBits, bool IsMutable, typename Layout>
0500 struct pixel_value_type<packed_dynamic_channel_reference<BitField, NumBits, IsMutable>, Layout>
0501     : packed_pixel_type<BitField, mp11::mp_list_c<unsigned, NumBits>, Layout>
0502 {};
0503 
0504 template <typename BitField, int NumBits, bool IsMutable, typename Layout>
0505 struct pixel_value_type<packed_dynamic_channel_reference<BitField, NumBits, IsMutable> const, Layout>
0506     : packed_pixel_type<BitField, mp11::mp_list_c<unsigned, NumBits>, Layout>
0507 {};
0508 
0509 template <typename BitField, int FirstBit, int NumBits, bool IsMutable, typename Layout>
0510 struct pixel_value_type<packed_channel_reference<BitField, FirstBit, NumBits, IsMutable>, Layout>
0511     : packed_pixel_type<BitField, mp11::mp_list_c<unsigned, NumBits>, Layout>
0512 {};
0513 
0514 template <typename BitField, int FirstBit, int NumBits, bool IsMutable, typename Layout>
0515 struct pixel_value_type<packed_channel_reference<BitField, FirstBit, NumBits, IsMutable> const, Layout>
0516     : packed_pixel_type<BitField, mp11::mp_list_c<unsigned, NumBits>, Layout>
0517 {};
0518 
0519 template <int NumBits, typename Layout>
0520 struct pixel_value_type<packed_channel_value<NumBits>, Layout>
0521     : packed_pixel_type<typename detail::min_fast_uint<NumBits>::type, mp11::mp_list_c<unsigned, NumBits>, Layout>
0522 {};
0523 
0524 /// \ingroup TypeFactoryFromElements
0525 /// \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
0526 template <typename T, typename L, bool IsPlanar = false, bool IsStepX = false, bool IsMutable = true>
0527 struct locator_type
0528 {
0529     using type = typename type_from_x_iterator
0530         <
0531             typename iterator_type<T, L, IsPlanar, IsStepX, IsMutable>::type
0532         >::xy_locator_type;
0533 };
0534 
0535 /// \ingroup TypeFactoryFromElements
0536 /// \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
0537 template <typename T, typename L, bool IsPlanar = false, bool IsStepX = false, bool IsMutable = true>
0538 struct view_type
0539 {
0540     using type = typename type_from_x_iterator
0541         <
0542             typename iterator_type<T, L, IsPlanar, IsStepX, IsMutable>::type
0543         >::view_t;
0544 };
0545 
0546 /// \ingroup TypeFactoryFromElements
0547 /// \brief Returns the type of a homogeneous image given the channel type, layout, and whether it operates on planar data
0548 template <typename T, typename L, bool IsPlanar = false, typename Alloc = std::allocator<unsigned char>>
0549 struct image_type
0550 {
0551     using type = image<pixel<T, L>, IsPlanar, Alloc>;
0552 };
0553 
0554 /// \ingroup TypeFactoryFromPixel
0555 /// \brief Returns the type of a view the pixel type, whether it operates on planar data and whether it has a step horizontally
0556 template <typename Pixel, bool IsPlanar=false, bool IsStepX=false, bool IsMutable=true>
0557 struct view_type_from_pixel {
0558     using type = typename type_from_x_iterator<typename iterator_type_from_pixel<Pixel,IsPlanar,IsStepX,IsMutable>::type>::view_t;
0559 };
0560 
0561 
0562 /// \brief Constructs a pixel reference type from a source pixel reference type by changing some of the properties.
0563 /// \ingroup TypeFactoryDerived
0564 ///  Use use_default for the properties of the source view that you want to keep
0565 template
0566 <
0567         typename Ref,
0568         typename T = use_default,
0569         typename L = use_default,
0570         typename IsPlanar = use_default,
0571         typename IsMutable = use_default>
0572 class derived_pixel_reference_type
0573 {
0574     using pixel_t = typename std::remove_reference<Ref>::type;
0575 
0576     using channel_t = typename mp11::mp_if
0577         <
0578             std::is_same<T, use_default>,
0579             typename channel_type<pixel_t>::type,
0580             T
0581         >::type;
0582 
0583     using layout_t = typename  mp11::mp_if
0584         <
0585             std::is_same<L, use_default>,
0586             layout
0587             <
0588                 typename color_space_type<pixel_t>::type,
0589                 typename channel_mapping_type<pixel_t>::type
0590             >,
0591             L
0592         >::type;
0593 
0594     static bool const mut = mp11::mp_if
0595         <
0596             std::is_same<IsMutable, use_default>,
0597             pixel_reference_is_mutable<Ref>,
0598             IsMutable
0599         >::value;
0600 
0601     static bool const planar = mp11::mp_if
0602         <
0603             std::is_same<IsPlanar, use_default>,
0604             is_planar<pixel_t>,
0605             IsPlanar
0606         >::value;
0607 
0608 public:
0609     using type = typename pixel_reference_type<channel_t, layout_t, planar, mut>::type;
0610 };
0611 
0612 /// \brief Constructs a pixel iterator type from a source pixel iterator type by changing some of the properties.
0613 /// \ingroup TypeFactoryDerived
0614 ///  Use use_default for the properties of the source view that you want to keep
0615 template
0616 <
0617     typename Iterator,
0618     typename T = use_default,
0619     typename L = use_default,
0620     typename IsPlanar = use_default,
0621     typename IsStep = use_default,
0622     typename IsMutable = use_default
0623 >
0624 class derived_iterator_type
0625 {
0626     using channel_t = typename mp11::mp_if
0627         <
0628             std::is_same<T, use_default>,
0629             typename channel_type<Iterator>::type,
0630             T
0631         >::type;
0632 
0633     using layout_t = typename mp11::mp_if
0634         <
0635             std::is_same<L, use_default>,
0636             layout
0637             <
0638                 typename color_space_type<Iterator>::type,
0639                 typename channel_mapping_type<Iterator>::type
0640             >,
0641             L
0642         >::type;
0643 
0644     static const bool mut = mp11::mp_if
0645         <
0646             std::is_same<IsMutable, use_default>,
0647             iterator_is_mutable<Iterator>,
0648             IsMutable
0649         >::value;
0650 
0651     static bool const planar = mp11::mp_if
0652         <
0653             std::is_same<IsPlanar, use_default>,
0654             is_planar<Iterator>,
0655             IsPlanar
0656         >::value;
0657 
0658     static bool const step = mp11::mp_if
0659         <
0660             std::is_same<IsStep, use_default>,
0661             iterator_is_step<Iterator>,
0662             IsStep
0663         >::type::value;
0664 
0665 public:
0666     using type = typename iterator_type<channel_t, layout_t, planar, step, mut>::type;
0667 };
0668 
0669 /// \brief Constructs an image view type from a source view type by changing some of the properties.
0670 /// \ingroup TypeFactoryDerived
0671 ///  Use use_default for the properties of the source view that you want to keep
0672 template <typename View, typename T = use_default, typename L = use_default, typename IsPlanar = use_default, typename StepX = use_default, typename IsMutable = use_default>
0673 class derived_view_type
0674 {
0675     using channel_t = typename mp11::mp_if
0676         <
0677             std::is_same<T, use_default>,
0678             typename channel_type<View>::type,
0679             T
0680         >;
0681 
0682     using layout_t = typename mp11::mp_if
0683         <
0684             std::is_same<L, use_default>,
0685             layout
0686             <
0687                 typename color_space_type<View>::type,
0688                 typename channel_mapping_type<View>::type
0689             >,
0690             L
0691         >;
0692 
0693     static bool const mut = mp11::mp_if
0694         <
0695             std::is_same<IsMutable, use_default>,
0696             view_is_mutable<View>,
0697             IsMutable
0698         >::value;
0699 
0700     static bool const planar = mp11::mp_if
0701         <
0702             std::is_same<IsPlanar, use_default>,
0703             is_planar<View>,
0704             IsPlanar
0705         >::value;
0706 
0707     static bool const step = mp11::mp_if
0708         <
0709             std::is_same<StepX, use_default>,
0710             view_is_step_in_x<View>,
0711             StepX
0712         >::value;
0713 
0714 public:
0715     using type = typename view_type<channel_t, layout_t, planar, step, mut>::type;
0716 };
0717 
0718 /// \brief Constructs a homogeneous image type from a source image type by changing some of the properties.
0719 /// \ingroup TypeFactoryDerived
0720 ///  Use use_default for the properties of the source image that you want to keep
0721 template <typename Image, typename T = use_default, typename L = use_default, typename IsPlanar = use_default>
0722 class derived_image_type
0723 {
0724     using channel_t = typename mp11::mp_if
0725         <
0726             std::is_same<T, use_default>,
0727             typename channel_type<Image>::type,
0728             T
0729         >::type;
0730 
0731     using layout_t = typename mp11::mp_if
0732         <
0733             std::is_same<L, use_default>,
0734             layout
0735             <
0736                 typename color_space_type<Image>::type,
0737                 typename channel_mapping_type<Image>::type>,
0738                 L
0739             >::type;
0740 
0741     static bool const planar = mp11::mp_if
0742         <
0743             std::is_same<IsPlanar, use_default>,
0744             is_planar<Image>,
0745             IsPlanar
0746         >::value;
0747 
0748 public:
0749     using type = typename image_type<channel_t, layout_t, planar>::type;
0750 };
0751 
0752 }}  // namespace boost::gil
0753 
0754 #endif