Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_hline_iterator.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2010 Lukáš Tvrdý <lukast.dev@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9
10KisHLineIterator2::KisHLineIterator2(KisDataManager *dataManager, qint32 x, qint32 y, qint32 w, qint32 offsetX, qint32 offsetY, bool writable, KisIteratorCompleteListener *completionListener)
11 : KisBaseIterator(dataManager, writable, completionListener),
12 m_offsetX(offsetX),
13 m_offsetY(offsetY)
14{
15 x -= m_offsetX;
16 y -= m_offsetY;
17 Q_ASSERT(dataManager);
18
19 if (w < 1) w = 1; // To make sure there's always at least one pixel read.
20
21 m_x = x;
22 m_y = y;
23
24 m_left = x;
25 m_right = x + w - 1;
26
27 m_top = y;
28
29 m_havePixels = (w == 0) ? false : true;
30 if (m_left > m_right) {
31 m_havePixels = false;
32 return;
33 }
34
37
38 m_row = yToRow(m_y);
40
42
45
47
48 // let's preallocate first row
49 for (quint32 i = 0; i < m_tilesCacheSize; i++){
51 }
52 m_index = 0;
54}
55
65
76
78{
79 // We won't increment m_x here as integer can overflow here
80 if (m_x >= m_right) {
81 //return !m_isDoneFlag;
82 return m_havePixels = false;
83 } else {
84 ++m_x;
88 else {
89 // Switching to the beginning of the next tile
90 ++m_index;
91 switchToTile(0);
92 }
93 }
94
95 return m_havePixels;
96}
97
98
100{
101 m_x = m_left;
102 ++m_y;
103
105 /* do nothing, usual case */
106 } else {
107 ++m_row;
108 m_yInTile = 0;
110 }
111 m_index = 0;
113
114 m_havePixels = true;
115}
116
117
119{
120 return qMin(m_rightmostInTile, m_right) - m_x + 1;
121}
122
123
124
126{
127 Q_ASSERT_X(!(m_x > 0 && (m_x + n) < 0), "hlineIt+=", "Integer overflow");
128
129 qint32 previousCol = xToCol(m_x);
130 // We won't increment m_x here first as integer can overflow
131 if (m_x >= m_right || (m_x += n) > m_right) {
132 m_havePixels = false;
133 } else {
134 qint32 col = xToCol(m_x);
135 // if we are in the same column in tiles
136 if (col == previousCol) {
137 m_data += n * m_pixelSize;
138 } else {
139 qint32 xInTile = calcXInTile(m_x, col);
140 m_index += col - previousCol;
141 switchToTile(xInTile);
142 }
143 }
144 return m_havePixels;
145}
146
147
148
150{
151 for (uint i = 0; i < m_tilesCacheSize; i++) {
152 unlockTile(m_tilesCache[i].tile);
153 unlockOldTile(m_tilesCache[i].oldtile);
154 }
155}
156
157
159{
160 return m_data;
161}
162
163
164const quint8* KisHLineIterator2::oldRawData() const
165{
166 return m_oldData;
167}
168
170{
171 return m_data;
172}
173
175{
176 // The caller must ensure that we are not out of bounds
177 Q_ASSERT(m_index < m_tilesCacheSize);
178
180 m_oldData = m_tilesCache[m_index].oldData;
181
182 int offset_row = m_pixelSize * (m_yInTile * KisTileData::WIDTH);
183 m_data += offset_row;
185 int offset_col = m_pixelSize * xInTile;
186 m_data += offset_col;
187 m_oldData += offset_row + offset_col;
188}
189
190
192{
193 m_dataManager->getTilesPair(col, row, m_writable, &kti.tile, &kti.oldtile);
194
195 lockTile(kti.tile);
196 kti.data = kti.tile->data();
197
198 lockOldTile(kti.oldtile);
199 kti.oldData = kti.oldtile->data();
200}
201
203{
204 for (quint32 i = 0; i < m_tilesCacheSize; ++i){
205 unlockTile(m_tilesCache[i].tile);
206 unlockOldTile(m_tilesCache[i].oldtile);
208 }
209}
210
212{
213 return m_x + m_offsetX;
214}
215
217{
218 return m_y + m_offsetY;
219}
unsigned int uint
void lockOldTile(KisTileSP &tile)
qint32 calcXInTile(qint32 x, qint32 col) const
void unlockOldTile(KisTileSP &tile)
void unlockTile(KisTileSP &tile)
quint32 yToRow(quint32 y) const
void lockTile(KisTileSP &tile)
qint32 calcYInTile(qint32 y, qint32 row) const
KisTiledDataManager * m_dataManager
quint32 xToCol(quint32 x) const
QVector< KisTileInfo > m_tilesCache
void nextRow() override
const quint8 * oldRawData() const override
KisHLineIterator2(const KisHLineIterator2 &)
void fetchTileDataForCache(KisTileInfo &kti, qint32 col, qint32 row)
bool nextPixels(qint32 n) override
bool nextPixel() override
quint8 * rawData() override
qint32 x() const override
void switchToTile(qint32 xInTile)
void resetRowPos() override
qint32 y() const override
qint32 nConseqPixels() const override
void resetPixelPos() override
const quint8 * rawDataConst() const override
static const qint32 HEIGHT
static const qint32 WIDTH
quint8 * data() const
Definition kis_tile.h:85
void getTilesPair(qint32 col, qint32 row, bool writable, KisTileSP *tile, KisTileSP *oldTile)
The KisIteratorCompleteListener struct is a special interface for notifying the paint device that an ...