Commit 02bdc53a authored by Dmitry Kazakov's avatar Dmitry Kazakov

Fix wrong borders on EdgeDetection and HeightToNormalMap filters

The color data should be premultiplied by the alpha channel to
get correct result on layers with transparency.

BUG:411922
parent 7f3ce472
......@@ -237,6 +237,9 @@ void KisEdgeDetectionKernel::applyEdgeDetection(KisPaintDeviceSP device,
KisSequentialIterator finalIt(device, rect);
const int pixelSize = device->colorSpace()->pixelSize();
const int channels = device->colorSpace()->channelCount();
const int alphaPos = device->colorSpace()->alphaPos();
KIS_SAFE_ASSERT_RECOVER_RETURN(alphaPos >= 0);
QVector<float> yNormalised(channels);
QVector<float> xNormalised(channels);
QVector<float> finalNorm(channels);
......@@ -269,6 +272,7 @@ void KisEdgeDetectionKernel::applyEdgeDetection(KisPaintDeviceSP device,
memcpy(finalIt.rawData(), col.data(), pixelSize);
} else {
quint8* f = finalIt.rawData();
finalNorm[alphaPos] = 1.0;
device->colorSpace()->fromNormalisedChannelsValue(f, finalNorm);
memcpy(finalIt.rawData(), f, pixelSize);
}
......@@ -327,6 +331,13 @@ void KisEdgeDetectionKernel::applyEdgeDetection(KisPaintDeviceSP device,
srcTopLeft - QPoint(0, ceil(center)),
srcTopLeft - QPoint(0, ceil(center)),
rect.size() + QSize(0, 2 * ceil(center)), BORDER_REPEAT);
KisSequentialIterator finalIt(device, rect);
int numConseqPixels = finalIt.nConseqPixels();
while (finalIt.nextPixels(numConseqPixels)) {
numConseqPixels = finalIt.nConseqPixels();
device->colorSpace()->setOpacity(finalIt.rawData(), 1.0, numConseqPixels);
}
}
}
}
......@@ -377,6 +388,9 @@ void KisEdgeDetectionKernel::convertToNormalMap(KisPaintDeviceSP device,
KisSequentialIterator finalIt(device, rect);
const int pixelSize = device->colorSpace()->pixelSize();
const int channels = device->colorSpace()->channelCount();
const int alphaPos = device->colorSpace()->alphaPos();
KIS_SAFE_ASSERT_RECOVER_RETURN(alphaPos >= 0);
QVector<float> yNormalised(channels);
QVector<float> xNormalised(channels);
QVector<float> finalNorm(channels);
......@@ -396,6 +410,8 @@ void KisEdgeDetectionKernel::convertToNormalMap(KisPaintDeviceSP device,
finalNorm[device->colorSpace()->channels().at(channelOrder[c])->displayPosition()] = (normal[channelOrder[c]]/2)+0.5;
}
finalNorm[alphaPos]= 1.0;
quint8* pixel = finalIt.rawData();
device->colorSpace()->fromNormalisedChannelsValue(pixel, finalNorm);
memcpy(finalIt.rawData(), pixel, pixelSize);
......
......@@ -131,6 +131,11 @@ public:
*/
virtual quint32 channelCount() const = 0;
/**
* Position of the alpha channel in a pixel
*/
virtual quint32 alphaPos() const = 0;
/**
* The total number of color channels (excludes alpha) for a single
* pixel in this color model.
......
......@@ -67,6 +67,11 @@ public:
return _CSTrait::channels_nb;
}
quint32 alphaPos() const override {
return _CSTrait::alpha_pos;
}
quint32 pixelSize() const override {
return _CSTrait::pixelSize;
}
......
......@@ -69,9 +69,6 @@ void KisConvertHeightToNormalMapFilter::processImpl(KisPaintDeviceSP device, con
if (configuration) {
channelFlags = configuration->channelFlags();
}
if (channelFlags.isEmpty() || !configuration) {
channelFlags = device->colorSpace()->channelFlags();
}
KisEdgeDetectionKernel::FilterType type = KisEdgeDetectionKernel::SobelVector;
if (configuration->getString("type") == "prewitt") {
......
......@@ -75,9 +75,6 @@ void KisEdgeDetectionFilter::processImpl(KisPaintDeviceSP device, const QRect &r
if (configuration) {
channelFlags = configuration->channelFlags();
}
if (channelFlags.isEmpty() || !configuration) {
channelFlags = device->colorSpace()->channelFlags();
}
KisEdgeDetectionKernel::FilterType type = KisEdgeDetectionKernel::SobelVector;
if (config->getString("type") == "prewitt") {
......
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