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_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_splitRect(0)
0021         , m_iteratorRowStart(KisWrappedRect::TOPLEFT)
0022         , m_lastRowCoord(-1)
0023     {
0024     }
0025 
0026     inline QSize originalRectToColumnsRows(const QRect &rect) {
0027         return rect.size();
0028     }
0029 
0030     inline QPoint columnRowToXY(const QPoint &pt) const {
0031         return pt;
0032     }
0033 
0034     inline IteratorTypeSP createIterator(KisDataManager *dataManager,
0035                                          const QRect &rc,
0036                                          qint32 offsetX, qint32 offsetY,
0037                                          bool writable,
0038                                          KisIteratorCompleteListener *listener) {
0039 
0040         return new KisHLineIterator2(dataManager,
0041                                      rc.x(), rc.y(),
0042                                      rc.width(),
0043                                      offsetX, offsetY,
0044                                      writable,
0045                                      listener);
0046     }
0047 
0048     inline void completeInitialization(QVector<IteratorTypeSP> *iterators,
0049                                        KisWrappedRect *splitRect) {
0050         m_splitRect = splitRect;
0051         m_iterators = iterators;
0052 
0053         m_lastRowCoord = m_splitRect->topLeft().bottom();
0054     }
0055 
0056     inline IteratorTypeSP leftColumnIterator() const {
0057         return m_iterators->at(m_iteratorRowStart + KisWrappedRect::TOPLEFT);
0058     }
0059 
0060     inline IteratorTypeSP rightColumnIterator() const {
0061         return m_iterators->at(m_iteratorRowStart + KisWrappedRect::TOPRIGHT);
0062     }
0063 
0064     inline bool trySwitchIteratorStripe() {
0065         bool needSwitching = leftColumnIterator()->y() == m_lastRowCoord;
0066 
0067         if (needSwitching) {
0068             if (m_iteratorRowStart == KisWrappedRect::TOPLEFT &&
0069                 m_iterators->at(KisWrappedRect::BOTTOMLEFT)) {
0070 
0071                 m_iteratorRowStart = KisWrappedRect::BOTTOMLEFT;
0072                 m_lastRowCoord = m_splitRect->bottomLeft().bottom();
0073             } else /* if (m_iteratorRowStart == KisWrappedRect::BOTTOMLEFT) */ {
0074                 m_iteratorRowStart = KisWrappedRect::TOPLEFT;
0075                 m_lastRowCoord = m_splitRect->topLeft().bottom();
0076 
0077                 Q_FOREACH (IteratorTypeSP it, *m_iterators) {
0078                     if (it) {
0079                         it->resetRowPos();
0080                     }
0081                 }
0082             }
0083         }
0084 
0085         return needSwitching;
0086     }
0087 
0088     inline void iteratorsToNextRow() {
0089         leftColumnIterator()->nextRow();
0090         if (rightColumnIterator()) {
0091             rightColumnIterator()->nextRow();
0092         }
0093     }
0094 
0095     inline bool trySwitchColumnForced() {
0096         leftColumnIterator()->resetPixelPos();
0097         if (rightColumnIterator()) {
0098             rightColumnIterator()->resetPixelPos();
0099         }
0100         return true;
0101     }
0102 
0103 private:
0104     KisWrappedRect *m_splitRect;
0105     QVector<IteratorTypeSP> *m_iterators;
0106     int m_iteratorRowStart; // may be either KisWrappedRect::TOPLEFT or KisWrappedRect::BOTTOMLEFT
0107     int m_lastRowCoord;
0108 };
0109 
0110 #include "kis_wrapped_line_iterator_base.h"
0111 typedef KisWrappedLineIteratorBase<WrappedHLineIteratorStrategy, KisHLineIteratorNG> KisWrappedHLineIterator;
0112 
0113 
0114 #endif /* __KIS_WRAPPED_HLINE_ITERATOR_H */