File indexing completed on 2024-05-12 15:58:48
0001 /* 0002 * SPDX-FileCopyrightText: 2013 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef __KIS_WRAPPED_HLINE_ITERATOR_H 0008 #define __KIS_WRAPPED_HLINE_ITERATOR_H 0009 0010 #include "kis_iterator_ng.h" 0011 #include "kis_wrapped_rect.h" 0012 0013 0014 class WrappedHLineIteratorStrategy 0015 { 0016 public: 0017 typedef KisHLineIteratorSP IteratorTypeSP; 0018 0019 WrappedHLineIteratorStrategy() 0020 : m_iteratorRowStart(KisWrappedRect::TOPLEFT), 0021 m_lastRowCoord(-1) 0022 { 0023 } 0024 0025 inline QSize originalRectToColumnsRows(const QRect &rect) { 0026 return rect.size(); 0027 } 0028 0029 inline QPoint columnRowToXY(const QPoint &pt) const { 0030 return pt; 0031 } 0032 0033 inline IteratorTypeSP createIterator(KisDataManager *dataManager, 0034 const QRect &rc, 0035 qint32 offsetX, qint32 offsetY, 0036 bool writable, 0037 KisIteratorCompleteListener *listener) { 0038 0039 return new KisHLineIterator2(dataManager, 0040 rc.x(), rc.y(), 0041 rc.width(), 0042 offsetX, offsetY, 0043 writable, 0044 listener); 0045 } 0046 0047 inline void completeInitialization(QVector<IteratorTypeSP> *iterators, 0048 KisWrappedRect *splitRect) { 0049 m_splitRect = splitRect; 0050 m_iterators = iterators; 0051 0052 m_lastRowCoord = m_splitRect->topLeft().bottom(); 0053 } 0054 0055 inline IteratorTypeSP leftColumnIterator() const { 0056 return m_iterators->at(m_iteratorRowStart + KisWrappedRect::TOPLEFT); 0057 } 0058 0059 inline IteratorTypeSP rightColumnIterator() const { 0060 return m_iterators->at(m_iteratorRowStart + KisWrappedRect::TOPRIGHT); 0061 } 0062 0063 inline bool trySwitchIteratorStripe() { 0064 bool needSwitching = leftColumnIterator()->y() == m_lastRowCoord; 0065 0066 if (needSwitching) { 0067 if (m_iteratorRowStart == KisWrappedRect::TOPLEFT && 0068 m_iterators->at(KisWrappedRect::BOTTOMLEFT)) { 0069 0070 m_iteratorRowStart = KisWrappedRect::BOTTOMLEFT; 0071 m_lastRowCoord = m_splitRect->bottomLeft().bottom(); 0072 } else /* if (m_iteratorRowStart == KisWrappedRect::BOTTOMLEFT) */ { 0073 m_iteratorRowStart = KisWrappedRect::TOPLEFT; 0074 m_lastRowCoord = m_splitRect->topLeft().bottom(); 0075 0076 Q_FOREACH (IteratorTypeSP it, *m_iterators) { 0077 if (it) { 0078 it->resetRowPos(); 0079 } 0080 } 0081 } 0082 } 0083 0084 return needSwitching; 0085 } 0086 0087 inline void iteratorsToNextRow() { 0088 leftColumnIterator()->nextRow(); 0089 if (rightColumnIterator()) { 0090 rightColumnIterator()->nextRow(); 0091 } 0092 } 0093 0094 inline bool trySwitchColumnForced() { 0095 leftColumnIterator()->resetPixelPos(); 0096 if (rightColumnIterator()) { 0097 rightColumnIterator()->resetPixelPos(); 0098 } 0099 return true; 0100 } 0101 0102 private: 0103 KisWrappedRect *m_splitRect; 0104 QVector<IteratorTypeSP> *m_iterators; 0105 int m_iteratorRowStart; // may be either KisWrappedRect::TOPLEFT or KisWrappedRect::BOTTOMLEFT 0106 int m_lastRowCoord; 0107 }; 0108 0109 #include "kis_wrapped_line_iterator_base.h" 0110 typedef KisWrappedLineIteratorBase<WrappedHLineIteratorStrategy, KisHLineIteratorNG> KisWrappedHLineIterator; 0111 0112 0113 #endif /* __KIS_WRAPPED_HLINE_ITERATOR_H */