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

#include <kis_grid_interpolation_tools.h>

Public Member Functions

void copyPreviousRects ()
 
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)
 
 ~QImagePolygonOp ()
 

Public Attributes

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

Private Attributes

bool m_canMergeRects {false}
 
QVector< QRect > m_rectsToCopy
 

Detailed Description

Definition at line 355 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

◆ ~QImagePolygonOp()

GridIterationTools::QImagePolygonOp::~QImagePolygonOp ( )
inline

When setCanMergeRects() is set to true, the caller should call finalize() to process all the postponed rects, which would clear the vector

Definition at line 368 of file kis_grid_interpolation_tools.h.

369 {
376 }
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130

References KIS_SAFE_ASSERT_RECOVER_NOOP, and m_rectsToCopy.

Member Function Documentation

◆ copyPreviousRects()

void GridIterationTools::QImagePolygonOp::copyPreviousRects ( )
inline

Definition at line 485 of file kis_grid_interpolation_tools.h.

485 {
486
488
489 for (QVector<QRect>::iterator it = m_rectsToCopy.begin(); it < end; it++) {
490 QRect areaToCopy = *it;
491 fastCopyArea(areaToCopy.adjusted(0, 0, 1, 1), false);
492 }
493
495 }
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().

◆ fastCopyArea() [1/2]

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

◆ fastCopyArea() [2/2]

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

Definition at line 382 of file kis_grid_interpolation_tools.h.

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

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

◆ finalize()

void GridIterationTools::QImagePolygonOp::finalize ( )
inline

◆ operator()() [1/2]

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

Definition at line 420 of file kis_grid_interpolation_tools.h.

420 {
421 this->operator() (srcPolygon, dstPolygon, dstPolygon);
422 }
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 424 of file kis_grid_interpolation_tools.h.

424 {
425 QRect boundRect = clipDstPolygon.boundingRect().toAlignedRect();
426
427 bool samePolygon = (m_dstImage.format() == m_srcImage.format())
428 && KisAlgebra2D::fuzzyPointCompare(srcPolygon, dstPolygon, m_epsilon)
429 && KisAlgebra2D::fuzzyPointCompare(srcPolygon, clipDstPolygon, m_epsilon);
430
431 if (samePolygon && KisAlgebra2D::isPolygonPixelAlignedRect(dstPolygon, m_epsilon)) {
432 QRect boundRect = dstPolygon.boundingRect().toAlignedRect();
433 fastCopyArea(boundRect);
434 return;
435 }
436
437 // provess previous rects so they are all processed
438 // in the same order as without any performance improvements
440
441 KisFourPointInterpolatorBackward interp(srcPolygon, dstPolygon);
442
443 for (int y = boundRect.top(); y <= boundRect.bottom(); y++) {
444 interp.setY(y);
445 for (int x = boundRect.left(); x <= boundRect.right(); x++) {
446
447 QPointF srcPoint(x, y);
448 if (clipDstPolygon.containsPoint(srcPoint, Qt::OddEvenFill)) {
449
450 interp.setX(srcPoint.x());
451 QPointF dstPoint = interp.getValue();
452
453 // about srcPoint/dstPoint hell please see a
454 // comment in PaintDevicePolygonOp::operator() ()
455
456 srcPoint -= m_dstImageOffset;
458
459 QPoint srcPointI = srcPoint.toPoint();
460 QPoint dstPointI = dstPoint.toPoint();
461
462 if (!m_dstImageRect.contains(srcPointI)) continue;
463 if (!m_srcImageRect.contains(dstPointI)) continue;
464
465 m_dstImage.setPixel(srcPointI, m_srcImage.pixel(dstPointI));
466 }
467 }
468 }
469
470#ifdef DEBUG_PAINTING_POLYGONS
471 QPainter gc(&m_dstImage);
472 gc.setPen(Qt::red);
473 gc.setOpacity(0.5);
474
475 gc.setBrush(Qt::green);
476 gc.drawPolygon(clipDstPolygon.translated(-m_dstImageOffset));
477
478 gc.setBrush(Qt::blue);
479 //gc.drawPolygon(dstPolygon.translated(-m_dstImageOffset));
480
481#endif /* DEBUG_PAINTING_POLYGONS */
482
483 }
QPointF dstPoint
qreal interp(qreal r, qreal a, qreal b)
private functions
bool isPolygonPixelAlignedRect(const Polygon &poly, Difference tolerance)
bool fuzzyPointCompare(const QPointF &p1, const QPointF &p2)

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

◆ setCanMergeRects()

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

IMPORTANT: When setCanMergeRects() is set to true, the caller should calls finalize() in the end of the processing action to actually copy all the lazily postponed rects.

Definition at line 507 of file kis_grid_interpolation_tools.h.

507 {
508 m_canMergeRects = canMergeRects;
509 }

References m_canMergeRects.

Member Data Documentation

◆ m_canMergeRects

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

Definition at line 522 of file kis_grid_interpolation_tools.h.

522{false};

◆ m_dstImage

QImage& GridIterationTools::QImagePolygonOp::m_dstImage

Definition at line 512 of file kis_grid_interpolation_tools.h.

◆ m_dstImageOffset

QPointF GridIterationTools::QImagePolygonOp::m_dstImageOffset

Definition at line 514 of file kis_grid_interpolation_tools.h.

◆ m_dstImageRect

QRect GridIterationTools::QImagePolygonOp::m_dstImageRect

Definition at line 517 of file kis_grid_interpolation_tools.h.

◆ m_epsilon

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

Definition at line 519 of file kis_grid_interpolation_tools.h.

519{0.001};

◆ m_rectsToCopy

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

Definition at line 523 of file kis_grid_interpolation_tools.h.

◆ m_srcImage

const QImage& GridIterationTools::QImagePolygonOp::m_srcImage

Definition at line 511 of file kis_grid_interpolation_tools.h.

◆ m_srcImageOffset

QPointF GridIterationTools::QImagePolygonOp::m_srcImageOffset

Definition at line 513 of file kis_grid_interpolation_tools.h.

◆ m_srcImageRect

QRect GridIterationTools::QImagePolygonOp::m_srcImageRect

Definition at line 516 of file kis_grid_interpolation_tools.h.


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