Krita Source Code Documentation
Loading...
Searching...
No Matches
GridIterationTools::PaintDevicePolygonOp Struct Reference

#include <kis_grid_interpolation_tools.h>

Public Member Functions

void fastCopyArea (QPolygonF areaToCopy)
 
void fastCopyArea (QRect areaToCopy)
 
void fastCopyArea (QRect areaToCopy, bool lazy)
 
void finalize ()
 
void operator() (const QPolygonF &srcPolygon, const QPolygonF &dstPolygon)
 
void operator() (const QPolygonF &srcPolygon, const QPolygonF &dstPolygon, const QPolygonF &clipDstPolygon)
 
 PaintDevicePolygonOp (KisPaintDeviceSP srcDev, KisPaintDeviceSP dstDev)
 
void setCanMergeRects (bool newCanMergeRects)
 

Public Attributes

KisPaintDeviceSP m_dstDev
 
const qreal m_epsilon {0.1}
 
KisPaintDeviceSP m_srcDev
 

Private Attributes

bool m_canMergeRects {true}
 
QVector< QRect > m_rectsToCopy
 

Detailed Description

Definition at line 169 of file kis_grid_interpolation_tools.h.

Constructor & Destructor Documentation

◆ PaintDevicePolygonOp()

GridIterationTools::PaintDevicePolygonOp::PaintDevicePolygonOp ( KisPaintDeviceSP srcDev,
KisPaintDeviceSP dstDev )
inline

Member Function Documentation

◆ fastCopyArea() [1/3]

void GridIterationTools::PaintDevicePolygonOp::fastCopyArea ( QPolygonF areaToCopy)
inline

Definition at line 175 of file kis_grid_interpolation_tools.h.

175 {
176 QRect boundRect = areaToCopy.boundingRect().toAlignedRect();
177 if (boundRect.isEmpty()) return;
178
179 bool isItRect = KisAlgebra2D::isPolygonRect(areaToCopy, m_epsilon); // no need for lower tolerance
180 if (isItRect) {
181 fastCopyArea(boundRect);
182 return;
183 }
184
185 KisSequentialIterator dstIt(m_dstDev, boundRect);
186 KisSequentialIterator srcIt(m_srcDev, boundRect);
187
188 // this can possibly be optimized with scanlining the polygon
189 // (use intersectLineConvexPolygon to get a line at every height)
190 // but it doesn't matter much because in the vast majority of cases
191 // it should go straight to the rect area copying
192
193 while (dstIt.nextPixel() && srcIt.nextPixel()) {
194 if (areaToCopy.containsPoint(QPoint(dstIt.x(), dstIt.y()), Qt::OddEvenFill)) {
195 memcpy(dstIt.rawData(), srcIt.oldRawData(), m_dstDev->pixelSize());
196 }
197 }
198 }
quint32 pixelSize() const
bool isPolygonRect(const Polygon &poly, Difference tolerance)

References fastCopyArea(), KisAlgebra2D::isPolygonRect(), m_dstDev, m_epsilon, m_srcDev, KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::nextPixel(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::oldRawData(), KisPaintDevice::pixelSize(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::rawData(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::x(), and KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::y().

◆ fastCopyArea() [2/3]

void GridIterationTools::PaintDevicePolygonOp::fastCopyArea ( QRect areaToCopy)
inline

◆ fastCopyArea() [3/3]

void GridIterationTools::PaintDevicePolygonOp::fastCopyArea ( QRect areaToCopy,
bool lazy )
inline

Definition at line 204 of file kis_grid_interpolation_tools.h.

204 {
205 if (lazy) {
206 m_rectsToCopy.append(areaToCopy.adjusted(0, 0, -1, -1));
207 } else {
208 KisPainter::copyAreaOptimized(areaToCopy.topLeft(), m_srcDev, m_dstDev, areaToCopy);
209 }
210 }
static void copyAreaOptimized(const QPoint &dstPt, KisPaintDeviceSP src, KisPaintDeviceSP dst, const QRect &originalSrcRect)

References KisPainter::copyAreaOptimized(), m_dstDev, m_rectsToCopy, and m_srcDev.

◆ finalize()

void GridIterationTools::PaintDevicePolygonOp::finalize ( )
inline

Definition at line 286 of file kis_grid_interpolation_tools.h.

286 {
287
289
290 for (QVector<QRect>::iterator it = m_rectsToCopy.begin(); it < end; it++) {
291 QRect areaToCopy = *it;
292 fastCopyArea(areaToCopy.adjusted(0, 0, 1, 1), false);
293 }
295 }
static QVector< QRect >::iterator mergeSparseRects(QVector< QRect >::iterator beginIt, QVector< QRect >::iterator endIt)
merge a set of rectangles into a smaller set of bigger rectangles

References fastCopyArea(), m_rectsToCopy, and KisRegion::mergeSparseRects().

◆ operator()() [1/2]

void GridIterationTools::PaintDevicePolygonOp::operator() ( const QPolygonF & srcPolygon,
const QPolygonF & dstPolygon )
inline

Definition at line 212 of file kis_grid_interpolation_tools.h.

212 {
213 operator() (srcPolygon, dstPolygon, dstPolygon);
214 }
void operator()(const QPolygonF &srcPolygon, const QPolygonF &dstPolygon)

References operator()().

◆ operator()() [2/2]

void GridIterationTools::PaintDevicePolygonOp::operator() ( const QPolygonF & srcPolygon,
const QPolygonF & dstPolygon,
const QPolygonF & clipDstPolygon )
inline

We need to make sure that the destination polygon is not too small, otherwise even small rounding will send the src-accessor into infinity

Definition at line 216 of file kis_grid_interpolation_tools.h.

216 {
217 QRect boundRect = clipDstPolygon.boundingRect().toAlignedRect();
218 if (boundRect.isEmpty()) return;
219
220 bool samePolygon = (m_dstDev->colorSpace() == m_srcDev->colorSpace()) && KisAlgebra2D::fuzzyPointCompare(srcPolygon, dstPolygon, m_epsilon);
221
222 if (samePolygon) {
223 // we can use clipDstPolygon here, because it will be smaller than dstPolygon and srcPolygon, because of how IncompletePolicy works
224 // we could also calculate intersection here if we're worried whether that fact is always true
225 fastCopyArea(clipDstPolygon);
226 return;
227 }
228
229
230 KisSequentialIterator dstIt(m_dstDev, boundRect);
232
233 KisFourPointInterpolatorBackward interp(srcPolygon, dstPolygon);
234
240 if (interp.isValid(0.1)) {
241 int y = boundRect.top();
242 interp.setY(y);
243
244 while (dstIt.nextPixel()) {
245 int newY = dstIt.y();
246
247 if (y != newY) {
248 y = newY;
249 interp.setY(y);
250 }
251
252 QPointF srcPoint(dstIt.x(), y);
253
254 if (clipDstPolygon.containsPoint(srcPoint, Qt::OddEvenFill)) {
255
256 interp.setX(srcPoint.x());
257 QPointF dstPoint = interp.getValue();
258
259 // brain-blowing part:
260 //
261 // since the interpolator does the inverted
262 // transformation we read data from "dstPoint"
263 // (which is non-transformed) and write it into
264 // "srcPoint" (which is transformed position)
265
266 srcAcc->moveTo(dstPoint);
267 quint8* rawData = dstIt.rawData();
268 srcAcc->sampledOldRawData(rawData);
269 }
270 }
271
272 } else {
273 srcAcc->moveTo(interp.fallbackSourcePoint());
274
275 while (dstIt.nextPixel()) {
276 QPointF srcPoint(dstIt.x(), dstIt.y());
277
278 if (clipDstPolygon.containsPoint(srcPoint, Qt::OddEvenFill)) {
279 srcAcc->sampledOldRawData(dstIt.rawData());
280 }
281 }
282 }
283
284 }
QPointF dstPoint
const KoColorSpace * colorSpace() const
KisRandomSubAccessorSP createRandomSubAccessor() const
void sampledOldRawData(quint8 *dst)
void moveTo(qreal x, qreal y)
qreal interp(qreal r, qreal a, qreal b)
private functions
bool fuzzyPointCompare(const QPointF &p1, const QPointF &p2)

References KisPaintDevice::colorSpace(), KisPaintDevice::createRandomSubAccessor(), dstPoint, fastCopyArea(), KisAlgebra2D::fuzzyPointCompare(), interp(), m_dstDev, m_epsilon, m_srcDev, KisRandomSubAccessor::moveTo(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::nextPixel(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::rawData(), KisRandomSubAccessor::sampledOldRawData(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::x(), and KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::y().

◆ setCanMergeRects()

void GridIterationTools::PaintDevicePolygonOp::setCanMergeRects ( bool newCanMergeRects)
inline

Definition at line 297 of file kis_grid_interpolation_tools.h.

297 {
298 m_canMergeRects = newCanMergeRects;
299 }

References m_canMergeRects.

Member Data Documentation

◆ m_canMergeRects

bool GridIterationTools::PaintDevicePolygonOp::m_canMergeRects {true}
private

Definition at line 306 of file kis_grid_interpolation_tools.h.

306{true};

◆ m_dstDev

KisPaintDeviceSP GridIterationTools::PaintDevicePolygonOp::m_dstDev

Definition at line 302 of file kis_grid_interpolation_tools.h.

◆ m_epsilon

const qreal GridIterationTools::PaintDevicePolygonOp::m_epsilon {0.1}

Definition at line 303 of file kis_grid_interpolation_tools.h.

303{0.1};

◆ m_rectsToCopy

QVector<QRect> GridIterationTools::PaintDevicePolygonOp::m_rectsToCopy
private

Definition at line 307 of file kis_grid_interpolation_tools.h.

◆ m_srcDev

KisPaintDeviceSP GridIterationTools::PaintDevicePolygonOp::m_srcDev

Definition at line 301 of file kis_grid_interpolation_tools.h.


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