Krita Source Code Documentation
Loading...
Searching...
No Matches
KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy > Class Template Reference

#include <kis_sequential_iterator.h>

Public Member Functions

 KisSequentialIteratorBase (SourcePolicy source, const QRect &rect, ProgressPolicy progressPolicy=ProgressPolicy())
 
int nConseqPixels () const
 
bool nextPixel ()
 
bool nextPixels (int numPixels)
 
ALWAYS_INLINE const quint8 * oldRawData () const
 
ALWAYS_INLINE quint8 * rawData ()
 
ALWAYS_INLINE const quint8 * rawDataConst () const
 
ALWAYS_INLINE int x () const
 
ALWAYS_INLINE int y () const
 
 ~KisSequentialIteratorBase ()
 

Private Attributes

int m_columnOffset
 
int m_columnsLeft
 
bool m_isStarted
 
int m_iteratorX
 
int m_iteratorY
 
int m_numConseqPixels
 
const int m_pixelSize
 
IteratorPolicy m_policy
 
ProgressPolicy m_progressPolicy
 
int m_rowsLeft
 

Detailed Description

template<class IteratorPolicy, class SourcePolicy = DevicePolicy, class ProgressPolicy = NoProgressPolicy>
class KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >

Sequential iterator is supposed to be used when you need to read/write a rect of the image and you don't want to think about row or column nested loops. For the sequential iterator you will need a single loop: the data will be read line-by-line using an internal hline iterator. Please note that thanks to inline optimizations inside the sequential iterator when doing pixel-by-pixel processing it is about twice faster(!) than a usual hline iterator.

The follows the "java-style" iterators rules. Before requesting the first pixel from the iterator you should call nextPixel() to "jump over" this first pixel. After the jump is accomplished, you can easily request the "jumped over" pixel data.

The modified rules apply when the user wants accesses consequent pixels in one go. The user first asks the iterator for the number of available consequent pixels, and then calls nextPixels(numConseqPixels). In this case, iterator inserts a "virtual" pixel that one should jump over before doing any real iteration.

Iteration in pixel-by-pixel manner:

while (it.nextPixel()) {
quint *ptr = it.rawDataConst();
// work with ptr...
}

Iteration with strides:

// Here we jump over the first "virtual" pixel,
// which helps us to avoid an empty rect problem
int numConseqPixels = it.nConseqPixels();
while (it.nextPixels(numConseqPixels)) {
// get real number of conseq pixels
numConseqPixels = it.nConseqPixels();
quint *ptr = it.rawDataConst();
// process the data
processPixelData(tr, numConseqPixels);
}

Implementation:

The iterator is implemented using a policy pattern. The class itself is a template which accepts a special class (policy) that defines: 1) which type of the hline iterator will be used; 2) what methods of the internal hline iterator will be called. The choice of the policy declares whether the iterator will be writable or const.

Definition at line 177 of file kis_sequential_iterator.h.

Constructor & Destructor Documentation

◆ KisSequentialIteratorBase()

template<class IteratorPolicy , class SourcePolicy = DevicePolicy, class ProgressPolicy = NoProgressPolicy>
KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::KisSequentialIteratorBase ( SourcePolicy source,
const QRect & rect,
ProgressPolicy progressPolicy = ProgressPolicy() )
inline

Definition at line 180 of file kis_sequential_iterator.h.

181 : m_policy(source, rect),
182 m_progressPolicy(progressPolicy),
183 m_pixelSize(source.pixelSize()),
184 m_rowsLeft(rect.height() - 1),
186 m_iteratorX(0),
187 m_iteratorY(0),
188 m_isStarted(false)
189 {
191 m_policy.m_iter ? m_policy.m_iter->nConseqPixels() : 0;
192
193 m_policy.updatePointersCache();
194 m_iteratorX = m_policy.m_iter ? m_policy.m_iter->x() : 0;
195 m_iteratorY = m_policy.m_iter ? m_policy.m_iter->y() : 0;
196
197 m_progressPolicy.setRange(rect.top(), rect.top() + rect.height());
198 m_progressPolicy.setValue(rect.top());
199 }
KisMagneticGraph::vertex_descriptor source(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)

References KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::m_columnsLeft, KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::m_iteratorX, KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::m_iteratorY, KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::m_numConseqPixels, KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::m_policy, and KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::m_progressPolicy.

◆ ~KisSequentialIteratorBase()

template<class IteratorPolicy , class SourcePolicy = DevicePolicy, class ProgressPolicy = NoProgressPolicy>
KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::~KisSequentialIteratorBase ( )
inline

Member Function Documentation

◆ nConseqPixels()

template<class IteratorPolicy , class SourcePolicy = DevicePolicy, class ProgressPolicy = NoProgressPolicy>
int KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::nConseqPixels ( ) const
inline

◆ nextPixel()

template<class IteratorPolicy , class SourcePolicy = DevicePolicy, class ProgressPolicy = NoProgressPolicy>
bool KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::nextPixel ( )
inline

Definition at line 219 of file kis_sequential_iterator.h.

219 {
220 if (!m_isStarted) {
221 m_isStarted = true;
222 return m_policy.m_iter;
223 }
224
226
227 if (m_columnsLeft > 0) {
229 return true;
230 } else {
231 bool result = m_policy.m_iter->nextPixels(m_numConseqPixels);
232 if (result) {
233 m_columnOffset = 0;
234 m_columnsLeft = m_numConseqPixels = m_policy.m_iter->nConseqPixels();
235 m_policy.updatePointersCache();
236 } else if (m_rowsLeft > 0) {
237 m_rowsLeft--;
238 m_policy.m_iter->nextRow();
239 m_columnOffset = 0;
240 m_columnsLeft = m_numConseqPixels = m_policy.m_iter->nConseqPixels();
241 m_policy.updatePointersCache();
242 m_progressPolicy.setValue(m_policy.m_iter->y());
243 } else if (m_rowsLeft == 0) {
244 // report that we have completed iteration
245 m_progressPolicy.setValue(m_policy.m_iter->y() + 1);
246 }
247
248 m_iteratorX = m_policy.m_iter->x();
249 m_iteratorY = m_policy.m_iter->y();
250 }
251 return m_columnsLeft > 0;
252 }

References KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::m_columnOffset, KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::m_columnsLeft, KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::m_isStarted, KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::m_iteratorX, KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::m_iteratorY, KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::m_numConseqPixels, KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::m_pixelSize, KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::m_policy, KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::m_progressPolicy, and KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::m_rowsLeft.

◆ nextPixels()

template<class IteratorPolicy , class SourcePolicy = DevicePolicy, class ProgressPolicy = NoProgressPolicy>
bool KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::nextPixels ( int numPixels)
inline

◆ oldRawData()

template<class IteratorPolicy , class SourcePolicy = DevicePolicy, class ProgressPolicy = NoProgressPolicy>
ALWAYS_INLINE const quint8 * KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::oldRawData ( ) const
inline

◆ rawData()

template<class IteratorPolicy , class SourcePolicy = DevicePolicy, class ProgressPolicy = NoProgressPolicy>
ALWAYS_INLINE quint8 * KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::rawData ( )
inline

◆ rawDataConst()

template<class IteratorPolicy , class SourcePolicy = DevicePolicy, class ProgressPolicy = NoProgressPolicy>
ALWAYS_INLINE const quint8 * KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::rawDataConst ( ) const
inline

◆ x()

template<class IteratorPolicy , class SourcePolicy = DevicePolicy, class ProgressPolicy = NoProgressPolicy>
ALWAYS_INLINE int KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::x ( ) const
inline

◆ y()

template<class IteratorPolicy , class SourcePolicy = DevicePolicy, class ProgressPolicy = NoProgressPolicy>
ALWAYS_INLINE int KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::y ( ) const
inline

Member Data Documentation

◆ m_columnOffset

template<class IteratorPolicy , class SourcePolicy = DevicePolicy, class ProgressPolicy = NoProgressPolicy>
int KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::m_columnOffset
private

Definition at line 287 of file kis_sequential_iterator.h.

◆ m_columnsLeft

template<class IteratorPolicy , class SourcePolicy = DevicePolicy, class ProgressPolicy = NoProgressPolicy>
int KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::m_columnsLeft
private

Definition at line 285 of file kis_sequential_iterator.h.

◆ m_isStarted

template<class IteratorPolicy , class SourcePolicy = DevicePolicy, class ProgressPolicy = NoProgressPolicy>
bool KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::m_isStarted
private

Definition at line 291 of file kis_sequential_iterator.h.

◆ m_iteratorX

template<class IteratorPolicy , class SourcePolicy = DevicePolicy, class ProgressPolicy = NoProgressPolicy>
int KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::m_iteratorX
private

Definition at line 288 of file kis_sequential_iterator.h.

◆ m_iteratorY

template<class IteratorPolicy , class SourcePolicy = DevicePolicy, class ProgressPolicy = NoProgressPolicy>
int KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::m_iteratorY
private

Definition at line 289 of file kis_sequential_iterator.h.

◆ m_numConseqPixels

template<class IteratorPolicy , class SourcePolicy = DevicePolicy, class ProgressPolicy = NoProgressPolicy>
int KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::m_numConseqPixels
private

Definition at line 284 of file kis_sequential_iterator.h.

◆ m_pixelSize

template<class IteratorPolicy , class SourcePolicy = DevicePolicy, class ProgressPolicy = NoProgressPolicy>
const int KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::m_pixelSize
private

Definition at line 281 of file kis_sequential_iterator.h.

◆ m_policy

template<class IteratorPolicy , class SourcePolicy = DevicePolicy, class ProgressPolicy = NoProgressPolicy>
IteratorPolicy KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::m_policy
private

Definition at line 279 of file kis_sequential_iterator.h.

◆ m_progressPolicy

template<class IteratorPolicy , class SourcePolicy = DevicePolicy, class ProgressPolicy = NoProgressPolicy>
ProgressPolicy KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::m_progressPolicy
private

Definition at line 280 of file kis_sequential_iterator.h.

◆ m_rowsLeft

template<class IteratorPolicy , class SourcePolicy = DevicePolicy, class ProgressPolicy = NoProgressPolicy>
int KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::m_rowsLeft
private

Definition at line 282 of file kis_sequential_iterator.h.


The documentation for this class was generated from the following file: