1 /*
2  *  Copyright (c) 2010 Lukáš Tvrdý <lukast.dev@gmail.com>
3  *  Copyright (c) 2010 Cyrille Berger <cberger@cberger.net>
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 
20 #ifndef _KIS_VLINE_ITERATOR_H_
21 #define _KIS_VLINE_ITERATOR_H_
22 
23 #include "kis_base_iterator.h"
24 #include "kritaimage_export.h"
25 #include "kis_iterator_ng.h"
26 
27 class KRITAIMAGE_EXPORT KisVLineIterator2 : public KisVLineIteratorNG, KisBaseIterator {
28     KisVLineIterator2(const KisVLineIterator2&);
29     KisVLineIterator2& operator=(const KisVLineIterator2&);
30 
31 public:
32     struct KisTileInfo {
33         KisTileSP tile;
34         KisTileSP oldtile;
35         quint8* data;
36         quint8* oldData;
37     };
38 
39 
40 public:
41     KisVLineIterator2(KisDataManager *dataManager, qint32 x, qint32 y, qint32 h, qint32 offsetX, qint32 offsetY, bool writable, KisIteratorCompleteListener *completeListener);
42     ~KisVLineIterator2() override;
43 
44     void resetPixelPos() override;
45     void resetColumnPos() override;
46 
47     bool nextPixel() override;
48     void nextColumn() override;
49     const quint8* rawDataConst() const override;
50     const quint8* oldRawData() const override;
51     quint8* rawData() override;
52     qint32 nConseqPixels() const override;
53     bool nextPixels(qint32 n) override;
54     qint32 x() const override;
55     qint32 y() const override;
56 
57 private:
58     qint32 m_offsetX;
59     qint32 m_offsetY;
60 
61     qint32 m_x;        // current x position
62     qint32 m_y;        // current y position
63     qint32 m_column;    // current column in tilemgr
64     qint32 m_index;    // current row in tilemgr
65     qint32 m_tileSize;
66     quint8 *m_data;
67     quint8 *m_dataBottom;
68     quint8 *m_oldData;
69     bool m_havePixels;
70 
71     qint32 m_top;
72     qint32 m_bottom;
73     qint32 m_left;
74     qint32 m_topRow;
75     qint32 m_bottomRow;
76 
77     qint32 m_topInTopmostTile;
78     qint32 m_xInTile;
79     qint32 m_lineStride;
80 
81     QVector<KisTileInfo> m_tilesCache;
82     qint32 m_tilesCacheSize;
83 
84 private:
85 
86     void switchToTile(qint32 xInTile);
87     void fetchTileDataForCache(KisTileInfo& kti, qint32 col, qint32 row);
88     void preallocateTiles();
89 };
90 #endif
91