Krita Source Code Documentation
Loading...
Searching...
No Matches
GridIterationTools::QImagePolygonOp 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)
 
 QImagePolygonOp (const QImage &srcImage, QImage &dstImage, const QPointF &srcImageOffset, const QPointF &dstImageOffset)
 
void setCanMergeRects (bool canMergeRects)
 

Public Attributes

QImage & m_dstImage
 
QPointF m_dstImageOffset
 
QRect m_dstImageRect
 
const qreal m_epsilon {0.1}
 
const QImage & m_srcImage
 
QPointF m_srcImageOffset
 
QRect m_srcImageRect
 

Private Attributes

bool m_canMergeRects {true}
 
QVector< QRect > m_rectsToCopy
 

Detailed Description

Definition at line 311 of file kis_grid_interpolation_tools.h.

Constructor & Destructor Documentation

◆ QImagePolygonOp()

GridIterationTools::QImagePolygonOp::QImagePolygonOp ( const QImage & srcImage,
QImage & dstImage,
const QPointF & srcImageOffset,
const QPointF & dstImageOffset )
inline

Member Function Documentation

◆ fastCopyArea() [1/3]

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

Definition at line 324 of file kis_grid_interpolation_tools.h.

324 {
325 QRect boundRect = areaToCopy.boundingRect().toAlignedRect();
326
327 if (boundRect.isEmpty()) return;
328
329 bool isItRect = KisAlgebra2D::isPolygonRect(areaToCopy, m_epsilon); // no need for lower tolerance
330 if (isItRect) {
331 fastCopyArea(boundRect);
332 return;
333 }
334
335 // this can possibly be optimized with scanlining the polygon
336 // (use intersectLineConvexPolygon to get a line at every height)
337 // but it doesn't matter much because in the vast majority of cases
338 // it should go straight to the rect area copying
339
340 for (int y = boundRect.top(); y <= boundRect.bottom(); y++) {
341 for (int x = boundRect.left(); x <= boundRect.right(); x++) {
342 QPointF dstPoint = QPointF(x, y);
343 QPointF srcPoint = dstPoint;
344
345 if (areaToCopy.containsPoint(srcPoint, Qt::OddEvenFill)) {
346
347 // about srcPoint/dstPoint hell please see a
348 // comment in PaintDevicePolygonOp::operator() ()
349
350 srcPoint -= m_dstImageOffset;
352
353 QPoint srcPointI = srcPoint.toPoint();
354 QPoint dstPointI = dstPoint.toPoint();
355
356 if (!m_dstImageRect.contains(srcPointI)) continue;
357 if (!m_srcImageRect.contains(dstPointI)) continue;
358
359 m_dstImage.setPixel(srcPointI, m_srcImage.pixel(dstPointI));
360 }
361
362 }
363 }
364
365 }
QPointF dstPoint
bool isPolygonRect(const Polygon &poly, Difference tolerance)

References dstPoint, fastCopyArea(), KisAlgebra2D::isPolygonRect(), m_dstImage, m_dstImageOffset, m_dstImageRect, m_epsilon, m_srcImage, m_srcImageOffset, and m_srcImageRect.

◆ fastCopyArea() [2/3]

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

◆ fastCopyArea() [3/3]

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

Definition at line 371 of file kis_grid_interpolation_tools.h.

371 {
372 if (lazy) {
373 m_rectsToCopy.append(areaToCopy.adjusted(0, 0, -1, -1));
374 return;
375 }
376
377 // only handling saved offsets
378 QRect srcArea = areaToCopy.translated(-m_srcImageOffset.toPoint());
379 QRect dstArea = areaToCopy.translated(-m_dstImageOffset.toPoint());
380
381 srcArea = srcArea.intersected(m_srcImageRect);
382 dstArea = dstArea.intersected(m_dstImageRect);
383
384 // it might look pointless but it cuts off unneeded areas on both rects based on where they end up
385 // since *I know* they are the same rectangle before translation
386 // TODO: I'm pretty sure this logic is correct, but let's check it when I'm less sleepy
387 QRect srcAreaUntranslated = srcArea.translated(m_srcImageOffset.toPoint());
388 QRect dstAreaUntranslated = dstArea.translated(m_dstImageOffset.toPoint());
389
390 QRect actualCopyArea = srcAreaUntranslated.intersected(dstAreaUntranslated);
391 srcArea = actualCopyArea.translated(-m_srcImageOffset.toPoint());
392 dstArea = actualCopyArea.translated(-m_dstImageOffset.toPoint());
393
394 int bytesPerPixel = m_srcImage.sizeInBytes()/m_srcImage.height()/m_srcImage.width();
395
396 int srcX = srcArea.left()*bytesPerPixel;
397 int dstX = dstArea.left()*bytesPerPixel;
398
399 for (int srcY = srcArea.top(); srcY <= srcArea.bottom(); ++srcY) {
400
401 int dstY = dstArea.top() + srcY - srcArea.top();
402 const uchar *srcLine = m_srcImage.constScanLine(srcY);
403 uchar *dstLine = m_dstImage.scanLine(dstY);
404 memcpy(dstLine + dstX, srcLine + srcX, srcArea.width()*bytesPerPixel);
405
406 }
407 }

References m_dstImage, m_dstImageOffset, m_dstImageRect, m_rectsToCopy, m_srcImage, m_srcImageOffset, and m_srcImageRect.

◆ finalize()

void GridIterationTools::QImagePolygonOp::finalize ( )
inline

Definition at line 469 of file kis_grid_interpolation_tools.h.

469 {
470
472
473 for (QVector<QRect>::iterator it = m_rectsToCopy.begin(); it < end; it++) {
474 QRect areaToCopy = *it;
475 fastCopyArea(areaToCopy.adjusted(0, 0, 1, 1), false);
476 }
477
479 }
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::QImagePolygonOp::operator() ( const QPolygonF & srcPolygon,
const QPolygonF & dstPolygon )
inline

Definition at line 409 of file kis_grid_interpolation_tools.h.

409 {
410 this->operator() (srcPolygon, dstPolygon, dstPolygon);
411 }
void operator()(const QPolygonF &srcPolygon, const QPolygonF &dstPolygon)

References operator()().

◆ operator()() [2/2]

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

Definition at line 413 of file kis_grid_interpolation_tools.h.

413 {
414 QRect boundRect = clipDstPolygon.boundingRect().toAlignedRect();
415
416 bool samePolygon = m_dstImage.format() == m_srcImage.format() && KisAlgebra2D::fuzzyPointCompare(srcPolygon, dstPolygon, m_epsilon);
417
418 if (samePolygon) {
419 // we can use clipDstPolygon here, because it will be smaller than dstPolygon and srcPolygon, because of how IncompletePolicy works
420 // we could also calculate intersection here if we're worried whether that fact is always true
421 fastCopyArea(clipDstPolygon);
422 return;
423 }
424
425 KisFourPointInterpolatorBackward interp(srcPolygon, dstPolygon);
426
427 for (int y = boundRect.top(); y <= boundRect.bottom(); y++) {
428 interp.setY(y);
429 for (int x = boundRect.left(); x <= boundRect.right(); x++) {
430
431 QPointF srcPoint(x, y);
432 if (clipDstPolygon.containsPoint(srcPoint, Qt::OddEvenFill)) {
433
434 interp.setX(srcPoint.x());
435 QPointF dstPoint = interp.getValue();
436
437 // about srcPoint/dstPoint hell please see a
438 // comment in PaintDevicePolygonOp::operator() ()
439
440 srcPoint -= m_dstImageOffset;
442
443 QPoint srcPointI = srcPoint.toPoint();
444 QPoint dstPointI = dstPoint.toPoint();
445
446 if (!m_dstImageRect.contains(srcPointI)) continue;
447 if (!m_srcImageRect.contains(dstPointI)) continue;
448
449 m_dstImage.setPixel(srcPointI, m_srcImage.pixel(dstPointI));
450 }
451 }
452 }
453
454#ifdef DEBUG_PAINTING_POLYGONS
455 QPainter gc(&m_dstImage);
456 gc.setPen(Qt::red);
457 gc.setOpacity(0.5);
458
459 gc.setBrush(Qt::green);
460 gc.drawPolygon(clipDstPolygon.translated(-m_dstImageOffset));
461
462 gc.setBrush(Qt::blue);
463 //gc.drawPolygon(dstPolygon.translated(-m_dstImageOffset));
464
465#endif /* DEBUG_PAINTING_POLYGONS */
466
467 }
qreal interp(qreal r, qreal a, qreal b)
private functions
bool fuzzyPointCompare(const QPointF &p1, const QPointF &p2)

References dstPoint, fastCopyArea(), KisAlgebra2D::fuzzyPointCompare(), interp(), m_dstImage, m_dstImageOffset, m_dstImageRect, m_epsilon, m_srcImage, m_srcImageOffset, and m_srcImageRect.

◆ setCanMergeRects()

void GridIterationTools::QImagePolygonOp::setCanMergeRects ( bool canMergeRects)
inline

Definition at line 481 of file kis_grid_interpolation_tools.h.

481 {
482 m_canMergeRects = canMergeRects;
483 }

References m_canMergeRects.

Member Data Documentation

◆ m_canMergeRects

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

Definition at line 497 of file kis_grid_interpolation_tools.h.

497{true};

◆ m_dstImage

QImage& GridIterationTools::QImagePolygonOp::m_dstImage

Definition at line 487 of file kis_grid_interpolation_tools.h.

◆ m_dstImageOffset

QPointF GridIterationTools::QImagePolygonOp::m_dstImageOffset

Definition at line 489 of file kis_grid_interpolation_tools.h.

◆ m_dstImageRect

QRect GridIterationTools::QImagePolygonOp::m_dstImageRect

Definition at line 492 of file kis_grid_interpolation_tools.h.

◆ m_epsilon

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

Definition at line 494 of file kis_grid_interpolation_tools.h.

494{0.1};

◆ m_rectsToCopy

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

Definition at line 498 of file kis_grid_interpolation_tools.h.

◆ m_srcImage

const QImage& GridIterationTools::QImagePolygonOp::m_srcImage

Definition at line 486 of file kis_grid_interpolation_tools.h.

◆ m_srcImageOffset

QPointF GridIterationTools::QImagePolygonOp::m_srcImageOffset

Definition at line 488 of file kis_grid_interpolation_tools.h.

◆ m_srcImageRect

QRect GridIterationTools::QImagePolygonOp::m_srcImageRect

Definition at line 491 of file kis_grid_interpolation_tools.h.


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