Ticket #4517: 4517-missing-std-qualifier-to-ptrdiff_t-in-headers.patch
File 4517-missing-std-qualifier-to-ptrdiff_t-in-headers.patch, 40.8 KB (added by , 10 years ago) |
---|
-
boost/gil/algorithm.hpp
1 1 /* 2 2 Copyright 2005-2007 Adobe Systems Incorporated 3 3 4 4 Use, modification and distribution are subject to the Boost Software License, 5 5 Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 6 http://www.boost.org/LICENSE_1_0.txt). … … 8 8 See http://opensource.adobe.com/gil for most recent version including documentation. 9 9 */ 10 10 11 12 11 /*************************************************************************************************/ 13 12 14 13 #ifndef GIL_ALGORITHM_HPP … … 34 33 #include "bit_aligned_pixel_iterator.hpp" 35 34 36 35 //////////////////////////////////////////////////////////////////////////////////////// 37 /// \file 36 /// \file 38 37 /// \brief Some basic STL-style algorithms when applied to image views 39 38 /// \author Lubomir Bourdev and Hailin Jin \n 40 39 /// Adobe Systems Incorporated … … 48 47 //#endif 49 48 50 49 namespace boost { namespace gil { 51 52 50 //forward declarations 53 51 template <typename ChannelPtr, typename ColorSpace> 54 52 struct planar_pixel_iterator; … … 82 80 /// is overloaded to perform \p std::copy for each of the planes. \p std::copy over bitwise-copiable pixels results in 83 81 /// std::copy over unsigned char, which STL typically implements via \p memmove. 84 82 /// 85 /// As a result \p copy_pixels may result in a single call to \p memmove for interleaved 1D-traversable views, 83 /// As a result \p copy_pixels may result in a single call to \p memmove for interleaved 1D-traversable views, 86 84 /// or one per each plane of planar 1D-traversable views, or one per each row of interleaved non-1D-traversable images, etc. 87 85 88 89 86 /// \defgroup STLOptimizations Performance overloads of STL algorithms 90 87 /// \ingroup ImageViewAlgorithm 91 88 /// \brief overloads of STL algorithms allowing more efficient implementation when used with GIL constructs … … 146 143 /// \brief std::copy for image views 147 144 148 145 namespace std { 149 150 146 /// \ingroup STLOptimizations 151 147 /// \brief Copy when both src and dst are interleaved and of the same type can be just memmove 152 template<typename T, typename Cs> 153 GIL_FORCEINLINE boost::gil::pixel<T,Cs>* 154 copy(boost::gil::pixel<T,Cs>* first, boost::gil::pixel<T,Cs>* last, 155 boost::gil::pixel<T,Cs>* dst) { 148 template<typename T, typename Cs> 149 GIL_FORCEINLINE boost::gil::pixel<T,Cs>* 150 copy(boost::gil::pixel<T,Cs>* first, boost::gil::pixel<T,Cs>* last, 151 boost::gil::pixel<T,Cs>* dst) { 156 152 return (boost::gil::pixel<T,Cs>*)std::copy((unsigned char*)first,(unsigned char*)last, (unsigned char*)dst); 157 153 } 158 154 159 155 /// \ingroup STLOptimizations 160 156 /// \brief Copy when both src and dst are interleaved and of the same type can be just memmove 161 template<typename T, typename Cs> 162 GIL_FORCEINLINE boost::gil::pixel<T,Cs>* 163 copy(const boost::gil::pixel<T,Cs>* first, const boost::gil::pixel<T,Cs>* last, 164 boost::gil::pixel<T,Cs>* dst) { 157 template<typename T, typename Cs> 158 GIL_FORCEINLINE boost::gil::pixel<T,Cs>* 159 copy(const boost::gil::pixel<T,Cs>* first, const boost::gil::pixel<T,Cs>* last, 160 boost::gil::pixel<T,Cs>* dst) { 165 161 return (boost::gil::pixel<T,Cs>*)std::copy((unsigned char*)first,(unsigned char*)last, (unsigned char*)dst); 166 162 } 167 163 } // namespace std 168 164 169 165 namespace boost { namespace gil { 170 166 namespace detail { 171 template <typename I, typename O> struct copy_fn { 172 GIL_FORCEINLINE I operator()(I first, I last, O dst) const { return std::copy(first,last,dst); } 167 template <typename I, typename O> struct copy_fn { 168 GIL_FORCEINLINE I operator()(I first, I last, O dst) const { return std::copy(first,last,dst); } 173 169 }; 174 170 } // namespace detail 175 171 } } // namespace boost::gil … … 178 174 /// \ingroup STLOptimizations 179 175 /// \brief Copy when both src and dst are planar pointers is copy for each channel 180 176 template<typename Cs, typename IC1, typename IC2> GIL_FORCEINLINE 181 boost::gil::planar_pixel_iterator<IC2,Cs> copy(boost::gil::planar_pixel_iterator<IC1,Cs> first, boost::gil::planar_pixel_iterator<IC1,Cs> last, boost::gil::planar_pixel_iterator<IC2,Cs> dst) { 177 boost::gil::planar_pixel_iterator<IC2,Cs> copy(boost::gil::planar_pixel_iterator<IC1,Cs> first, boost::gil::planar_pixel_iterator<IC1,Cs> last, boost::gil::planar_pixel_iterator<IC2,Cs> dst) { 182 178 boost::gil::gil_function_requires<boost::gil::ChannelsCompatibleConcept<typename std::iterator_traits<IC1>::value_type,typename std::iterator_traits<IC2>::value_type> >(); 183 179 static_for_each(first,last,dst,boost::gil::detail::copy_fn<IC1,IC2>()); 184 180 return dst+(last-first); … … 274 270 } 275 271 return dst+n; 276 272 } 277 278 273 } // namespace detail 279 274 } } // namespace boost::gil 280 275 … … 285 280 GIL_FORCEINLINE boost::gil::iterator_from_2d<OL> copy1(boost::gil::iterator_from_2d<IL> first, boost::gil::iterator_from_2d<IL> last, boost::gil::iterator_from_2d<OL> dst) { 286 281 return boost::gil::detail::copy_with_2d_iterators(first,last,dst); 287 282 } 288 289 283 } // namespace std 290 284 291 285 namespace boost { namespace gil { 292 293 294 286 /// \ingroup ImageViewSTLAlgorithmsCopyPixels 295 287 /// \brief std::copy for image views 296 288 template <typename View1, typename View2> GIL_FORCEINLINE 297 void copy_pixels(const View1& src, const View2& dst) { 289 void copy_pixels(const View1& src, const View2& dst) { 298 290 assert(src.dimensions()==dst.dimensions()); 299 291 detail::copy_with_2d_iterators(src.begin(),src.end(),dst.begin()); 300 292 } … … 321 313 copy_and_convert_pixels_fn() {} 322 314 copy_and_convert_pixels_fn(CC cc_in) : _cc(cc_in) {} 323 315 // when the two color spaces are incompatible, a color conversion is performed 324 template <typename V1, typename V2> GIL_FORCEINLINE 316 template <typename V1, typename V2> GIL_FORCEINLINE 325 317 result_type apply_incompatible(const V1& src, const V2& dst) const { 326 318 copy_pixels(color_converted_view<typename V2::value_type>(src,_cc),dst); 327 319 } 328 320 329 321 // If the two color spaces are compatible, copy_and_convert is just copy 330 template <typename V1, typename V2> GIL_FORCEINLINE 322 template <typename V1, typename V2> GIL_FORCEINLINE 331 323 result_type apply_compatible(const V1& src, const V2& dst) const { 332 324 copy_pixels(src,dst); 333 325 } … … 335 327 } // namespace detail 336 328 337 329 /// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels 338 template <typename V1, typename V2,typename CC> 339 GIL_FORCEINLINE 340 void copy_and_convert_pixels(const V1& src, const V2& dst,CC cc) { 330 template <typename V1, typename V2,typename CC> 331 GIL_FORCEINLINE 332 void copy_and_convert_pixels(const V1& src, const V2& dst,CC cc) { 341 333 detail::copy_and_convert_pixels_fn<CC> ccp(cc); 342 334 ccp(src,dst); 343 335 } … … 345 337 struct default_color_converter; 346 338 347 339 /// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels 348 template <typename View1, typename View2> 349 GIL_FORCEINLINE 350 void copy_and_convert_pixels(const View1& src, const View2& dst) { 340 template <typename View1, typename View2> 341 GIL_FORCEINLINE 342 void copy_and_convert_pixels(const View1& src, const View2& dst) { 351 343 detail::copy_and_convert_pixels_fn<default_color_converter> ccp; 352 344 ccp(src,dst); 353 345 } 354 355 346 } } // namespace boost::gil 356 347 357 348 ////////////////////////////////////////////////////////////////////////////////////// … … 364 355 /// \ingroup ImageViewSTLAlgorithms 365 356 /// \brief std::fill for image views 366 357 367 368 358 namespace std { 369 359 /// \ingroup STLOptimizations 370 360 /// \brief std::fill(I,I,V) with I being a iterator_from_2d 371 361 /// 372 362 /// Invoked when one calls std::fill(I,I,V) with I being a iterator_from_2d (which is 373 363 /// a 1D iterator over the pixels in an image). For contiguous images (i.e. images that have 374 /// no alignment gap at the end of each row) it is more efficient to use the underlying 364 /// no alignment gap at the end of each row) it is more efficient to use the underlying 375 365 /// pixel iterator that does not check for the end of rows. For non-contiguous images fill 376 366 /// resolves to fill of each row using the underlying pixel iterator, which is still faster 377 367 template <typename IL, typename V> … … 389 379 n-=numToDo; 390 380 } 391 381 } 392 } 382 } 393 383 } // namespace std 394 384 395 385 namespace boost { namespace gil { 396 397 386 namespace detail { 398 387 /// struct to do std::fill 399 388 struct std_fill_t { … … 404 393 }; 405 394 /// std::fill for planar iterators 406 395 template <typename It, typename P> 407 GIL_FORCEINLINE 396 GIL_FORCEINLINE 408 397 void fill_aux(It first, It last, const P& p, mpl::true_) { 409 398 static_for_each(first,last,p,std_fill_t()); 410 399 } 411 400 /// std::fill for interleaved iterators 412 401 template <typename It, typename P> 413 GIL_FORCEINLINE 402 GIL_FORCEINLINE 414 403 void fill_aux(It first, It last, const P& p,mpl::false_) { 415 404 std::fill(first,last,p); 416 405 } … … 418 407 419 408 /// \ingroup ImageViewSTLAlgorithmsFillPixels 420 409 /// \brief std::fill for image views 421 template <typename View, typename Value> GIL_FORCEINLINE 410 template <typename View, typename Value> GIL_FORCEINLINE 422 411 void fill_pixels(const View& img_view, const Value& val) { 423 412 if (img_view.is_1d_traversable()) 424 detail::fill_aux(img_view.begin().x(), img_view.end().x(), 413 detail::fill_aux(img_view.begin().x(), img_view.end().x(), 425 414 val,is_planar<View>()); 426 415 else 427 416 for (std::ptrdiff_t y=0; y<img_view.height(); ++y) … … 439 428 /// \ingroup ImageViewSTLAlgorithms 440 429 /// \brief invokes the destructor on every pixel of an image view 441 430 442 443 431 namespace detail { 444 445 432 template <typename It> GIL_FORCEINLINE 446 433 void destruct_range_impl( It first 447 434 , It last … … 461 448 void destruct_range_impl( It 462 449 , It 463 450 , typename enable_if< mpl::or_< mpl::not_< is_pointer< It > > 464 , boost::has_trivial_destructor< typename std::iterator_traits< It >::value_type > 451 , boost::has_trivial_destructor< typename std::iterator_traits< It >::value_type > 465 452 > 466 453 >::type* /* ptr */ = 0) 467 454 {} 468 455 469 456 template <typename It> GIL_FORCEINLINE 470 457 void destruct_range(It first, It last) { 471 472 458 destruct_range_impl( first 473 459 , last 474 460 ); … … 480 466 481 467 /// destruct for planar iterators 482 468 template <typename It> 483 GIL_FORCEINLINE 469 GIL_FORCEINLINE 484 470 void destruct_aux(It first, It last, mpl::true_) { 485 471 static_for_each(first,last,std_destruct_t()); 486 472 } 487 473 /// destruct for interleaved iterators 488 474 template <typename It> 489 GIL_FORCEINLINE 475 GIL_FORCEINLINE 490 476 void destruct_aux(It first, It last, mpl::false_) { 491 477 destruct_range(first,last); 492 478 } 493 494 479 } // namespace detail 495 480 496 481 /// \ingroup ImageViewSTLAlgorithmsDestructPixels 497 482 /// \brief Invokes the in-place destructor on every pixel of the view 498 template <typename View> GIL_FORCEINLINE 483 template <typename View> GIL_FORCEINLINE 499 484 void destruct_pixels(const View& img_view) { 500 if (img_view.is_1d_traversable()) 501 detail::destruct_aux(img_view.begin().x(), img_view.end().x(), 485 if (img_view.is_1d_traversable()) 486 detail::destruct_aux(img_view.begin().x(), img_view.end().x(), 502 487 is_planar<View>()); 503 488 else 504 489 for (std::ptrdiff_t y=0; y<img_view.height(); ++y) … … 516 501 /// \ingroup ImageViewSTLAlgorithms 517 502 /// \brief std::uninitialized_fill for image views 518 503 519 520 504 namespace detail { 521 522 505 /// std::uninitialized_fill for planar iterators 523 506 /// If an exception is thrown destructs any in-place copy-constructed objects 524 507 template <typename It, typename P> 525 GIL_FORCEINLINE 508 GIL_FORCEINLINE 526 509 void uninitialized_fill_aux(It first, It last, 527 510 const P& p, mpl::true_) { 528 511 int channel=0; 529 512 try { 530 513 typedef typename std::iterator_traits<It>::value_type pixel_t; 531 514 while (channel < num_channels<pixel_t>::value) { 532 std::uninitialized_fill(dynamic_at_c(first,channel), dynamic_at_c(last,channel), 515 std::uninitialized_fill(dynamic_at_c(first,channel), dynamic_at_c(last,channel), 533 516 dynamic_at_c(p,channel)); 534 517 ++channel; 535 518 } … … 543 526 /// std::uninitialized_fill for interleaved iterators 544 527 /// If an exception is thrown destructs any in-place copy-constructed objects 545 528 template <typename It, typename P> 546 GIL_FORCEINLINE 529 GIL_FORCEINLINE 547 530 void uninitialized_fill_aux(It first, It last, 548 531 const P& p,mpl::false_) { 549 532 std::uninitialized_fill(first,last,p); 550 533 } 551 552 534 } // namespace detail 553 535 554 536 /// \ingroup ImageViewSTLAlgorithmsUninitializedFillPixels 555 537 /// \brief std::uninitialized_fill for image views. 556 538 /// Does not support planar heterogeneous views. 557 539 /// If an exception is thrown destructs any in-place copy-constructed pixels 558 template <typename View, typename Value> 540 template <typename View, typename Value> 559 541 void uninitialized_fill_pixels(const View& img_view, const Value& val) { 560 if (img_view.is_1d_traversable()) 561 detail::uninitialized_fill_aux(img_view.begin().x(), img_view.end().x(), 542 if (img_view.is_1d_traversable()) 543 detail::uninitialized_fill_aux(img_view.begin().x(), img_view.end().x(), 562 544 val,is_planar<View>()); 563 545 else { 564 546 typename View::y_coord_t y; … … 585 567 /// \brief invokes the default constructor on every pixel of an image view 586 568 587 569 namespace detail { 588 589 template <typename It> GIL_FORCEINLINE 570 template <typename It> GIL_FORCEINLINE 590 571 void default_construct_range_impl(It first, It last, mpl::true_) { 591 572 typedef typename std::iterator_traits<It>::value_type value_t; 592 573 It first1=first; … … 601 582 } 602 583 } 603 584 604 template <typename It> GIL_FORCEINLINE 585 template <typename It> GIL_FORCEINLINE 605 586 void default_construct_range_impl(It, It, mpl::false_) {} 606 587 607 template <typename It> GIL_FORCEINLINE 588 template <typename It> GIL_FORCEINLINE 608 589 void default_construct_range(It first, It last) { default_construct_range_impl(first, last, typename is_pointer<It>::type()); } 609 590 610 591 /// uninitialized_default_construct for planar iterators 611 592 template <typename It> 612 GIL_FORCEINLINE 593 GIL_FORCEINLINE 613 594 void default_construct_aux(It first, It last, mpl::true_) { 614 595 int channel=0; 615 596 try { … … 627 608 628 609 /// uninitialized_default_construct for interleaved iterators 629 610 template <typename It> 630 GIL_FORCEINLINE 611 GIL_FORCEINLINE 631 612 void default_construct_aux(It first, It last, mpl::false_) { 632 613 default_construct_range(first,last); 633 614 } … … 636 617 struct has_trivial_pixel_constructor : public boost::has_trivial_constructor<typename View::value_type> {}; 637 618 template <typename View> 638 619 struct has_trivial_pixel_constructor<View, true> : public boost::has_trivial_constructor<typename channel_type<View>::type> {}; 639 640 620 } // namespace detail 641 621 642 622 namespace detail { 643 644 623 template< typename View, bool B > GIL_FORCEINLINE 645 624 void default_construct_pixels_impl( const View& img_view 646 625 , boost::enable_if< is_same< mpl::bool_< B > … … 649 628 >* /* ptr */ = 0 650 629 ) 651 630 { 652 if( img_view.is_1d_traversable() ) 631 if( img_view.is_1d_traversable() ) 653 632 { 654 633 detail::default_construct_aux( img_view.begin().x() 655 634 , img_view.end().x() … … 681 660 throw; 682 661 } 683 662 } 684 685 663 } 686 687 664 } // namespace detail 688 665 689 690 666 /// \ingroup ImageViewSTLAlgorithmsDefaultConstructPixels 691 667 /// \brief Invokes the in-place default constructor on every pixel of the (uninitialized) view. 692 668 /// Does not support planar heterogeneous views. 693 669 /// If an exception is thrown destructs any in-place default-constructed pixels 694 template <typename View> 670 template <typename View> 695 671 void default_construct_pixels(const View& img_view) { 696 697 672 detail::default_construct_pixels_impl< View 698 673 , detail::has_trivial_pixel_constructor< View 699 674 , is_planar< View >::value … … 701 676 >( img_view ); 702 677 } 703 678 704 705 679 ////////////////////////////////////////////////////////////////////////////////////// 706 680 /// 707 681 /// uninitialized_copy_pixels … … 713 687 /// \brief std::uninitialized_copy for image views 714 688 715 689 namespace detail { 716 717 690 /// std::uninitialized_copy for pairs of planar iterators 718 691 template <typename It1, typename It2> 719 GIL_FORCEINLINE 692 GIL_FORCEINLINE 720 693 void uninitialized_copy_aux(It1 first1, It1 last1, 721 694 It2 first2, mpl::true_) { 722 695 int channel=0; … … 736 709 } 737 710 /// std::uninitialized_copy for interleaved or mixed iterators 738 711 template <typename It1, typename It2> 739 GIL_FORCEINLINE 712 GIL_FORCEINLINE 740 713 void uninitialized_copy_aux(It1 first1, It1 last1, 741 714 It2 first2,mpl::false_) { 742 715 std::uninitialized_copy(first1,last1,first2); … … 747 720 /// \brief std::uninitialized_copy for image views. 748 721 /// Does not support planar heterogeneous views. 749 722 /// If an exception is thrown destructs any in-place copy-constructed objects 750 template <typename View1, typename View2> 723 template <typename View1, typename View2> 751 724 void uninitialized_copy_pixels(const View1& view1, const View2& view2) { 752 typedef mpl::bool_<is_planar<View1>::value && is_planar<View2>::value> is_planar; 725 typedef mpl::bool_<is_planar<View1>::value && is_planar<View2>::value> is_planar; 753 726 assert(view1.dimensions()==view2.dimensions()); 754 727 if (view1.is_1d_traversable() && view2.is_1d_traversable()) 755 detail::uninitialized_copy_aux(view1.begin().x(), view1.end().x(), 756 view2.begin().x(), 728 detail::uninitialized_copy_aux(view1.begin().x(), view1.end().x(), 729 view2.begin().x(), 757 730 is_planar()); 758 731 else { 759 732 typename View1::y_coord_t y; … … 780 753 /// \ingroup ImageViewSTLAlgorithms 781 754 /// \brief std::for_each for image views 782 755 /// 783 /// For contiguous images (i.e. images that have no alignment gap at the end of each row) it is 784 /// more efficient to use the underlying pixel iterator that does not check for the end of rows. 785 /// For non-contiguous images for_each_pixel resolves to for_each of each row using the underlying 756 /// For contiguous images (i.e. images that have no alignment gap at the end of each row) it is 757 /// more efficient to use the underlying pixel iterator that does not check for the end of rows. 758 /// For non-contiguous images for_each_pixel resolves to for_each of each row using the underlying 786 759 /// pixel iterator, which is still faster 787 760 788 761 /// \ingroup ImageViewSTLAlgorithmsForEachPixel … … 813 786 return fun; 814 787 } 815 788 816 817 789 ////////////////////////////////////////////////////////////////////////////////////// 818 790 /// 819 791 /// generate_pixels … … 849 821 template <typename I1, typename I2> GIL_FORCEINLINE bool equal_n(I1 i1, std::ptrdiff_t n, I2 i2); 850 822 851 823 namespace detail { 852 853 824 template <typename I1, typename I2> 854 825 struct equal_n_fn { 855 826 GIL_FORCEINLINE bool operator()(I1 i1, std::ptrdiff_t n, I2 i2) const { return std::equal(i1,i1+n, i2); } 856 827 }; 857 828 858 /// Equal when both ranges are interleaved and of the same type. 829 /// Equal when both ranges are interleaved and of the same type. 859 830 /// GIL pixels are bitwise comparable, so memcmp is used. User-defined pixels that are not bitwise comparable need to provide an overload 860 831 template<typename T, typename Cs> 861 832 struct equal_n_fn<const pixel<T,Cs>*, const pixel<T,Cs>*> { 862 GIL_FORCEINLINE bool operator()(const pixel<T,Cs>* i1, std::ptrdiff_t n, const pixel<T,Cs>* i2) const { 833 GIL_FORCEINLINE bool operator()(const pixel<T,Cs>* i1, std::ptrdiff_t n, const pixel<T,Cs>* i2) const { 863 834 return memcmp(i1, i2, n*sizeof(pixel<T,Cs>))==0; 864 835 } 865 836 }; … … 871 842 /// User-defined channels that are not bitwise comparable need to provide an overload 872 843 template<typename IC, typename Cs> 873 844 struct equal_n_fn<planar_pixel_iterator<IC,Cs>, planar_pixel_iterator<IC,Cs> > { 874 GIL_FORCEINLINE bool operator()(const planar_pixel_iterator<IC,Cs> i1, std::ptrdiff_t n, const planar_pixel_iterator<IC,Cs> i2) const { 875 ptrdiff_t numBytes=n*sizeof(typename std::iterator_traits<IC>::value_type);845 GIL_FORCEINLINE bool operator()(const planar_pixel_iterator<IC,Cs> i1, std::ptrdiff_t n, const planar_pixel_iterator<IC,Cs> i2) const { 846 std::ptrdiff_t numBytes=n*sizeof(typename std::iterator_traits<IC>::value_type); 876 847 877 848 for (std::ptrdiff_t i=0; i<mpl::size<Cs>::value; ++i) 878 849 if (memcmp(dynamic_at_c(i1,i), dynamic_at_c(i2,i), numBytes)!=0) … … 881 852 } 882 853 }; 883 854 884 885 855 /// Source range is delimited by image iterators 886 856 template <typename Loc, typename I2> // IL Models ConstPixelLocatorConcept, O Models PixelIteratorConcept 887 857 struct equal_n_fn<boost::gil::iterator_from_2d<Loc>,I2> { … … 953 923 /// \brief std::equal(I1,I1,I2) with I1 and I2 being a iterator_from_2d 954 924 /// 955 925 /// Invoked when one calls std::equal(I1,I1,I2) with I1 and I2 being a iterator_from_2d (which is 956 /// a 1D iterator over the pixels in an image). Attempts to demote the source and destination 926 /// a 1D iterator over the pixels in an image). Attempts to demote the source and destination 957 927 /// iterators to simpler/faster types if the corresponding range is contiguous. 958 928 /// For contiguous images (i.e. images that have 959 /// no alignment gap at the end of each row) it is more efficient to use the underlying 929 /// no alignment gap at the end of each row) it is more efficient to use the underlying 960 930 /// pixel iterator that does not check for the end of rows. If the underlying pixel iterator 961 931 /// happens to be a fundamental planar/interleaved pointer, the call may further resolve 962 932 /// to memcmp. Otherwise it resolves to copying each row using the underlying pixel iterator 963 template <typename Loc1, typename Loc2> GIL_FORCEINLINE 933 template <typename Loc1, typename Loc2> GIL_FORCEINLINE 964 934 bool equal(boost::gil::iterator_from_2d<Loc1> first, boost::gil::iterator_from_2d<Loc1> last, boost::gil::iterator_from_2d<Loc2> first2) { 965 935 boost::gil::gil_function_requires<boost::gil::PixelLocatorConcept<Loc1> >(); 966 936 boost::gil::gil_function_requires<boost::gil::PixelLocatorConcept<Loc2> >(); … … 980 950 } // namespace std 981 951 982 952 namespace boost { namespace gil { 983 984 953 /// \ingroup ImageViewSTLAlgorithmsEqualPixels 985 954 /// \brief std::equal for image views 986 template <typename View1, typename View2> GIL_FORCEINLINE 955 template <typename View1, typename View2> GIL_FORCEINLINE 987 956 bool equal_pixels(const View1& v1, const View2& v2) { 988 957 assert(v1.dimensions()==v2.dimensions()); 989 958 return std::equal(v1.begin(),v1.end(),v2.begin()); // std::equal has overloads with GIL iterators for optimal performance … … 1001 970 1002 971 /// \ingroup ImageViewSTLAlgorithmsTransformPixels 1003 972 /// \brief std::transform for image views 1004 template <typename View1, typename View2, typename F> GIL_FORCEINLINE 973 template <typename View1, typename View2, typename F> GIL_FORCEINLINE 1005 974 F transform_pixels(const View1& src,const View2& dst, F fun) { 1006 975 assert(src.dimensions()==dst.dimensions()); 1007 976 for (std::ptrdiff_t y=0; y<src.height(); ++y) { … … 1015 984 1016 985 /// \ingroup ImageViewSTLAlgorithmsTransformPixels 1017 986 /// \brief transform_pixels with two sources 1018 template <typename View1, typename View2, typename View3, typename F> GIL_FORCEINLINE 987 template <typename View1, typename View2, typename View3, typename F> GIL_FORCEINLINE 1019 988 F transform_pixels(const View1& src1, const View2& src2,const View3& dst, F fun) { 1020 989 for (std::ptrdiff_t y=0; y<dst.height(); ++y) { 1021 990 typename View1::x_iterator srcIt1=src1.row_begin(y); … … 1029 998 1030 999 /// \defgroup ImageViewSTLAlgorithmsTransformPixelPositions transform_pixel_positions 1031 1000 /// \ingroup ImageViewSTLAlgorithms 1032 /// \brief adobe::transform_positions for image views (passes locators, instead of pixel references, to the function object) 1001 /// \brief adobe::transform_positions for image views (passes locators, instead of pixel references, to the function object) 1033 1002 1034 1003 /// \ingroup ImageViewSTLAlgorithmsTransformPixelPositions 1035 1004 /// \brief Like transform_pixels but passes to the function object pixel locators instead of pixel references 1036 template <typename View1, typename View2, typename F> GIL_FORCEINLINE 1005 template <typename View1, typename View2, typename F> GIL_FORCEINLINE 1037 1006 F transform_pixel_positions(const View1& src,const View2& dst, F fun) { 1038 1007 assert(src.dimensions()==dst.dimensions()); 1039 1008 typename View1::xy_locator loc=src.xy_at(0,0); … … 1048 1017 1049 1018 /// \ingroup ImageViewSTLAlgorithmsTransformPixelPositions 1050 1019 /// \brief transform_pixel_positions with two sources 1051 template <typename View1, typename View2, typename View3, typename F> GIL_FORCEINLINE 1020 template <typename View1, typename View2, typename View3, typename F> GIL_FORCEINLINE 1052 1021 F transform_pixel_positions(const View1& src1,const View2& src2,const View3& dst, F fun) { 1053 1022 assert(src1.dimensions()==dst.dimensions()); 1054 1023 assert(src2.dimensions()==dst.dimensions()); … … 1063 1032 } 1064 1033 return fun; 1065 1034 } 1066 1067 1035 } } // namespace boost::gil 1068 1036 1069 1037 //#ifdef _MSC_VER 1070 1038 //#pragma warning(pop) 1071 1039 //#endif 1072 1040 1073 #endif 1041 #endif 1042 No newline at end of file -
boost/gil/locator.hpp
1 1 /* 2 2 Copyright 2005-2007 Adobe Systems Incorporated 3 3 4 4 Use, modification and distribution are subject to the Boost Software License, 5 5 Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 6 http://www.boost.org/LICENSE_1_0.txt). … … 13 13 #ifndef GIL_LOCATOR_H 14 14 #define GIL_LOCATOR_H 15 15 16 17 16 //////////////////////////////////////////////////////////////////////////////////////// 18 /// \file 17 /// \file 19 18 /// \brief pixel 2D locator 20 19 /// \author Lubomir Bourdev and Hailin Jin \n 21 20 /// Adobe Systems Incorporated … … 31 30 /// Pixel 2D LOCATOR 32 31 //////////////////////////////////////////////////////////////////////////////////////// 33 32 34 35 33 namespace boost { namespace gil { 36 37 34 //forward declarations 38 template <typename P> ptrdiff_t memunit_step(const P*);39 template <typename P> P* memunit_advanced(const P* p, ptrdiff_t diff);40 template <typename P> P& memunit_advanced_ref(P* p, ptrdiff_t diff);35 template <typename P> std::ptrdiff_t memunit_step(const P*); 36 template <typename P> P* memunit_advanced(const P* p, std::ptrdiff_t diff); 37 template <typename P> P& memunit_advanced_ref(P* p, std::ptrdiff_t diff); 41 38 template <typename Iterator, typename D> struct iterator_add_deref; 42 39 template <typename T> class point2; 43 40 namespace detail { … … 62 59 /// \brief base class for models of PixelLocatorConcept 63 60 /// \ingroup PixelLocatorModel PixelBasedModel 64 61 /// 65 /// Pixel locator is similar to a pixel iterator, but allows for 2D navigation of pixels within an image view. 62 /// Pixel locator is similar to a pixel iterator, but allows for 2D navigation of pixels within an image view. 66 63 /// It has a 2D difference_type and supports random access operations like: 67 64 /// \code 68 65 /// difference_type offset2(2,3); … … 76 73 /// It is called a locator because it doesn't implement the complete interface of a random access iterator. 77 74 /// For example, increment and decrement operations don't make sense (no way to specify dimension). 78 75 /// Also 2D difference between two locators cannot be computed without knowledge of the X position within the image. 79 /// 76 /// 80 77 /// This base class provides most of the methods and typedefs needed to create a model of a locator. GIL provides two 81 78 /// locator models as subclasses of \p pixel_2d_locator_base. A memory-based locator, \p memory_based_2d_locator and a virtual 82 79 /// locator, \p virtual_2d_locator. … … 108 105 /// // return the vertical distance to another locator. Some models need the horizontal distance to compute it 109 106 /// y_coord_t y_distance_to(const my_locator& loc2, x_coord_t xDiff) const; 110 107 /// 111 /// // return true iff incrementing an x-iterator located at the last column will position it at the first 108 /// // return true iff incrementing an x-iterator located at the last column will position it at the first 112 109 /// // column of the next row. Some models need the image width to determine that. 113 110 /// bool is_1d_traversable(x_coord_t width) const; 114 111 /// }; … … 159 156 160 157 Loc& operator+=(const difference_type& d) { concrete().x()+=d.x; concrete().y()+=d.y; return concrete(); } 161 158 Loc& operator-=(const difference_type& d) { concrete().x()-=d.x; concrete().y()-=d.y; return concrete(); } 162 159 163 160 Loc operator+(const difference_type& d) const { return xy_at(d); } 164 161 Loc operator-(const difference_type& d) const { return xy_at(-d); } 165 162 166 163 // Some locators can cache 2D coordinates for faster subsequent access. By default there is no caching 167 typedef difference_type cached_location_t; 164 typedef difference_type cached_location_t; 168 165 cached_location_t cache_location(const difference_type& d) const { return d; } 169 166 cached_location_t cache_location(x_coord_t dx, y_coord_t dy)const { return difference_type(dx,dy); } 170 167 … … 177 174 178 175 // helper classes for each axis of pixel_2d_locator_base 179 176 namespace detail { 180 template <typename Loc> 177 template <typename Loc> 181 178 class locator_axis<0,Loc> { 182 179 typedef typename Loc::point_t point_t; 183 180 public: … … 190 187 inline iterator operator()(const Loc& loc, const point_t& d) const { return loc.x_at(d); } 191 188 }; 192 189 193 template <typename Loc> 190 template <typename Loc> 194 191 class locator_axis<1,Loc> { 195 192 typedef typename Loc::point_t point_t; 196 193 public: … … 224 221 /// while its base iterator provides horizontal navigation. 225 222 /// 226 223 /// Each instantiation is optimal in terms of size and efficiency. 227 /// For example, xy locator over interleaved rgb image results in a step iterator consisting of 228 /// one std::ptrdiff_t for the row size and one native pointer (8 bytes total). ++locator.x() resolves to pointer 229 /// increment. At the other extreme, a 2D navigation of the even pixels of a planar CMYK image results in a step 230 /// iterator consisting of one std::ptrdiff_t for the doubled row size, and one step iterator consisting of 224 /// For example, xy locator over interleaved rgb image results in a step iterator consisting of 225 /// one std::ptrdiff_t for the row size and one native pointer (8 bytes total). ++locator.x() resolves to pointer 226 /// increment. At the other extreme, a 2D navigation of the even pixels of a planar CMYK image results in a step 227 /// iterator consisting of one std::ptrdiff_t for the doubled row size, and one step iterator consisting of 231 228 /// one std::ptrdiff_t for the horizontal step of two and a CMYK planar_pixel_iterator consisting of 4 pointers (24 bytes). 232 229 /// In this case ++locator.x() results in four native pointer additions. 233 230 /// … … 255 252 256 253 template <typename Deref> struct add_deref { 257 254 typedef memory_based_2d_locator<typename iterator_add_deref<StepIterator,Deref>::type> type; 258 static type make(const memory_based_2d_locator<StepIterator>& loc, const Deref& nderef) { 259 return type(iterator_add_deref<StepIterator,Deref>::make(loc.y(),nderef)); 255 static type make(const memory_based_2d_locator<StepIterator>& loc, const Deref& nderef) { 256 return type(iterator_add_deref<StepIterator,Deref>::make(loc.y(),nderef)); 260 257 } 261 258 }; 262 259 … … 278 275 x_iterator& x() { return _p.base(); } 279 276 y_iterator& y() { return _p; } 280 277 281 // These are faster versions of functions already provided in the superclass 282 x_iterator x_at (x_coord_t dx, y_coord_t dy) const { return memunit_advanced(x(), offset(dx,dy)); } 278 // These are faster versions of functions already provided in the superclass 279 x_iterator x_at (x_coord_t dx, y_coord_t dy) const { return memunit_advanced(x(), offset(dx,dy)); } 283 280 x_iterator x_at (const difference_type& d) const { return memunit_advanced(x(), offset(d.x,d.y)); } 284 281 this_t xy_at (x_coord_t dx, y_coord_t dy) const { return this_t(x_at( dx , dy ), row_size()); } 285 282 this_t xy_at (const difference_type& d) const { return this_t(x_at( d.x, d.y), row_size()); } … … 301 298 bool is_1d_traversable(x_coord_t width) const { return row_size()-pixel_size()*width==0; } // is there no gap at the end of each row? 302 299 303 300 // Returns the vertical distance (it2.y-it1.y) between two x_iterators given the difference of their x positions 304 std::ptrdiff_t y_distance_to(const this_t& p2, x_coord_t xDiff) const { 301 std::ptrdiff_t y_distance_to(const this_t& p2, x_coord_t xDiff) const { 305 302 std::ptrdiff_t rowDiff=memunit_distance(x(),p2.x())-pixel_size()*xDiff; 306 303 assert(( rowDiff % row_size())==0); 307 304 return rowDiff / row_size(); … … 356 353 struct dynamic_y_step_type<memory_based_2d_locator<SI> > { 357 354 typedef memory_based_2d_locator<SI> type; 358 355 }; 359 360 356 } } // namespace boost::gil 361 357 362 #endif 358 #endif 359 No newline at end of file -
boost/gil/planar_pixel_iterator.hpp
1 1 /* 2 2 Copyright 2005-2007 Adobe Systems Incorporated 3 3 4 4 Use, modification and distribution are subject to the Boost Software License, 5 5 Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 6 http://www.boost.org/LICENSE_1_0.txt). … … 14 14 #define GIL_PLANAR_PTR_H 15 15 16 16 //////////////////////////////////////////////////////////////////////////////////////// 17 /// \file 17 /// \file 18 18 /// \brief planar pixel pointer class 19 19 /// \author Lubomir Bourdev and Hailin Jin \n 20 20 /// Adobe Systems Incorporated … … 30 30 #include "step_iterator.hpp" 31 31 32 32 namespace boost { namespace gil { 33 34 33 //forward declaration (as this file is included in planar_pixel_reference.hpp) 35 template <typename ChannelReference, typename ColorSpace> 34 template <typename ChannelReference, typename ColorSpace> 36 35 struct planar_pixel_reference; 37 36 38 /// \defgroup ColorBaseModelPlanarPtr planar_pixel_iterator 37 /// \defgroup ColorBaseModelPlanarPtr planar_pixel_iterator 39 38 /// \ingroup ColorBaseModel 40 39 /// \brief A homogeneous color base whose element is a channel iterator. Models HomogeneousColorBaseValueConcept 41 40 /// This class is used as an iterator to a planar pixel. … … 49 48 /// 50 49 /// Planar pixels have channel data that is not consecutive in memory. 51 50 /// To abstract this we use classes to represent references and pointers to planar pixels. 52 /// 51 /// 53 52 /// \ingroup PixelIteratorModelPlanarPtr ColorBaseModelPlanarPtr PixelBasedModel 54 53 template <typename ChannelPtr, typename ColorSpace> 55 54 struct planar_pixel_iterator : public iterator_facade<planar_pixel_iterator<ChannelPtr,ColorSpace>, … … 69 68 typedef typename parent_t::reference reference; 70 69 typedef typename parent_t::difference_type difference_type; 71 70 72 planar_pixel_iterator() : color_base_parent_t(0) {} 71 planar_pixel_iterator() : color_base_parent_t(0) {} 73 72 planar_pixel_iterator(bool) {} // constructor that does not fill with zero (for performance) 74 73 75 74 planar_pixel_iterator(const ChannelPtr& v0, const ChannelPtr& v1) : color_base_parent_t(v0,v1) {} … … 77 76 planar_pixel_iterator(const ChannelPtr& v0, const ChannelPtr& v1, const ChannelPtr& v2, const ChannelPtr& v3) : color_base_parent_t(v0,v1,v2,v3) {} 78 77 planar_pixel_iterator(const ChannelPtr& v0, const ChannelPtr& v1, const ChannelPtr& v2, const ChannelPtr& v3, const ChannelPtr& v4) : color_base_parent_t(v0,v1,v2,v3,v4) {} 79 78 80 template <typename IC1,typename C1> 79 template <typename IC1,typename C1> 81 80 planar_pixel_iterator(const planar_pixel_iterator<IC1,C1>& ptr) : color_base_parent_t(ptr) {} 82 81 83 84 82 /// Copy constructor and operator= from pointers to compatible planar pixels or planar pixel references. 85 83 /// That allow constructs like pointer = &value or pointer = &reference 86 84 /// Since we should not override operator& that's the best we can do. 87 template <typename P> 85 template <typename P> 88 86 planar_pixel_iterator(P* pix) : color_base_parent_t(pix, true) { 89 87 function_requires<PixelsCompatibleConcept<P,value_type> >(); 90 88 } 91 89 92 90 struct address_of { template <typename T> T* operator()(T& t) { return &t; } }; 93 template <typename P> 91 template <typename P> 94 92 planar_pixel_iterator& operator=(P* pix) { 95 93 function_requires<PixelsCompatibleConcept<P,value_type> >(); 96 94 static_transform(*pix,*this, address_of()); … … 116 114 117 115 void increment() { static_transform(*this,*this,detail::inc<ChannelPtr>()); } 118 116 void decrement() { static_transform(*this,*this,detail::dec<ChannelPtr>()); } 119 void advance( ptrdiff_t d) { static_transform(*this,*this,std::bind2nd(detail::plus_asymmetric<ChannelPtr,ptrdiff_t>(),d)); }117 void advance(std::ptrdiff_t d) { static_transform(*this,*this,std::bind2nd(detail::plus_asymmetric<ChannelPtr,std::ptrdiff_t>(),d)); } 120 118 reference dereference() const { return this->template deref<reference>(); } 121 119 122 ptrdiff_t distance_to(const planar_pixel_iterator& it) const { return gil::at_c<0>(it)-gil::at_c<0>(*this); }120 std::ptrdiff_t distance_to(const planar_pixel_iterator& it) const { return gil::at_c<0>(it)-gil::at_c<0>(*this); } 123 121 bool equal(const planar_pixel_iterator& it) const { return gil::at_c<0>(*this)==gil::at_c<0>(it); } 124 122 }; 125 123 … … 128 126 template <typename T> struct channel_iterator_is_mutable<const T*> : public mpl::false_ {}; 129 127 } 130 128 131 template <typename IC, typename C> 132 struct const_iterator_type<planar_pixel_iterator<IC,C> > { 129 template <typename IC, typename C> 130 struct const_iterator_type<planar_pixel_iterator<IC,C> > { 133 131 private: 134 132 typedef typename std::iterator_traits<IC>::value_type channel_t; 135 133 public: 136 typedef planar_pixel_iterator<typename channel_traits<channel_t>::const_pointer,C> type; 134 typedef planar_pixel_iterator<typename channel_traits<channel_t>::const_pointer,C> type; 137 135 }; 138 136 139 137 // The default implementation when the iterator is a C pointer is to use the standard constness semantics 140 template <typename IC, typename C> 138 template <typename IC, typename C> 141 139 struct iterator_is_mutable<planar_pixel_iterator<IC,C> > : public detail::channel_iterator_is_mutable<IC> {}; 142 140 143 141 ///////////////////////////// 144 142 // ColorBasedConcept 145 143 ///////////////////////////// 146 144 147 template <typename IC, typename C, int K> 145 template <typename IC, typename C, int K> 148 146 struct kth_element_type<planar_pixel_iterator<IC,C>, K> { 149 147 typedef IC type; 150 148 }; 151 149 152 template <typename IC, typename C, int K> 150 template <typename IC, typename C, int K> 153 151 struct kth_element_reference_type<planar_pixel_iterator<IC,C>, K> : public add_reference<IC> {}; 154 152 155 template <typename IC, typename C, int K> 153 template <typename IC, typename C, int K> 156 154 struct kth_element_const_reference_type<planar_pixel_iterator<IC,C>, K> : public add_reference<typename add_const<IC>::type> {}; 157 155 158 156 ///////////////////////////// … … 183 181 inline std::ptrdiff_t memunit_step(const planar_pixel_iterator<IC,C>&) { return sizeof(typename std::iterator_traits<IC>::value_type); } 184 182 185 183 template <typename IC, typename C> 186 inline std::ptrdiff_t memunit_distance(const planar_pixel_iterator<IC,C>& p1, const planar_pixel_iterator<IC,C>& p2) { 187 return memunit_distance(gil::at_c<0>(p1),gil::at_c<0>(p2)); 184 inline std::ptrdiff_t memunit_distance(const planar_pixel_iterator<IC,C>& p1, const planar_pixel_iterator<IC,C>& p2) { 185 return memunit_distance(gil::at_c<0>(p1),gil::at_c<0>(p2)); 188 186 } 189 187 190 188 template <typename IC> … … 196 194 }; 197 195 198 196 template <typename IC, typename C> 199 inline void memunit_advance(planar_pixel_iterator<IC,C>& p, std::ptrdiff_t diff) { 197 inline void memunit_advance(planar_pixel_iterator<IC,C>& p, std::ptrdiff_t diff) { 200 198 static_transform(p, p, memunit_advance_fn<IC>(diff)); 201 199 } 202 200 … … 208 206 } 209 207 210 208 template <typename ChannelPtr, typename ColorSpace> 211 inline planar_pixel_reference<typename std::iterator_traits<ChannelPtr>::reference,ColorSpace> 209 inline planar_pixel_reference<typename std::iterator_traits<ChannelPtr>::reference,ColorSpace> 212 210 memunit_advanced_ref(const planar_pixel_iterator<ChannelPtr,ColorSpace>& ptr, std::ptrdiff_t diff) { 213 211 return planar_pixel_reference<typename std::iterator_traits<ChannelPtr>::reference,ColorSpace>(ptr, diff); 214 212 } … … 221 219 struct dynamic_x_step_type<planar_pixel_iterator<IC,C> > { 222 220 typedef memory_based_step_iterator<planar_pixel_iterator<IC,C> > type; 223 221 }; 224 225 222 } } // namespace boost::gil 226 223 227 #endif 224 #endif 225 No newline at end of file