From 1694b9bebf0fdb118c51c4ee855c40646fbe9911 Mon Sep 17 00:00:00 2001 From: Jens-Heiner Rechtien Date: Wed, 27 Jun 2007 11:41:22 +0000 Subject: INTEGRATION: CWS basebmp01 (1.4.16); FILE MERGED 2007/05/22 09:59:17 thb 1.4.16.1: #147378# Added support for foreign formats (via GenericColorImageAccessor); fixed typos in CompositeIterator and StridedArrayIterator; fixed comparisons for (Packed)PixelIterator and StridedArrayIterator (which got negative strides wrong); avoiding unnecessary copying in scale_image() now; cleaned up bitmapdevice.cxx from cruft/ad hoc debug code; made unit tests run again --- basebmp/inc/basebmp/stridedarrayiterator.hxx | 45 +++++++++++++++++++--------- 1 file changed, 31 insertions(+), 14 deletions(-) (limited to 'basebmp/inc') diff --git a/basebmp/inc/basebmp/stridedarrayiterator.hxx b/basebmp/inc/basebmp/stridedarrayiterator.hxx index ca3717da5af1..77b60ee00c5a 100644 --- a/basebmp/inc/basebmp/stridedarrayiterator.hxx +++ b/basebmp/inc/basebmp/stridedarrayiterator.hxx @@ -4,9 +4,9 @@ * * $RCSfile: stridedarrayiterator.hxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: obo $ $Date: 2006-10-12 13:47:26 $ + * last change: $Author: hr $ $Date: 2007-06-27 12:41:22 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -41,19 +41,36 @@ namespace basebmp { -// changed semantics re. DirectionSelector: stride -// now counts in raw bytes! +/** Like vigra::StridedArrayIterator + + Changed semantics re. DirectionSelector: stride + now counts in raw bytes + + Adapts given ptr, in a way that iterator increments move forward + in strided steps. Stride can, by the way, also be negative + */ template< typename T > class StridedArrayIterator { public: typedef typename clone_const::type internal_type; - StridedArrayIterator(int stride, T* ptr = 0) : + /** Create iterator + + @param stride + + Stride in bytes. Given value should better match memory layout + of T, as memory gets reinterpret-casted. + */ + explicit StridedArrayIterator(int stride, T* ptr = 0) : stride_(stride), current_(reinterpret_cast(ptr)) {} - /// Copy from other StridedArrayIterator, plus given offset + /** Copy from other StridedArrayIterator, plus given offset + + @param offset + Offset in bytes + */ StridedArrayIterator( StridedArrayIterator const& rSrc, int offset ) : stride_(rSrc.stride_), @@ -61,13 +78,16 @@ public: reinterpret_cast(rSrc.current_)+offset)) {} - void operator++() { current_ += stride_; } + void operator++() {current_ += stride_; } void operator++(int) {current_ += stride_; } void operator--() {current_ -= stride_; } void operator--(int) {current_ -= stride_; } void operator+=(int dy) {current_ += dy*stride_; } void operator-=(int dy) {current_ -= dy*stride_; } + int operator-(StridedArrayIterator const & rhs) const + { return (current_ - rhs.current_) / stride_; } + bool operator==(StridedArrayIterator const & rhs) const { return current_ == rhs.current_; } @@ -75,19 +95,16 @@ public: { return current_ != rhs.current_; } bool operator<(StridedArrayIterator const & rhs) const - { return current_ < rhs.current_; } + { return *this - rhs < 0; } bool operator<=(StridedArrayIterator const & rhs) const - { return current_ <= rhs.current_; } + { return *this - rhs <= 0; } bool operator>(StridedArrayIterator const & rhs) const - { return current_ > rhs.current_; } + { return *this - rhs > 0; } bool operator>=(StridedArrayIterator const & rhs) const - { return current_ >= rhs.current_; } - - int operator-(StridedArrayIterator const & rhs) const - { return (current_ - rhs.current_) / stride_; } + { return *this - rhs >= 0; } T* operator()() const { return reinterpret_cast(current_); } -- cgit v1.2.3