LCOV - code coverage report
Current view: top level - basebmp/inc/basebmp - pixeliterator.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 42 42 100.0 %
Date: 2012-08-25 Functions: 43 64 67.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     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                 :   95929412 :     bool equal( PixelColumnIterator const & rhs ) const
      48                 :            :     {
      49                 :   95929412 :         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                 :     885378 :     PixelColumnIterator( const MoveY& pos, int x ) :
      67                 :     885378 :         y(pos,x)
      68                 :     885378 :     {}
      69                 :            : 
      70                 :   16130779 :     PixelColumnIterator& operator+=( difference_type d )
      71                 :            :     {
      72                 :   16130779 :         y += d;
      73                 :   16130779 :         return *this;
      74                 :            :     }
      75                 :            : 
      76                 :            :     PixelColumnIterator& operator-=( difference_type d )
      77                 :            :     {
      78                 :            :         y -= d;
      79                 :            :         return *this;
      80                 :            :     }
      81                 :            : 
      82                 :     859097 :     PixelColumnIterator operator+( difference_type d )
      83                 :            :     {
      84                 :     859097 :         PixelColumnIterator res(*this);
      85                 :     859097 :         res += d;
      86                 :     859097 :         return res;
      87                 :            :     }
      88                 :            : 
      89                 :            :     PixelColumnIterator operator-( difference_type d )
      90                 :            :     {
      91                 :            :         PixelColumnIterator res(*this);
      92                 :            :         res -= d;
      93                 :            :         return res;
      94                 :            :     }
      95                 :            : 
      96                 :   95647196 :     PixelColumnIterator& operator++()
      97                 :            :     {
      98                 :   95647196 :         ++y;
      99                 :   95647196 :         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                 :        550 :     bool operator==(PixelColumnIterator const & rhs) const
     123                 :            :     {
     124                 :        550 :         return equal( rhs );
     125                 :            :     }
     126                 :            : 
     127                 :   95928862 :     bool operator!=(PixelColumnIterator const & rhs) const
     128                 :            :     {
     129                 :   95928862 :         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                 :     282236 :     difference_type operator-(PixelColumnIterator const & rhs) const
     153                 :            :     {
     154                 :     282236 :         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                 :  112636881 :     reference operator*() const
     178                 :            :     {
     179                 :  112636881 :         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                 :   25702823 :     pointer current() const
     223                 :            :     {
     224                 :   25702823 :         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                 :    3115030 :     PixelIterator(pointer base, int ystride) :
     239                 :            :         x(0),
     240                 :    3115030 :         y(ystride,base)
     241                 :    3115030 :     {}
     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                 :   37788133 :     PixelIterator & operator+=(difference_type const & s)
     262                 :            :     {
     263                 :   37788133 :         x += s.x;
     264                 :   37788133 :         y += s.y;
     265                 :   37788133 :         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                 :   37603490 :     PixelIterator operator+(difference_type const & s) const
     276                 :            :     {
     277                 :   37603490 :         PixelIterator ret(*this);
     278                 :   37603490 :         ret += s;
     279                 :   37603490 :         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                 :  196860993 :     row_iterator rowIterator() const
     290                 :            :     {
     291                 :  196860993 :         return row_iterator(y()+x);
     292                 :            :     }
     293                 :            : 
     294                 :     885378 :     column_iterator columnIterator() const
     295                 :            :     {
     296                 :     885378 :         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                 :   25702823 :     reference operator*() const
     320                 :            :     {
     321                 :   25702823 :         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