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

trying vector approach

Ken Lo1791b1b8608c
diff --git a/libs/image/brushengine/kis_paintop.cc b/libs/image/brushengine/kis_paintop.cc
index 0551876a6e..025ca15926 100644
--- a/libs/image/brushengine/kis_paintop.cc
+++ b/libs/image/brushengine/kis_paintop.cc
@@ -108,8 +108,11 @@ static void paintBezierCurve(KisPaintOp *paintOp,
if ((d1 < BEZIER_FLATNESS_THRESHOLD && d2 < BEZIER_FLATNESS_THRESHOLD)
|| qIsNaN(d1) || qIsNaN(d2)) {
+ //qDebug() << "kis_paintop:paintBeziercurve -> paintline"; this one
+ //qDebug() << "kis_paintop bezier curve" << "pi1: " << pi1 << "pi2: " << pi2 << "currentDistance" << currentDistance;
paintOp->paintLine(pi1, pi2, currentDistance);
} else {
+ //qDebug() << "kis_paintop:paintBeziercurve -> else";
// Midpoint subdivision. See Foley & Van Dam Computer Graphics P.508
KisVector2D l2 = (toKisVector2D(pi1.pos()) + control1) / 2;
KisVector2D h = (control1 + control2) / 2;
@@ -139,6 +142,7 @@ void KisPaintOp::paintLine(const KisPaintInformation &pi1,
const KisPaintInformation &pi2,
KisDistanceInformation *currentDistance)
{
+ qDebug()<< "KisPaintOp::paintLine";
KisPaintOpUtils::paintLine(*this, pi1, pi2, currentDistance,
d->fanCornersEnabled,
d->fanCornersStep);
@@ -147,7 +151,7 @@ void KisPaintOp::paintLine(const KisPaintInformation &pi1,
void KisPaintOp::paintAt(const KisPaintInformation& info, KisDistanceInformation *currentDistance)
{
Q_ASSERT(currentDistance);
-
+ qDebug()<< "kis_paintop::paintAt";
KisPaintInformation pi(info);
pi.paintAt(*this, currentDistance);
}
diff --git a/libs/image/kis_painter.cc b/libs/image/kis_painter.cc
index b15c6123a5..436da8f431 100644
--- a/libs/image/kis_painter.cc
+++ b/libs/image/kis_painter.cc
@@ -1152,7 +1152,8 @@ void KisPainter::bltFixedWithFixedSelection(qint32 dstX, qint32 dstY,
void KisPainter::paintLine(const KisPaintInformation &pi1,
const KisPaintInformation &pi2,
KisDistanceInformation *currentDistance)
-{
+{
+ //qDebug()<< "kis_painter::paintLine";
if (d->device && d->paintOp && d->paintOp->canPaint()) {
d->paintOp->paintLine(pi1, pi2, currentDistance);
}
@@ -1238,7 +1239,8 @@ void KisPainter::paintBezierCurve(const KisPaintInformation &pi1,
const QPointF &control2,
const KisPaintInformation &pi2,
KisDistanceInformation *currentDistance)
-{
+{
+ //qDebug() << "KisPainter::paintBezierCurve";
if (d->paintOp && d->paintOp->canPaint()) {
d->paintOp->paintBezierCurve(pi1, control1, control2, pi2, currentDistance);
}
@@ -1635,6 +1637,7 @@ void KisPainter::drawPainterPath(const QPainterPath& path, const QPen& _pen, con
inline void KisPainter::compositeOnePixel(quint8 *dst, const KoColor &color)
{
+ //qDebug()<< "kis_painter compositeOnePixel";
d->paramInfo.dstRowStart = dst;
d->paramInfo.dstRowStride = 0;
d->paramInfo.srcRowStart = color.data();
@@ -1651,6 +1654,7 @@ inline void KisPainter::compositeOnePixel(quint8 *dst, const KoColor &color)
/**/
void KisPainter::drawLine(const QPointF& start, const QPointF& end, qreal width, bool antialias){
+ //qDebug()<< "kis_painter::drawLine";
int x1 = qFloor(start.x());
int y1 = qFloor(start.y());
int x2 = qFloor(end.x());
@@ -1737,7 +1741,7 @@ void KisPainter::drawLine(const QPointF & start, const QPointF & end)
drawThickLine(start, end, 1, 1);
}
-
+//original drawDDALine
void KisPainter::drawDDALine(const QPointF & start, const QPointF & end)
{
int x = qFloor(start.x());
@@ -1745,7 +1749,8 @@ void KisPainter::drawDDALine(const QPointF & start, const QPointF & end)
int x2 = qFloor(end.x());
int y2 = qFloor(end.y());
-
+ //qDebug() << " start: " << x <<" start " << x2 << " y: " << y << " y2 " << y2 ;
+ //qDebug() << "drawDDAlinepainter x: " << x <<" x2 " << x2 << " y: " << y << " y2 " << y2 ;
// Width and height of the line
int xd = x2 - x;
int yd = y2 - y;
@@ -1779,6 +1784,7 @@ void KisPainter::drawDDALine(const QPointF & start, const QPointF & end)
}
if (fabs(m) > 1.0f) {
+ //qDebug() << "fabs in kis_painter";
inc = (yd > 0) ? 1 : -1;
m = (lockAxis)? 0 : 1.0f / m;
m *= inc;
@@ -1795,6 +1801,7 @@ void KisPainter::drawDDALine(const QPointF & start, const QPointF & end)
}
}
} else {
+ //qDebug() << "not fabs in kis_painter";
inc = (xd > 0) ? 1 : -1;
m *= inc;
while (x != x2) {
@@ -1812,6 +1819,8 @@ void KisPainter::drawDDALine(const QPointF & start, const QPointF & end)
}
}
+//qDebug() << " x: " << x << " y: " << y << " x2 " << x2 << " y2 " << y2 ;
+
void KisPainter::drawWobblyLine(const QPointF & start, const QPointF & end)
{
KoColor mycolor(d->paintColor);
diff --git a/libs/ui/canvas/kis_tool_proxy.cpp b/libs/ui/canvas/kis_tool_proxy.cpp
index c41513ac04..9d4d3f3b27 100644
--- a/libs/ui/canvas/kis_tool_proxy.cpp
+++ b/libs/ui/canvas/kis_tool_proxy.cpp
@@ -170,6 +170,7 @@ void KisToolProxy::forwardToTool(ActionState state, KisTool::ToolAction action,
if (event->type() == QEvent::MouseButtonDblClick) {
activeTool->beginPrimaryDoubleClickAction(&ev);
} else {
+ //qDebug() << "kis_tool_proxy in forwardToTool";
activeTool->beginPrimaryAction(&ev);
}
} else {
diff --git a/libs/ui/tool/kis_tool_freehand.cc b/libs/ui/tool/kis_tool_freehand.cc
index 5a510f971a..6db34efc21 100644
--- a/libs/ui/tool/kis_tool_freehand.cc
+++ b/libs/ui/tool/kis_tool_freehand.cc
@@ -49,6 +49,7 @@
#include "kis_tool_freehand_helper.h"
#include "strokes/freehand_stroke.h"
#include "kis_tool_utils.h"
+//#include "smoothedpointsmanager.h"
using namespace std::placeholders; // For _1 placeholder
@@ -169,26 +170,122 @@ void KisToolFreehand::deactivate()
}
KisToolPaint::deactivate();
}
+//original
+// void KisToolFreehand::initStroke(KoPointerEvent *event)
+// {
+// //qDebug() << "KisToolFreehand:initStroke";
+// m_helper->initPaint(event,
+// convertToPixelCoord(event),
+// image(),
+// currentNode(),
+// image().data());
+// }
+
+// void KisToolFreehand::initStroke(KoPointerEvent *event)
+// {
+// qDebug() << "KisToolFreehand:initStroke";
+// qDebug() << "Event Position (global):" << event->globalPos();
+// qDebug() << "Event Position (widget):" << event->pos();
+// qDebug() << "Event Document Coordinates:" << event->point;
+// qDebug() << "Event Pressure:" << event->pressure();
+// qDebug() << "Event Rotation:" << event->rotation();
+// qDebug() << "Event Tangential Pressure:" << event->tangentialPressure();
+// qDebug() << "Event xTilt:" << event->xTilt();
+// qDebug() << "Event yTilt:" << event->yTilt();
+// qDebug() << "Event z Position:" << event->z();
+// qDebug() << "Event Time:" << event->time();
+// qDebug() << "Event isTabletEvent:" << event->isTabletEvent();
+
+// m_helper->initPaint(event,
+// convertToPixelCoord(event),
+// image(),
+// currentNode(),
+// image().data());
+// }
void KisToolFreehand::initStroke(KoPointerEvent *event)
{
+ qDebug() << "KisToolFreehand:initStroke";
m_helper->initPaint(event,
convertToPixelCoord(event),
image(),
currentNode(),
image().data());
+
+ strokeCoordinates.clear();
+ strokeCoordinates.push_back(convertToPixelCoord(event));
}
+//original
+// void KisToolFreehand::doStroke(KoPointerEvent *event)
+// {
+// m_helper->paintEvent(event);
+// }
+
void KisToolFreehand::doStroke(KoPointerEvent *event)
{
+ // qDebug() << "KisToolFreehand:doStroke";
m_helper->paintEvent(event);
+
+ strokeCoordinates.push_back(convertToPixelCoord(event)); // Track the coordinates
}
+//original
+// void KisToolFreehand::endStroke()
+// {
+// //qDebug() << "KisToolFreehand:endStroke";
+// m_helper->endPaint();
+// bool paintOpIgnoredEvent = currentPaintOpPreset()->settings()->mouseReleaseEvent();
+// Q_UNUSED(paintOpIgnoredEvent);
+// }
+
void KisToolFreehand::endStroke()
{
+ qDebug() << "KisToolFreehand:endStroke";
m_helper->endPaint();
bool paintOpIgnoredEvent = currentPaintOpPreset()->settings()->mouseReleaseEvent();
Q_UNUSED(paintOpIgnoredEvent);
+
+ std::vector<QPoint> points;
+ for (const QPointF& point : strokeCoordinates) {
+ QPoint intPoint = point.toPoint(); //convert QPointF to QPoint
+ points.push_back(intPoint);
+ }
+
+ std::vector<QPoint> uniquePoints = removeDuplicates(points);
+
+ std::vector<QPoint> smoothedPoints = removeLShapes(uniquePoints);
+
+ for (const QPoint& point : smoothedPoints) {
+ qDebug() << "Smoothed Stroke Point (Integer):" << point.x() << point.y();
+ }
+
+ strokeCoordinates.clear();
+}
+
+std::vector<QPoint> KisToolFreehand::removeDuplicates(const std::vector<QPoint>& points) {
+ std::vector<QPoint> uniquePoints;
+ for (const auto& point : points) {
+ if (uniquePoints.empty() || uniquePoints.back() != point) {
+ uniquePoints.push_back(point);
+ }
+ }
+ return uniquePoints;
+}
+
+std::vector<QPoint> KisToolFreehand::removeLShapes(const std::vector<QPoint>& points) {
+ std::vector<QPoint> smoothedPoints;
+ for (size_t c = 0; c < points.size(); ++c) {
+ if (c > 0 && c + 1 < points.size() &&
+ (points[c - 1].x() == points[c].x() || points[c - 1].y() == points[c].y()) &&
+ (points[c + 1].x() == points[c].x() || points[c + 1].y() == points[c].y()) &&
+ points[c - 1].x() != points[c + 1].x() &&
+ points[c - 1].y() != points[c + 1].y()) {
+ continue;
+ }
+ smoothedPoints.push_back(points[c]);
+ }
+ return smoothedPoints;
}
bool KisToolFreehand::primaryActionSupportsHiResEvents() const
diff --git a/libs/ui/tool/kis_tool_freehand.h b/libs/ui/tool/kis_tool_freehand.h
index 68ff322ab9..3beaabfe92 100644
--- a/libs/ui/tool/kis_tool_freehand.h
+++ b/libs/ui/tool/kis_tool_freehand.h
@@ -35,6 +35,7 @@ public:
~KisToolFreehand() override;
int flags() const override;
void mouseMoveEvent(KoPointerEvent *event) override;
+ const std::vector<QPoint>& getSmoothedPoints() const { return smoothedPoints; }
public Q_SLOTS:
void activate(const QSet<KoShape*> &shapes) override;
@@ -62,6 +63,11 @@ protected:
virtual void doStroke(KoPointerEvent *event);
virtual void endStroke();
+ extern std::vector<QPointF> strokeCoordinates;
+ std::vector<QPoint> removeDuplicates(const std::vector<QPoint>& points);
+ std::vector<QPoint> removeLShapes(const std::vector<QPoint>& points);
+
+
KisOptimizedBrushOutline getOutlinePath(const QPointF &documentPos,
const KoPointerEvent *event,
KisPaintOpSettings::OutlineMode outlineMode) override;
@@ -116,6 +122,7 @@ private:
bool m_paintopBasedSamplingInAction {false};
KisSignalCompressorWithParam<qreal> m_brushResizeCompressor;
+ std::vector<QPoint> smoothedPoints;
};
diff --git a/libs/ui/tool/kis_tool_freehand_helper.cpp b/libs/ui/tool/kis_tool_freehand_helper.cpp
index fcd139e80d..a677bf8965 100644
--- a/libs/ui/tool/kis_tool_freehand_helper.cpp
+++ b/libs/ui/tool/kis_tool_freehand_helper.cpp
@@ -450,6 +450,7 @@ void KisToolFreehandHelper::paintEvent(KoPointerEvent *event)
void KisToolFreehandHelper::paint(KisPaintInformation &info)
{
+ //qDebug()<< "kis_tool_freehand_helper::paint";
/**
* Smooth the coordinates out using the history and the
* distance. This is a heavily modified version of an algo used in
@@ -471,7 +472,7 @@ void KisToolFreehandHelper::paint(KisPaintInformation &info)
*/
if (m_d->smoothingOptions->smoothingType() == KisSmoothingOptions::WEIGHTED_SMOOTHING
&& m_d->smoothingOptions->smoothnessDistance() > 0.0) {
-
+ //qDebug() << "weighted smoothing in kistool freehand";
{ // initialize current distance
QPointF prevPos;
@@ -564,6 +565,7 @@ void KisToolFreehandHelper::paint(KisPaintInformation &info)
if (m_d->smoothingOptions->smoothingType() == KisSmoothingOptions::SIMPLE_SMOOTHING
|| m_d->smoothingOptions->smoothingType() == KisSmoothingOptions::WEIGHTED_SMOOTHING)
{
+ //qDebug() << "simple smoothing in kistool freehand";
// Now paint between the coordinates, using the bezier curve interpolation
if (!m_d->haveTangent) {
m_d->haveTangent = true;
@@ -576,8 +578,12 @@ void KisToolFreehandHelper::paint(KisPaintInformation &info)
if (newTangent.isNull() || m_d->previousTangent.isNull())
{
+ // qDebug() << "if in simple";
paintLine(m_d->previousPaintInformation, info);
} else {
+ //qDebug() << "else in simple"; this one
+ //qDebug() << m_d->olderPaintInformation << m_d->previousPaintInformation << m_d->previousTangent << newTangent;
+
paintBezierSegment(m_d->olderPaintInformation, m_d->previousPaintInformation,
m_d->previousTangent, newTangent);
}
@@ -592,21 +598,25 @@ void KisToolFreehandHelper::paint(KisPaintInformation &info)
}
}
else if (m_d->smoothingOptions->smoothingType() == KisSmoothingOptions::NO_SMOOTHING){
+ //qDebug() << "no smoothing in kistool freehand";
paintLine(m_d->previousPaintInformation, info);
}
if (m_d->smoothingOptions->smoothingType() == KisSmoothingOptions::STABILIZER) {
m_d->stabilizedSampler.addEvent(info);
+ //qDebug() << "stablizer in kistool freehand";
if (m_d->stabilizerDelayedPaintHelper.running()) {
// Paint here so we don't have to rely on the timer
// This is just a tricky source for a relatively stable 7ms "timer"
m_d->stabilizerDelayedPaintHelper.paintSome();
}
} else {
+ //qDebug() << "else";
m_d->previousPaintInformation = info;
}
if(m_d->airbrushingTimer.isActive()) {
+ //qDebug() << "airbrush timer";
m_d->airbrushingTimer.start();
}
}
diff --git a/plugins/paintops/defaultpaintops/brush/kis_brushop.cpp b/plugins/paintops/defaultpaintops/brush/kis_brushop.cpp
index b9a1c3f44d..5d825c6643 100644
--- a/plugins/paintops/defaultpaintops/brush/kis_brushop.cpp
+++ b/plugins/paintops/defaultpaintops/brush/kis_brushop.cpp
@@ -33,6 +33,8 @@
#include <KisDabRenderingExecutor.h>
#include <KisDabCacheUtils.h>
#include <KisRenderedDab.h>
+#include <kis_tool_freehand.h>
+// #include "smoothedpointsmanager.h"
#include "KisBrushOpResources.h"
#include <KisRunnableStrokeJobData.h>
@@ -105,6 +107,7 @@ KisSpacingInformation KisBrushOp::paintAt(const KisPaintInformation& info)
{
if (!painter()->device()) return KisSpacingInformation(1.0);
+ qDebug()<< "kis_brushop::paintAt";
KisBrushSP brush = m_brush;
Q_ASSERT(brush);
if (!brush)
@@ -381,28 +384,61 @@ KisTimingInformation KisBrushOp::updateTimingImpl(const KisPaintInformation &inf
{
return KisPaintOpPluginUtils::effectiveTiming(&m_airbrushData, &m_rateOption, info);
}
-
-void KisBrushOp::paintLine(const KisPaintInformation& pi1, const KisPaintInformation& pi2, KisDistanceInformation *currentDistance)
-{
+//original kisbrushop:paintline
+// void KisBrushOp::paintLine(const KisPaintInformation& pi1, const KisPaintInformation& pi2, KisDistanceInformation *currentDistance)
+// {
+// //qDebug() << "KisBrushOp::paintLine";
+// if (m_sharpnessOption.isChecked() && m_brush && (m_brush->width() == 1) && (m_brush->height() == 1)) {
+
+// if (!m_lineCacheDevice) {
+// m_lineCacheDevice = source()->createCompositionSourceDevice();
+// }
+// else {
+// m_lineCacheDevice->clear();
+// }
+
+// KisPainter p(m_lineCacheDevice);
+// //qDebug()<< "p(m_lineCacheDevice): " << m_lineCacheDevice;
+// p.setPaintColor(painter()->paintColor());
+// //qDebug() << "pi1.posx: "<< pi1.pos().x()<< "pi1.posy: "<< pi1.pos().y();
+// p.drawDDALine(pi1.pos(), pi2.pos());
+
+// QRect rc = m_lineCacheDevice->extent();
+// painter()->bitBlt(rc.x(), rc.y(), m_lineCacheDevice, rc.x(), rc.y(), rc.width(), rc.height());
+// //fixes Bug 338011
+// painter()->renderMirrorMask(rc, m_lineCacheDevice);
+// }
+// else {
+// KisPaintOp::paintLine(pi1, pi2, currentDistance);
+// }
+// }
+
+void KisBrushOp::paintLine(const KisPaintInformation& pi1, const KisPaintInformation& pi2, KisDistanceInformation *currentDistance) {
+ qDebug() << "KisBrushOp::paintLine";
if (m_sharpnessOption.isChecked() && m_brush && (m_brush->width() == 1) && (m_brush->height() == 1)) {
if (!m_lineCacheDevice) {
m_lineCacheDevice = source()->createCompositionSourceDevice();
- }
- else {
+ } else {
m_lineCacheDevice->clear();
}
KisPainter p(m_lineCacheDevice);
p.setPaintColor(painter()->paintColor());
- p.drawDDALine(pi1.pos(), pi2.pos());
+
+
+ qDebug() << "Number of smoothed points:" << smoothedPoints.size();
+ for (size_t i = 1; i < smoothedPoints.size(); ++i) {
+ const QPoint& point1 = smoothedPoints[i - 1];
+ const QPoint& point2 = smoothedPoints[i];
+ qDebug() << "Drawing line from" << point1 << "to" << point2;
+ p.drawDDALine(point1, point2);
+ }
QRect rc = m_lineCacheDevice->extent();
painter()->bitBlt(rc.x(), rc.y(), m_lineCacheDevice, rc.x(), rc.y(), rc.width(), rc.height());
- //fixes Bug 338011
- painter()->renderMirrorMask(rc, m_lineCacheDevice);
- }
- else {
+ painter()->renderMirrorMask(rc, m_lineCacheDevice);
+ } else {
KisPaintOp::paintLine(pi1, pi2, currentDistance);
}
-}
+}
\ No newline at end of file
diff --git a/plugins/paintops/libpaintop/KisSharpnessOption.cpp b/plugins/paintops/libpaintop/KisSharpnessOption.cpp
index 33eaa7b3d7..581a71482a 100644
--- a/plugins/paintops/libpaintop/KisSharpnessOption.cpp
+++ b/plugins/paintops/libpaintop/KisSharpnessOption.cpp
@@ -98,7 +98,7 @@ bool KisSharpnessOption::alignOutlineToPixels() const
return m_alignOutlinePixels;
}
-// bool KisSharpnessOption::applyPerfectPixels() const
-// {
-// qDebug() << "applied perfect pixels";
-// }
+bool KisSharpnessOption::perfectPixelOption() const
+{
+ return m_perfectPixel;
+}
\ No newline at end of file
diff --git a/plugins/paintops/libpaintop/KisSharpnessOption.h b/plugins/paintops/libpaintop/KisSharpnessOption.h
index 1fc69d3a6a..42e8f88543 100644
--- a/plugins/paintops/libpaintop/KisSharpnessOption.h
+++ b/plugins/paintops/libpaintop/KisSharpnessOption.h
@@ -24,9 +24,10 @@ public:
* Apply threshold specified by user
*/
void applyThreshold(KisFixedPaintDeviceSP dab, const KisPaintInformation &info);
+ // void applyPerfectPixel(KisFixedPaintDeviceSP device, const KisPaintInformation &info);
bool alignOutlineToPixels() const;
- // bool applyPerfectPixels() const;
+ bool perfectPixelOption() const;
private:
KisSharpnessOption(const KisSharpnessOptionData &data);
diff --git a/plugins/paintops/libpaintop/kis_current_outline_fetcher.cpp b/plugins/paintops/libpaintop/kis_current_outline_fetcher.cpp
index f69650c597..2071c247c9 100644
--- a/plugins/paintops/libpaintop/kis_current_outline_fetcher.cpp
+++ b/plugins/paintops/libpaintop/kis_current_outline_fetcher.cpp
@@ -137,6 +137,7 @@ KisOptimizedBrushOutline KisCurrentOutlineFetcher::fetchOutline(const KisPaintIn
QPointF pos = info.pos();
if (d->sharpnessOption && d->sharpnessOption->alignOutlineToPixels()) {
+ // qDebug() << "perfectPixelOption in kis_current_outline_fetcher" << d->sharpnessOption->perfectPixelOption() ;
qint32 x = 0;
qint32 y = 0;
qreal subPixelX = 0.0;