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 Mateusz Loskot, 10 years ago)

Adds missing std:: qualifier to ptrdiff_t in GIL headers only.

  • boost/gil/algorithm.hpp

     
    11/*
    22    Copyright 2005-2007 Adobe Systems Incorporated
    3    
     3
    44    Use, modification and distribution are subject to the Boost Software License,
    55    Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
    66    http://www.boost.org/LICENSE_1_0.txt).
     
    88    See http://opensource.adobe.com/gil for most recent version including documentation.
    99*/
    1010
    11 
    1211/*************************************************************************************************/
    1312
    1413#ifndef GIL_ALGORITHM_HPP
     
    3433#include "bit_aligned_pixel_iterator.hpp"
    3534
    3635////////////////////////////////////////////////////////////////////////////////////////
    37 /// \file               
     36/// \file
    3837/// \brief Some basic STL-style algorithms when applied to image views
    3938/// \author Lubomir Bourdev and Hailin Jin \n
    4039///         Adobe Systems Incorporated
     
    4847//#endif
    4948
    5049namespace boost { namespace gil {
    51 
    5250//forward declarations
    5351template <typename ChannelPtr, typename ColorSpace>
    5452struct planar_pixel_iterator;
     
    8280/// is overloaded to perform \p std::copy for each of the planes. \p std::copy over bitwise-copiable pixels results in
    8381/// std::copy over unsigned char, which STL typically implements via \p memmove.
    8482///
    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,
    8684/// or one per each plane of planar 1D-traversable views, or one per each row of interleaved non-1D-traversable images, etc.
    8785
    88 
    8986/// \defgroup STLOptimizations  Performance overloads of STL algorithms
    9087/// \ingroup ImageViewAlgorithm
    9188/// \brief overloads of STL algorithms allowing more efficient implementation when used with GIL constructs
     
    146143/// \brief std::copy for image views
    147144
    148145namespace std {
    149 
    150146/// \ingroup STLOptimizations
    151147/// \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) { 
     148template<typename T, typename Cs>
     149GIL_FORCEINLINE boost::gil::pixel<T,Cs>*
     150copy(boost::gil::pixel<T,Cs>* first, boost::gil::pixel<T,Cs>* last,
     151     boost::gil::pixel<T,Cs>* dst) {
    156152    return (boost::gil::pixel<T,Cs>*)std::copy((unsigned char*)first,(unsigned char*)last, (unsigned char*)dst);
    157153}
    158154
    159155/// \ingroup STLOptimizations
    160156/// \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) { 
     157template<typename T, typename Cs>
     158GIL_FORCEINLINE boost::gil::pixel<T,Cs>*
     159copy(const boost::gil::pixel<T,Cs>* first, const boost::gil::pixel<T,Cs>* last,
     160     boost::gil::pixel<T,Cs>* dst) {
    165161    return (boost::gil::pixel<T,Cs>*)std::copy((unsigned char*)first,(unsigned char*)last, (unsigned char*)dst);
    166162}
    167163} // namespace std
    168164
    169165namespace boost { namespace gil {
    170166namespace 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); } 
     167template <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); }
    173169};
    174170} // namespace detail
    175171} }  // namespace boost::gil
     
    178174/// \ingroup STLOptimizations
    179175/// \brief Copy when both src and dst are planar pointers is copy for each channel
    180176template<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) { 
     177boost::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) {
    182178    boost::gil::gil_function_requires<boost::gil::ChannelsCompatibleConcept<typename std::iterator_traits<IC1>::value_type,typename std::iterator_traits<IC2>::value_type> >();
    183179    static_for_each(first,last,dst,boost::gil::detail::copy_fn<IC1,IC2>());
    184180    return dst+(last-first);
     
    274270    }
    275271    return dst+n;
    276272}
    277 
    278273} // namespace detail
    279274} }  // namespace boost::gil
    280275
     
    285280GIL_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) {
    286281    return boost::gil::detail::copy_with_2d_iterators(first,last,dst);
    287282}
    288 
    289283} // namespace std
    290284
    291285namespace boost { namespace gil {
    292 
    293 
    294286/// \ingroup ImageViewSTLAlgorithmsCopyPixels
    295287/// \brief std::copy for image views
    296288template <typename View1, typename View2> GIL_FORCEINLINE
    297 void copy_pixels(const View1& src, const View2& dst) { 
     289void copy_pixels(const View1& src, const View2& dst) {
    298290    assert(src.dimensions()==dst.dimensions());
    299291    detail::copy_with_2d_iterators(src.begin(),src.end(),dst.begin());
    300292}
     
    321313    copy_and_convert_pixels_fn() {}
    322314    copy_and_convert_pixels_fn(CC cc_in) : _cc(cc_in) {}
    323315   // 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
    325317    result_type apply_incompatible(const V1& src, const V2& dst) const {
    326318        copy_pixels(color_converted_view<typename V2::value_type>(src,_cc),dst);
    327319    }
    328320
    329321    // 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
    331323    result_type apply_compatible(const V1& src, const V2& dst) const {
    332324         copy_pixels(src,dst);
    333325    }
     
    335327} // namespace detail
    336328
    337329/// \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) { 
     330template <typename V1, typename V2,typename CC>
     331GIL_FORCEINLINE
     332void copy_and_convert_pixels(const V1& src, const V2& dst,CC cc) {
    341333    detail::copy_and_convert_pixels_fn<CC> ccp(cc);
    342334    ccp(src,dst);
    343335}
     
    345337struct default_color_converter;
    346338
    347339/// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
    348 template <typename View1, typename View2> 
    349 GIL_FORCEINLINE 
    350 void copy_and_convert_pixels(const View1& src, const View2& dst) { 
     340template <typename View1, typename View2>
     341GIL_FORCEINLINE
     342void copy_and_convert_pixels(const View1& src, const View2& dst) {
    351343    detail::copy_and_convert_pixels_fn<default_color_converter> ccp;
    352344    ccp(src,dst);
    353345}
    354 
    355346} }  // namespace boost::gil
    356347
    357348//////////////////////////////////////////////////////////////////////////////////////
     
    364355/// \ingroup ImageViewSTLAlgorithms
    365356/// \brief std::fill for image views
    366357
    367 
    368358namespace std {
    369359/// \ingroup STLOptimizations
    370360/// \brief std::fill(I,I,V) with I being a iterator_from_2d
    371361///
    372362/// Invoked when one calls std::fill(I,I,V) with I being a iterator_from_2d (which is
    373363/// 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
    375365/// pixel iterator that does not check for the end of rows. For non-contiguous images fill
    376366/// resolves to fill of each row using the underlying pixel iterator, which is still faster
    377367template <typename IL, typename V>
     
    389379            n-=numToDo;
    390380        }
    391381    }
    392 } 
     382}
    393383} // namespace std
    394384
    395385namespace boost { namespace gil {
    396 
    397386namespace detail {
    398387/// struct to do std::fill
    399388struct std_fill_t {
     
    404393};
    405394/// std::fill for planar iterators
    406395template <typename It, typename P>
    407 GIL_FORCEINLINE 
     396GIL_FORCEINLINE
    408397void fill_aux(It first, It last, const P& p, mpl::true_) {
    409398    static_for_each(first,last,p,std_fill_t());
    410399}
    411400/// std::fill for interleaved iterators
    412401template <typename It, typename P>
    413 GIL_FORCEINLINE 
     402GIL_FORCEINLINE
    414403void fill_aux(It first, It last, const P& p,mpl::false_) {
    415404    std::fill(first,last,p);
    416405}
     
    418407
    419408/// \ingroup ImageViewSTLAlgorithmsFillPixels
    420409/// \brief std::fill for image views
    421 template <typename View, typename Value> GIL_FORCEINLINE 
     410template <typename View, typename Value> GIL_FORCEINLINE
    422411void fill_pixels(const View& img_view, const Value& val) {
    423412    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(),
    425414                 val,is_planar<View>());
    426415    else
    427416        for (std::ptrdiff_t y=0; y<img_view.height(); ++y)
     
    439428/// \ingroup ImageViewSTLAlgorithms
    440429/// \brief invokes the destructor on every pixel of an image view
    441430
    442 
    443431namespace detail {
    444 
    445432template <typename It> GIL_FORCEINLINE
    446433void destruct_range_impl( It first
    447434                        , It last
     
    461448void destruct_range_impl( It
    462449                        , It
    463450                        , 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 >
    465452                                                      >
    466453                                            >::type* /* ptr */ = 0)
    467454{}
    468455
    469456template <typename It> GIL_FORCEINLINE
    470457void destruct_range(It first, It last) {
    471 
    472458    destruct_range_impl( first
    473459                       , last
    474460                       );
     
    480466
    481467/// destruct for planar iterators
    482468template <typename It>
    483 GIL_FORCEINLINE 
     469GIL_FORCEINLINE
    484470void destruct_aux(It first, It last, mpl::true_) {
    485471    static_for_each(first,last,std_destruct_t());
    486472}
    487473/// destruct for interleaved iterators
    488474template <typename It>
    489 GIL_FORCEINLINE 
     475GIL_FORCEINLINE
    490476void destruct_aux(It first, It last, mpl::false_) {
    491477    destruct_range(first,last);
    492478}
    493 
    494479} // namespace detail
    495480
    496481/// \ingroup ImageViewSTLAlgorithmsDestructPixels
    497482/// \brief Invokes the in-place destructor on every pixel of the view
    498 template <typename View> GIL_FORCEINLINE 
     483template <typename View> GIL_FORCEINLINE
    499484void 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(),
    502487                                       is_planar<View>());
    503488    else
    504489        for (std::ptrdiff_t y=0; y<img_view.height(); ++y)
     
    516501/// \ingroup ImageViewSTLAlgorithms
    517502/// \brief std::uninitialized_fill for image views
    518503
    519 
    520504namespace detail {
    521 
    522505/// std::uninitialized_fill for planar iterators
    523506/// If an exception is thrown destructs any in-place copy-constructed objects
    524507template <typename It, typename P>
    525 GIL_FORCEINLINE 
     508GIL_FORCEINLINE
    526509void uninitialized_fill_aux(It first, It last,
    527510                            const P& p, mpl::true_) {
    528511    int channel=0;
    529512    try {
    530513        typedef typename std::iterator_traits<It>::value_type pixel_t;
    531514        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),
    533516                                    dynamic_at_c(p,channel));
    534517            ++channel;
    535518        }
     
    543526/// std::uninitialized_fill for interleaved iterators
    544527/// If an exception is thrown destructs any in-place copy-constructed objects
    545528template <typename It, typename P>
    546 GIL_FORCEINLINE 
     529GIL_FORCEINLINE
    547530void uninitialized_fill_aux(It first, It last,
    548531                            const P& p,mpl::false_) {
    549532    std::uninitialized_fill(first,last,p);
    550533}
    551 
    552534} // namespace detail
    553535
    554536/// \ingroup ImageViewSTLAlgorithmsUninitializedFillPixels
    555537/// \brief std::uninitialized_fill for image views.
    556538/// Does not support planar heterogeneous views.
    557539/// If an exception is thrown destructs any in-place copy-constructed pixels
    558 template <typename View, typename Value> 
     540template <typename View, typename Value>
    559541void 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(),
    562544                                       val,is_planar<View>());
    563545    else {
    564546        typename View::y_coord_t y;
     
    585567/// \brief invokes the default constructor on every pixel of an image view
    586568
    587569namespace detail {
    588 
    589 template <typename It> GIL_FORCEINLINE
     570template <typename It> GIL_FORCEINLINE
    590571void default_construct_range_impl(It first, It last, mpl::true_) {
    591572    typedef typename std::iterator_traits<It>::value_type value_t;
    592573    It first1=first;
     
    601582    }
    602583}
    603584
    604 template <typename It> GIL_FORCEINLINE 
     585template <typename It> GIL_FORCEINLINE
    605586void default_construct_range_impl(It, It, mpl::false_) {}
    606587
    607 template <typename It> GIL_FORCEINLINE 
     588template <typename It> GIL_FORCEINLINE
    608589void default_construct_range(It first, It last) { default_construct_range_impl(first, last, typename is_pointer<It>::type()); }
    609590
    610591/// uninitialized_default_construct for planar iterators
    611592template <typename It>
    612 GIL_FORCEINLINE 
     593GIL_FORCEINLINE
    613594void default_construct_aux(It first, It last, mpl::true_) {
    614595    int channel=0;
    615596    try {
     
    627608
    628609/// uninitialized_default_construct for interleaved iterators
    629610template <typename It>
    630 GIL_FORCEINLINE 
     611GIL_FORCEINLINE
    631612void default_construct_aux(It first, It last, mpl::false_) {
    632613    default_construct_range(first,last);
    633614}
     
    636617struct has_trivial_pixel_constructor : public boost::has_trivial_constructor<typename View::value_type> {};
    637618template <typename View>
    638619struct has_trivial_pixel_constructor<View, true> : public boost::has_trivial_constructor<typename channel_type<View>::type> {};
    639 
    640620} // namespace detail
    641621
    642622namespace detail {
    643 
    644623template< typename View, bool B > GIL_FORCEINLINE
    645624void default_construct_pixels_impl( const View& img_view
    646625                                  , boost::enable_if< is_same< mpl::bool_< B >
     
    649628                                                    >* /* ptr */ = 0
    650629                                  )
    651630{
    652     if( img_view.is_1d_traversable() ) 
     631    if( img_view.is_1d_traversable() )
    653632    {
    654633        detail::default_construct_aux( img_view.begin().x()
    655634                                     , img_view.end().x()
     
    681660            throw;
    682661        }
    683662    }
    684 
    685663}
    686 
    687664} // namespace detail
    688665
    689 
    690666/// \ingroup ImageViewSTLAlgorithmsDefaultConstructPixels
    691667/// \brief Invokes the in-place default constructor on every pixel of the (uninitialized) view.
    692668/// Does not support planar heterogeneous views.
    693669/// If an exception is thrown destructs any in-place default-constructed pixels
    694 template <typename View> 
     670template <typename View>
    695671void default_construct_pixels(const View& img_view) {
    696 
    697672    detail::default_construct_pixels_impl< View
    698673                                        , detail::has_trivial_pixel_constructor< View
    699674                                                                               , is_planar< View >::value
     
    701676                                         >( img_view );
    702677}
    703678
    704 
    705679//////////////////////////////////////////////////////////////////////////////////////
    706680///
    707681/// uninitialized_copy_pixels
     
    713687/// \brief std::uninitialized_copy for image views
    714688
    715689namespace detail {
    716 
    717690/// std::uninitialized_copy for pairs of planar iterators
    718691template <typename It1, typename It2>
    719 GIL_FORCEINLINE 
     692GIL_FORCEINLINE
    720693void uninitialized_copy_aux(It1 first1, It1 last1,
    721694                            It2 first2, mpl::true_) {
    722695    int channel=0;
     
    736709}
    737710/// std::uninitialized_copy for interleaved or mixed iterators
    738711template <typename It1, typename It2>
    739 GIL_FORCEINLINE 
     712GIL_FORCEINLINE
    740713void uninitialized_copy_aux(It1 first1, It1 last1,
    741714                            It2 first2,mpl::false_) {
    742715    std::uninitialized_copy(first1,last1,first2);
     
    747720/// \brief std::uninitialized_copy for image views.
    748721/// Does not support planar heterogeneous views.
    749722/// If an exception is thrown destructs any in-place copy-constructed objects
    750 template <typename View1, typename View2> 
     723template <typename View1, typename View2>
    751724void 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;
    753726    assert(view1.dimensions()==view2.dimensions());
    754727    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(),
    757730                                       is_planar());
    758731    else {
    759732        typename View1::y_coord_t y;
     
    780753/// \ingroup ImageViewSTLAlgorithms
    781754/// \brief std::for_each for image views
    782755///
    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
    786759/// pixel iterator, which is still faster
    787760
    788761/// \ingroup ImageViewSTLAlgorithmsForEachPixel
     
    813786    return fun;
    814787}
    815788
    816 
    817789//////////////////////////////////////////////////////////////////////////////////////
    818790///
    819791/// generate_pixels
     
    849821template <typename I1, typename I2> GIL_FORCEINLINE bool equal_n(I1 i1, std::ptrdiff_t n, I2 i2);
    850822
    851823namespace detail {
    852 
    853824template <typename I1, typename I2>
    854825struct equal_n_fn {
    855826    GIL_FORCEINLINE bool operator()(I1 i1, std::ptrdiff_t n, I2 i2) const { return std::equal(i1,i1+n, i2); }
    856827};
    857828
    858 /// Equal when both ranges are interleaved and of the same type. 
     829/// Equal when both ranges are interleaved and of the same type.
    859830/// GIL pixels are bitwise comparable, so memcmp is used. User-defined pixels that are not bitwise comparable need to provide an overload
    860831template<typename T, typename Cs>
    861832struct 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 {
    863834        return memcmp(i1, i2, n*sizeof(pixel<T,Cs>))==0;
    864835    }
    865836};
     
    871842///  User-defined channels that are not bitwise comparable need to provide an overload
    872843template<typename IC, typename Cs>
    873844struct 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);
    876847
    877848        for (std::ptrdiff_t i=0; i<mpl::size<Cs>::value; ++i)
    878849            if (memcmp(dynamic_at_c(i1,i), dynamic_at_c(i2,i), numBytes)!=0)
     
    881852    }
    882853};
    883854
    884 
    885855/// Source range is delimited by image iterators
    886856template <typename Loc, typename I2>  // IL Models ConstPixelLocatorConcept, O Models PixelIteratorConcept
    887857struct equal_n_fn<boost::gil::iterator_from_2d<Loc>,I2> {
     
    953923/// \brief  std::equal(I1,I1,I2) with I1 and I2 being a iterator_from_2d
    954924///
    955925/// 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
    957927/// iterators to simpler/faster types if the corresponding range is contiguous.
    958928/// 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
    960930/// pixel iterator that does not check for the end of rows. If the underlying pixel iterator
    961931/// happens to be a fundamental planar/interleaved pointer, the call may further resolve
    962932/// to memcmp. Otherwise it resolves to copying each row using the underlying pixel iterator
    963 template <typename Loc1, typename Loc2> GIL_FORCEINLINE 
     933template <typename Loc1, typename Loc2> GIL_FORCEINLINE
    964934bool equal(boost::gil::iterator_from_2d<Loc1> first, boost::gil::iterator_from_2d<Loc1> last, boost::gil::iterator_from_2d<Loc2> first2) {
    965935    boost::gil::gil_function_requires<boost::gil::PixelLocatorConcept<Loc1> >();
    966936    boost::gil::gil_function_requires<boost::gil::PixelLocatorConcept<Loc2> >();
     
    980950} // namespace std
    981951
    982952namespace boost { namespace gil {
    983 
    984953/// \ingroup ImageViewSTLAlgorithmsEqualPixels
    985954/// \brief std::equal for image views
    986 template <typename View1, typename View2> GIL_FORCEINLINE 
     955template <typename View1, typename View2> GIL_FORCEINLINE
    987956bool equal_pixels(const View1& v1, const View2& v2) {
    988957    assert(v1.dimensions()==v2.dimensions());
    989958    return std::equal(v1.begin(),v1.end(),v2.begin()); // std::equal has overloads with GIL iterators for optimal performance
     
    1001970
    1002971/// \ingroup ImageViewSTLAlgorithmsTransformPixels
    1003972/// \brief std::transform for image views
    1004 template <typename View1, typename View2, typename F> GIL_FORCEINLINE 
     973template <typename View1, typename View2, typename F> GIL_FORCEINLINE
    1005974F transform_pixels(const View1& src,const View2& dst, F fun) {
    1006975    assert(src.dimensions()==dst.dimensions());
    1007976    for (std::ptrdiff_t y=0; y<src.height(); ++y) {
     
    1015984
    1016985/// \ingroup ImageViewSTLAlgorithmsTransformPixels
    1017986/// \brief transform_pixels with two sources
    1018 template <typename View1, typename View2, typename View3, typename F> GIL_FORCEINLINE 
     987template <typename View1, typename View2, typename View3, typename F> GIL_FORCEINLINE
    1019988F transform_pixels(const View1& src1, const View2& src2,const View3& dst, F fun) {
    1020989    for (std::ptrdiff_t y=0; y<dst.height(); ++y) {
    1021990        typename View1::x_iterator srcIt1=src1.row_begin(y);
     
    1029998
    1030999/// \defgroup ImageViewSTLAlgorithmsTransformPixelPositions transform_pixel_positions
    10311000/// \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)
    10331002
    10341003/// \ingroup ImageViewSTLAlgorithmsTransformPixelPositions
    10351004/// \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 
     1005template <typename View1, typename View2, typename F> GIL_FORCEINLINE
    10371006F transform_pixel_positions(const View1& src,const View2& dst, F fun) {
    10381007    assert(src.dimensions()==dst.dimensions());
    10391008    typename View1::xy_locator loc=src.xy_at(0,0);
     
    10481017
    10491018/// \ingroup ImageViewSTLAlgorithmsTransformPixelPositions
    10501019/// \brief transform_pixel_positions with two sources
    1051 template <typename View1, typename View2, typename View3, typename F> GIL_FORCEINLINE 
     1020template <typename View1, typename View2, typename View3, typename F> GIL_FORCEINLINE
    10521021F transform_pixel_positions(const View1& src1,const View2& src2,const View3& dst, F fun) {
    10531022    assert(src1.dimensions()==dst.dimensions());
    10541023    assert(src2.dimensions()==dst.dimensions());
     
    10631032    }
    10641033    return fun;
    10651034}
    1066 
    10671035} }  // namespace boost::gil
    10681036
    10691037//#ifdef _MSC_VER
    10701038//#pragma warning(pop)
    10711039//#endif
    10721040
    1073 #endif
     1041#endif
     1042 No newline at end of file
  • boost/gil/locator.hpp

     
    11/*
    22    Copyright 2005-2007 Adobe Systems Incorporated
    3    
     3
    44    Use, modification and distribution are subject to the Boost Software License,
    55    Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
    66    http://www.boost.org/LICENSE_1_0.txt).
     
    1313#ifndef GIL_LOCATOR_H
    1414#define GIL_LOCATOR_H
    1515
    16 
    1716////////////////////////////////////////////////////////////////////////////////////////
    18 /// \file               
     17/// \file
    1918/// \brief pixel 2D locator
    2019/// \author Lubomir Bourdev and Hailin Jin \n
    2120///         Adobe Systems Incorporated
     
    3130///                 Pixel 2D LOCATOR
    3231////////////////////////////////////////////////////////////////////////////////////////
    3332
    34 
    3533namespace boost { namespace gil {
    36 
    3734//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);
     35template <typename P> std::ptrdiff_t memunit_step(const P*);
     36template <typename P> P* memunit_advanced(const P* p, std::ptrdiff_t diff);
     37template <typename P> P& memunit_advanced_ref(P* p, std::ptrdiff_t diff);
    4138template <typename Iterator, typename D> struct iterator_add_deref;
    4239template <typename T> class point2;
    4340namespace detail {
     
    6259/// \brief base class for models of PixelLocatorConcept
    6360/// \ingroup PixelLocatorModel PixelBasedModel
    6461///
    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.
    6663/// It has a 2D difference_type and supports random access operations like:
    6764/// \code
    6865///     difference_type offset2(2,3);
     
    7673/// It is called a locator because it doesn't implement the complete interface of a random access iterator.
    7774/// For example, increment and decrement operations don't make sense (no way to specify dimension).
    7875/// Also 2D difference between two locators cannot be computed without knowledge of the X position within the image.
    79 /// 
     76///
    8077/// This base class provides most of the methods and typedefs needed to create a model of a locator. GIL provides two
    8178/// locator models as subclasses of \p pixel_2d_locator_base. A memory-based locator, \p memory_based_2d_locator and a virtual
    8279/// locator, \p virtual_2d_locator.
     
    108105///        // return the vertical distance to another locator. Some models need the horizontal distance to compute it
    109106///        y_coord_t         y_distance_to(const my_locator& loc2, x_coord_t xDiff) const;
    110107///
    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
    112109///        // column of the next row. Some models need the image width to determine that.
    113110///        bool              is_1d_traversable(x_coord_t width) const;
    114111/// };
     
    159156
    160157    Loc&              operator+=(const difference_type& d)         { concrete().x()+=d.x; concrete().y()+=d.y; return concrete(); }
    161158    Loc&              operator-=(const difference_type& d)         { concrete().x()-=d.x; concrete().y()-=d.y; return concrete(); }
    162    
     159
    163160    Loc               operator+(const difference_type& d)    const { return xy_at(d); }
    164161    Loc               operator-(const difference_type& d)    const { return xy_at(-d); }
    165162
    166163    // 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;
    168165    cached_location_t cache_location(const difference_type& d)  const { return d; }
    169166    cached_location_t cache_location(x_coord_t dx, y_coord_t dy)const { return difference_type(dx,dy); }
    170167
     
    177174
    178175// helper classes for each axis of pixel_2d_locator_base
    179176namespace detail {
    180     template <typename Loc> 
     177    template <typename Loc>
    181178    class locator_axis<0,Loc> {
    182179        typedef typename Loc::point_t                       point_t;
    183180    public:
     
    190187        inline iterator         operator()(const Loc& loc, const point_t& d) const { return loc.x_at(d); }
    191188    };
    192189
    193     template <typename Loc> 
     190    template <typename Loc>
    194191    class locator_axis<1,Loc> {
    195192        typedef typename Loc::point_t                       point_t;
    196193    public:
     
    224221/// while its base iterator provides horizontal navigation.
    225222///
    226223/// 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
    231228/// one std::ptrdiff_t for the horizontal step of two and a CMYK planar_pixel_iterator consisting of 4 pointers (24 bytes).
    232229/// In this case ++locator.x() results in four native pointer additions.
    233230///
     
    255252
    256253    template <typename Deref> struct add_deref {
    257254        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));
    260257        }
    261258    };
    262259
     
    278275    x_iterator&           x()                                { return _p.base(); }
    279276    y_iterator&           y()                                { return _p; }
    280277
    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)); }
    283280    x_iterator x_at      (const difference_type& d)    const { return memunit_advanced(x(), offset(d.x,d.y)); }
    284281    this_t     xy_at     (x_coord_t dx, y_coord_t dy)  const { return this_t(x_at( dx , dy ), row_size()); }
    285282    this_t     xy_at     (const difference_type& d)    const { return this_t(x_at( d.x, d.y), row_size()); }
     
    301298    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?
    302299
    303300    // 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 {
    305302        std::ptrdiff_t rowDiff=memunit_distance(x(),p2.x())-pixel_size()*xDiff;
    306303        assert(( rowDiff % row_size())==0);
    307304        return rowDiff / row_size();
     
    356353struct dynamic_y_step_type<memory_based_2d_locator<SI> > {
    357354    typedef memory_based_2d_locator<SI> type;
    358355};
    359 
    360356} }  // namespace boost::gil
    361357
    362 #endif
     358#endif
     359 No newline at end of file
  • boost/gil/planar_pixel_iterator.hpp

     
    11/*
    22    Copyright 2005-2007 Adobe Systems Incorporated
    3    
     3
    44    Use, modification and distribution are subject to the Boost Software License,
    55    Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
    66    http://www.boost.org/LICENSE_1_0.txt).
     
    1414#define GIL_PLANAR_PTR_H
    1515
    1616////////////////////////////////////////////////////////////////////////////////////////
    17 /// \file               
     17/// \file
    1818/// \brief planar pixel pointer class
    1919/// \author Lubomir Bourdev and Hailin Jin \n
    2020///         Adobe Systems Incorporated
     
    3030#include "step_iterator.hpp"
    3131
    3232namespace boost { namespace gil {
    33 
    3433//forward declaration (as this file is included in planar_pixel_reference.hpp)
    35 template <typename ChannelReference, typename ColorSpace> 
     34template <typename ChannelReference, typename ColorSpace>
    3635struct planar_pixel_reference;
    3736
    38 /// \defgroup ColorBaseModelPlanarPtr planar_pixel_iterator 
     37/// \defgroup ColorBaseModelPlanarPtr planar_pixel_iterator
    3938/// \ingroup ColorBaseModel
    4039/// \brief A homogeneous color base whose element is a channel iterator. Models HomogeneousColorBaseValueConcept
    4140/// This class is used as an iterator to a planar pixel.
     
    4948///
    5049/// Planar pixels have channel data that is not consecutive in memory.
    5150/// To abstract this we use classes to represent references and pointers to planar pixels.
    52 /// 
     51///
    5352/// \ingroup PixelIteratorModelPlanarPtr ColorBaseModelPlanarPtr PixelBasedModel
    5453template <typename ChannelPtr, typename ColorSpace>
    5554struct planar_pixel_iterator : public iterator_facade<planar_pixel_iterator<ChannelPtr,ColorSpace>,
     
    6968    typedef typename parent_t::reference                  reference;
    7069    typedef typename parent_t::difference_type            difference_type;
    7170
    72     planar_pixel_iterator() : color_base_parent_t(0) {} 
     71    planar_pixel_iterator() : color_base_parent_t(0) {}
    7372    planar_pixel_iterator(bool) {}        // constructor that does not fill with zero (for performance)
    7473
    7574    planar_pixel_iterator(const ChannelPtr& v0, const ChannelPtr& v1) : color_base_parent_t(v0,v1) {}
     
    7776    planar_pixel_iterator(const ChannelPtr& v0, const ChannelPtr& v1, const ChannelPtr& v2, const ChannelPtr& v3) : color_base_parent_t(v0,v1,v2,v3) {}
    7877    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) {}
    7978
    80     template <typename IC1,typename C1> 
     79    template <typename IC1,typename C1>
    8180    planar_pixel_iterator(const planar_pixel_iterator<IC1,C1>& ptr) : color_base_parent_t(ptr) {}
    8281
    83 
    8482    /// Copy constructor and operator= from pointers to compatible planar pixels or planar pixel references.
    8583    /// That allow constructs like pointer = &value or pointer = &reference
    8684    /// Since we should not override operator& that's the best we can do.
    87     template <typename P> 
     85    template <typename P>
    8886    planar_pixel_iterator(P* pix) : color_base_parent_t(pix, true) {
    8987        function_requires<PixelsCompatibleConcept<P,value_type> >();
    9088    }
    9189
    9290    struct address_of { template <typename T> T* operator()(T& t) { return &t; } };
    93     template <typename P> 
     91    template <typename P>
    9492    planar_pixel_iterator& operator=(P* pix) {
    9593        function_requires<PixelsCompatibleConcept<P,value_type> >();
    9694        static_transform(*pix,*this, address_of());
     
    116114
    117115    void increment()            { static_transform(*this,*this,detail::inc<ChannelPtr>()); }
    118116    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)); }
    120118    reference dereference() const { return this->template deref<reference>(); }
    121119
    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); }
    123121    bool equal(const planar_pixel_iterator& it) const { return gil::at_c<0>(*this)==gil::at_c<0>(it); }
    124122};
    125123
     
    128126    template <typename T>  struct channel_iterator_is_mutable<const T*> : public mpl::false_ {};
    129127}
    130128
    131 template <typename IC, typename C> 
    132 struct const_iterator_type<planar_pixel_iterator<IC,C> > { 
     129template <typename IC, typename C>
     130struct const_iterator_type<planar_pixel_iterator<IC,C> > {
    133131private:
    134132    typedef typename std::iterator_traits<IC>::value_type channel_t;
    135133public:
    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;
    137135};
    138136
    139137// The default implementation when the iterator is a C pointer is to use the standard constness semantics
    140 template <typename IC, typename C> 
     138template <typename IC, typename C>
    141139struct iterator_is_mutable<planar_pixel_iterator<IC,C> > : public detail::channel_iterator_is_mutable<IC> {};
    142140
    143141/////////////////////////////
    144142//  ColorBasedConcept
    145143/////////////////////////////
    146144
    147 template <typename IC, typename C, int K> 
     145template <typename IC, typename C, int K>
    148146struct kth_element_type<planar_pixel_iterator<IC,C>, K> {
    149147    typedef IC type;
    150148};
    151149
    152 template <typename IC, typename C, int K> 
     150template <typename IC, typename C, int K>
    153151struct kth_element_reference_type<planar_pixel_iterator<IC,C>, K> : public add_reference<IC> {};
    154152
    155 template <typename IC, typename C, int K> 
     153template <typename IC, typename C, int K>
    156154struct kth_element_const_reference_type<planar_pixel_iterator<IC,C>, K> : public add_reference<typename add_const<IC>::type> {};
    157155
    158156/////////////////////////////
     
    183181inline std::ptrdiff_t memunit_step(const planar_pixel_iterator<IC,C>&) { return sizeof(typename std::iterator_traits<IC>::value_type); }
    184182
    185183template <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)); 
     184inline 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));
    188186}
    189187
    190188template <typename IC>
     
    196194};
    197195
    198196template <typename IC, typename C>
    199 inline void memunit_advance(planar_pixel_iterator<IC,C>& p, std::ptrdiff_t diff) { 
     197inline void memunit_advance(planar_pixel_iterator<IC,C>& p, std::ptrdiff_t diff) {
    200198    static_transform(p, p, memunit_advance_fn<IC>(diff));
    201199}
    202200
     
    208206}
    209207
    210208template <typename ChannelPtr, typename ColorSpace>
    211 inline planar_pixel_reference<typename std::iterator_traits<ChannelPtr>::reference,ColorSpace> 
     209inline planar_pixel_reference<typename std::iterator_traits<ChannelPtr>::reference,ColorSpace>
    212210    memunit_advanced_ref(const planar_pixel_iterator<ChannelPtr,ColorSpace>& ptr, std::ptrdiff_t diff) {
    213211    return planar_pixel_reference<typename std::iterator_traits<ChannelPtr>::reference,ColorSpace>(ptr, diff);
    214212}
     
    221219struct dynamic_x_step_type<planar_pixel_iterator<IC,C> > {
    222220    typedef memory_based_step_iterator<planar_pixel_iterator<IC,C> > type;
    223221};
    224 
    225222} }  // namespace boost::gil
    226223
    227 #endif
     224#endif
     225 No newline at end of file