1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_BASEBMP_PIXELITERATOR_HXX
21 #define INCLUDED_BASEBMP_PIXELITERATOR_HXX
23 #include <basebmp/metafunctions.hxx>
24 #include <basebmp/stridedarrayiterator.hxx>
26 #include <vigra/metaprogramming.hxx>
27 #include <vigra/diff2d.hxx>
32 template< typename Valuetype
> class PixelColumnIterator
35 typedef Valuetype value_type
;
36 typedef Valuetype
& reference
;
37 typedef reference index_reference
;
38 typedef Valuetype
* pointer
;
39 typedef int difference_type
;
40 typedef image_traverser_tag iterator_category
;
42 typedef StridedArrayIterator
< value_type
> MoveY
;
47 bool equal( PixelColumnIterator
const & rhs
) const
52 bool less( PixelColumnIterator
const & rhs
) const
58 PixelColumnIterator() :
62 explicit PixelColumnIterator( const MoveY
& pos
) :
66 PixelColumnIterator( const MoveY
& pos
, int x
) :
70 PixelColumnIterator
& operator+=( difference_type d
)
76 PixelColumnIterator
& operator-=( difference_type d
)
82 PixelColumnIterator
operator+( difference_type d
)
84 PixelColumnIterator
res(*this);
89 PixelColumnIterator
operator-( difference_type d
)
91 PixelColumnIterator
res(*this);
96 PixelColumnIterator
& operator++()
102 PixelColumnIterator
& operator--()
108 PixelColumnIterator
operator++(int)
110 PixelColumnIterator
res(*this);
115 PixelColumnIterator
operator--(int)
117 PixelColumnIterator
res(*this);
122 bool operator==(PixelColumnIterator
const & rhs
) const
127 bool operator!=(PixelColumnIterator
const & rhs
) const
129 return !equal( rhs
);
132 bool operator<(PixelColumnIterator
const & rhs
) const
137 bool operator<=(PixelColumnIterator
const & rhs
) const
139 return !rhs
.less(*this);
142 bool operator>(PixelColumnIterator
const & rhs
) const
144 return rhs
.less(*this);
147 bool operator>=(PixelColumnIterator
const & rhs
) const
152 difference_type
operator-(PixelColumnIterator
const & rhs
) const
157 value_type
get() const
162 value_type
get(difference_type d
) const
167 void set( value_type v
) const
172 void set( value_type v
, difference_type d
) const
177 reference
operator*() const
182 pointer
operator->() const
187 reference
operator[](difference_type d
) const
192 reference
operator()(int dy
) const
198 template< typename Valuetype
> class PixelIterator
201 typedef Valuetype value_type
;
202 typedef Valuetype
& reference
;
203 typedef reference index_reference
;
204 typedef Valuetype
* pointer
;
205 typedef vigra::Diff2D difference_type
;
206 typedef image_traverser_tag iterator_category
;
207 typedef pointer row_iterator
;
208 typedef PixelColumnIterator
<value_type
> column_iterator
;
211 typedef StridedArrayIterator
< value_type
> MoveY
;
213 // TODO(F2): direction of iteration (ImageIterator can be made to
217 bool equal(PixelIterator
const & rhs
) const
219 return (x
== rhs
.x
) && (y
== rhs
.y
);
222 pointer
current() const
227 pointer
current(int dx
, int dy
) const
238 PixelIterator(pointer base
, int ystride
) :
243 bool operator==(PixelIterator
const & rhs
) const
248 bool operator!=(PixelIterator
const & rhs
) const
253 difference_type
operator-(PixelIterator
const & rhs
) const
255 return difference_type(x
- rhs
.x
, y
- rhs
.y
);
261 PixelIterator
& operator+=(difference_type
const & s
)
268 PixelIterator
& operator-=(difference_type
const & s
)
275 PixelIterator
operator+(difference_type
const & s
) const
277 PixelIterator
ret(*this);
282 PixelIterator
operator-(difference_type
const & s
) const
284 PixelIterator
ret(*this);
289 row_iterator
rowIterator() const
291 return row_iterator(y()+x
);
294 column_iterator
columnIterator() const
296 return column_iterator(y
,x
);
299 value_type
get() const
304 value_type
get(difference_type
const & d
) const
306 return *current(d
.y
, d
.x
);
309 void set( value_type v
) const
314 void set( value_type v
, difference_type
const & d
) const
316 *current(d
.y
,d
.x
) = v
;
319 reference
operator*() const
324 pointer
operator->() const
329 reference
operator[]( const vigra::Diff2D
& d
) const
331 return *current(d
.x
,d
.y
);
334 reference
operator()(int dx
, int dy
) const
336 return *current(dx
,dy
);
339 pointer
operator[](int dy
) const
345 } // namespace basebmp
347 #endif /* INCLUDED_BASEBMP_PIXELITERATOR_HXX */
349 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */