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++
Add debug painting for Liquify tool
Agata Cacko4cb9a28aa06c
diff --git a/libs/image/kis_grid_interpolation_tools.h b/libs/image/kis_grid_interpolation_tools.hindex 9ff672e054..8a9faf1add 100644--- a/libs/image/kis_grid_interpolation_tools.h+++ b/libs/image/kis_grid_interpolation_tools.h@@ -189,6 +189,10 @@ struct PaintDevicePolygonOpif (boundRect.isEmpty()) return;bool isItRect = KisAlgebra2D::isPolygonRect(areaToCopy, m_epsilon); // no need for lower tolerance++#ifdef DEBUG_PAINTING_POLYGONS+ isItRect = false; // force to use the code below, to not have to rewrite it for a workaround for copyAreaOptimized+#endifif (isItRect) {fastCopyArea(boundRect);return;@@ -205,6 +209,9 @@ struct PaintDevicePolygonOpwhile (dstIt.nextPixel() && srcIt.nextPixel()) {if (areaToCopy.containsPoint(middlePoint(dstIt.x(), dstIt.y()), Qt::OddEvenFill)) {memcpy(dstIt.rawData(), srcIt.oldRawData(), m_dstDev->pixelSize());+#ifdef DEBUG_PAINTING_POLYGONS+ m_dstDev->colorSpace()->fromQColor(m_debugColor, dstIt.rawData());+#endif}}}@@ -214,6 +221,10 @@ struct PaintDevicePolygonOp}void fastCopyArea(QRect areaToCopy, bool lazy) {+#ifdef DEBUG_PAINTING_POLYGONS+ fastCopyArea(QPolygon(areaToCopy));+ return;+#endifif (lazy) {m_rectsToCopy.append(areaToCopy.adjusted(0, 0, -1, -1));} else {@@ -243,6 +254,9 @@ struct PaintDevicePolygonOpKisRandomSubAccessorSP srcAcc = m_srcDev->createRandomSubAccessor();KisFourPointInterpolatorBackward interp(srcPolygon, dstPolygon);+#ifdef DEBUG_PAINTING_POLYGONS+ int pixelId = 0;+#endif/*** We need to make sure that the destination polygon is not too small,@@ -278,6 +292,12 @@ struct PaintDevicePolygonOpsrcAcc->moveTo(dstPoint);quint8* rawData = dstIt.rawData();srcAcc->sampledOldRawData(rawData);+#ifdef DEBUG_PAINTING_POLYGONS+ QColor color = m_debugColor;+ color.setHsl(m_debugColor.hslHue(), m_debugColor.hslSaturation(), qMin(m_debugColor.lightness() - 50 - pixelId, 100));+ pixelId++;+ m_dstDev->colorSpace()->fromQColor(color, rawData);+#endif}}@@ -289,6 +309,11 @@ struct PaintDevicePolygonOpif (clipDstPolygon.containsPoint(middlePoint(srcPoint), Qt::OddEvenFill)) {srcAcc->sampledOldRawData(dstIt.rawData());+#ifdef DEBUG_PAINTING_POLYGONS+ QColor color = m_debugColor;+ color.setHsl(m_debugColor.hslHue(), m_debugColor.hslSaturation(), m_debugColor.lightness() + 50);+ m_dstDev->colorSpace()->fromQColor(color, dstIt.rawData());+#endif}}}@@ -314,6 +339,13 @@ struct PaintDevicePolygonOpKisPaintDeviceSP m_dstDev;const qreal m_epsilon {0.1};+#ifdef DEBUG_PAINTING_POLYGONS+ QColor m_debugColor;+ inline void setDebugColor(QColor color) {+ m_debugColor = color;+ }+#endif+private:bool m_canMergeRects {true};QVector<QRect> m_rectsToCopy;diff --git a/libs/image/kis_liquify_transform_worker.cpp b/libs/image/kis_liquify_transform_worker.cppindex 063be650f7..62f1bbee1c 100644--- a/libs/image/kis_liquify_transform_worker.cpp+++ b/libs/image/kis_liquify_transform_worker.cpp@@ -435,13 +435,23 @@ void KisLiquifyTransformWorker::run(KisPaintDeviceSP srcDevice, KisPaintDeviceSPbool canMergeRects = GridIterationTools::canProcessRectsInRandomOrder(indexesOp, m_d->transformedPoints, correctSubGrid);polygonOp.setCanMergeRects(canMergeRects);+#ifdef DEBUG_PAINTING_POLYGONS+ polygonOp.setDebugColor(Qt::red);+#endif+iterateThroughGrid<AlwaysCompletePolygonPolicy>(polygonOp, indexesOp,m_d->gridSize,m_d->originalPoints,m_d->transformedPoints,correctSubGrid);QList<QRectF> areasToCopy = cutOutSubgridFromBounds(correctSubGrid, m_d->srcBounds, m_d->gridSize, m_d->originalPoints);+#ifdef DEBUG_PAINTING_POLYGONS+ QList<QColor> colors = {Qt::blue, Qt::green, Qt::yellow, Qt::black};+#endiffor (int i = 0; i < areasToCopy.length(); i++) {+#ifdef DEBUG_PAINTING_POLYGONS+ polygonOp.setDebugColor(colors[i]);+#endifpolygonOp.fastCopyArea(areasToCopy[i].toRect(), false);}}