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 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
|
/*
* Copyright (c) 2008 Cyrille Berger <cberger@cberger.net>
*
* 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_REPEAT_ITERATORS_PIXEL_H_
#define _KIS_REPEAT_ITERATORS_PIXEL_H_
#include <QRect>
#include "kis_shared.h"
#include "tiles3/kis_hline_iterator.h"
#include "tiles3/kis_vline_iterator.h"
template<class T>
class KisRepeatHLineIteratorPixelBase;
template<class T>
class KisRepeatVLineIteratorPixelBase;
/**
* This iterator is an iterator that will "artificially" extend the paint device with the
* value of the border when trying to access values outside the range of data.
*/
template<class T>
class KisRepeatLineIteratorPixelBase : public KisShared
{
Q_DISABLE_COPY(KisRepeatLineIteratorPixelBase)
public:
friend class KisRepeatHLineIteratorPixelBase<T>;
friend class KisRepeatVLineIteratorPixelBase<T>;
/**
* @param rc indicates the rectangle that truly contains data
*/
inline KisRepeatLineIteratorPixelBase(KisDataManager *dm, qint32 x, qint32 y, qint32 offsetx, qint32 offsety, const QRect& _rc);
virtual inline ~KisRepeatLineIteratorPixelBase();
public:
inline qint32 x() const {
return m_realX;
}
inline qint32 y() const {
return m_realY;
}
inline const quint8 * oldRawData() const {
return m_iterator->oldRawData();
}
private:
KisDataManager* m_dm;
qint32 m_realX, m_realY;
qint32 m_offsetX, m_offsetY;
QRect m_dataRect;
T* m_iterator;
};
/**
* This iterator is an iterator that will "artificially" extend the paint device with the
* value of the border when trying to access values outside the range of data.
*/
template<class T>
class KisRepeatHLineIteratorPixelBase : public KisRepeatLineIteratorPixelBase<T>
{
public:
/**
* @param rc indicates the rectangle that trully contains data
*/
inline KisRepeatHLineIteratorPixelBase(KisDataManager *dm, qint32 x, qint32 y, qint32 w, qint32 offsetx, qint32 offsety, const QRect& _rc);
virtual inline ~KisRepeatHLineIteratorPixelBase();
inline bool nextPixel();
/**
* Reach next row.
*/
inline void nextRow();
private:
void createIterator();
private:
qint32 m_startX;
qint32 m_startIteratorX;
qint32 m_width;
};
/**
* This iterator is an iterator that will "artificially" extend the paint device with the
* value of the border when trying to access values outside the range of data.
*/
template<class T>
class KisRepeatVLineIteratorPixelBase : public KisRepeatLineIteratorPixelBase<T>
{
public:
/**
* @param rc indicates the rectangle that trully contains data
*/
inline KisRepeatVLineIteratorPixelBase(KisDataManager *dm, qint32 x, qint32 y, qint32 h, qint32 offsetx, qint32 offsety, const QRect& _rc);
virtual inline ~KisRepeatVLineIteratorPixelBase();
inline KisRepeatVLineIteratorPixelBase<T> & operator ++();
inline bool nextPixel();
/**
* Reach next row.
*/
inline void nextColumn();
private:
void createIterator();
private:
qint32 m_startY;
qint32 m_startIteratorY;
qint32 m_height;
};
//------------------------ Implementations ------------------------//
//---------------- KisRepeatLineIteratorPixelBase -----------------//
template<class T>
KisRepeatLineIteratorPixelBase<T>::KisRepeatLineIteratorPixelBase(KisDataManager *dm, qint32 x, qint32 y, qint32 offsetx, qint32 offsety, const QRect& _rc) :
m_dm(dm),
m_realX(x), m_realY(y),
m_offsetX(offsetx), m_offsetY(offsety),
m_dataRect(_rc),
m_iterator(0)
{
}
template<class T>
KisRepeatLineIteratorPixelBase<T>::~KisRepeatLineIteratorPixelBase()
{
delete m_iterator;
}
//---------------- KisRepeatHLineIteratorPixelBase ----------------//
template<class T>
KisRepeatHLineIteratorPixelBase<T>::KisRepeatHLineIteratorPixelBase(KisDataManager *dm, qint32 x, qint32 y, qint32 w, qint32 offsetx, qint32 offsety, const QRect& _rc)
: KisRepeatLineIteratorPixelBase<T>(dm, x, y, offsetx, offsety , _rc),
m_startX(x), m_startIteratorX(x),
m_width(w)
{
// Compute the startx value of the iterator
if (m_startIteratorX < _rc.left()) {
m_startIteratorX = _rc.left();
}
createIterator();
}
template<class T>
KisRepeatHLineIteratorPixelBase<T>::~KisRepeatHLineIteratorPixelBase()
{
}
template<class T>
inline bool KisRepeatHLineIteratorPixelBase<T>::nextPixel()
{
Q_ASSERT(this->m_iterator);
if (this->m_realX >= this->m_dataRect.x() && this->m_realX < this->m_dataRect.x() + this->m_dataRect.width() - 1) {
this->m_iterator->nextPixel();
}
++this->m_realX;
return (this->m_realX < m_startX + m_width);
}
template<class T>
inline void KisRepeatHLineIteratorPixelBase<T>::nextRow()
{
if (this->m_realY >= this->m_dataRect.y() && this->m_realY < this->m_dataRect.y() + this->m_dataRect.height() - 1) {
this->m_iterator->nextRow();
} else {
createIterator();
}
this->m_realX = this->m_startX;
++this->m_realY;
}
template<class T>
void KisRepeatHLineIteratorPixelBase<T>::createIterator()
{
// Cleanup
delete this->m_iterator;
qint32 startY = this->m_realY;
if (startY < this->m_dataRect.y()) {
startY = this->m_dataRect.top();
}
if (startY > (this->m_dataRect.y() + this->m_dataRect.height() - 1)) {
startY = (this->m_dataRect.y() + this->m_dataRect.height() - 1);
}
int width = this->m_dataRect.x() + this->m_dataRect.width() - this->m_startIteratorX;
this->m_iterator = new T(this->m_dm, this->m_startIteratorX, startY, width, this->m_offsetX, this->m_offsetY, false);
this->m_realX = this->m_startX;
}
//---------------- KisRepeatVLineIteratorPixelBase ----------------//
template<class T>
KisRepeatVLineIteratorPixelBase<T>::KisRepeatVLineIteratorPixelBase(KisDataManager *dm, qint32 x, qint32 y, qint32 h, qint32 offsetx, qint32 offsety, const QRect& _rc)
: KisRepeatLineIteratorPixelBase<T>(dm, x, y, offsetx, offsety , _rc),
m_startY(y), m_startIteratorY(y),
m_height(h)
{
// Compute the startx value of the iterator
if (m_startIteratorY < _rc.top()) {
m_startIteratorY = _rc.top();
}
createIterator();
}
template<class T>
KisRepeatVLineIteratorPixelBase<T>::~KisRepeatVLineIteratorPixelBase()
{
}
template<class T>
inline bool KisRepeatVLineIteratorPixelBase<T>::nextPixel()
{
Q_ASSERT(this->m_iterator);
if (this->m_realY >= this->m_dataRect.y() && this->m_realY < this->m_dataRect.y() + this->m_dataRect.height() - 1) {
this->m_iterator->nextPixel();
}
++this->m_realY;
return (this->m_realY < m_startY + m_height);
}
template<class T>
inline void KisRepeatVLineIteratorPixelBase<T>::nextColumn()
{
if (this->m_realX >= this->m_dataRect.x() && this->m_realX < this->m_dataRect.x() + this->m_dataRect.width() - 1) {
this->m_iterator->nextColumn();
} else {
createIterator();
}
this->m_realY = this->m_startY;
++this->m_realX;
}
template<class T>
void KisRepeatVLineIteratorPixelBase<T>::createIterator()
{
// Cleanup
delete this->m_iterator;
qint32 startX = this->m_realX;
if (startX < this->m_dataRect.x()) {
startX = this->m_dataRect.x();
}
if (startX > (this->m_dataRect.x() + this->m_dataRect.width() - 1)) {
startX = (this->m_dataRect.x() + this->m_dataRect.width() - 1);
}
int height = this->m_dataRect.y() + this->m_dataRect.height() - this->m_startIteratorY;
this->m_iterator = new T(this->m_dm, startX, this->m_startIteratorY, height, this->m_offsetX, this->m_offsetY, false);
this->m_realY = this->m_startY;
}
#endif
|