fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / include / basebmp / pixeliterator.hxx
blobe629af275dd9d74122aefb1e6533681a8bc8e04c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
29 namespace basebmp
32 template< typename Valuetype > class PixelColumnIterator
34 public:
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;
44 private:
45 MoveY y;
47 bool equal( PixelColumnIterator const & rhs ) const
49 return rhs.y == y;
52 bool less( PixelColumnIterator const & rhs ) const
54 return y < rhs.y;
57 public:
58 PixelColumnIterator() :
59 y(0)
62 explicit PixelColumnIterator( const MoveY& pos ) :
63 y(pos)
66 PixelColumnIterator( const MoveY& pos, int x ) :
67 y(pos,x)
70 PixelColumnIterator& operator+=( difference_type d )
72 y += d;
73 return *this;
76 PixelColumnIterator& operator-=( difference_type d )
78 y -= d;
79 return *this;
82 PixelColumnIterator operator+( difference_type d )
84 PixelColumnIterator res(*this);
85 res += d;
86 return res;
89 PixelColumnIterator operator-( difference_type d )
91 PixelColumnIterator res(*this);
92 res -= d;
93 return res;
96 PixelColumnIterator& operator++()
98 ++y;
99 return *this;
102 PixelColumnIterator& operator--()
104 --y;
105 return *this;
108 PixelColumnIterator operator++(int)
110 PixelColumnIterator res(*this);
111 ++y;
112 return res;
115 PixelColumnIterator operator--(int)
117 PixelColumnIterator res(*this);
118 --y;
119 return res;
122 bool operator==(PixelColumnIterator const & rhs) const
124 return equal( rhs );
127 bool operator!=(PixelColumnIterator const & rhs) const
129 return !equal( rhs );
132 bool operator<(PixelColumnIterator const & rhs) const
134 return less(rhs);
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
149 return !less(rhs);
152 difference_type operator-(PixelColumnIterator const & rhs) const
154 return y - rhs.y;
157 value_type get() const
159 return *y();
162 value_type get(difference_type d) const
164 return *y(d);
167 void set( value_type v ) const
169 *y() = v;
172 void set( value_type v, difference_type d ) const
174 *y(d) = v;
177 reference operator*() const
179 return *y();
182 pointer operator->() const
184 return y();
187 reference operator[](difference_type d) const
189 return *y(d);
192 reference operator()(int dy) const
194 return *y(dy);
198 template< typename Valuetype > class PixelIterator
200 public:
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;
210 typedef int MoveX;
211 typedef StridedArrayIterator< value_type > MoveY;
213 // TODO(F2): direction of iteration (ImageIterator can be made to
214 // run backwards)
216 private:
217 bool equal(PixelIterator const & rhs) const
219 return (x == rhs.x) && (y == rhs.y);
222 pointer current() const
224 return y() + x;
227 pointer current(int dx, int dy) const
229 return y(dy) + x+dx;
232 public:
233 PixelIterator() :
234 x(0),
235 y(0)
238 PixelIterator(pointer base, int ystride) :
239 x(0),
240 y(ystride,base)
243 bool operator==(PixelIterator const & rhs) const
245 return equal(rhs);
248 bool operator!=(PixelIterator const & rhs) const
250 return !equal(rhs);
253 difference_type operator-(PixelIterator const & rhs) const
255 return difference_type(x - rhs.x, y - rhs.y);
258 MoveX x;
259 MoveY y;
261 PixelIterator & operator+=(difference_type const & s)
263 x += s.x;
264 y += s.y;
265 return *this;
268 PixelIterator & operator-=(difference_type const & s)
270 x -= s.x;
271 y -= s.y;
272 return *this;
275 PixelIterator operator+(difference_type const & s) const
277 PixelIterator ret(*this);
278 ret += s;
279 return ret;
282 PixelIterator operator-(difference_type const & s) const
284 PixelIterator ret(*this);
285 ret -= s;
286 return ret;
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
301 return *current();
304 value_type get(difference_type const & d) const
306 return *current(d.y, d.x);
309 void set( value_type v ) const
311 *current() = v;
314 void set( value_type v, difference_type const & d ) const
316 *current(d.y,d.x) = v;
319 reference operator*() const
321 return *current();
324 pointer operator->() const
326 return current();
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
341 return y(dy) + x;
345 } // namespace basebmp
347 #endif /* INCLUDED_BASEBMP_PIXELITERATOR_HXX */
349 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */