Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Remove unnecessary fastCopyArea of a polygon

Agata Cacko712e8f51a939
diff --git a/libs/image/kis_grid_interpolation_tools.h b/libs/image/kis_grid_interpolation_tools.h
index f1be4904ca..9763b44932 100644
--- a/libs/image/kis_grid_interpolation_tools.h
+++ b/libs/image/kis_grid_interpolation_tools.h
@@ -171,21 +171,14 @@ struct PaintDevicePolygonOp
PaintDevicePolygonOp(KisPaintDeviceSP srcDev, KisPaintDeviceSP dstDev)
: m_srcDev(srcDev), m_dstDev(dstDev) {}
+ void fastCopyArea(QRect areaToCopy) {
+ fastCopyArea(areaToCopy, m_canMergeRects);
+ }
- void fastCopyArea(QPolygonF areaToCopy) {
- QRect boundRect = areaToCopy.boundingRect().toAlignedRect();
- if (boundRect.isEmpty()) return;
-
- bool isItRect = KisAlgebra2D::isPolygonPixelAlignedRect(areaToCopy, m_epsilon);
-
+ void fastCopyArea(QRect areaToCopy, bool lazy) {
#ifdef DEBUG_PAINTING_POLYGONS
- isItRect = false; // force to use the code below, to not have to rewrite it for a workaround for copyAreaOptimized
-#endif
- if (isItRect) {
- fastCopyArea(boundRect);
- return;
- }
+ QRect boundRect = areaToCopy;
KisSequentialIterator dstIt(m_dstDev, boundRect);
KisSequentialIterator srcIt(m_srcDev, boundRect);
@@ -195,24 +188,11 @@ struct PaintDevicePolygonOp
// it should go straight to the rect area copying
while (dstIt.nextPixel() && srcIt.nextPixel()) {
- if (areaToCopy.containsPoint(QPoint(dstIt.x(), dstIt.y()), Qt::OddEvenFill)) {
- memcpy(dstIt.rawData(), srcIt.oldRawData(), m_dstDev->pixelSize());
-#ifdef DEBUG_PAINTING_POLYGONS
- QColor color = m_debugColor;
- color.setHsl(KisAlgebra2D::wrapValue(m_debugColor.hslHue() + 20, 0, 360), m_debugColor.hslSaturation(), m_debugColor.lightness());
- m_dstDev->colorSpace()->fromQColor(color, dstIt.rawData());
-#endif
- }
+ memcpy(dstIt.rawData(), srcIt.oldRawData(), m_dstDev->pixelSize());
+ QColor color = m_debugColor;
+ color.setHsl(KisAlgebra2D::wrapValue(m_debugColor.hslHue() + 20, 0, 360), m_debugColor.hslSaturation(), m_debugColor.lightness());
+ m_dstDev->colorSpace()->fromQColor(color, dstIt.rawData());
}
- }
-
- void fastCopyArea(QRect areaToCopy) {
- fastCopyArea(areaToCopy, m_canMergeRects);
- }
-
- void fastCopyArea(QRect areaToCopy, bool lazy) {
-#ifdef DEBUG_PAINTING_POLYGONS
- fastCopyArea(QPolygon(areaToCopy));
return;
#endif
if (lazy) {
@@ -369,49 +349,6 @@ struct QImagePolygonOp
{
}
- void fastCopyArea(QPolygonF areaToCopy) {
- QRect boundRect = areaToCopy.boundingRect().toAlignedRect();
-
- if (boundRect.isEmpty()) return;
-
- bool isItRect = KisAlgebra2D::isPolygonPixelAlignedRect(areaToCopy, m_epsilon);
- if (isItRect) {
- fastCopyArea(boundRect);
- return;
- }
-
- // this can possibly be optimized with scanlining the polygon
- // (use intersectLineConvexPolygon to get a line at every height)
- // but it doesn't matter much because in the vast majority of cases
- // it should go straight to the rect area copying
-
- for (int y = boundRect.top(); y <= boundRect.bottom(); y++) {
- for (int x = boundRect.left(); x <= boundRect.right(); x++) {
- QPointF dstPoint = QPointF(x, y);
- QPointF srcPoint = dstPoint;
-
- if (areaToCopy.containsPoint(srcPoint, Qt::OddEvenFill)) {
-
- // about srcPoint/dstPoint hell please see a
- // comment in PaintDevicePolygonOp::operator() ()
-
- srcPoint -= m_dstImageOffset;
- dstPoint -= m_srcImageOffset;
-
- QPoint srcPointI = srcPoint.toPoint();
- QPoint dstPointI = dstPoint.toPoint();
-
- if (!m_dstImageRect.contains(srcPointI)) continue;
- if (!m_srcImageRect.contains(dstPointI)) continue;
-
- m_dstImage.setPixel(srcPointI, m_srcImage.pixel(dstPointI));
- }
-
- }
- }
-
- }
-
void fastCopyArea(QRect areaToCopy) {
fastCopyArea(areaToCopy, m_canMergeRects);
}
diff --git a/libs/image/kis_liquify_transform_worker.cpp b/libs/image/kis_liquify_transform_worker.cpp
index f7ad5c657d..7906cf20e7 100644
--- a/libs/image/kis_liquify_transform_worker.cpp
+++ b/libs/image/kis_liquify_transform_worker.cpp
@@ -563,12 +563,19 @@ QImage KisLiquifyTransformWorker::runOnQImage(const QImage &srcImage,
QList<QRectF> areasToCopy = GridIterationTools::cutOutSubgridFromBounds(correctSubGrid, m_d->srcBounds, m_d->gridSize, m_d->originalPoints);
polygonOp.setCanMergeRects(false);
+ const qreal eps = 0.001;
for (int i = 0; i < areasToCopy.length(); i++) {
- polygonOp.fastCopyArea(imageToThumbTransform.map(QPolygonF(areasToCopy[i])));
+ QPolygonF transformed = imageToThumbTransform.map(QPolygonF(areasToCopy[i]));
+ if (KisAlgebra2D::isPolygonPixelAlignedRect(transformed, eps)) {
+ polygonOp.fastCopyArea(transformed.boundingRect().toRect());
+ } else {
+ polygonOp.operator()(transformed, transformed);
+ }
}
return dstImage;
}
+
void KisLiquifyTransformWorker::toXML(QDomElement *e) const
{
QDomDocument doc = e->ownerDocument();
diff --git a/libs/image/tests/KisGridInterpolationToolsTest.cpp b/libs/image/tests/KisGridInterpolationToolsTest.cpp
index 9f09a6b388..e5df03cdfb 100644
--- a/libs/image/tests/KisGridInterpolationToolsTest.cpp
+++ b/libs/image/tests/KisGridInterpolationToolsTest.cpp
@@ -334,7 +334,7 @@ void KisGridInterpolationToolsTest::testQImagePolygonOpStructFastAreaCopy()
QImage dstImage(srcImage.size(), srcImage.format());
GridIterationTools::QImagePolygonOp op(srcImage, dstImage, QPointF(), QPointF(-100, 100));
- op.fastCopyArea(QRectF(QPointF(), srcImage.size()));
+ op.fastCopyArea(QRect(QPoint(), srcImage.size()));
//dstImage.save("fast_area_copy_result.png");
}