chalk

kis_iterators_pixel.h
1/* This file is part of the KDE project
2 * Copyright (c) 2004 Cyrille Berger <cberger@cberger.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17*/
18
19#ifndef KIS_ITERATORS_PIXEL_H_
20#define KIS_ITERATORS_PIXEL_H_
21
22#include "kis_iterator.h"
23#include "kis_iteratorpixeltrait.h"
24
32class KisHLineIteratorPixel : public KisHLineIterator, public KisIteratorPixelTrait <KisHLineIterator>
33{
34
35public:
36
38 TQ_INT32 x , TQ_INT32 y , TQ_INT32 w, TQ_INT32 offsetx, TQ_INT32 offsety,
39 bool writable);
40
41 KisHLineIteratorPixel(const KisHLineIteratorPixel& rhs) : KisHLineIterator(rhs), KisIteratorPixelTrait<KisHLineIterator>(rhs)
42 { m_offsetx = rhs.m_offsetx; m_offsety = rhs.m_offsety; }
43
44 KisHLineIteratorPixel& operator=(const KisHLineIteratorPixel& rhs)
45 {
46 KisHLineIterator::operator=(rhs);
47 KisIteratorPixelTrait<KisHLineIterator>::operator=(rhs);
48 m_offsetx = rhs.m_offsetx; m_offsety = rhs.m_offsety;
49 return *this;
50 }
51
52 inline KisHLineIteratorPixel & operator ++() { KisHLineIterator::operator++(); advance(1); return *this;}
53 inline KisHLineIteratorPixel & operator --() { KisHLineIterator::operator--(); retreat(); return *this;}
54
55 inline void nextRow() {
56 KisHLineIterator::nextRow();
57 if (m_selectionIterator) m_selectionIterator->nextRow();
58 }
59
61 KisHLineIteratorPixel & operator+=(int n) { KisHLineIterator::operator+=(n); advance(n); return *this; };
62
63 TQ_INT32 x() const { return KisHLineIterator::x() + m_offsetx; }
64
65 TQ_INT32 y() const { return KisHLineIterator::y() + m_offsety; }
66
67 TQ_INT32 nConseqHPixels() const {
68 if (m_selectionIterator) {
69 TQ_INT32 parent = KisHLineIteratorPixel::nConseqHPixels();
70 TQ_INT32 selection = m_selectionIterator->nConseqHPixels();
71 if (parent < selection)
72 return parent;
73 return selection;
74 }
75 return KisHLineIteratorPixel::nConseqHPixels();
76 }
77protected:
78
79 TQ_INT32 m_offsetx, m_offsety;
80};
81
82class KisVLineIteratorPixel : public KisVLineIterator, public KisIteratorPixelTrait <KisVLineIterator>
83{
84public:
85 KisVLineIteratorPixel( KisPaintDevice *ndevice, KisDataManager *dm, KisDataManager *sel_dm,
86 TQ_INT32 xpos , TQ_INT32 ypos , TQ_INT32 height, TQ_INT32 offsetx, TQ_INT32 offsety,
87 bool writable);
88
89 KisVLineIteratorPixel(const KisVLineIteratorPixel& rhs) : KisVLineIterator(rhs), KisIteratorPixelTrait<KisVLineIterator>(rhs)
90 { m_offsetx = rhs.m_offsetx; m_offsety = rhs.m_offsety; }
91
92 KisVLineIteratorPixel& operator=(const KisVLineIteratorPixel& rhs)
93 {
94 KisVLineIterator::operator=(rhs);
95 KisIteratorPixelTrait<KisVLineIterator>::operator=(rhs);
96 m_offsetx = rhs.m_offsetx; m_offsety = rhs.m_offsety;
97 return *this; }
98
99 inline KisVLineIteratorPixel & operator ++() { KisVLineIterator::operator++(); advance(1); return *this;}
100
101 inline void nextRow() {
102 KisVLineIterator::nextCol();
103 if (m_selectionIterator) m_selectionIterator->nextCol();
104 }
105
106 TQ_INT32 x() const { return KisVLineIterator::x() + m_offsetx; }
107
108 TQ_INT32 y() const { return KisVLineIterator::y() + m_offsety; }
109
110protected:
111
112 TQ_INT32 m_offsetx, m_offsety;
113};
114
115class KisRectIteratorPixel : public KisRectIterator, public KisIteratorPixelTrait <KisRectIterator>
116{
117public:
118 KisRectIteratorPixel( KisPaintDevice *ndevice, KisDataManager *dm, KisDataManager *sel_dm,
119 TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h, TQ_INT32 offsetx, TQ_INT32 offsety,
120 bool writable);
121
122 KisRectIteratorPixel(const KisRectIteratorPixel& rhs) : KisRectIterator(rhs), KisIteratorPixelTrait<KisRectIterator>(rhs)
123 { m_offsetx = rhs.m_offsetx; m_offsety = rhs.m_offsety; }
124
125 KisRectIteratorPixel& operator=(const KisRectIteratorPixel& rhs)
126 {
127 KisRectIterator::operator=(rhs);
128 KisIteratorPixelTrait<KisRectIterator>::operator=(rhs);
129 m_offsetx = rhs.m_offsetx; m_offsety = rhs.m_offsety;
130 return *this; }
131
132 inline KisRectIteratorPixel & operator ++() { KisRectIterator::operator++(); advance(1); return *this;}
133
134 TQ_INT32 x() const { return KisRectIterator::x() + m_offsetx; }
135
136 TQ_INT32 y() const { return KisRectIterator::y() + m_offsety; }
137
138 TQ_INT32 nConseqPixels() const {
139 if (m_selectionIterator) {
140 TQ_INT32 parent = KisRectIterator::nConseqPixels();
141 TQ_INT32 selection = m_selectionIterator->nConseqPixels();
142 if (parent < selection)
143 return parent;
144 return selection;
145 }
147 }
148
149protected:
150
151 TQ_INT32 m_offsetx, m_offsety;
152};
153
154#endif
KisDataManager defines the interface that modules responsible for storing and retrieving data must in...
The pixel iterators are high level iterarators.
KisHLineIteratorPixel & operator+=(int n)
Advances a number of pixels until it reaches the end of the line.
A paint device contains the actual pixel data and offers methods to read and write pixels.
The KisRectIterator iterators over a rectangular area in the most efficient order.
KisRectIterator & operator++()
Advances one pixel going to the beginning of the next line when it reaches the end of a line.
TQ_INT32 nConseqPixels() const
Returns the number of consequtive pixels that we point at This is useful for optimizing.