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
|
/*
* This file is part of the Chalk
*
* Copyright (c) 2004 Casper Boemann <cbr@boemann.dk>
*
* 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.
*/
#include <kdebug.h>
#include "kis_tile_global.h"
#include "kis_tilediterator.h"
KisTiledIterator::KisTiledIterator( KisTiledDataManager *ndevice)
{
Q_ASSERT(ndevice != 0);
m_ktm = ndevice;
m_x = 0;
m_y = 0;
m_row = 0;
m_col = 0;
m_pixelSize = m_ktm->pixelSize();
m_tile = 0;
m_oldTile = 0;
}
KisTiledIterator::~KisTiledIterator( )
{
if (m_tile)
m_tile->removeReader();
if (m_oldTile)
m_oldTile->removeReader();
}
KisTiledIterator::KisTiledIterator(const KisTiledIterator& rhs)
: TDEShared()
{
if (this != &rhs) {
m_ktm = rhs.m_ktm;
m_pixelSize = rhs.m_pixelSize;
m_x = rhs.m_x;
m_y = rhs.m_y;
m_row = rhs.m_row;
m_col = rhs.m_col;
m_data = rhs.m_data;
m_oldData = rhs.m_oldData;
m_offset = rhs.m_offset;
m_tile = rhs.m_tile;
m_oldTile = rhs.m_oldTile;
m_writable = rhs.m_writable;
if (m_tile)
m_tile->addReader();
}
}
KisTiledIterator& KisTiledIterator::operator=(const KisTiledIterator& rhs)
{
if (this != &rhs) {
if (m_tile)
m_tile->removeReader();
if (m_oldTile)
m_oldTile->removeReader();
m_ktm = rhs.m_ktm;
m_pixelSize = rhs.m_pixelSize;
m_x = rhs.m_x;
m_y = rhs.m_y;
m_row = rhs.m_row;
m_col = rhs.m_col;
m_data = rhs.m_data;
m_oldData = rhs.m_oldData;
m_offset = rhs.m_offset;
m_tile = rhs.m_tile;
m_oldTile = rhs.m_oldTile;
m_writable = rhs.m_writable;
if (m_tile)
m_tile->addReader();
}
return *this;
}
TQ_UINT8 * KisTiledIterator::rawData() const
{
return m_data + m_offset;
}
const TQ_UINT8 * KisTiledIterator::oldRawData() const
{
#ifdef DEBUG
// Warn if we're misusing oldRawData(). If there's no memento, oldRawData is the same
// as rawData().
kdWarning(!m_ktm->hasCurrentMemento(), DBG_AREA_TILES) << "Accessing oldRawData() when no transaction is in progress.\n";
#endif
return m_oldData + m_offset;
}
void KisTiledIterator::fetchTileData(TQ_INT32 col, TQ_INT32 row)
{
if (m_tile)
m_tile->removeReader();
if (m_oldTile)
m_oldTile->removeReader();
m_oldTile = 0;
m_tile = m_ktm->getTile(col, row, m_writable);
if (m_tile == 0) return;
//Q_ASSERT(m_tile != 0);
m_tile->addReader();
m_data = m_tile->data();
if (m_data == 0) return;
//Q_ASSERT(m_data != 0);
// set old data but default to current value
m_oldTile = m_ktm->getOldTile(col, row, m_tile);
m_oldTile->addReader(); // Double locking in case m_oldTile==m_tile is no problem
m_oldData = m_oldTile->data();
}
|