summaryrefslogtreecommitdiffstats
path: root/chalk/core/kis_iterator.h
blob: 893461a56012bf1977aa82bbc33210c81b81f1fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/* This file is part of the KDE project
 *   Copyright (c) 2004 Casper Boemann <cbr@boemann.dkt>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

*/
#ifndef KIS_ITERATOR_H_
#define KIS_ITERATOR_H_

#include <tqglobal.h>
#include <ksharedptr.h>

class KisTiledRectIterator;
typedef KSharedPtr<KisTiledRectIterator> KisTiledRectIteratorSP;

class KisTiledVLineIterator;
typedef KSharedPtr<KisTiledVLineIterator> KisTiledVLineIteratorSP;

class KisTiledHLineIterator;
typedef KSharedPtr<KisTiledHLineIterator> KisTiledHLineIteratorSP;

class KisDataManager;

/**
 * The KisRectIterator iterators over a rectangular area in the most efficient order. That is,
 * there is no guarantee that the iterator will work scanline by scanline.
 */
class KisRectIterator
{


public:
    KisRectIterator ( KisDataManager *dm, TQ_INT32  x, TQ_INT32  y, TQ_INT32  w, TQ_INT32  h, bool writable);

public:
    virtual ~KisRectIterator();
    KisRectIterator(const KisRectIterator& rhs);
    KisRectIterator& operator=(const KisRectIterator& rhs);


public:
    /// returns a pointer to the pixel data. Do NOT interpret the data - leave that to a colorstrategy
    TQ_UINT8 * rawData() const;

    /// Returns a pointer to the pixel data as it was at the moment of the last memento creation.
    const TQ_UINT8 * oldRawData() const;

    /// Returns the number of consequtive pixels that we point at
    /// This is useful for optimizing
    TQ_INT32 nConseqPixels() const;

    /// Advances a number of pixels until it reaches the end of the rect
    KisRectIterator & operator+=(int n);

    /// Advances one pixel going to the beginning of the next line when it reaches the end of a line
    KisRectIterator & operator++();

    /// returns true when iterators has reached the end
    bool isDone()  const;

     // current x position
     TQ_INT32 x() const;

     // current y position
     TQ_INT32 y() const;

private:

    KisTiledRectIteratorSP m_iter;
};

class KisHLineIterator
{

public:

    KisHLineIterator ( KisDataManager *dm, TQ_INT32  x, TQ_INT32 y, TQ_INT32 w, bool writable);

public:

    virtual ~KisHLineIterator();
    KisHLineIterator(const KisHLineIterator& rhs);
    KisHLineIterator& operator=(const KisHLineIterator& rhs);

public:
    /// Returns a pointer to the pixel data. Do NOT interpret the data - leave that to a colorstrategy
    TQ_UINT8 *rawData() const;

    /// Returns a pointer to the pixel data as it was at the moment of the last memento creation.
    const TQ_UINT8 *oldRawData() const;

    /// Advances one pixel until it reaches the end of the line
    KisHLineIterator & operator++();

    /// Returns the number of consequtive horizontal pixels that we point at
    /// This is useful for optimizing
    TQ_INT32 nConseqHPixels() const;

    /// Advances a number of pixels until it reaches the end of the line
    KisHLineIterator & operator+=(int n);

    /// Goes back one pixel until it reaches the beginning of the line
    KisHLineIterator & operator--();

    /// returns true when iterators has reached the end
    bool isDone()  const;

    /// current x position
    TQ_INT32 x() const;

    /// current y position
    TQ_INT32 y() const;

    /// increment to the next row and rewind to the begining
    void nextRow();


private:

    KisTiledHLineIteratorSP m_iter;
};

class KisVLineIterator
{

public:
    KisVLineIterator ( KisDataManager *dm, TQ_INT32  x, TQ_INT32 y, TQ_INT32  h, bool writable);
public:
    ~KisVLineIterator();
    KisVLineIterator(const KisVLineIterator& rhs);
    KisVLineIterator& operator=(const KisVLineIterator& rhs);

public:
    /// returns a pointer to the pixel data. Do NOT interpret the data - leave that to a colorstrategy
    TQ_UINT8 *rawData() const;

    /// Returns a pointer to the pixel data as it was at the moment of the last memento creation.
    const TQ_UINT8 * oldRawData() const;

    /// Advances one pixel until it reaches the end of the line
    KisVLineIterator & operator++();

    /// returns true when iterators has reached the end
    bool isDone() const;

    /// current x position
    TQ_INT32 x() const;

    /// current y position
    TQ_INT32 y() const;
    
    /// increment to the next column and rewind to the begining
    void nextCol();

private:

    KisTiledVLineIteratorSP m_iter;

};

#endif