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 to methods in kis_brushop

Ken Loda33dfecc1a2
diff --git a/libs/image/brushengine/kis_paintop.cc b/libs/image/brushengine/kis_paintop.cc
index 025ca15926..cfa122d9d9 100644
--- a/libs/image/brushengine/kis_paintop.cc
+++ b/libs/image/brushengine/kis_paintop.cc
@@ -142,7 +142,7 @@ void KisPaintOp::paintLine(const KisPaintInformation &pi1,
const KisPaintInformation &pi2,
KisDistanceInformation *currentDistance)
{
- qDebug()<< "KisPaintOp::paintLine";
+ //qDebug()<< "KisPaintOp::paintLine";
KisPaintOpUtils::paintLine(*this, pi1, pi2, currentDistance,
d->fanCornersEnabled,
d->fanCornersStep);
diff --git a/libs/image/kis_painter.cc b/libs/image/kis_painter.cc
index 436da8f431..347139e153 100644
--- a/libs/image/kis_painter.cc
+++ b/libs/image/kis_painter.cc
@@ -1819,6 +1819,326 @@ void KisPainter::drawDDALine(const QPointF & start, const QPointF & end)
}
}
+// void KisPainter::drawDDALine(const QPointF & start, const QPointF & end)
+// {
+// static QPoint lastDrawnPixel(-1, -1);
+// static QPoint waitingPixel(-1, -1);
+
+// int x = qFloor(start.x());
+// int y = qFloor(start.y());
+
+// int x2 = qFloor(end.x());
+// int y2 = qFloor(end.y());
+
+// int xd = x2 - x;
+// int yd = y2 - y;
+
+// float m = 0;
+// bool lockAxis = true;
+
+// if (xd == 0) {
+// m = 2.0;
+// } else if (yd != 0) {
+// lockAxis = false;
+// m = (float)yd / (float)xd;
+// }
+
+// float fx = x;
+// float fy = y;
+// int inc;
+
+// KisRandomAccessorSP accessor = d->device->createRandomAccessorNG();
+// KisRandomConstAccessorSP selectionAccessor;
+// if (d->selection) {
+// selectionAccessor = d->selection->projection()->createRandomConstAccessorNG();
+// }
+
+// QPoint currentPixel(x, y);
+
+// auto drawPixel = [&](int x, int y) {
+// accessor->moveTo(x, y);
+// if (selectionAccessor) selectionAccessor->moveTo(x, y);
+
+// if (!selectionAccessor || *selectionAccessor->oldRawData() > SELECTION_THRESHOLD) {
+// compositeOnePixel(accessor->rawData(), d->paintColor);
+// qDebug() << "Drawing pixel at: " << x << ", " << y;
+// }
+// };
+
+// // for the first pixel if its not drawn yet
+// if (lastDrawnPixel == QPoint(-1, -1)) {
+// drawPixel(x, y);
+// lastDrawnPixel = QPoint(x, y);
+// waitingPixel = QPoint(-1, -1);
+// }
+
+// if (fabs(m) > 1.0f) {
+// inc = (yd > 0) ? 1 : -1;
+// m = (lockAxis) ? 0 : 1.0f / m;
+// m *= inc;
+// while (y != y2) {
+// y += inc;
+// fx += m;
+// x = qRound(fx);
+
+// currentPixel = QPoint(x, y);
+// if (currentPixel == lastDrawnPixel) continue;
+
+// if (waitingPixel == QPoint(-1, -1)) {
+// waitingPixel = currentPixel;
+// } else {
+// QPoint dir = currentPixel - lastDrawnPixel;
+// QPoint waitingDir = waitingPixel - lastDrawnPixel;
+
+// if (dir == waitingDir) {
+// drawPixel(waitingPixel.x(), waitingPixel.y());
+// lastDrawnPixel = waitingPixel;
+// waitingPixel = currentPixel;
+// } else {
+// waitingPixel = currentPixel;
+// }
+// }
+// }
+// } else {
+// inc = (xd > 0) ? 1 : -1;
+// m *= inc;
+// while (x != x2) {
+// x += inc;
+// fy += m;
+// y = qRound(fy);
+
+// currentPixel = QPoint(x, y);
+// if (currentPixel == lastDrawnPixel) continue;
+
+// if (waitingPixel == QPoint(-1, -1)) {
+// waitingPixel = currentPixel;
+// } else {
+// QPoint dir = currentPixel - lastDrawnPixel;
+// QPoint waitingDir = waitingPixel - lastDrawnPixel;
+
+// if (dir == waitingDir) {
+// drawPixel(waitingPixel.x(), waitingPixel.y());
+// lastDrawnPixel = waitingPixel;
+// waitingPixel = currentPixel;
+// } else {
+// waitingPixel = currentPixel;
+// }
+// }
+// }
+// }
+
+// if (x == x2 && y == y2) {
+// lastDrawnPixel = QPoint(-1, -1);
+// waitingPixel = QPoint(-1, -1);
+// }
+// }
+
+// void KisPainter::drawDDALine(const QPointF & start, const QPointF & end)
+// {
+// static QPoint lastDrawnPixel(-1, -1);
+// static QPoint waitingPixel(-1, -1);
+
+// int x = qFloor(start.x());
+// int y = qFloor(start.y());
+
+// int x2 = qFloor(end.x());
+// int y2 = qFloor(end.y());
+
+// int xd = x2 - x;
+// int yd = y2 - y;
+
+// float m = 0;
+// bool lockAxis = true;
+
+// if (xd == 0) {
+// m = 2.0;
+// } else if (yd != 0) {
+// lockAxis = false;
+// m = (float)yd / (float)xd;
+// }
+
+// float fx = x;
+// float fy = y;
+// int inc;
+
+// KisRandomAccessorSP accessor = d->device->createRandomAccessorNG();
+// KisRandomConstAccessorSP selectionAccessor;
+// if (d->selection) {
+// selectionAccessor = d->selection->projection()->createRandomConstAccessorNG();
+// }
+
+// QPoint currentPixel(x, y);
+
+// auto drawPixel = [&](int x, int y) {
+// accessor->moveTo(x, y);
+// if (selectionAccessor) selectionAccessor->moveTo(x, y);
+
+// if (!selectionAccessor || *selectionAccessor->oldRawData() > SELECTION_THRESHOLD) {
+// compositeOnePixel(accessor->rawData(), d->paintColor);
+// qDebug() << "Drawing pixel at: " << x << ", " << y;
+// }
+// };
+
+// if (lastDrawnPixel == QPoint(-1, -1)) {
+// drawPixel(x, y);
+// lastDrawnPixel = QPoint(x, y);
+// waitingPixel = QPoint(-1, -1);
+// }
+
+// if (fabs(m) > 1.0f) {
+// inc = (yd > 0) ? 1 : -1;
+// m = (lockAxis) ? 0 : 1.0f / m;
+// m *= inc;
+// while (y != y2) {
+// y += inc;
+// fx += m;
+// x = qRound(fx);
+
+// currentPixel = QPoint(x, y);
+// if (currentPixel == lastDrawnPixel) continue;
+
+// if (waitingPixel == QPoint(-1, -1)) {
+// waitingPixel = currentPixel;
+// } else {
+// QPoint dir = currentPixel - lastDrawnPixel;
+// QPoint waitingDir = waitingPixel - lastDrawnPixel;
+
+// if (dir == waitingDir) {
+// drawPixel(waitingPixel.x(), waitingPixel.y());
+// lastDrawnPixel = waitingPixel;
+// waitingPixel = currentPixel;
+// } else {
+// waitingPixel = currentPixel;
+// }
+// }
+// }
+// } else {
+// inc = (xd > 0) ? 1 : -1;
+// m *= inc;
+// while (x != x2) {
+// x += inc;
+// fy += m;
+// y = qRound(fy);
+
+// currentPixel = QPoint(x, y);
+// if (currentPixel == lastDrawnPixel) continue;
+
+// if (waitingPixel == QPoint(-1, -1)) {
+// waitingPixel = currentPixel;
+// } else {
+// QPoint dir = currentPixel - lastDrawnPixel;
+// QPoint waitingDir = waitingPixel - lastDrawnPixel;
+
+// if (dir == waitingDir) {
+// drawPixel(waitingPixel.x(), waitingPixel.y());
+// lastDrawnPixel = waitingPixel;
+// waitingPixel = currentPixel;
+// } else {
+// waitingPixel = currentPixel;
+// }
+// }
+// }
+// }
+
+// // Reset static variables after completing the stroke
+// if (x == x2 && y == y2) {
+// lastDrawnPixel = QPoint(-1, -1);
+// waitingPixel = QPoint(-1, -1);
+// }
+// }
+
+// void KisPainter::drawDDALine(const QPointF & start, const QPointF & end) {
+// int x = qFloor(start.x());
+// int y = qFloor(start.y());
+
+// int x2 = qFloor(end.x());
+// int y2 = qFloor(end.y());
+
+// int xd = x2 - x;
+// int yd = y2 - y;
+
+// float m = 0;
+// bool lockAxis = true;
+
+// if (xd == 0) {
+// m = 2.0;
+// } else if (yd != 0) {
+// lockAxis = false;
+// m = static_cast<float>(yd) / static_cast<float>(xd);
+// }
+
+// float fx = x;
+// float fy = y;
+// int inc;
+
+// KisRandomAccessorSP accessor = d->device->createRandomAccessorNG();
+// KisRandomConstAccessorSP selectionAccessor;
+// if (d->selection) {
+// selectionAccessor = d->selection->projection()->createRandomConstAccessorNG();
+// }
+
+// accessor->moveTo(x, y);
+// if (selectionAccessor) selectionAccessor->moveTo(x, y);
+
+// if (!selectionAccessor || *selectionAccessor->oldRawData() > SELECTION_THRESHOLD) {
+// compositeOnePixel(accessor->rawData(), d->paintColor);
+// }
+
+// QPoint lastDrawnPixel(x, y);
+// QPoint waitingPixel(x, y);
+// QPoint currentPixel(x, y);
+
+// auto drawPixel = [&](int px, int py) {
+// accessor->moveTo(px, py);
+// if (selectionAccessor) selectionAccessor->moveTo(px, py);
+
+// if (!selectionAccessor || *selectionAccessor->oldRawData() > SELECTION_THRESHOLD) {
+// compositeOnePixel(accessor->rawData(), d->paintColor);
+// qDebug() << "Drawing pixel at: " << x << ", " << y;
+// }
+// };
+
+// if (fabs(m) > 1.0f) {
+// inc = (yd > 0) ? 1 : -1;
+// m = (lockAxis) ? 0 : 1.0f / m;
+// m *= inc;
+// while (y != y2) {
+// y = y + inc;
+// fx = fx + m;
+// x = qRound(fx);
+
+// currentPixel = QPoint(x, y);
+// if ((abs(currentPixel.x() - lastDrawnPixel.x()) > 1) || (abs(currentPixel.y() - lastDrawnPixel.y()) > 1)) {
+// drawPixel(waitingPixel.x(), waitingPixel.y());
+// lastDrawnPixel = waitingPixel;
+// waitingPixel = currentPixel;
+// } else if ((abs(currentPixel.x() - waitingPixel.x()) > 1) || (abs(currentPixel.y() - waitingPixel.y()) > 1)) {
+// waitingPixel = currentPixel;
+// }
+// }
+// } else {
+// inc = (xd > 0) ? 1 : -1;
+// m *= inc;
+// while (x != x2) {
+// x = x + inc;
+// fy = fy + m;
+// y = qRound(fy);
+
+// currentPixel = QPoint(x, y);
+// if ((abs(currentPixel.x() - lastDrawnPixel.x()) > 1) || (abs(currentPixel.y() - lastDrawnPixel.y()) > 1)) {
+// drawPixel(waitingPixel.x(), waitingPixel.y());
+// lastDrawnPixel = waitingPixel;
+// waitingPixel = currentPixel;
+// } else if ((abs(currentPixel.x() - waitingPixel.x()) > 1) || (abs(currentPixel.y() - waitingPixel.y()) > 1)) {
+// waitingPixel = currentPixel;
+// }
+// }
+// }
+
+// drawPixel(waitingPixel.x(), waitingPixel.y());
+// }
+
+
//qDebug() << " x: " << x << " y: " << y << " x2 " << x2 << " y2 " << y2 ;
void KisPainter::drawWobblyLine(const QPointF & start, const QPointF & end)
diff --git a/libs/ui/tool/kis_smoothing_options.h b/libs/ui/tool/kis_smoothing_options.h
index 8da13c1582..16208d0ae6 100644
--- a/libs/ui/tool/kis_smoothing_options.h
+++ b/libs/ui/tool/kis_smoothing_options.h
@@ -21,7 +21,8 @@ public:
NO_SMOOTHING = 0,
SIMPLE_SMOOTHING,
WEIGHTED_SMOOTHING,
- STABILIZER
+ STABILIZER,
+ PIXEL_PERFECT
};
public:
diff --git a/libs/ui/tool/kis_tool_freehand.cc b/libs/ui/tool/kis_tool_freehand.cc
index 6db34efc21..bfa2a1eb19 100644
--- a/libs/ui/tool/kis_tool_freehand.cc
+++ b/libs/ui/tool/kis_tool_freehand.cc
@@ -10,6 +10,9 @@
*/
#include "kis_tool_freehand.h"
+//#include "../../../plugins/paintops/defaultpaintops/brush/kis_brushop.h"
+//#include <../../../plugins/paintops/defaultpaintops/brush/kis_brushop.>
+#include "plugins/paintops/defaultpaintops/brush/kis_brushop.h"
#include <QPainter>
#include <QRect>
#include <QThreadPool>
@@ -181,40 +184,40 @@ void KisToolFreehand::deactivate()
// 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";
-// 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));
-}
+// strokeCoordinates.clear();
+// strokeCoordinates.push_back(convertToPixelCoord(event));
+// }
//original
// void KisToolFreehand::doStroke(KoPointerEvent *event)
@@ -260,6 +263,13 @@ void KisToolFreehand::endStroke()
qDebug() << "Smoothed Stroke Point (Integer):" << point.x() << point.y();
}
+ //KisBrushOp::smoothedPoints = smoothedPoints;
+ KisBrushOp* brushOp = dynamic_cast<KisBrushOp*>(currentPaintOp());
+ if (brushOp) {
+ brushOp->setSmoothedPoints(smoothedPoints);
+ }
+
+
strokeCoordinates.clear();
}
diff --git a/libs/ui/tool/kis_tool_freehand.h b/libs/ui/tool/kis_tool_freehand.h
index 3beaabfe92..2cef2b2c94 100644
--- a/libs/ui/tool/kis_tool_freehand.h
+++ b/libs/ui/tool/kis_tool_freehand.h
@@ -35,7 +35,8 @@ public:
~KisToolFreehand() override;
int flags() const override;
void mouseMoveEvent(KoPointerEvent *event) override;
- const std::vector<QPoint>& getSmoothedPoints() const { return smoothedPoints; }
+ //const std::vector<QPoint>& getSmoothedPoints() const { return smoothedPoints; }
+ std::vector<QPoint> smoothedPoints;
public Q_SLOTS:
void activate(const QSet<KoShape*> &shapes) override;
@@ -63,7 +64,8 @@ protected:
virtual void doStroke(KoPointerEvent *event);
virtual void endStroke();
- extern std::vector<QPointF> strokeCoordinates;
+ //extern std::vector<QPointF> strokeCoordinates;
+ std::vector<QPointF> strokeCoordinates;
std::vector<QPoint> removeDuplicates(const std::vector<QPoint>& points);
std::vector<QPoint> removeLShapes(const std::vector<QPoint>& points);
@@ -122,7 +124,6 @@ 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 a677bf8965..ee28b9815e 100644
--- a/libs/ui/tool/kis_tool_freehand_helper.cpp
+++ b/libs/ui/tool/kis_tool_freehand_helper.cpp
@@ -472,8 +472,9 @@ 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
+ // initialize current distance
QPointF prevPos;
if (!m_d->history.isEmpty()) {
@@ -597,11 +598,18 @@ void KisToolFreehandHelper::paint(KisPaintInformation &info)
m_d->strokeTimeoutTimer.start(100);
}
}
+
+
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::PIXEL_PERFECT) {
+ // m_d->history.clear();
+ // qDebug() << "pixel perfect option detected";
+ // }
+
if (m_d->smoothingOptions->smoothingType() == KisSmoothingOptions::STABILIZER) {
m_d->stabilizedSampler.addEvent(info);
//qDebug() << "stablizer in kistool freehand";
@@ -658,7 +666,36 @@ void KisToolFreehandHelper::endPaint()
m_d->strokeId.clear();
m_d->infoBuilder->reset();
}
+//origin
+// void KisToolFreehandHelper::cancelPaint()
+// {
+// if (!m_d->strokeId) return;
+
+// m_d->strokeTimeoutTimer.stop();
+
+// if (m_d->airbrushingTimer.isActive()) {
+// m_d->airbrushingTimer.stop();
+// }
+
+// if (m_d->asyncUpdateHelper.isActive()) {
+// m_d->asyncUpdateHelper.cancelUpdateStream();
+// }
+// if (m_d->stabilizerPollTimer.isActive()) {
+// m_d->stabilizerPollTimer.stop();
+// }
+
+// if (m_d->stabilizerDelayedPaintHelper.running()) {
+// m_d->stabilizerDelayedPaintHelper.cancel();
+// }
+
+// // see a comment in endPaint()
+// m_d->strokeInfos.clear();
+
+// m_d->strokesFacade->cancelStroke(m_d->strokeId);
+// m_d->strokeId.clear();
+
+// }
void KisToolFreehandHelper::cancelPaint()
{
if (!m_d->strokeId) return;
@@ -681,12 +718,13 @@ void KisToolFreehandHelper::cancelPaint()
m_d->stabilizerDelayedPaintHelper.cancel();
}
+ //pixelPerfectLinePainter();
+
// see a comment in endPaint()
m_d->strokeInfos.clear();
m_d->strokesFacade->cancelStroke(m_d->strokeId);
m_d->strokeId.clear();
-
}
int KisToolFreehandHelper::elapsedStrokeTime() const
@@ -769,7 +807,7 @@ KisToolFreehandHelper::getStabilizedPaintInfo(const QQueue<KisPaintInformation>
return result;
}
-
+//original
void KisToolFreehandHelper::stabilizerPollAndPaint()
{
KisStabilizedEventsSampler::iterator it;
@@ -777,6 +815,10 @@ void KisToolFreehandHelper::stabilizerPollAndPaint()
std::tie(it, end) = m_d->stabilizedSampler.range();
QVector<KisPaintInformation> delayedPaintTodoItems;
+ // for (const KisPaintInformation &info : m_d->stabilizerDeque) {
+ // qDebug() << info.pos();
+ // }
+
for (; it != end; ++it) {
KisPaintInformation sampledInfo = *it;
@@ -803,8 +845,10 @@ void KisToolFreehandHelper::stabilizerPollAndPaint()
KisPaintInformation newInfo = getStabilizedPaintInfo(m_d->stabilizerDeque, sampledInfo);
if (m_d->stabilizerDelayedPaintHelper.running()) {
+ //qDebug() << "if in stablizer reached new infopos: " << newInfo.pos();
delayedPaintTodoItems.append(newInfo);
} else {
+ //qDebug() << "else in stablizer reached new infopos: " << newInfo.pos();
paintLine(m_d->previousPaintInformation, newInfo);
}
m_d->previousPaintInformation = newInfo;
@@ -813,7 +857,7 @@ void KisToolFreehandHelper::stabilizerPollAndPaint()
m_d->stabilizerDeque.dequeue();
m_d->stabilizerDeque.enqueue(sampledInfo);
} else if (m_d->stabilizerDeque.head().pos() != m_d->previousPaintInformation.pos()) {
-
+ //qDebug() << "else if : " << m_d->stabilizerDeque.head().pos();
QQueue<KisPaintInformation>::iterator it = m_d->stabilizerDeque.begin();
QQueue<KisPaintInformation>::iterator end = m_d->stabilizerDeque.end();
@@ -833,6 +877,61 @@ void KisToolFreehandHelper::stabilizerPollAndPaint()
}
}
+// void KisToolFreehandHelper::stabilizerPollAndPaint()
+// {
+// KisStabilizedEventsSampler::iterator it;
+// KisStabilizedEventsSampler::iterator end;
+// std::tie(it, end) = m_d->stabilizedSampler.range();
+// QVector<KisPaintInformation> delayedPaintTodoItems;
+
+// // Variables to store the accumulated movement and last valid position
+// QPointF accumulatedMovement(0, 0);
+// QPointF lastValidPoint = m_d->previousPaintInformation.pos();
+
+// for (; it != end; ++it) {
+// KisPaintInformation sampledInfo = *it;
+
+// // Calculate the movement difference from the last valid point
+// QPointF diff = sampledInfo.pos() - lastValidPoint;
+// accumulatedMovement += diff;
+
+// qreal accumulatedDistance = sqrt(pow(accumulatedMovement.x(), 2) + pow(accumulatedMovement.y(), 2));
+
+// // Check if the accumulated distance is greater than 1 pixel
+// if (accumulatedDistance >= 1.0) {
+// // Update the last valid point
+// lastValidPoint = sampledInfo.pos();
+// accumulatedMovement = QPointF(0, 0); // Reset the accumulated movement
+
+// KisPaintInformation newInfo = getStabilizedPaintInfo(m_d->stabilizerDeque, sampledInfo);
+
+// if (m_d->stabilizerDelayedPaintHelper.running()) {
+// delayedPaintTodoItems.append(newInfo);
+// } else {
+// paintLine(m_d->previousPaintInformation, newInfo);
+// }
+
+// m_d->previousPaintInformation = newInfo;
+
+// // Push the new entry through the queue
+// m_d->stabilizerDeque.dequeue();
+// m_d->stabilizerDeque.enqueue(sampledInfo);
+// } else {
+// // Enqueue the sampled info for future processing
+// m_d->stabilizerDeque.enqueue(sampledInfo);
+// }
+// }
+
+// m_d->stabilizedSampler.clear();
+
+// if (m_d->stabilizerDelayedPaintHelper.running()) {
+// m_d->stabilizerDelayedPaintHelper.update(delayedPaintTodoItems);
+// } else {
+// emit requestExplicitUpdateOutline();
+// }
+// }
+
+
void KisToolFreehandHelper::stabilizerEnd()
{
// Stop the timer
@@ -841,11 +940,13 @@ void KisToolFreehandHelper::stabilizerEnd()
// Finish the line
if (m_d->smoothingOptions->finishStabilizedCurve()) {
// Process all the existing events first
- stabilizerPollAndPaint();
+ //stabilizerPollAndPaint();
+ //pixelPerfectLinePainter();
// Draw the finish line with pending events and a time override
m_d->stabilizedSampler.addFinishingEvent(m_d->stabilizerDeque.size());
- stabilizerPollAndPaint();
+ //stabilizerPollAndPaint();
+ //pixelPerfectLinePainter();
}
if (m_d->stabilizerDelayedPaintHelper.running()) {
@@ -883,8 +984,56 @@ void KisToolFreehandHelper::finishStroke()
m_d->previousTangent,
newTangent);
}
+
+ // pixelPerfectLinePainter();
+
}
+// QVector<KisPaintInformation> KisToolFreehandHelper::filterSubpixelMovements(const QVector<KisPaintInformation> &points) {
+// QVector<KisPaintInformation> filteredPoints;
+
+// if (points.isEmpty()) return filteredPoints;
+
+// KisPaintInformation prevInfo = points.first();
+// filteredPoints.append(prevInfo);
+
+// for (int i = 1; i < points.size(); ++i) {
+// KisPaintInformation currentInfo = points[i];
+
+// QPointF diff = currentInfo.pos() - prevInfo.pos();
+// qreal distance = sqrt(diff.x() * diff.x() + diff.y() * diff.y());
+
+// if (distance > 1.0) {
+// filteredPoints.append(currentInfo);
+// prevInfo = currentInfo;
+// }
+// }
+
+// return filteredPoints;
+// }
+
+// void KisToolFreehandHelper::pixelPerfectLinePainter() {
+// QVector<KisPaintInformation> historyVector = m_d->history.toVector();
+// QVector<KisPaintInformation> filteredPoints = filterSubpixelMovements(historyVector);
+
+// //qDebug() << "Filtered Points:" << filteredPoints;
+
+// if (filteredPoints.size() > 1) {
+// for (int i = 1; i < filteredPoints.size(); ++i) {
+// KisPaintInformation currentInfo = filteredPoints[i];
+// KisPaintInformation prevInfo = filteredPoints[i - 1];
+
+// paintLine(prevInfo, currentInfo);
+// }
+// } else if (filteredPoints.size() == 1) {
+// // If there's only one point, ensure it's drawn
+// paintLine(filteredPoints.first(), filteredPoints.first());
+// }
+
+// // clear the history to avoid reprocessing the same points
+// m_d->history.clear();
+// }
+
void KisToolFreehandHelper::doAirbrushing()
{
// Check that the stroke hasn't ended.
@@ -924,6 +1073,15 @@ qreal KisToolFreehandHelper::currentPhysicalZoom() const
{
return m_d->resourceManager ? m_d->resourceManager->resource(KoCanvasResource::EffectivePhysicalZoom).toReal() : 1.0;
}
+//origin
+// void KisToolFreehandHelper::paintAt(int strokeInfoId,
+// const KisPaintInformation &pi)
+// {
+// m_d->hasPaintAtLeastOnce = true;
+// m_d->strokesFacade->addJob(m_d->strokeId,
+// new FreehandStrokeStrategy::Data(strokeInfoId, pi));
+
+// }
void KisToolFreehandHelper::paintAt(int strokeInfoId,
const KisPaintInformation &pi)
@@ -932,8 +1090,20 @@ void KisToolFreehandHelper::paintAt(int strokeInfoId,
m_d->strokesFacade->addJob(m_d->strokeId,
new FreehandStrokeStrategy::Data(strokeInfoId, pi));
+ // Add point to history for pixel-perfect processing
+ m_d->history.append(pi);
}
+//origin
+// void KisToolFreehandHelper::paintLine(int strokeInfoId,
+// const KisPaintInformation &pi1,
+// const KisPaintInformation &pi2)
+// {
+// m_d->hasPaintAtLeastOnce = true;
+// m_d->strokesFacade->addJob(m_d->strokeId,
+// new FreehandStrokeStrategy::Data(strokeInfoId, pi1, pi2));
+
+// }
void KisToolFreehandHelper::paintLine(int strokeInfoId,
const KisPaintInformation &pi1,
const KisPaintInformation &pi2)
@@ -942,6 +1112,9 @@ void KisToolFreehandHelper::paintLine(int strokeInfoId,
m_d->strokesFacade->addJob(m_d->strokeId,
new FreehandStrokeStrategy::Data(strokeInfoId, pi1, pi2));
+ // add points to history for pixel-perfect processing
+ // m_d->history.append(pi1);
+ // m_d->history.append(pi2);
}
void KisToolFreehandHelper::paintBezierCurve(int strokeInfoId,
diff --git a/libs/ui/tool/kis_tool_freehand_helper.h b/libs/ui/tool/kis_tool_freehand_helper.h
index dba9faf92f..0d7391bd53 100644
--- a/libs/ui/tool/kis_tool_freehand_helper.h
+++ b/libs/ui/tool/kis_tool_freehand_helper.h
@@ -145,6 +145,8 @@ private Q_SLOTS:
void finishStroke();
void doAirbrushing();
void stabilizerPollAndPaint();
+ // QVector<KisPaintInformation> filterSubpixelMovements(const QVector<KisPaintInformation> &points);
+ // void pixelPerfectLinePainter();
void slotSmoothingTypeChanged();
private:
diff --git a/plugins/paintops/defaultpaintops/brush/kis_brushop.cpp b/plugins/paintops/defaultpaintops/brush/kis_brushop.cpp
index 5d825c6643..182c1772b7 100644
--- a/plugins/paintops/defaultpaintops/brush/kis_brushop.cpp
+++ b/plugins/paintops/defaultpaintops/brush/kis_brushop.cpp
@@ -107,7 +107,7 @@ KisSpacingInformation KisBrushOp::paintAt(const KisPaintInformation& info)
{
if (!painter()->device()) return KisSpacingInformation(1.0);
- qDebug()<< "kis_brushop::paintAt";
+ //qDebug()<< "kis_brushop::paintAt";
KisBrushSP brush = m_brush;
Q_ASSERT(brush);
if (!brush)
@@ -385,9 +385,37 @@ KisTimingInformation KisBrushOp::updateTimingImpl(const KisPaintInformation &inf
return KisPaintOpPluginUtils::effectiveTiming(&m_airbrushData, &m_rateOption, info);
}
//original kisbrushop:paintline
-// void KisBrushOp::paintLine(const KisPaintInformation& pi1, const KisPaintInformation& pi2, KisDistanceInformation *currentDistance)
-// {
-// //qDebug() << "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);
+ }
+}
+// This is a vector approach where we populate/filter out corner pixels in kis_tool_freehand and than call draw line on that (don't know how to get the vector here)
+// std::vector<QPoint> KisBrushOp::smoothedPoints;
+// void KisBrushOp::paintLine(const KisPaintInformation& pi1, const KisPaintInformation& pi2, KisDistanceInformation *currentDistance) {
+
// if (m_sharpnessOption.isChecked() && m_brush && (m_brush->width() == 1) && (m_brush->height() == 1)) {
// if (!m_lineCacheDevice) {
@@ -398,47 +426,105 @@ KisTimingInformation KisBrushOp::updateTimingImpl(const KisPaintInformation &inf
// }
// 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());
+
+// // Use smoothedPoints to draw lines
+// for (size_t i = 0; i < smoothedPoints.size() - 1; ++i) {
+// qDebug() << "smoothedPoints[i], smoothedPoints[i + 1]: " << smoothedPoints[i], smoothedPoints[i + 1];
+// p.drawDDALine(smoothedPoints[i], smoothedPoints[i + 1]);
+// }
// 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);
+
+// // 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)) {
+// void KisBrushOp::setSmoothedPoints(const std::vector<QPoint>& points) {
+// smoothedPoints = points;
+// }
- if (!m_lineCacheDevice) {
- m_lineCacheDevice = source()->createCompositionSourceDevice();
- } else {
- m_lineCacheDevice->clear();
- }
- KisPainter p(m_lineCacheDevice);
- p.setPaintColor(painter()->paintColor());
+// Trying the 3 pixel approach where we track current/lastdrawn/waiting pixel see blog 1 for more info
+// basically if currentpixel deviates from the x/y axis of lastdrawn pixel we skip over the intermediary waiting pixel (needs fixes)
+// void KisBrushOp::paintLine(const KisPaintInformation& pi1, const KisPaintInformation& pi2, KisDistanceInformation *currentDistance) {
+// static bool lastDrawnPixelInitialized = false;
+// static QPoint lastDrawnPixel;
+// if (m_sharpnessOption.isChecked() && m_brush && (m_brush->width() == 1) && (m_brush->height() == 1)) {
- 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);
- }
+// if (!m_lineCacheDevice) {
+// m_lineCacheDevice = source()->createCompositionSourceDevice();
+// } else {
+// m_lineCacheDevice->clear();
+// }
- QRect rc = m_lineCacheDevice->extent();
- painter()->bitBlt(rc.x(), rc.y(), m_lineCacheDevice, rc.x(), rc.y(), rc.width(), rc.height());
- painter()->renderMirrorMask(rc, m_lineCacheDevice);
- } else {
- KisPaintOp::paintLine(pi1, pi2, currentDistance);
- }
-}
\ No newline at end of file
+// KisPainter p(m_lineCacheDevice);
+// p.setPaintColor(painter()->paintColor());
+
+// QPoint currentPixel = pi2.pos().toPoint();
+ //this is for the case where last drawn isn't initialized so we draw at least one pixel
+// if (!lastDrawnPixelInitialized) {
+// // First call, initialize lastDrawnPixel and set the flag
+// lastDrawnPixel = pi1.pos().toPoint();
+// lastDrawnPixelInitialized = true;
+
+// p.drawDDALine(pi1.pos(), pi2.pos());
+
+// // update lastDrawnPixel to the endpoint of the first drawDDALine call (might not work)
+// lastDrawnPixel = currentPixel;
+// } else {
+
+// //
+// QPoint waitingPixel = lastDrawnPixel;
+// qDebug() << "waitingPixel: " << waitingPixel << "currentPixel: " << currentPixel << "lastDrawnPixel: "<< lastDrawnPixel;
+// // Function to draw a line between two points
+// auto drawLine = [&](const QPoint& start, const QPoint& end) {
+// p.drawDDALine(QPointF(start), QPointF(end));
+// };
+
+// // determine the movement direction
+// int dx = currentPixel.x() - lastDrawnPixel.x();
+// int dy = currentPixel.y() - lastDrawnPixel.y();
+
+// int steps = std::max(abs(dx), abs(dy));
+// float xIncrement = dx / static_cast<float>(steps);
+// float yIncrement = dy / static_cast<float>(steps);
+
+// float x = lastDrawnPixel.x();
+// float y = lastDrawnPixel.y();
+
+// for (int i = 0; i <= steps; ++i) {
+// QPoint tempPixel = QPoint(qRound(x), qRound(y));
+
+// // check if tempPixel is in the same direction as lastDrawnPixel
+// if ((abs(tempPixel.x() - lastDrawnPixel.x()) <= 1 && tempPixel.y() == lastDrawnPixel.y()) ||
+// (abs(tempPixel.y() - lastDrawnPixel.y()) <= 1 && tempPixel.x() == lastDrawnPixel.x())) {
+// // continue drawing in the same direction
+// waitingPixel = tempPixel;
+// drawLine(lastDrawnPixel, waitingPixel);
+// lastDrawnPixel = waitingPixel;
+// } else {
+// // current pixel deviates from x and y, do not draw waiting pixel
+// lastDrawnPixel = tempPixel;
+// }
+
+// x += xIncrement;
+// y += yIncrement;
+// }
+// }
+
+// QRect rc = m_lineCacheDevice->extent();
+// painter()->bitBlt(rc.x(), rc.y(), m_lineCacheDevice, rc.x(), rc.y(), rc.width(), rc.height());
+// painter()->renderMirrorMask(rc, m_lineCacheDevice);
+// } else {
+// KisPaintOp::paintLine(pi1, pi2, currentDistance);
+// // Reset the flag when not in pixel-perfect mode
+// lastDrawnPixelInitialized = false;
+// }
+// }
diff --git a/plugins/paintops/defaultpaintops/brush/kis_brushop.h b/plugins/paintops/defaultpaintops/brush/kis_brushop.h
index 8bcb3971c0..6d8cfa1a6e 100644
--- a/plugins/paintops/defaultpaintops/brush/kis_brushop.h
+++ b/plugins/paintops/defaultpaintops/brush/kis_brushop.h
@@ -21,6 +21,8 @@
#include <KisRotationOption.h>
#include <KisFlowOpacityOption.h>
+ #include <kis_tool_freehand.h>
+
#include <KisRollingMeanAccumulatorWrapper.h>
#include <QElapsedTimer>
@@ -43,6 +45,8 @@ public:
std::pair<int, bool> doAsynchronousUpdate(QVector<KisRunnableStrokeJobData *> &jobs) override;
+ // void setSmoothedPoints(const std::vector<QPoint>& points);
+
protected:
KisSpacingInformation paintAt(const KisPaintInformation& info) override;
@@ -88,6 +92,7 @@ private:
const int m_minUpdatePeriod;
const int m_maxUpdatePeriod;
+ // std::vector<QPoint> smoothedPoints;
};
#endif // KIS_BRUSHOP_H_
diff --git a/plugins/tools/basictools/kis_tool_brush.cc b/plugins/tools/basictools/kis_tool_brush.cc
index 425388d4b3..7959a32e46 100644
--- a/plugins/tools/basictools/kis_tool_brush.cc
+++ b/plugins/tools/basictools/kis_tool_brush.cc
@@ -345,7 +345,8 @@ QWidget * KisToolBrush::createOptionWidget()
<< i18nc("@item:inlistbox Brush Smoothing", "None")
<< i18nc("@item:inlistbox Brush Smoothing", "Basic")
<< i18nc("@item:inlistbox Brush Smoothing", "Weighted")
- << i18nc("@item:inlistbox Brush Smoothing", "Stabilizer"));
+ << i18nc("@item:inlistbox Brush Smoothing", "Stabilizer")
+ << i18nc("@item:inlistbox Brush Smoothing", "Pixel"));
connect(m_cmbSmoothingType, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSetSmoothingType(int)));
addOptionWidgetOption(m_cmbSmoothingType, new QLabel(i18n("Brush Smoothing:"), optionsWidget));