1 // 2 // Copyright 2005-2007 Adobe Systems Incorporated 3 // 4 // Distributed under the Boost Software License, Version 1.0 5 // See accompanying file LICENSE_1_0.txt or copy at 6 // http://www.boost.org/LICENSE_1_0.txt 7 // 8 #ifndef BOOST_GIL_METAFUNCTIONS_HPP 9 #define BOOST_GIL_METAFUNCTIONS_HPP 10 11 #include <boost/gil/channel.hpp> 12 #include <boost/gil/dynamic_step.hpp> 13 #include <boost/gil/concepts.hpp> 14 #include <boost/gil/concepts/detail/type_traits.hpp> 15 #include <boost/gil/detail/mp11.hpp> 16 17 #include <iterator> 18 #include <type_traits> 19 20 namespace boost { namespace gil { 21 22 // forward declarations 23 template <typename T, typename L> struct pixel; 24 template <typename BitField,typename ChannelRefs,typename Layout> struct packed_pixel; 25 template <typename T, typename C> struct planar_pixel_reference; 26 template <typename IC, typename C> struct planar_pixel_iterator; 27 template <typename I> class memory_based_step_iterator; 28 template <typename I> class memory_based_2d_locator; 29 template <typename L> class image_view; 30 template <typename Pixel, bool IsPlanar, typename Alloc> class image; 31 template <typename T> struct channel_type; 32 template <typename T> struct color_space_type; 33 template <typename T> struct channel_mapping_type; 34 template <typename It> struct is_iterator_adaptor; 35 template <typename It> struct iterator_adaptor_get_base; 36 template <typename BitField, typename ChannelBitSizes, typename Layout, bool IsMutable> struct bit_aligned_pixel_reference; 37 38 ////////////////////////////////////////////////// 39 /// 40 /// TYPE ANALYSIS METAFUNCTIONS 41 /// Predicate metafunctions determining properties of GIL types 42 /// 43 ////////////////////////////////////////////////// 44 45 46 /// \defgroup GILIsBasic xxx_is_basic 47 /// \ingroup TypeAnalysis 48 /// \brief Determines if GIL constructs are basic. 49 /// Basic constructs are the ones that can be generated with the type 50 /// factory methods pixel_reference_type, iterator_type, locator_type, view_type and image_type 51 /// They can be mutable/immutable, planar/interleaved, step/nonstep. They must use GIL-provided models. 52 53 /// \brief Determines if a given pixel reference is basic 54 /// Basic references must use gil::pixel& (if interleaved), gil::planar_pixel_reference (if planar). They must use the standard constness rules. 55 /// \ingroup GILIsBasic 56 template <typename PixelRef> 57 struct pixel_reference_is_basic : public std::false_type {}; 58 59 template <typename T, typename L> 60 struct pixel_reference_is_basic<pixel<T, L>&> : std::true_type {}; 61 62 template <typename T, typename L> 63 struct pixel_reference_is_basic<const pixel<T, L>&> : std::true_type {}; 64 65 template <typename TR, typename CS> 66 struct pixel_reference_is_basic<planar_pixel_reference<TR, CS>> : std::true_type {}; 67 68 template <typename TR, typename CS> 69 struct pixel_reference_is_basic<const planar_pixel_reference<TR, CS>> : std::true_type {}; 70 71 /// \brief Determines if a given pixel iterator is basic 72 /// 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. 73 /// \ingroup GILIsBasic 74 template <typename Iterator> 75 struct iterator_is_basic : std::false_type {}; 76 77 /// \tparam T mutable interleaved pixel type 78 template <typename T, typename L> 79 struct iterator_is_basic<pixel<T, L>*> : std::true_type {}; 80 81 /// \tparam T immutable interleaved pixel type 82 template <typename T, typename L> 83 struct iterator_is_basic<pixel<T, L> const*> : std::true_type {}; 84 85 /// \tparam T mutable planar pixel type 86 template <typename T, typename CS> 87 struct iterator_is_basic<planar_pixel_iterator<T*, CS>> : std::true_type {}; 88 89 /// \tparam T immutable planar pixel type 90 template <typename T, typename CS> 91 struct iterator_is_basic<planar_pixel_iterator<T const*, CS>> : std::true_type {}; 92 93 /// \tparam T mutable interleaved step 94 template <typename T, typename L> 95 struct iterator_is_basic<memory_based_step_iterator<pixel<T, L>*>> : std::true_type {}; 96 97 /// \tparam T immutable interleaved step 98 template <typename T, typename L> 99 struct iterator_is_basic<memory_based_step_iterator<pixel<T, L> const*>> : std::true_type {}; 100 101 /// \tparam T mutable planar step 102 template <typename T, typename CS> 103 struct iterator_is_basic<memory_based_step_iterator<planar_pixel_iterator<T*, CS>>> 104 : std::true_type 105 {}; 106 107 /// \tparam T immutable planar step 108 template <typename T, typename CS> 109 struct iterator_is_basic<memory_based_step_iterator<planar_pixel_iterator<T const*, CS>>> 110 : std::true_type 111 {}; 112 113 114 /// \ingroup GILIsBasic 115 /// \brief Determines if a given locator is basic. A basic locator is memory-based and has basic x_iterator and y_iterator 116 template <typename Loc> 117 struct locator_is_basic : std::false_type {}; 118 119 template <typename Iterator> 120 struct locator_is_basic 121 < 122 memory_based_2d_locator<memory_based_step_iterator<Iterator>> 123 > : iterator_is_basic<Iterator> 124 {}; 125 126 /// \ingroup GILIsBasic 127 /// \brief Basic views must be over basic locators 128 template <typename View> 129 struct view_is_basic : std::false_type {}; 130 131 template <typename Loc> 132 struct view_is_basic<image_view<Loc>> : locator_is_basic<Loc> {}; 133 134 /// \ingroup GILIsBasic 135 /// \brief Basic images must use basic views and std::allocator 136 template <typename Img> 137 struct image_is_basic : std::false_type {}; 138 139 template <typename Pixel, bool IsPlanar, typename Alloc> 140 struct image_is_basic<image<Pixel, IsPlanar, Alloc>> : std::true_type {}; 141 142 143 /// \defgroup GILIsStep xxx_is_step 144 /// \ingroup TypeAnalysis 145 /// \brief Determines if the given iterator/locator/view has a step that could be set dynamically 146 147 template <typename I> 148 struct iterator_is_step; 149 150 namespace detail { 151 152 template <typename It, bool IsBase, bool EqualsStepType> 153 struct iterator_is_step_impl; 154 155 // iterator that has the same type as its dynamic_x_step_type must be a step iterator 156 template <typename It, bool IsBase> 157 struct iterator_is_step_impl<It, IsBase, true> : std::true_type {}; 158 159 // base iterator can never be a step iterator 160 template <typename It> 161 struct iterator_is_step_impl<It, true, false> : std::false_type {}; 162 163 // for an iterator adaptor, see if its base is step 164 template <typename It> 165 struct iterator_is_step_impl<It, false, false> 166 : public iterator_is_step<typename iterator_adaptor_get_base<It>::type> {}; 167 168 } // namespace detail 169 170 /// \ingroup GILIsStep 171 /// \brief Determines if the given iterator has a step that could be set dynamically 172 template <typename I> 173 struct iterator_is_step 174 : detail::iterator_is_step_impl 175 < 176 I, 177 !is_iterator_adaptor<I>::value, 178 std::is_same<I, typename dynamic_x_step_type<I>::type 179 >::value 180 > 181 {}; 182 183 /// \ingroup GILIsStep 184 /// \brief Determines if the given locator has a horizontal step that could be set dynamically 185 template <typename L> struct locator_is_step_in_x : public iterator_is_step<typename L::x_iterator> {}; 186 187 /// \ingroup GILIsStep 188 /// \brief Determines if the given locator has a vertical step that could be set dynamically 189 template <typename L> struct locator_is_step_in_y : public iterator_is_step<typename L::y_iterator> {}; 190 191 /// \ingroup GILIsStep 192 /// \brief Determines if the given view has a horizontal step that could be set dynamically 193 template <typename V> struct view_is_step_in_x : public locator_is_step_in_x<typename V::xy_locator> {}; 194 195 /// \ingroup GILIsStep 196 /// \brief Determines if the given view has a vertical step that could be set dynamically 197 template <typename V> struct view_is_step_in_y : public locator_is_step_in_y<typename V::xy_locator> {}; 198 199 /// \brief Determines whether the given pixel reference is a proxy class or a native C++ reference 200 /// \ingroup TypeAnalysis 201 template <typename PixelReference> 202 struct pixel_reference_is_proxy 203 : mp11::mp_not 204 < 205 std::is_same 206 < 207 typename detail::remove_const_and_reference<PixelReference>::type, 208 typename detail::remove_const_and_reference<PixelReference>::type::value_type 209 > 210 > 211 {}; 212 213 /// \brief Given a model of a pixel, determines whether the model represents a pixel reference (as opposed to pixel value) 214 /// \ingroup TypeAnalysis 215 template <typename Pixel> 216 struct pixel_is_reference 217 : mp11::mp_or<is_reference<Pixel>, pixel_reference_is_proxy<Pixel>> {}; 218 219 /// \defgroup GILIsMutable xxx_is_mutable 220 /// \ingroup TypeAnalysis 221 /// \brief Determines if the given pixel reference/iterator/locator/view is mutable (i.e. its pixels can be changed) 222 223 /// \ingroup GILIsMutable 224 /// \brief Determines if the given pixel reference is mutable (i.e. its channels can be changed) 225 /// 226 /// Note that built-in C++ references obey the const qualifier but reference proxy classes do not. 227 template <typename R> 228 struct pixel_reference_is_mutable 229 : std::integral_constant<bool, std::remove_reference<R>::type::is_mutable> 230 {}; 231 232 template <typename R> 233 struct pixel_reference_is_mutable<R const&> 234 : mp11::mp_and<pixel_reference_is_proxy<R>, pixel_reference_is_mutable<R>> 235 {}; 236 237 /// \ingroup GILIsMutable 238 /// \brief Determines if the given locator is mutable (i.e. its pixels can be changed) 239 template <typename L> struct locator_is_mutable : public iterator_is_mutable<typename L::x_iterator> {}; 240 /// \ingroup GILIsMutable 241 /// \brief Determines if the given view is mutable (i.e. its pixels can be changed) 242 template <typename V> struct view_is_mutable : public iterator_is_mutable<typename V::x_iterator> {}; 243 244 245 ////////////////////////////////////////////////// 246 /// 247 /// TYPE FACTORY METAFUNCTIONS 248 /// Metafunctions returning GIL types from other GIL types 249 /// 250 ////////////////////////////////////////////////// 251 252 /// \defgroup TypeFactoryFromElements xxx_type 253 /// \ingroup TypeFactory 254 /// \brief Returns the type of a homogeneous GIL construct given its elements (channel, layout, whether it is planar, step, mutable, etc.) 255 256 /// \defgroup TypeFactoryFromPixel xxx_type_from_pixel 257 /// \ingroup TypeFactory 258 /// \brief Returns the type of a GIL construct given its pixel type, whether it is planar, step, mutable, etc. 259 260 /// \defgroup TypeFactoryDerived derived_xxx_type 261 /// \ingroup TypeFactory 262 /// \brief Returns the type of a homogeneous GIL construct given a related construct by changing some of its properties 263 264 /// \ingroup TypeFactoryFromElements 265 /// \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 266 template <typename T, typename L, bool IsPlanar=false, bool IsMutable=true> struct pixel_reference_type{}; 267 template <typename T, typename L> struct pixel_reference_type<T,L,false,true > { using type = pixel<T,L>&; }; 268 template <typename T, typename L> struct pixel_reference_type<T,L,false,false> { using type = pixel<T,L> const&; }; 269 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 270 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 271 272 /// \ingroup TypeFactoryFromPixel 273 /// \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 274 template <typename Pixel, bool IsPlanar=false, bool IsStep=false, bool IsMutable=true> struct iterator_type_from_pixel{}; 275 template <typename Pixel> struct iterator_type_from_pixel<Pixel,false,false,true > { using type = Pixel *; }; 276 template <typename Pixel> struct iterator_type_from_pixel<Pixel,false,false,false> { using type = const Pixel *; }; 277 template <typename Pixel> struct iterator_type_from_pixel<Pixel,true,false,true> { 278 using type = planar_pixel_iterator<typename channel_traits<typename channel_type<Pixel>::type>::pointer,typename color_space_type<Pixel>::type>; 279 }; 280 template <typename Pixel> struct iterator_type_from_pixel<Pixel,true,false,false> { 281 using type = planar_pixel_iterator<typename channel_traits<typename channel_type<Pixel>::type>::const_pointer,typename color_space_type<Pixel>::type>; 282 }; 283 template <typename Pixel, bool IsPlanar, bool IsMutable> struct iterator_type_from_pixel<Pixel,IsPlanar,true,IsMutable> { 284 using type = memory_based_step_iterator<typename iterator_type_from_pixel<Pixel,IsPlanar,false,IsMutable>::type>; 285 }; 286 287 /// \ingroup TypeFactoryFromElements 288 /// \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 289 template <typename T, typename L, bool IsPlanar=false, bool IsStep=false, bool IsMutable=true> struct iterator_type{}; 290 template <typename T, typename L> struct iterator_type<T,L,false,false,true > { using type = pixel<T,L>*; }; 291 template <typename T, typename L> struct iterator_type<T,L,false,false,false> { using type = pixel<T,L> const*; }; 292 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 293 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 294 template <typename T, typename L, bool IsPlanar, bool IsMutable> struct iterator_type<T,L,IsPlanar,true,IsMutable> { 295 using type = memory_based_step_iterator<typename iterator_type<T,L,IsPlanar,false,IsMutable>::type>; 296 }; 297 298 /// \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 299 /// \ingroup TypeFactory 300 template <typename XIterator> 301 struct type_from_x_iterator 302 { 303 using step_iterator_t = memory_based_step_iterator<XIterator>; 304 using xy_locator_t = memory_based_2d_locator<step_iterator_t>; 305 using view_t = image_view<xy_locator_t>; 306 }; 307 308 namespace detail { 309 310 template <typename BitField, typename FirstBit, typename NumBits> 311 struct packed_channel_reference_type 312 { 313 using type = packed_channel_reference 314 < 315 BitField, FirstBit::value, NumBits::value, true 316 > const; 317 }; 318 319 template <typename BitField, typename ChannelBitSizes> 320 class packed_channel_references_vector_type 321 { 322 template <typename FirstBit, typename NumBits> 323 using reference_type = typename packed_channel_reference_type<BitField, FirstBit, NumBits>::type; 324 325 // If ChannelBitSizesVector is mp11::mp_list_c<int,7,7,2> 326 // Then first_bits_vector will be mp11::mp_list_c<int,0,7,14,16> 327 using first_bit_list = mp11::mp_fold_q 328 < 329 ChannelBitSizes, 330 mp11::mp_list<std::integral_constant<int, 0>>, 331 mp11::mp_bind 332 < 333 mp11::mp_push_back, 334 mp11::_1, 335 mp11::mp_bind 336 < 337 mp11::mp_plus, 338 mp11::mp_bind<mp_back, mp11::_1>, 339 mp11::_2 340 > 341 > 342 >; 343 344 static_assert(mp11::mp_at_c<first_bit_list, 0>::value == 0, "packed channel first bit must be 0"); 345 346 public: 347 using type = mp11::mp_transform 348 < 349 reference_type, 350 mp_pop_back<first_bit_list>, 351 ChannelBitSizes 352 >; 353 }; 354 355 } // namespace detail 356 357 /// \ingroup TypeFactoryFromElements 358 /// \brief Returns the type of a packed pixel given its bitfield type, the bit size of its channels and its layout. 359 /// 360 /// A packed pixel has channels that cover bit ranges but itself is byte aligned. RGB565 pixel is an example. 361 /// 362 /// The size of ChannelBitSizes must equal the number of channels in the given layout 363 /// 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). 364 /// If it is less than the number of bits in BitField, the last bits will be unused. 365 template <typename BitField, typename ChannelBitSizes, typename Layout> 366 struct packed_pixel_type 367 { 368 using type = packed_pixel 369 < 370 BitField, 371 typename detail::packed_channel_references_vector_type 372 < 373 BitField, 374 ChannelBitSizes 375 >::type, 376 Layout>; 377 }; 378 379 /// \defgroup TypeFactoryPacked packed_image_type,bit_aligned_image_type 380 /// \ingroup TypeFactoryFromElements 381 /// \brief Returns the type of an image whose channels are not byte-aligned. 382 /// 383 /// A packed image is an image whose pixels are byte aligned, such as "rgb565". <br> 384 /// A bit-aligned image is an image whose pixels are not byte aligned, such as "rgb222". <br> 385 /// 386 /// The sum of the bit sizes of all channels cannot exceed 64. 387 388 /// \ingroup TypeFactoryPacked 389 /// \brief Returns the type of an interleaved packed image: an image whose channels may not be byte-aligned, but whose pixels are byte aligned. 390 template <typename BitField, typename ChannelBitSizes, typename Layout, typename Alloc=std::allocator<unsigned char>> 391 struct packed_image_type 392 { 393 using type = image<typename packed_pixel_type<BitField,ChannelBitSizes,Layout>::type,false,Alloc>; 394 }; 395 396 /// \ingroup TypeFactoryPacked 397 /// \brief Returns the type of a single-channel image given its bitfield type, the bit size of its channel and its layout 398 template <typename BitField, unsigned Size1, typename Layout, typename Alloc = std::allocator<unsigned char>> 399 struct packed_image1_type 400 : packed_image_type<BitField, mp11::mp_list_c<unsigned, Size1>, Layout, Alloc> 401 {}; 402 403 /// \ingroup TypeFactoryPacked 404 /// \brief Returns the type of a two channel image given its bitfield type, the bit size of its channels and its layout 405 template <typename BitField, unsigned Size1, unsigned Size2, typename Layout, typename Alloc = std::allocator<unsigned char>> 406 struct packed_image2_type 407 : packed_image_type<BitField, mp11::mp_list_c<unsigned, Size1, Size2>, Layout, Alloc> 408 {}; 409 410 /// \ingroup TypeFactoryPacked 411 /// \brief Returns the type of a three channel image given its bitfield type, the bit size of its channels and its layout 412 template <typename BitField, unsigned Size1, unsigned Size2, unsigned Size3, typename Layout, typename Alloc = std::allocator<unsigned char>> 413 struct packed_image3_type 414 : packed_image_type<BitField, mp11::mp_list_c<unsigned, Size1, Size2, Size3>, Layout, Alloc> 415 {}; 416 417 /// \ingroup TypeFactoryPacked 418 /// \brief Returns the type of a four channel image given its bitfield type, the bit size of its channels and its layout 419 template <typename BitField, unsigned Size1, unsigned Size2, unsigned Size3, unsigned Size4, typename Layout, typename Alloc = std::allocator<unsigned char>> 420 struct packed_image4_type 421 : packed_image_type<BitField, mp11::mp_list_c<unsigned, Size1, Size2, Size3, Size4>, Layout, Alloc> 422 {}; 423 424 /// \ingroup TypeFactoryPacked 425 /// \brief Returns the type of a five channel image given its bitfield type, the bit size of its channels and its layout 426 template <typename BitField, unsigned Size1, unsigned Size2, unsigned Size3, unsigned Size4, unsigned Size5, typename Layout, typename Alloc = std::allocator<unsigned char>> 427 struct packed_image5_type 428 : packed_image_type<BitField, mp11::mp_list_c<unsigned, Size1, Size2, Size3, Size4, Size5>, Layout, Alloc> {}; 429 430 431 /// \ingroup TypeFactoryPacked 432 /// \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. 433 /// 434 /// 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 435 /// image whose rows are byte-aligned, use 8 as the alignment parameter, not 1. 436 /// 437 template 438 < 439 typename ChannelBitSizes, 440 typename Layout, 441 typename Alloc = std::allocator<unsigned char> 442 > 443 struct bit_aligned_image_type 444 { 445 private: 446 447 static constexpr int bit_size = 448 mp11::mp_fold 449 < 450 ChannelBitSizes, 451 std::integral_constant<int, 0>, 452 mp11::mp_plus 453 >::value; 454 455 using bitfield_t = typename detail::min_fast_uint<bit_size + 7>::type; 456 using bit_alignedref_t = bit_aligned_pixel_reference<bitfield_t, ChannelBitSizes, Layout, true> const; 457 458 public: 459 using type = image<bit_alignedref_t,false,Alloc>; 460 }; 461 462 /// \ingroup TypeFactoryPacked 463 /// \brief Returns the type of a single-channel bit-aligned image given the bit size of its channel and its layout 464 template <unsigned Size1, typename Layout, typename Alloc = std::allocator<unsigned char>> 465 struct bit_aligned_image1_type : bit_aligned_image_type<mp11::mp_list_c<unsigned, Size1>, Layout, Alloc> {}; 466 467 /// \ingroup TypeFactoryPacked 468 /// \brief Returns the type of a two channel bit-aligned image given the bit size of its channels and its layout 469 template <unsigned Size1, unsigned Size2, typename Layout, typename Alloc = std::allocator<unsigned char>> 470 struct bit_aligned_image2_type : bit_aligned_image_type<mp11::mp_list_c<unsigned, Size1, Size2>, Layout, Alloc> {}; 471 472 /// \ingroup TypeFactoryPacked 473 /// \brief Returns the type of a three channel bit-aligned image given the bit size of its channels and its layout 474 template <unsigned Size1, unsigned Size2, unsigned Size3, typename Layout, typename Alloc = std::allocator<unsigned char>> 475 struct bit_aligned_image3_type : bit_aligned_image_type<mp11::mp_list_c<unsigned, Size1, Size2, Size3>, Layout, Alloc> {}; 476 477 /// \ingroup TypeFactoryPacked 478 /// \brief Returns the type of a four channel bit-aligned image given the bit size of its channels and its layout 479 template <unsigned Size1, unsigned Size2, unsigned Size3, unsigned Size4, typename Layout, typename Alloc = std::allocator<unsigned char>> 480 struct bit_aligned_image4_type : bit_aligned_image_type<mp11::mp_list_c<unsigned, Size1, Size2, Size3, Size4>, Layout, Alloc> {}; 481 482 /// \ingroup TypeFactoryPacked 483 /// \brief Returns the type of a five channel bit-aligned image given the bit size of its channels and its layout 484 template <unsigned Size1, unsigned Size2, unsigned Size3, unsigned Size4, unsigned Size5, typename Layout, typename Alloc = std::allocator<unsigned char>> 485 struct bit_aligned_image5_type : bit_aligned_image_type<mp11::mp_list_c<unsigned, Size1, Size2, Size3, Size4, Size5>, Layout, Alloc> {}; 486 487 488 /// \ingroup TypeFactoryFromElements 489 /// \brief Returns the type of a homogeneous pixel given the channel type and layout 490 template <typename Channel, typename Layout> 491 struct pixel_value_type 492 { 493 // by default use gil::pixel. Specializations are provided for 494 using type = pixel<Channel, Layout>; 495 }; 496 497 // Specializations for packed channels 498 template <typename BitField, int NumBits, bool IsMutable, typename Layout> 499 struct pixel_value_type<packed_dynamic_channel_reference<BitField, NumBits, IsMutable>, Layout> 500 : packed_pixel_type<BitField, mp11::mp_list_c<unsigned, NumBits>, Layout> 501 {}; 502 503 template <typename BitField, int NumBits, bool IsMutable, typename Layout> 504 struct pixel_value_type<packed_dynamic_channel_reference<BitField, NumBits, IsMutable> const, Layout> 505 : packed_pixel_type<BitField, mp11::mp_list_c<unsigned, NumBits>, Layout> 506 {}; 507 508 template <typename BitField, int FirstBit, int NumBits, bool IsMutable, typename Layout> 509 struct pixel_value_type<packed_channel_reference<BitField, FirstBit, NumBits, IsMutable>, Layout> 510 : packed_pixel_type<BitField, mp11::mp_list_c<unsigned, NumBits>, Layout> 511 {}; 512 513 template <typename BitField, int FirstBit, int NumBits, bool IsMutable, typename Layout> 514 struct pixel_value_type<packed_channel_reference<BitField, FirstBit, NumBits, IsMutable> const, Layout> 515 : packed_pixel_type<BitField, mp11::mp_list_c<unsigned, NumBits>, Layout> 516 {}; 517 518 template <int NumBits, typename Layout> 519 struct pixel_value_type<packed_channel_value<NumBits>, Layout> 520 : packed_pixel_type<typename detail::min_fast_uint<NumBits>::type, mp11::mp_list_c<unsigned, NumBits>, Layout> 521 {}; 522 523 /// \ingroup TypeFactoryFromElements 524 /// \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 525 template <typename T, typename L, bool IsPlanar = false, bool IsStepX = false, bool IsMutable = true> 526 struct locator_type 527 { 528 using type = typename type_from_x_iterator 529 < 530 typename iterator_type<T, L, IsPlanar, IsStepX, IsMutable>::type 531 >::xy_locator_type; 532 }; 533 534 /// \ingroup TypeFactoryFromElements 535 /// \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 536 template <typename T, typename L, bool IsPlanar = false, bool IsStepX = false, bool IsMutable = true> 537 struct view_type 538 { 539 using type = typename type_from_x_iterator 540 < 541 typename iterator_type<T, L, IsPlanar, IsStepX, IsMutable>::type 542 >::view_t; 543 }; 544 545 /// \ingroup TypeFactoryFromElements 546 /// \brief Returns the type of a homogeneous image given the channel type, layout, and whether it operates on planar data 547 template <typename T, typename L, bool IsPlanar = false, typename Alloc = std::allocator<unsigned char>> 548 struct image_type 549 { 550 using type = image<pixel<T, L>, IsPlanar, Alloc>; 551 }; 552 553 /// \ingroup TypeFactoryFromPixel 554 /// \brief Returns the type of a view the pixel type, whether it operates on planar data and whether it has a step horizontally 555 template <typename Pixel, bool IsPlanar=false, bool IsStepX=false, bool IsMutable=true> 556 struct view_type_from_pixel { 557 using type = typename type_from_x_iterator<typename iterator_type_from_pixel<Pixel,IsPlanar,IsStepX,IsMutable>::type>::view_t; 558 }; 559 560 561 /// \brief Constructs a pixel reference type from a source pixel reference type by changing some of the properties. 562 /// \ingroup TypeFactoryDerived 563 /// Use use_default for the properties of the source view that you want to keep 564 template 565 < 566 typename Ref, 567 typename T = use_default, 568 typename L = use_default, 569 typename IsPlanar = use_default, 570 typename IsMutable = use_default> 571 class derived_pixel_reference_type 572 { 573 using pixel_t = typename std::remove_reference<Ref>::type; 574 575 using channel_t = typename mp11::mp_if 576 < 577 std::is_same<T, use_default>, 578 typename channel_type<pixel_t>::type, 579 T 580 >::type; 581 582 using layout_t = typename mp11::mp_if 583 < 584 std::is_same<L, use_default>, 585 layout 586 < 587 typename color_space_type<pixel_t>::type, 588 typename channel_mapping_type<pixel_t>::type 589 >, 590 L 591 >::type; 592 593 static bool const mut = mp11::mp_if 594 < 595 std::is_same<IsMutable, use_default>, 596 pixel_reference_is_mutable<Ref>, 597 IsMutable 598 >::value; 599 600 static bool const planar = mp11::mp_if 601 < 602 std::is_same<IsPlanar, use_default>, 603 is_planar<pixel_t>, 604 IsPlanar 605 >::value; 606 607 public: 608 using type = typename pixel_reference_type<channel_t, layout_t, planar, mut>::type; 609 }; 610 611 /// \brief Constructs a pixel iterator type from a source pixel iterator type by changing some of the properties. 612 /// \ingroup TypeFactoryDerived 613 /// Use use_default for the properties of the source view that you want to keep 614 template 615 < 616 typename Iterator, 617 typename T = use_default, 618 typename L = use_default, 619 typename IsPlanar = use_default, 620 typename IsStep = use_default, 621 typename IsMutable = use_default 622 > 623 class derived_iterator_type 624 { 625 using channel_t = typename mp11::mp_if 626 < 627 std::is_same<T, use_default>, 628 typename channel_type<Iterator>::type, 629 T 630 >::type; 631 632 using layout_t = typename mp11::mp_if 633 < 634 std::is_same<L, use_default>, 635 layout 636 < 637 typename color_space_type<Iterator>::type, 638 typename channel_mapping_type<Iterator>::type 639 >, 640 L 641 >::type; 642 643 static const bool mut = mp11::mp_if 644 < 645 std::is_same<IsMutable, use_default>, 646 iterator_is_mutable<Iterator>, 647 IsMutable 648 >::value; 649 650 static bool const planar = mp11::mp_if 651 < 652 std::is_same<IsPlanar, use_default>, 653 is_planar<Iterator>, 654 IsPlanar 655 >::value; 656 657 static bool const step = mp11::mp_if 658 < 659 std::is_same<IsStep, use_default>, 660 iterator_is_step<Iterator>, 661 IsStep 662 >::type::value; 663 664 public: 665 using type = typename iterator_type<channel_t, layout_t, planar, step, mut>::type; 666 }; 667 668 /// \brief Constructs an image view type from a source view type by changing some of the properties. 669 /// \ingroup TypeFactoryDerived 670 /// Use use_default for the properties of the source view that you want to keep 671 template <typename View, typename T = use_default, typename L = use_default, typename IsPlanar = use_default, typename StepX = use_default, typename IsMutable = use_default> 672 class derived_view_type 673 { 674 using channel_t = typename mp11::mp_if 675 < 676 std::is_same<T, use_default>, 677 typename channel_type<View>::type, 678 T 679 >; 680 681 using layout_t = typename mp11::mp_if 682 < 683 std::is_same<L, use_default>, 684 layout 685 < 686 typename color_space_type<View>::type, 687 typename channel_mapping_type<View>::type 688 >, 689 L 690 >; 691 692 static bool const mut = mp11::mp_if 693 < 694 std::is_same<IsMutable, use_default>, 695 view_is_mutable<View>, 696 IsMutable 697 >::value; 698 699 static bool const planar = mp11::mp_if 700 < 701 std::is_same<IsPlanar, use_default>, 702 is_planar<View>, 703 IsPlanar 704 >::value; 705 706 static bool const step = mp11::mp_if 707 < 708 std::is_same<StepX, use_default>, 709 view_is_step_in_x<View>, 710 StepX 711 >::value; 712 713 public: 714 using type = typename view_type<channel_t, layout_t, planar, step, mut>::type; 715 }; 716 717 /// \brief Constructs a homogeneous image type from a source image type by changing some of the properties. 718 /// \ingroup TypeFactoryDerived 719 /// Use use_default for the properties of the source image that you want to keep 720 template <typename Image, typename T = use_default, typename L = use_default, typename IsPlanar = use_default> 721 class derived_image_type 722 { 723 using channel_t = typename mp11::mp_if 724 < 725 std::is_same<T, use_default>, 726 typename channel_type<Image>::type, 727 T 728 >::type; 729 730 using layout_t = typename mp11::mp_if 731 < 732 std::is_same<L, use_default>, 733 layout 734 < 735 typename color_space_type<Image>::type, 736 typename channel_mapping_type<Image>::type>, 737 L 738 >::type; 739 740 static bool const planar = mp11::mp_if 741 < 742 std::is_same<IsPlanar, use_default>, 743 is_planar<Image>, 744 IsPlanar 745 >::value; 746 747 public: 748 using type = typename image_type<channel_t, layout_t, planar>::type; 749 }; 750 751 }} // namespace boost::gil 752 753 #endif 754