LCOV - code coverage report
Current view: top level - libreoffice/basebmp/inc/basebmp - pixeliterator.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 42 42 100.0 %
Date: 2012-12-27 Functions: 43 64 67.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_BASEBMP_PIXELITERATOR_HXX
      21             : #define INCLUDED_BASEBMP_PIXELITERATOR_HXX
      22             : 
      23             : #include <basebmp/metafunctions.hxx>
      24             : #include <basebmp/stridedarrayiterator.hxx>
      25             : 
      26             : #include <vigra/metaprogramming.hxx>
      27             : #include <vigra/diff2d.hxx>
      28             : 
      29             : namespace basebmp
      30             : {
      31             : 
      32             : template< typename Valuetype > class PixelColumnIterator
      33             : {
      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;
      41             : 
      42             :     typedef StridedArrayIterator< value_type >  MoveY;
      43             : 
      44             : private:
      45             :     MoveY           y;
      46             : 
      47      574444 :     bool equal( PixelColumnIterator const & rhs ) const
      48             :     {
      49      574444 :         return rhs.y == y;
      50             :     }
      51             : 
      52             :     bool less( PixelColumnIterator const & rhs ) const
      53             :     {
      54             :         return y < rhs.y;
      55             :     }
      56             : 
      57             : public:
      58             :     PixelColumnIterator() :
      59             :         y(0)
      60             :     {}
      61             : 
      62             :     explicit PixelColumnIterator( const MoveY& pos ) :
      63             :         y(pos)
      64             :     {}
      65             : 
      66       26452 :     PixelColumnIterator( const MoveY& pos, int x ) :
      67       26452 :         y(pos,x)
      68       26452 :     {}
      69             : 
      70      446925 :     PixelColumnIterator& operator+=( difference_type d )
      71             :     {
      72      446925 :         y += d;
      73      446925 :         return *this;
      74             :     }
      75             : 
      76             :     PixelColumnIterator& operator-=( difference_type d )
      77             :     {
      78             :         y -= d;
      79             :         return *this;
      80             :     }
      81             : 
      82       26438 :     PixelColumnIterator operator+( difference_type d )
      83             :     {
      84       26438 :         PixelColumnIterator res(*this);
      85       26438 :         res += d;
      86       26438 :         return res;
      87             :     }
      88             : 
      89             :     PixelColumnIterator operator-( difference_type d )
      90             :     {
      91             :         PixelColumnIterator res(*this);
      92             :         res -= d;
      93             :         return res;
      94             :     }
      95             : 
      96      569827 :     PixelColumnIterator& operator++()
      97             :     {
      98      569827 :         ++y;
      99      569827 :         return *this;
     100             :     }
     101             : 
     102             :     PixelColumnIterator& operator--()
     103             :     {
     104             :         --y;
     105             :         return *this;
     106             :     }
     107             : 
     108             :     PixelColumnIterator operator++(int)
     109             :     {
     110             :         PixelColumnIterator res(*this);
     111             :         ++y;
     112             :         return res;
     113             :     }
     114             : 
     115             :     PixelColumnIterator operator--(int)
     116             :     {
     117             :         PixelColumnIterator res(*this);
     118             :         --y;
     119             :         return res;
     120             :     }
     121             : 
     122         110 :     bool operator==(PixelColumnIterator const & rhs) const
     123             :     {
     124         110 :         return equal( rhs );
     125             :     }
     126             : 
     127      574334 :     bool operator!=(PixelColumnIterator const & rhs) const
     128             :     {
     129      574334 :         return !equal( rhs );
     130             :     }
     131             : 
     132             :     bool operator<(PixelColumnIterator const & rhs) const
     133             :     {
     134             :         return less(rhs);
     135             :     }
     136             : 
     137             :     bool operator<=(PixelColumnIterator const & rhs) const
     138             :     {
     139             :         return !rhs.less(*this);
     140             :     }
     141             : 
     142             :     bool operator>(PixelColumnIterator const & rhs) const
     143             :     {
     144             :         return rhs.less(*this);
     145             :     }
     146             : 
     147             :     bool operator>=(PixelColumnIterator const & rhs) const
     148             :     {
     149             :         return !less(rhs);
     150             :     }
     151             : 
     152        4621 :     difference_type operator-(PixelColumnIterator const & rhs) const
     153             :     {
     154        4621 :         return y - rhs.y;
     155             :     }
     156             : 
     157             :     value_type get() const
     158             :     {
     159             :         return *y();
     160             :     }
     161             : 
     162             :     value_type get(difference_type d) const
     163             :     {
     164             :         return *y(d);
     165             :     }
     166             : 
     167             :     void set( value_type v ) const
     168             :     {
     169             :         *y() = v;
     170             :     }
     171             : 
     172             :     void set( value_type v, difference_type d ) const
     173             :     {
     174             :         *y(d) = v;
     175             :     }
     176             : 
     177     1011846 :     reference operator*() const
     178             :     {
     179     1011846 :         return *y();
     180             :     }
     181             : 
     182             :     pointer operator->() const
     183             :     {
     184             :         return y();
     185             :     }
     186             : 
     187             :     reference operator[](difference_type d) const
     188             :     {
     189             :         return *y(d);
     190             :     }
     191             : 
     192             :     reference operator()(int dy) const
     193             :     {
     194             :         return *y(dy);
     195             :     }
     196             : };
     197             : 
     198             : template< typename Valuetype > class PixelIterator
     199             : {
     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;
     209             : 
     210             :     typedef int                                MoveX;
     211             :     typedef StridedArrayIterator< value_type > MoveY;
     212             : 
     213             :     // TODO(F2): direction of iteration (ImageIterator can be made to
     214             :     // run backwards)
     215             : 
     216             : private:
     217             :     bool equal(PixelIterator const & rhs) const
     218             :     {
     219             :         return (x == rhs.x) && (y == rhs.y);
     220             :     }
     221             : 
     222      160921 :     pointer current() const
     223             :     {
     224      160921 :         return y() + x;
     225             :     }
     226             : 
     227             :     pointer current(int dx, int dy) const
     228             :     {
     229             :         return y(dy) + x+dx;
     230             :     }
     231             : 
     232             : public:
     233             :     PixelIterator() :
     234             :         x(0),
     235             :         y(0)
     236             :     {}
     237             : 
     238       32552 :     PixelIterator(pointer base, int ystride) :
     239             :         x(0),
     240       32552 :         y(ystride,base)
     241       32552 :     {}
     242             : 
     243             :     bool operator==(PixelIterator const & rhs) const
     244             :     {
     245             :         return equal(rhs);
     246             :     }
     247             : 
     248             :     bool operator!=(PixelIterator const & rhs) const
     249             :     {
     250             :         return !equal(rhs);
     251             :     }
     252             : 
     253             :     difference_type operator-(PixelIterator const & rhs) const
     254             :     {
     255             :         return difference_type(x - rhs.x, y - rhs.y);
     256             :     }
     257             : 
     258             :     MoveX x;
     259             :     MoveY y;
     260             : 
     261      386558 :     PixelIterator & operator+=(difference_type const & s)
     262             :     {
     263      386558 :         x += s.x;
     264      386558 :         y += s.y;
     265      386558 :         return *this;
     266             :     }
     267             : 
     268             :     PixelIterator & operator-=(difference_type const & s)
     269             :     {
     270             :         x -= s.x;
     271             :         y -= s.y;
     272             :         return *this;
     273             :     }
     274             : 
     275      386452 :     PixelIterator operator+(difference_type const & s) const
     276             :     {
     277      386452 :         PixelIterator ret(*this);
     278      386452 :         ret += s;
     279      386452 :         return ret;
     280             :     }
     281             : 
     282             :     PixelIterator operator-(difference_type const & s) const
     283             :     {
     284             :         PixelIterator ret(*this);
     285             :         ret -= s;
     286             :         return ret;
     287             :     }
     288             : 
     289     5308212 :     row_iterator rowIterator() const
     290             :     {
     291     5308212 :         return row_iterator(y()+x);
     292             :     }
     293             : 
     294       26452 :     column_iterator columnIterator() const
     295             :     {
     296       26452 :         return column_iterator(y,x);
     297             :     }
     298             : 
     299             :     value_type get() const
     300             :     {
     301             :         return *current();
     302             :     }
     303             : 
     304             :     value_type get(difference_type const & d) const
     305             :     {
     306             :         return *current(d.y, d.x);
     307             :     }
     308             : 
     309             :     void set( value_type v ) const
     310             :     {
     311             :         *current() = v;
     312             :     }
     313             : 
     314             :     void set( value_type v, difference_type const & d ) const
     315             :     {
     316             :         *current(d.y,d.x) = v;
     317             :     }
     318             : 
     319      160921 :     reference operator*() const
     320             :     {
     321      160921 :         return *current();
     322             :     }
     323             : 
     324             :     pointer operator->() const
     325             :     {
     326             :         return current();
     327             :     }
     328             : 
     329             :     reference operator[]( const vigra::Diff2D& d ) const
     330             :     {
     331             :         return *current(d.x,d.y);
     332             :     }
     333             : 
     334             :     reference operator()(int dx, int dy) const
     335             :     {
     336             :         return *current(dx,dy);
     337             :     }
     338             : 
     339             :     pointer operator[](int dy) const
     340             :     {
     341             :         return y(dy) + x;
     342             :     }
     343             : };
     344             : 
     345             : } // namespace basebmp
     346             : 
     347             : #endif /* INCLUDED_BASEBMP_PIXELITERATOR_HXX */
     348             : 
     349             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10