diff --git a/libs/image/kis_convolution_painter.cc b/libs/image/kis_convolution_painter.cc index 7ec9e31ca4..384f59f55f 100644 --- a/libs/image/kis_convolution_painter.cc +++ b/libs/image/kis_convolution_painter.cc @@ -1,189 +1,189 @@ /* * 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 "kis_convolution_painter.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "kis_convolution_kernel.h" #include "kis_global.h" #include "kis_image.h" #include "kis_layer.h" #include "kis_paint_device.h" #include "kis_painter.h" #include "KoColorSpace.h" #include #include "kis_types.h" #include "kis_selection.h" #include "kis_convolution_worker.h" #include "kis_convolution_worker_spatial.h" #include "config_convolution.h" #ifdef HAVE_FFTW3 #include "kis_convolution_worker_fft.h" #endif -bool KisConvolutionPainter::useFFTImplemenation(const KisConvolutionKernelSP kernel) const +bool KisConvolutionPainter::useFFTImplementation(const KisConvolutionKernelSP kernel) const { bool result = false; #ifdef HAVE_FFTW3 #define THRESHOLD_SIZE 5 result = m_enginePreference == FFTW || (m_enginePreference == NONE && (kernel->width() > THRESHOLD_SIZE || kernel->height() > THRESHOLD_SIZE)); #else Q_UNUSED(kernel); #endif return result; } template KisConvolutionWorker* KisConvolutionPainter::createWorker(const KisConvolutionKernelSP kernel, KisPainter *painter, KoUpdater *progress) { KisConvolutionWorker *worker; #ifdef HAVE_FFTW3 - if (useFFTImplemenation(kernel)) { + if (useFFTImplementation(kernel)) { worker = new KisConvolutionWorkerFFT(painter, progress); } else { worker = new KisConvolutionWorkerSpatial(painter, progress); } #else Q_UNUSED(kernel); worker = new KisConvolutionWorkerSpatial(painter, progress); #endif return worker; } bool KisConvolutionPainter::supportsFFTW() { #ifdef HAVE_FFTW3 return true; #else return false; #endif } KisConvolutionPainter::KisConvolutionPainter() : KisPainter(), m_enginePreference(NONE) { } KisConvolutionPainter::KisConvolutionPainter(KisPaintDeviceSP device) : KisPainter(device), m_enginePreference(NONE) { } KisConvolutionPainter::KisConvolutionPainter(KisPaintDeviceSP device, KisSelectionSP selection) : KisPainter(device, selection), m_enginePreference(NONE) { } KisConvolutionPainter::KisConvolutionPainter(KisPaintDeviceSP device, TestingEnginePreference enginePreference) : KisPainter(device), m_enginePreference(enginePreference) { } void KisConvolutionPainter::applyMatrix(const KisConvolutionKernelSP kernel, const KisPaintDeviceSP src, QPoint srcPos, QPoint dstPos, QSize areaSize, KisConvolutionBorderOp borderOp) { /** * Force BORDER_IGNORE op for the wraparound mode, * because the paint device has its own special * iterators, which do everything for us. */ if (src->defaultBounds()->wrapAroundMode()) { borderOp = BORDER_IGNORE; } // Determine whether we convolve border pixels, or not. switch (borderOp) { case BORDER_REPEAT: { const QRect boundsRect = src->defaultBounds()->bounds(); const QRect requestedRect = QRect(srcPos, areaSize); QRect dataRect = requestedRect | boundsRect; KIS_SAFE_ASSERT_RECOVER(boundsRect != KisDefaultBounds().bounds()) { dataRect = requestedRect | src->exactBounds(); } /** * FIXME: Implementation can return empty destination device * on faults and has no way to report this. This will cause a crash * on sequential convolutions inside iteratiors. * * o implementation should do it's work or assert otherwise * (or report the issue somehow) * o check other cases of the switch for the vulnerability */ if(dataRect.isValid()) { KisConvolutionWorker *worker; worker = createWorker(kernel, this, progressUpdater()); worker->execute(kernel, src, srcPos, dstPos, areaSize, dataRect); delete worker; } break; } case BORDER_IGNORE: default: { KisConvolutionWorker *worker; worker = createWorker(kernel, this, progressUpdater()); worker->execute(kernel, src, srcPos, dstPos, areaSize, QRect()); delete worker; } } } bool KisConvolutionPainter::needsTransaction(const KisConvolutionKernelSP kernel) const { - return !useFFTImplemenation(kernel); + return !useFFTImplementation(kernel); } diff --git a/libs/image/kis_convolution_painter.h b/libs/image/kis_convolution_painter.h index 4f0a17910d..2db38414a7 100644 --- a/libs/image/kis_convolution_painter.h +++ b/libs/image/kis_convolution_painter.h @@ -1,104 +1,104 @@ /* * 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 KIS_CONVOLUTION_PAINTER_H_ #define KIS_CONVOLUTION_PAINTER_H_ #include "kis_types.h" #include "kis_painter.h" #include "kis_image.h" #include "kritaimage_export.h" template class KisConvolutionWorker; enum KisConvolutionBorderOp { BORDER_IGNORE = 0, // read the pixels outside of the application rect BORDER_REPEAT = 1 // Use the border for the missing pixels }; /** * @brief The KisConvolutionPainter class applies a convolution kernel to a paint device. * * * Note: https://bugs.kde.org/show_bug.cgi?id=220310 shows that there's something here * that we need to fix... */ class KRITAIMAGE_EXPORT KisConvolutionPainter : public KisPainter { public: KisConvolutionPainter(); KisConvolutionPainter(KisPaintDeviceSP device); KisConvolutionPainter(KisPaintDeviceSP device, KisSelectionSP selection); enum TestingEnginePreference { NONE, SPATIAL, FFTW }; KisConvolutionPainter(KisPaintDeviceSP device, TestingEnginePreference enginePreference); /** * Convolve all channels in src using the specified kernel; there is only one kernel for all * channels possible. By default the border pixels are not convolved, that is, convolving * starts with at (x + kernel.width/2, y + kernel.height/2) and stops at w - (kernel.width/2) * and h - (kernel.height/2) * * The border op decides what to do with pixels too close to the edge of the rect as defined above. * * The channels flag determines which set out of color channels, alpha channels. * channels we convolve. * * Note that we do not (currently) support different kernels for * different channels _or_ channel types. * * If you want to convolve a subset of the channels in a pixel, * set those channels with KisPainter::setChannelFlags(); */ void applyMatrix(const KisConvolutionKernelSP kernel, const KisPaintDeviceSP src, QPoint srcPos, QPoint dstPos, QSize areaSize, KisConvolutionBorderOp borderOp = BORDER_REPEAT); /** * The caller should ask if the painter needs an explicit transaction iff * the source and destination devices coincide. Otherwise, the transaction is * just not needed. */ bool needsTransaction(const KisConvolutionKernelSP kernel) const; static bool supportsFFTW(); protected: friend class KisConvolutionPainterTest; private: template KisConvolutionWorker* createWorker(const KisConvolutionKernelSP kernel, KisPainter *painter, KoUpdater *progress); - bool useFFTImplemenation(const KisConvolutionKernelSP kernel) const; + bool useFFTImplementation(const KisConvolutionKernelSP kernel) const; private: TestingEnginePreference m_enginePreference; }; #endif //KIS_CONVOLUTION_PAINTER_H_