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)
 

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 {true}
 
QVector< QRect > m_rectsToCopy
 

Detailed Description

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

◆ copyPreviousRects()

void GridIterationTools::QImagePolygonOp::copyPreviousRects ( )
inline

Definition at line 459 of file kis_grid_interpolation_tools.h.

459 {
460
462
463 for (QVector<QRect>::iterator it = m_rectsToCopy.begin(); it < end; it++) {
464 QRect areaToCopy = *it;
465 fastCopyArea(areaToCopy.adjusted(0, 0, 1, 1), false);
466 }
467
469 }
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 356 of file kis_grid_interpolation_tools.h.

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

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 394 of file kis_grid_interpolation_tools.h.

394 {
395 this->operator() (srcPolygon, dstPolygon, dstPolygon);
396 }
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 398 of file kis_grid_interpolation_tools.h.

398 {
399 QRect boundRect = clipDstPolygon.boundingRect().toAlignedRect();
400
401 bool samePolygon = (m_dstImage.format() == m_srcImage.format())
402 && KisAlgebra2D::fuzzyPointCompare(srcPolygon, dstPolygon, m_epsilon)
403 && KisAlgebra2D::fuzzyPointCompare(srcPolygon, clipDstPolygon, m_epsilon);
404
405 if (samePolygon && KisAlgebra2D::isPolygonPixelAlignedRect(dstPolygon, m_epsilon)) {
406 QRect boundRect = dstPolygon.boundingRect().toAlignedRect();
407 fastCopyArea(boundRect);
408 return;
409 }
410
411 // provess previous rects so they are all processed
412 // in the same order as without any performance improvements
414
415 KisFourPointInterpolatorBackward interp(srcPolygon, dstPolygon);
416
417 for (int y = boundRect.top(); y <= boundRect.bottom(); y++) {
418 interp.setY(y);
419 for (int x = boundRect.left(); x <= boundRect.right(); x++) {
420
421 QPointF srcPoint(x, y);
422 if (clipDstPolygon.containsPoint(srcPoint, Qt::OddEvenFill)) {
423
424 interp.setX(srcPoint.x());
425 QPointF dstPoint = interp.getValue();
426
427 // about srcPoint/dstPoint hell please see a
428 // comment in PaintDevicePolygonOp::operator() ()
429
430 srcPoint -= m_dstImageOffset;
432
433 QPoint srcPointI = srcPoint.toPoint();
434 QPoint dstPointI = dstPoint.toPoint();
435
436 if (!m_dstImageRect.contains(srcPointI)) continue;
437 if (!m_srcImageRect.contains(dstPointI)) continue;
438
439 m_dstImage.setPixel(srcPointI, m_srcImage.pixel(dstPointI));
440 }
441 }
442 }
443
444#ifdef DEBUG_PAINTING_POLYGONS
445 QPainter gc(&m_dstImage);
446 gc.setPen(Qt::red);
447 gc.setOpacity(0.5);
448
449 gc.setBrush(Qt::green);
450 gc.drawPolygon(clipDstPolygon.translated(-m_dstImageOffset));
451
452 gc.setBrush(Qt::blue);
453 //gc.drawPolygon(dstPolygon.translated(-m_dstImageOffset));
454
455#endif /* DEBUG_PAINTING_POLYGONS */
456
457 }
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

Definition at line 475 of file kis_grid_interpolation_tools.h.

475 {
476 m_canMergeRects = canMergeRects;
477 }

References m_canMergeRects.

Member Data Documentation

◆ m_canMergeRects

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

Definition at line 491 of file kis_grid_interpolation_tools.h.

491{true};

◆ m_dstImage

QImage& GridIterationTools::QImagePolygonOp::m_dstImage

Definition at line 481 of file kis_grid_interpolation_tools.h.

◆ m_dstImageOffset

QPointF GridIterationTools::QImagePolygonOp::m_dstImageOffset

Definition at line 483 of file kis_grid_interpolation_tools.h.

◆ m_dstImageRect

QRect GridIterationTools::QImagePolygonOp::m_dstImageRect

Definition at line 486 of file kis_grid_interpolation_tools.h.

◆ m_epsilon

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

Definition at line 488 of file kis_grid_interpolation_tools.h.

488{0.001};

◆ m_rectsToCopy

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

Definition at line 492 of file kis_grid_interpolation_tools.h.

◆ m_srcImage

const QImage& GridIterationTools::QImagePolygonOp::m_srcImage

Definition at line 480 of file kis_grid_interpolation_tools.h.

◆ m_srcImageOffset

QPointF GridIterationTools::QImagePolygonOp::m_srcImageOffset

Definition at line 482 of file kis_grid_interpolation_tools.h.

◆ m_srcImageRect

QRect GridIterationTools::QImagePolygonOp::m_srcImageRect

Definition at line 485 of file kis_grid_interpolation_tools.h.


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