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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
/* This file is part of the KDE project
* Copyright (c) 2004 Casper Boemann <[email protected]>
* 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_TILED_ITERATOR_H_
#define KIS_TILED_ITERATOR_H_
#include <tqglobal.h>
#include <ksharedptr.h>
#include <kis_tile.h>
#include <kis_tileddatamanager.h>
#include <koffice_export.h>
/**
* The KisIterator class iterates through the pixels of a KisPaintDevice hiding the tile structure
*/
class KRITACORE_EXPORT KisTiledIterator : public TDEShared {
protected:
KisTiledDataManager *m_ktm;
TQ_INT32 m_pixelSize; // bytes per pixel
TQ_INT32 m_x; // current x position
TQ_INT32 m_y; // cirrent y position
TQ_INT32 m_row; // row in tilemgr
TQ_INT32 m_col; // col in tilemgr
TQ_UINT8 *m_data;
TQ_UINT8 *m_oldData;
TQ_INT32 m_offset;
KisTile *m_tile;
KisTile* m_oldTile;
bool m_writable;
protected:
inline TQ_UINT32 xToCol(TQ_UINT32 x) const { if (m_ktm) return m_ktm->xToCol(x); else return 0; };
inline TQ_UINT32 yToRow(TQ_UINT32 y) const { if (m_ktm) return m_ktm->yToRow(y); else return 0; };
void fetchTileData(TQ_INT32 col, TQ_INT32 row);
public:
KisTiledIterator( KisTiledDataManager *ktm);
KisTiledIterator(const KisTiledIterator&);
KisTiledIterator& operator=(const KisTiledIterator&);
~KisTiledIterator();
public:
// current x position
TQ_INT32 x() const { return m_x; };
// cirrent y position
TQ_INT32 y() const { return m_y; };
/// 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 tof he last memento creation.
const TQ_UINT8 * oldRawData() const;
};
/**
* The KisRectIterator class iterates through the pixels of a rect in a KisPaintDevice hiding the
* tile structure
*/
class KRITACORE_EXPORT KisTiledRectIterator : public KisTiledIterator
{
public:
/// do not call constructor directly use factory method in KisDataManager instead.
KisTiledRectIterator( KisTiledDataManager *dm, TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h, bool writable);
KisTiledRectIterator(const KisTiledRectIterator&);
KisTiledRectIterator& operator=(const KisTiledRectIterator&);
~KisTiledRectIterator();
public:
TQ_INT32 nConseqPixels() const;
/// Advances a number of pixels until it reaches the end of the rect
KisTiledRectIterator & operator+=(int n);
/// Advances one pixel. Going to the beginning of the next line when it reaches the end of a line
KisTiledRectIterator & operator++();
/// Goes back one pixel. Going to the end of the line above when it reaches the beginning of a line
//KisTiledRectIterator & operator--();
/// returns true when the iterator has reached the end
inline bool isDone() const { return m_beyondEnd; }
protected:
TQ_INT32 m_left;
TQ_INT32 m_top;
TQ_INT32 m_w;
TQ_INT32 m_h;
TQ_INT32 m_topRow;
TQ_INT32 m_bottomRow;
TQ_INT32 m_leftCol;
TQ_INT32 m_rightCol;
TQ_INT32 m_xInTile;
TQ_INT32 m_yInTile;
TQ_INT32 m_leftInTile;
TQ_INT32 m_rightInTile;
TQ_INT32 m_topInTile;
TQ_INT32 m_bottomInTile;
bool m_beyondEnd;
private:
void nextTile();
};
/**
* The KisHLineIterator class iterates through the pixels of a horizontal line in a KisPaintDevice hiding the
* tile structure
*/
class KRITACORE_EXPORT KisTiledHLineIterator : public KisTiledIterator
{
public:
/// do not call constructor directly use factory method in KisDataManager instead.
KisTiledHLineIterator( KisTiledDataManager *dm, TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, bool writable);
KisTiledHLineIterator(const KisTiledHLineIterator&);
KisTiledHLineIterator& operator=(const KisTiledHLineIterator&);
~KisTiledHLineIterator();
public:
/// Advances one pixel. Going to the beginning of the next line when it reaches the end of a line
KisTiledHLineIterator & 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
KisTiledHLineIterator & operator+=(int);
/// Goes back one pixel. Going to the end of the line above when it reaches the beginning of a line
KisTiledHLineIterator & operator--();
/// returns true when the iterator has reached the end
bool isDone() const { return m_x > m_right; }
/// increment to the next row and rewind to the begining
void nextRow();
protected:
TQ_INT32 m_right;
TQ_INT32 m_left;
TQ_INT32 m_leftCol;
TQ_INT32 m_rightCol;
TQ_INT32 m_xInTile;
TQ_INT32 m_yInTile;
TQ_INT32 m_leftInTile;
TQ_INT32 m_rightInTile;
private:
void nextTile();
void prevTile();
};
/**
* The KisVLineIterator class iterates through the pixels of a vertical line in a KisPaintDevice hiding the
* tile structure
*/
class KRITACORE_EXPORT KisTiledVLineIterator : public KisTiledIterator
{
public:
/// do not call constructor directly use factory method in KisDataManager instead.
KisTiledVLineIterator( KisTiledDataManager *dm, TQ_INT32 x, TQ_INT32 y, TQ_INT32 h, bool writable);
KisTiledVLineIterator(const KisTiledVLineIterator&);
KisTiledVLineIterator& operator=(const KisTiledVLineIterator&);
~KisTiledVLineIterator();
public:
/// Advances one pixel. Going to the beginning of the next line when it reaches the end of a line
KisTiledVLineIterator & operator++();
/// Goes back one pixel. Going to the end of the line above when it reaches the beginning of a line
//KisTiledVLineIterator & operator--();
/// returns true when the iterator has reached the end
bool isDone() const { return m_y > m_bottom; }
/// increment to the next column and rewind to the begining
void nextCol();
protected:
TQ_INT32 m_top;
TQ_INT32 m_bottom;
TQ_INT32 m_topRow;
TQ_INT32 m_bottomRow;
TQ_INT32 m_xInTile;
TQ_INT32 m_yInTile;
TQ_INT32 m_topInTile;
TQ_INT32 m_bottomInTile;
private:
void nextTile();
};
#endif // KIS_TILED_ITERATOR_H_
|