diff --git a/plugins/filters/convolutionfilters/kis_convolution_filter.cpp b/plugins/filters/convolutionfilters/kis_convolution_filter.cpp index 23080fe6ea..d91e293303 100644 --- a/plugins/filters/convolutionfilters/kis_convolution_filter.cpp +++ b/plugins/filters/convolutionfilters/kis_convolution_filter.cpp @@ -1,71 +1,89 @@ /* * This file is part of the KDE project * * Copyright (c) 2004 Cyrille Berger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kis_convolution_filter.h" #include #include #include #include "kis_painter.h" #include "kis_convolution_painter.h" #include "kis_convolution_kernel.h" #include #include #include #include +#include "kis_lod_transform.h" KisConvolutionFilter::KisConvolutionFilter(const KoID& id, const KoID & category, const QString & entry) : KisFilter(id, category, entry) { setColorSpaceIndependence(FULLY_INDEPENDENT); + setSupportsLevelOfDetail(true); } void KisConvolutionFilter::processImpl(KisPaintDeviceSP device, const QRect& applyRect, const KisFilterConfigurationSP config, KoUpdater* progressUpdater) const { Q_UNUSED(config); QPoint srcTopLeft = applyRect.topLeft(); Q_ASSERT(device != 0); KisConvolutionPainter painter(device); QBitArray channelFlags; if (config) { channelFlags = config->channelFlags(); } if (channelFlags.isEmpty() || !config) { channelFlags = QBitArray(device->colorSpace()->channelCount(), true); } painter.setChannelFlags(channelFlags); painter.setProgress(progressUpdater); painter.applyMatrix(m_matrix, device, srcTopLeft, srcTopLeft, applyRect.size(), BORDER_REPEAT); } +QRect KisConvolutionFilter::neededRect(const QRect &rect, const KisFilterConfigurationSP _config, int lod) const +{ + Q_UNUSED(_config); + + KisLodTransformScalar t(lod); + + const int windowsize = qMax(m_matrix->width(), m_matrix->height()); + const int margin = qCeil(t.scale(0.5 * windowsize)) + 1; + return kisGrowRect(rect, margin); +} + +QRect KisConvolutionFilter::changedRect(const QRect &rect, const KisFilterConfigurationSP _config, int lod) const +{ + return neededRect(rect, _config, lod); +} + void KisConvolutionFilter::setIgnoreAlpha(bool v) { m_ignoreAlpha = v; } diff --git a/plugins/filters/convolutionfilters/kis_convolution_filter.h b/plugins/filters/convolutionfilters/kis_convolution_filter.h index ab7cdb45d9..5026b22497 100644 --- a/plugins/filters/convolutionfilters/kis_convolution_filter.h +++ b/plugins/filters/convolutionfilters/kis_convolution_filter.h @@ -1,47 +1,51 @@ /* * This file is part of Krita * * Copyright (c) 2004 Cyrille Berger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _KIS_CONVOLUTION_FILTER_H_ #define _KIS_CONVOLUTION_FILTER_H_ #include "filter/kis_filter.h" #include "filter/kis_filter_registry.h" #include "filter/kis_filter_configuration.h" #include "kis_convolution_painter.h" class KisConvolutionFilter : public KisFilter { public: KisConvolutionFilter(const KoID& id, const KoID & category, const QString & entry); public: void processImpl(KisPaintDeviceSP device, const QRect& applyRect, const KisFilterConfigurationSP config, KoUpdater* progressUpdater) const override; + + QRect neededRect(const QRect & rect, const KisFilterConfigurationSP _config, int lod) const override; + QRect changedRect(const QRect & rect, const KisFilterConfigurationSP _config, int lod) const override; + protected: void setIgnoreAlpha(bool v); protected: KisConvolutionKernelSP m_matrix; bool m_ignoreAlpha; }; #endif diff --git a/plugins/filters/imageenhancement/kis_simple_noise_reducer.cpp b/plugins/filters/imageenhancement/kis_simple_noise_reducer.cpp index fccafd3542..cf8331c46a 100644 --- a/plugins/filters/imageenhancement/kis_simple_noise_reducer.cpp +++ b/plugins/filters/imageenhancement/kis_simple_noise_reducer.cpp @@ -1,113 +1,128 @@ /* * Copyright (c) 2005 Cyrille Berger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include //MSVC requires that Vc come first #include "kis_simple_noise_reducer.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include +#include "kis_lod_transform.h" KisSimpleNoiseReducer::KisSimpleNoiseReducer() : KisFilter(id(), FiltersCategoryEnhanceId, i18n("&Gaussian Noise Reduction...")) { setSupportsPainting(false); + setSupportsLevelOfDetail(true); } KisSimpleNoiseReducer::~KisSimpleNoiseReducer() { } KisConfigWidget * KisSimpleNoiseReducer::createConfigurationWidget(QWidget* parent, const KisPaintDeviceSP dev, bool) const { Q_UNUSED(dev); vKisIntegerWidgetParam param; param.push_back(KisIntegerWidgetParam(0, 255, 15, i18n("Threshold"), "threshold")); param.push_back(KisIntegerWidgetParam(0, 10, 1, i18n("Window size"), "windowsize")); return new KisMultiIntegerFilterWidget(id().id(), parent, id().id(), param); } KisFilterConfigurationSP KisSimpleNoiseReducer::factoryConfiguration() const { KisFilterConfigurationSP config = new KisFilterConfiguration(id().id(), 0); config->setProperty("threshold", 15); config->setProperty("windowsize", 1); return config; } inline int ABS(int v) { if (v < 0) return -v; return v; } void KisSimpleNoiseReducer::processImpl(KisPaintDeviceSP device, const QRect& applyRect, const KisFilterConfigurationSP _config, KoUpdater* progressUpdater ) const { QPoint srcTopLeft = applyRect.topLeft(); Q_ASSERT(device); KisFilterConfigurationSP config = _config ? _config : defaultConfiguration(); const int threshold = config->getInt("threshold", 15); const int windowsize = config->getInt("windowsize", 1); const KoColorSpace* cs = device->colorSpace(); // Compute the blur mask KisCircleMaskGenerator* kas = new KisCircleMaskGenerator(2*windowsize + 1, 1, windowsize, windowsize, 2, true); KisConvolutionKernelSP kernel = KisConvolutionKernel::fromMaskGenerator(kas); delete kas; KisPaintDeviceSP interm = new KisPaintDevice(*device); // TODO no need for a full copy and then a transaction KisConvolutionPainter painter(interm); painter.beginTransaction(); painter.applyMatrix(kernel, interm, srcTopLeft, srcTopLeft, applyRect.size(), BORDER_REPEAT); painter.deleteTransaction(); KisSequentialConstIteratorProgress intermIt(interm, applyRect, progressUpdater); KisSequentialIterator dstIt(device, applyRect); while (dstIt.nextPixel() && intermIt.nextPixel()) { const quint8 diff = cs->difference(dstIt.oldRawData(), intermIt.oldRawData()); if (diff > threshold) { memcpy(dstIt.rawData(), intermIt.oldRawData(), cs->pixelSize()); } } } +QRect KisSimpleNoiseReducer::neededRect(const QRect & rect, const KisFilterConfigurationSP _config, int lod) const +{ + KisLodTransformScalar t(lod); + + const int windowsize = _config->getInt("windowsize", 1); + const int margin = qCeil(t.scale(qreal(windowsize))) + 1; + return kisGrowRect(rect, margin); +} + +QRect KisSimpleNoiseReducer::changedRect(const QRect & rect, const KisFilterConfigurationSP _config, int lod) const +{ + return neededRect(rect, _config, lod); +} diff --git a/plugins/filters/imageenhancement/kis_simple_noise_reducer.h b/plugins/filters/imageenhancement/kis_simple_noise_reducer.h index 2766507f16..dbdf44b604 100644 --- a/plugins/filters/imageenhancement/kis_simple_noise_reducer.h +++ b/plugins/filters/imageenhancement/kis_simple_noise_reducer.h @@ -1,48 +1,52 @@ /* a * Copyright (c) 2005 Cyrille Berger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KISSIMPLENOISEREDUCER_H #define KISSIMPLENOISEREDUCER_H #include #include "kis_config_widget.h" /** @author Cyrille Berger */ class KisSimpleNoiseReducer : public KisFilter { public: KisSimpleNoiseReducer(); ~KisSimpleNoiseReducer() override; public: void processImpl(KisPaintDeviceSP device, const QRect& applyRect, const KisFilterConfigurationSP config, KoUpdater* progressUpdater ) const override; KisConfigWidget * createConfigurationWidget(QWidget* parent, const KisPaintDeviceSP dev, bool useForMasks) const override; static inline KoID id() { return KoID("gaussiannoisereducer", i18n("Gaussian Noise Reducer")); } + + QRect changedRect(const QRect &rect, const KisFilterConfigurationSP _config, int lod) const override; + QRect neededRect(const QRect &rect, const KisFilterConfigurationSP _config, int lod) const override; + protected: KisFilterConfigurationSP factoryConfiguration() const override; }; #endif