Commit d6862e32 authored by Lukáš Tvrdý's avatar Lukáš Tvrdý

Fix deform brush painting

Bring back some removed code from iteratorsNG porting
o provide sampledRawData in KisRandomSubAccessor

BUG:299701
FIXED-IN:2.5.2
REVIEW:106222
parent 1d3397c9
......@@ -26,10 +26,10 @@
#include "kis_paint_device.h"
KisRandomSubAccessor::KisRandomSubAccessor(const KisPaintDeviceSP device)
KisRandomSubAccessor::KisRandomSubAccessor(KisPaintDeviceSP device)
: m_device(device)
, m_currentPoint(0, 0)
, m_randomAccessor(device->createRandomConstAccessorNG(0, 0))
, m_randomAccessor(device->createRandomAccessorNG(0, 0))
{
}
......@@ -63,3 +63,29 @@ void KisRandomSubAccessor::sampledOldRawData(quint8* dst)
pixels[3] = m_randomAccessor->oldRawData();
m_device->colorSpace()->mixColorsOp()->mixColors(pixels, weights, 4, dst);
}
void KisRandomSubAccessor::sampledRawData(quint8* dst)
{
const quint8* pixels[4];
qint16 weights[4];
int x = (int)floor(m_currentPoint.x());
int y = (int)floor(m_currentPoint.y());
double hsub = m_currentPoint.x() - x;
if (hsub < 0.0) hsub = 1.0 + hsub;
double vsub = m_currentPoint.y() - y;
if (vsub < 0.0) vsub = 1.0 + vsub;
weights[0] = (int)round((1.0 - hsub) * (1.0 - vsub) * 255);
m_randomAccessor->moveTo(x, y);
pixels[0] = m_randomAccessor->rawData();
weights[1] = (int)round((1.0 - vsub) * hsub * 255);
m_randomAccessor->moveTo(x + 1, y);
pixels[1] = m_randomAccessor->rawData();
weights[2] = (int)round(vsub * (1.0 - hsub) * 255);
m_randomAccessor->moveTo(x, y + 1);
pixels[2] = m_randomAccessor->rawData();
weights[3] = (int)round(hsub * vsub * 255);
m_randomAccessor->moveTo(x + 1, y + 1);
pixels[3] = m_randomAccessor->rawData();
m_device->colorSpace()->mixColorsOp()->mixColors(pixels, weights, 4, dst);
}
......@@ -35,13 +35,18 @@
class KRITAIMAGE_EXPORT KisRandomSubAccessor : public KisShared
{
public:
KisRandomSubAccessor(const KisPaintDeviceSP device);
KisRandomSubAccessor(KisPaintDeviceSP device);
~KisRandomSubAccessor();
/**
* Copy the sampled old value to destination
*/
void sampledOldRawData(quint8* dst);
/**
* Copy the sampled value to destination
*/
void sampledRawData(quint8* dst);
inline void moveTo(double x, double y) {
m_currentPoint.setX(x); m_currentPoint.setY(y);
}
......@@ -52,7 +57,7 @@ private:
KisPaintDeviceSP m_device;
int m_position, m_end;
QPointF m_currentPoint;
KisRandomConstAccessorSP m_randomAccessor;
KisRandomAccessorSP m_randomAccessor;
};
#endif
......@@ -58,11 +58,12 @@ inline void DeformBrush::movePixel(qreal newX, qreal newY, quint8 *dst)
newY = qRound(newY);
}
m_srcAcc->moveTo(newX, newY);
// here there was a switch to select between new and old sampled data, but the
// sub accessor always used a const accessor, which means that there was no
// difference.
m_srcAcc->sampledOldRawData(dst);
if (m_properties->useOldData) {
m_srcAcc->sampledOldRawData(dst);
} else {
m_srcAcc->sampledRawData(dst);
}
}
void DeformBrush::oldDeform(KisPaintDeviceSP dab,KisPaintDeviceSP layer,QPointF pos)
......@@ -110,7 +111,7 @@ void DeformBrush::oldDeform(KisPaintDeviceSP dab,KisPaintDeviceSP layer,QPointF
void DeformBrush::initDeformAction()
{
DeformModes mode = DeformModes(m_properties->action-1);
switch(mode){
case GROW:
case SHRINK:
......@@ -217,10 +218,10 @@ bool DeformBrush::setupAction(DeformModes mode,const QPointF& pos)
return true;
}
KisFixedPaintDeviceSP DeformBrush::paintMask(KisFixedPaintDeviceSP dab,
KisPaintDeviceSP layer,
qreal scale,
qreal rotation,
KisFixedPaintDeviceSP DeformBrush::paintMask(KisFixedPaintDeviceSP dab,
KisPaintDeviceSP layer,
qreal scale,
qreal rotation,
QPointF pos, qreal subPixelX, qreal subPixelY, int dabX, int dabY)
{
KisFixedPaintDeviceSP mask = new KisFixedPaintDevice(KoColorSpaceRegistry::instance()->alpha8());
......@@ -271,13 +272,13 @@ KisFixedPaintDeviceSP DeformBrush::paintMask(KisFixedPaintDeviceSP dab,
qreal bcosa = cos(rotation);
qreal bsina = sin(rotation);
mask->setRect(dab->bounds());
mask->initialize();
quint8* maskPointer = mask->data();
qint8 maskPixelSize = mask->pixelSize();
KoColor pixel(dab->colorSpace());
for (int y = 0; y < dstHeight; y++){
for (int x = 0; x < dstWidth; x++){
maskX = x - m_centerX;
......@@ -317,10 +318,10 @@ KisFixedPaintDeviceSP DeformBrush::paintMask(KisFixedPaintDeviceSP dab,
movePixel(maskX, maskY, dabPointer);
dabPointer += m_pixelSize;
*maskPointer = OPACITY_OPAQUE_U8;
maskPointer += maskPixelSize;
}
}
m_counter++;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment