Commit 24f5bf41 authored by L. E. Segovia's avatar L. E. Segovia

Merge branch 'master' into amyspark/T13097-gsoc2020-seexpr-master

parents e4dbb4d8 a899f2f4
......@@ -493,7 +493,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;
......@@ -541,12 +542,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
......@@ -557,6 +556,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;
......@@ -580,9 +589,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.
......
......@@ -23,6 +23,23 @@
#include "KoMixColorsOp.h"
#include <type_traits>
#include <KisCppQuirks.h>
template <typename T>
static inline T safeDivideWithRound(T dividend,
std::enable_if_t<std::is_floating_point<T>::value, T> divisor) {
return dividend / divisor;
}
template <typename T>
static inline T safeDivideWithRound(T dividend,
std::enable_if_t<std::is_integral<T>::value, T> divisor) {
return (dividend + divisor / 2) / divisor;
}
template<class _CSTrait>
class KoMixColorsOpImpl : public KoMixColorsOp
{
......@@ -168,7 +185,7 @@ private:
}
// set totalAlpha to the minimum between its value and the unit value of the channels
const int sumOfWeights = weightsWrapper.normalizeFactor();
const typename KoColorSpaceMathsTraits<typename _CSTrait::channels_type>::compositetype sumOfWeights = weightsWrapper.normalizeFactor();
if (totalAlpha > KoColorSpaceMathsTraits<typename _CSTrait::channels_type>::unitValue * sumOfWeights) {
totalAlpha = KoColorSpaceMathsTraits<typename _CSTrait::channels_type>::unitValue * sumOfWeights;
......@@ -186,10 +203,7 @@ private:
for (int i = 0; i < (int)_CSTrait::channels_nb; i++) {
if (i != _CSTrait::alpha_pos) {
typename KoColorSpaceMathsTraits<typename _CSTrait::channels_type>::compositetype v = (totals[i] + totalAlpha / 2) / totalAlpha;
if (KoColorSpaceMathsTraits<typename _CSTrait::channels_type>::unitValue == 1.0) {
v = totals[i] / totalAlpha;
}
typename KoColorSpaceMathsTraits<typename _CSTrait::channels_type>::compositetype v = safeDivideWithRound(totals[i], totalAlpha);
if (v > KoColorSpaceMathsTraits<typename _CSTrait::channels_type>::max) {
v = KoColorSpaceMathsTraits<typename _CSTrait::channels_type>::max;
......@@ -202,11 +216,7 @@ private:
}
if (_CSTrait::alpha_pos != -1) {
if (KoColorSpaceMathsTraits<typename _CSTrait::channels_type>::unitValue == 1.0) {
dstColor[ _CSTrait::alpha_pos ] = totalAlpha / sumOfWeights;
} else {
dstColor[ _CSTrait::alpha_pos ] = (totalAlpha + sumOfWeights / 2) / sumOfWeights;
}
dstColor[ _CSTrait::alpha_pos ] = safeDivideWithRound(totalAlpha, sumOfWeights);
}
} else {
memset(dst, 0, sizeof(typename _CSTrait::channels_type) * _CSTrait::channels_nb);
......
......@@ -115,8 +115,8 @@ void KisControlFrame::setup(QWidget *parent)
action->setDefaultWidget(m_dual);
connect(m_dual, SIGNAL(foregroundColorChanged(KoColor)), m_viewManager->canvasResourceProvider(), SLOT(slotSetFGColor(KoColor)));
connect(m_dual, SIGNAL(backgroundColorChanged(KoColor)), m_viewManager->canvasResourceProvider(), SLOT(slotSetBGColor(KoColor)));
connect(m_viewManager->canvasResourceProvider(), SIGNAL(sigFGColorChanged(KoColor)), m_dual, SLOT(setForegroundColor(KoColor)));
connect(m_viewManager->canvasResourceProvider(), SIGNAL(sigBGColorChanged(KoColor)), m_dual, SLOT(setBackgroundColor(KoColor)));
connect(m_viewManager->canvasResourceProvider(), SIGNAL(sigFGColorChanged(KoColor)), m_dual, SLOT(setForegroundColor(KoColor)));
connect(m_viewManager->canvasResourceProvider(), SIGNAL(sigFGColorChanged(KoColor)), m_gradientWidget, SLOT(update()));
connect(m_viewManager->canvasResourceProvider(), SIGNAL(sigBGColorChanged(KoColor)), m_gradientWidget, SLOT(update()));
m_dual->setFixedSize(28, 28);
......@@ -235,8 +235,8 @@ void KisControlFrame::createGradientsChooser(KisViewManager * view)
m_gradientChooser->setFont(m_font);
m_gradientTab->addTab(m_gradientChooser, i18n("Gradients"));
connect(m_gradientChooser, SIGNAL(resourceSelected(KoResourceSP )),
view->canvasResourceProvider(), SLOT(slotGradientActivated(KoResourceSP )));
connect(m_gradientChooser, SIGNAL(resourceSelected(KoResourceSP)),
view->canvasResourceProvider(), SLOT(slotGradientActivated(KoResourceSP)));
connect (view->mainWindow(), SIGNAL(themeChanged()), m_gradientChooser, SLOT(slotUpdateIcons()));
......@@ -251,9 +251,6 @@ void KisControlFrame::createGradientsChooser(KisViewManager * view)
connect(view->canvasResourceProvider(), SIGNAL(sigGradientChanged(KoAbstractGradientSP)),
this, SLOT(slotSetGradient(KoAbstractGradientSP)));
connect(view->canvasResourceProvider(), SIGNAL(sigFGColorChanged(KoColor)), m_gradientChooser, SLOT(setForegroundColor(KoColor)));
connect(view->canvasResourceProvider(), SIGNAL(sigBGColorChanged(KoColor)), m_gradientChooser, SLOT(setBackgroundColor(KoColor)));
m_gradientChooser->setCurrentItem(0);
......
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