Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_vline_iterator.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2010 Lukáš Tvrdý <lukast.dev@gmail.com>
3 * SPDX-FileCopyrightText: 2010 Cyrille Berger <cberger@cberger.net>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
9
10#include <iostream>
11
12KisVLineIterator2::KisVLineIterator2(KisDataManager *dataManager, qint32 x, qint32 y, qint32 h, qint32 offsetX, qint32 offsetY, bool writable, KisIteratorCompleteListener *completeListener)
13 : KisBaseIterator(dataManager, writable, completeListener),
14 m_offsetX(offsetX),
15 m_offsetY(offsetY)
16{
17 x -= m_offsetX;
18 y -= m_offsetY;
19 Q_ASSERT(dataManager != 0);
20
21 Q_ASSERT(h > 0); // for us, to warn us when abusing the iterators
22 if (h < 1) h = 1; // for release mode, to make sure there's always at least one pixel read.
23
25
26 m_x = x;
27 m_y = y;
28
29 m_top = y;
30 m_bottom = y + h - 1;
31
32 m_left = m_x;
33
34 m_havePixels = (h == 0) ? false : true;
35 if (m_top > m_bottom) {
36 m_havePixels = false;
37 return;
38 }
39
42
45
47
50
52
53 // let's preallocate first row
54 for (int i = 0; i < m_tilesCacheSize; i++){
56 }
57 m_index = 0;
59}
60
70
81
83{
84 // We won't increment m_x here as integer can overflow here
85 if (m_y >= m_bottom) {
86 //return !m_isDoneFlag;
87 return m_havePixels = false;
88 } else {
89 ++m_y;
91 if (m_data < m_dataBottom)
93 else {
94 // Switching to the beginning of the next tile
95 ++m_index;
96 switchToTile(0);
97 }
98 }
99
100 return m_havePixels;
101}
102
103
105{
106 m_y = m_top;
107 ++m_x;
108
110 /* do nothing, usual case */
111 } else {
112 ++m_column;
113 m_xInTile = 0;
115 }
116 m_index = 0;
118
119 m_havePixels = true;
120}
121
122
124{
125 return 1;
126}
127
129{
130 Q_ASSERT_X(!(m_y > 0 && (m_y + n) < 0), "vlineIt+=", "Integer overflow");
131
132 qint32 previousRow = yToRow(m_y);
133 // We won't increment m_x here first as integer can overflow
134 if (m_y >= m_bottom || (m_y += n) > m_bottom) {
135 m_havePixels = false;
136 } else {
137 qint32 row = yToRow(m_y);
138 // if we are in the same column in tiles
139 if (row == previousRow) {
140 m_data += n * m_pixelSize;
141 } else {
142 qint32 yInTile = calcYInTile(m_y, row);
143 m_index += row - previousRow;
144 switchToTile(yInTile);
145 }
146 }
147 return m_havePixels;
148}
149
150
151
153{
154 for (int i = 0; i < m_tilesCacheSize; i++) {
155 unlockTile(m_tilesCache[i].tile);
156 unlockOldTile(m_tilesCache[i].oldtile);
157 }
158}
159
160
162{
163 return m_data;
164}
165
166
167const quint8* KisVLineIterator2::oldRawData() const
168{
169 return m_oldData;
170}
171
173{
174 return m_data;
175}
176
178{
179 // The caller must ensure that we are not out of bounds
180 Q_ASSERT(m_index < m_tilesCacheSize);
181 Q_ASSERT(m_index >= 0);
182
183 int offset_row = m_pixelSize * m_xInTile;
185 m_oldData = m_tilesCache[m_index].oldData;
186 m_data += offset_row;
188 int offset_col = m_pixelSize * yInTile * KisTileData::WIDTH;
189 m_data += offset_col;
190 m_oldData += offset_row + offset_col;
191}
192
193
195{
196 m_dataManager->getTilesPair(col, row, m_writable, &kti.tile, &kti.oldtile);
197
198 lockTile(kti.tile);
199 kti.data = kti.tile->data();
200
201 lockOldTile(kti.oldtile);
202 kti.oldData = kti.oldtile->data();
203}
204
206{
207 for (int i = 0; i < m_tilesCacheSize; ++i){
208 unlockTile(m_tilesCache[i].tile);
209 unlockOldTile(m_tilesCache[i].oldtile);
211 }
212}
213
215{
216 return m_x + m_offsetX;
217}
218
220{
221 return m_y + m_offsetY;
222}
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
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)
const quint8 * oldRawData() const override
void resetColumnPos() override
quint8 * rawData() override
QVector< KisTileInfo > m_tilesCache
void resetPixelPos() override
qint32 x() const override
bool nextPixels(qint32 n) override
void switchToTile(qint32 xInTile)
bool nextPixel() override
qint32 y() const override
qint32 nConseqPixels() const override
KisVLineIterator2(const KisVLineIterator2 &)
void fetchTileDataForCache(KisTileInfo &kti, qint32 col, qint32 row)
const quint8 * rawDataConst() const override
void nextColumn() override
The KisIteratorCompleteListener struct is a special interface for notifying the paint device that an ...