Commit c4d0924a authored by Dmitry Kazakov's avatar Dmitry Kazakov
Browse files

Fix painting with colorsmudge brush when a selection is active

Selection crops destination rect, not the source one

BUG:394439
CCBUG:423851
parent 7a0e9727
......@@ -495,7 +495,8 @@ inline bool KisPainter::Private::tryReduceSourceRect(const KisPaintDevice *srcDe
* We should also crop the blitted area by the selected region,
* because we cannot paint outside the selection.
*/
*srcRect &= selection->selectedRect();
*srcRect &= selection->selectedRect().translated(*srcX - *dstX,
*srcY - *dstY);
if (srcRect->isEmpty()) return true;
needsReadjustParams = true;
......@@ -543,12 +544,10 @@ void KisPainter::bitBltWithFixedSelection(qint32 dstX, qint32 dstY,
Q_ASSERT(selection->colorSpace() == KoColorSpaceRegistry::instance()->alpha8());
QRect srcRect = QRect(srcX, srcY, srcWidth, srcHeight);
QRect selRect = QRect(selX, selY, srcWidth, srcHeight);
/* Trying to read outside a KisFixedPaintDevice is inherently wrong and shouldn't be done,
so crash if someone attempts to do this. Don't resize YET as it would obfuscate the mistake. */
Q_ASSERT(selection->bounds().contains(selRect));
Q_UNUSED(selRect); // only used by the above Q_ASSERT
// save selection offset in case tryReduceSourceRect() will change rects
const int xSelectionOffset = selX - srcX;
const int ySelectionOffset = selY - srcY;
/**
* An optimization, which crops the source rect by the bounds of
......@@ -559,6 +558,16 @@ void KisPainter::bitBltWithFixedSelection(qint32 dstX, qint32 dstY,
&srcWidth, &srcHeight,
&dstX, &dstY)) return;
const QRect selRect = QRect(srcX + xSelectionOffset,
srcY + ySelectionOffset,
srcWidth, srcHeight);
/* Trying to read outside a KisFixedPaintDevice is inherently wrong and shouldn't be done,
so crash if someone attempts to do this. Don't resize YET as it would obfuscate the mistake. */
KIS_SAFE_ASSERT_RECOVER_RETURN(selection->bounds().contains(selRect));
Q_UNUSED(selRect); // only used by the above Q_ASSERT
/* Create an intermediate byte array to hold information before it is written
to the current paint device (d->device) */
quint8* dstBytes = 0;
......@@ -582,9 +591,9 @@ void KisPainter::bitBltWithFixedSelection(qint32 dstX, qint32 dstY,
srcDev->readBytes(srcBytes, srcX, srcY, srcWidth, srcHeight);
QRect selBounds = selection->bounds();
const QRect selBounds = selection->bounds();
const quint8 *selRowStart = selection->data() +
(selBounds.width() * (selY - selBounds.top()) + (selX - selBounds.left())) * selection->pixelSize();
(selBounds.width() * (selRect.y() - selBounds.top()) + (selRect.x() - selBounds.left())) * selection->pixelSize();
/*
* This checks whether there is nothing selected.
......
Supports Markdown
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