File indexing completed on 2024-05-19 04:26:40
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_VLINE_ITERATOR_H 0008 #define __KIS_WRAPPED_VLINE_ITERATOR_H 0009 0010 #include "kis_iterator_ng.h" 0011 #include "kis_wrapped_rect.h" 0012 0013 class WrappedVLineIteratorStrategy 0014 { 0015 private: 0016 static const int TOP_OFFSET = 0; 0017 static const int BOTTOM_OFFSET = 2; 0018 0019 public: 0020 typedef KisVLineIteratorSP IteratorTypeSP; 0021 0022 WrappedVLineIteratorStrategy() 0023 : m_splitRect(0) 0024 , m_iteratorColumnStart(KisWrappedRect::TOPLEFT) 0025 , m_lastColumnCoord(-1) 0026 { 0027 } 0028 0029 inline QSize originalRectToColumnsRows(const QRect &rect) { 0030 return QSize(rect.height(), rect.width()); 0031 } 0032 0033 inline QPoint columnRowToXY(const QPoint &pt) const { 0034 return QPoint(pt.y(), pt.x()); 0035 } 0036 0037 inline IteratorTypeSP createIterator(KisDataManager *dataManager, 0038 const QRect &rc, 0039 qint32 offsetX, qint32 offsetY, 0040 bool writable, 0041 KisIteratorCompleteListener *completeListener) { 0042 0043 return new KisVLineIterator2(dataManager, 0044 rc.x(), rc.y(), 0045 rc.height(), 0046 offsetX, offsetY, 0047 writable, 0048 completeListener); 0049 } 0050 0051 inline void completeInitialization(QVector<IteratorTypeSP> *iterators, 0052 KisWrappedRect *splitRect) { 0053 m_splitRect = splitRect; 0054 m_iterators = iterators; 0055 0056 m_lastColumnCoord = m_splitRect->topLeft().right(); 0057 } 0058 0059 inline IteratorTypeSP leftColumnIterator() const { 0060 return m_iterators->at(m_iteratorColumnStart + TOP_OFFSET); 0061 } 0062 0063 inline IteratorTypeSP rightColumnIterator() const { 0064 return m_iterators->at(m_iteratorColumnStart + BOTTOM_OFFSET); 0065 } 0066 0067 inline bool trySwitchIteratorStripe() { 0068 bool needSwitching = leftColumnIterator()->x() == m_lastColumnCoord; 0069 0070 if (needSwitching) { 0071 if (m_iteratorColumnStart == KisWrappedRect::TOPLEFT && 0072 m_iterators->at(KisWrappedRect::TOPRIGHT)) { 0073 0074 m_iteratorColumnStart = KisWrappedRect::TOPRIGHT; 0075 m_lastColumnCoord = m_splitRect->topRight().right(); 0076 } else /* if (m_iteratorColumnStart == KisWrappedRect::TOPRIGHT) */ { 0077 m_iteratorColumnStart = KisWrappedRect::TOPLEFT; 0078 m_lastColumnCoord = m_splitRect->topLeft().right(); 0079 0080 Q_FOREACH (IteratorTypeSP it, *m_iterators) { 0081 if (it) { 0082 it->resetColumnPos(); 0083 } 0084 } 0085 } 0086 } 0087 0088 return needSwitching; 0089 } 0090 0091 inline void iteratorsToNextRow() { 0092 leftColumnIterator()->nextColumn(); 0093 if (rightColumnIterator()) { 0094 rightColumnIterator()->nextColumn(); 0095 } 0096 } 0097 0098 inline bool trySwitchColumnForced() { 0099 leftColumnIterator()->resetPixelPos(); 0100 if (rightColumnIterator()) { 0101 rightColumnIterator()->resetPixelPos(); 0102 } 0103 0104 return true; 0105 } 0106 0107 private: 0108 KisWrappedRect *m_splitRect; 0109 QVector<IteratorTypeSP> *m_iterators; 0110 int m_iteratorColumnStart; // may be either KisWrappedRect::TOPLEFT or KisWrappedRect::TOPRIGHT 0111 int m_lastColumnCoord; 0112 }; 0113 0114 #include "kis_wrapped_line_iterator_base.h" 0115 typedef KisWrappedLineIteratorBase<WrappedVLineIteratorStrategy, KisVLineIteratorNG> KisWrappedVLineIterator; 0116 0117 0118 #endif /* __KIS_WRAPPED_VLINE_ITERATOR_H */