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++

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.h
index 9ff672e054..8a9faf1add 100644
--- a/libs/image/kis_grid_interpolation_tools.h
+++ b/libs/image/kis_grid_interpolation_tools.h
@@ -189,6 +189,10 @@ struct PaintDevicePolygonOp
if (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
+#endif
if (isItRect) {
fastCopyArea(boundRect);
return;
@@ -205,6 +209,9 @@ struct PaintDevicePolygonOp
while (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;
+#endif
if (lazy) {
m_rectsToCopy.append(areaToCopy.adjusted(0, 0, -1, -1));
} else {
@@ -243,6 +254,9 @@ struct PaintDevicePolygonOp
KisRandomSubAccessorSP 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 PaintDevicePolygonOp
srcAcc->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 PaintDevicePolygonOp
if (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 PaintDevicePolygonOp
KisPaintDeviceSP 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.cpp
index 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, KisPaintDeviceSP
bool 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};
+#endif
for (int i = 0; i < areasToCopy.length(); i++) {
+#ifdef DEBUG_PAINTING_POLYGONS
+ polygonOp.setDebugColor(colors[i]);
+#endif
polygonOp.fastCopyArea(areasToCopy[i].toRect(), false);
}
}