diff --git a/plugins/filters/CMakeLists.txt b/plugins/filters/CMakeLists.txt --- a/plugins/filters/CMakeLists.txt +++ b/plugins/filters/CMakeLists.txt @@ -3,6 +3,7 @@ add_subdirectory( colors ) add_subdirectory( colorsfilters ) add_subdirectory( convolutionfilters ) +add_subdirectory( guassianhighpass) add_subdirectory( embossfilter ) add_subdirectory( example ) add_subdirectory( fastcolortransfer ) diff --git a/plugins/filters/guassianhighpass/CMakeLists.txt b/plugins/filters/guassianhighpass/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/plugins/filters/guassianhighpass/CMakeLists.txt @@ -0,0 +1,15 @@ +set(kritahighpassfilter_SOURCES + guassianhighpass.cpp + wdg_guassianhighpass.cpp + guassianhighpass_filter.cpp + ) + +ki18n_wrap_ui(kritahighpassfilter_SOURCES + wdgguassianhighpass.ui + ) + +add_library(kritaguassianhighpassfilter MODULE ${kritahighpassfilter_SOURCES}) + +target_link_libraries(kritaguassianhighpassfilter kritaui) + +install(TARGETS kritaguassianhighpassfilter DESTINATION ${KRITA_PLUGIN_INSTALL_DIR}) diff --git a/plugins/filters/guassianhighpass/guassianhighpass.h b/plugins/filters/guassianhighpass/guassianhighpass.h new file mode 100644 --- /dev/null +++ b/plugins/filters/guassianhighpass/guassianhighpass.h @@ -0,0 +1,35 @@ +/* + * This file is part of Krita + * + * Copyright (c) 2019 Miguel Lopez + * + * 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 _GUASSIANHIGHPASS_PLUGIN_H_ +#define _GUASSIANHIGHPASS_PLUGIN_H_ + +#include +#include + +class GuassianHighPassPlugin : public QObject +{ + Q_OBJECT +public: + GuassianHighPassPlugin(QObject *parent, const QVariantList &); + ~GuassianHighPassPlugin() override; +}; + +#endif diff --git a/plugins/filters/guassianhighpass/guassianhighpass.cpp b/plugins/filters/guassianhighpass/guassianhighpass.cpp new file mode 100644 --- /dev/null +++ b/plugins/filters/guassianhighpass/guassianhighpass.cpp @@ -0,0 +1,41 @@ +/* + * This file is part of Krita + * + * Copyright (c) 2019 Miguel Lopez + * + * 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 "guassianhighpass.h" +#include + +#include "guassianhighpass_filter.h" + +#include + +K_PLUGIN_FACTORY_WITH_JSON(GuassianHighPassPluginFactory, "kritaguassianhighpassfilter.json", registerPlugin();) + +GuassianHighPassPlugin::GuassianHighPassPlugin(QObject *parent, const QVariantList &) + : QObject(parent) +{ + KisFilterRegistry::instance()->add(new KisGuassianHighPassFilter()); + +} + +GuassianHighPassPlugin::~GuassianHighPassPlugin() +{ +} + +#include "guassianhighpass.moc" diff --git a/plugins/filters/guassianhighpass/guassianhighpass_filter.h b/plugins/filters/guassianhighpass/guassianhighpass_filter.h new file mode 100644 --- /dev/null +++ b/plugins/filters/guassianhighpass/guassianhighpass_filter.h @@ -0,0 +1,57 @@ +/* + * This file is part of Krita + * + * Copyright (c) 2019 Miguel Lopez + * + * 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_GUASSIANHIGHPASS_FILTER_H +#define KIS_GUASSIANHIGHPASS_FILTER_H + +#include "filter/kis_filter.h" + +class KisGuassianHighPassFilter : public KisFilter +{ +public: + + KisGuassianHighPassFilter(); + + void processImpl(KisPaintDeviceSP device, + const QRect& applyRect, + const KisFilterConfigurationSP config, + KoUpdater* progressUpdater + ) const override; + + static inline KoID id() { + return KoID("guassianhighpass", i18n("Guassian High Pass")); + } + + KisConfigWidget * createConfigurationWidget(QWidget* parent, const KisPaintDeviceSP dev) const override; + KisFilterConfigurationSP factoryConfiguration() const override; + + QRect changedRect(const QRect & rect, const KisFilterConfigurationSP _config, int lod) const override; + QRect neededRect(const QRect & rect, const KisFilterConfigurationSP _config, int lod) const override; + +private: + + void processRaw(KisPaintDeviceSP device, + const QRect &rect, + qreal weights[1], + qreal factor, + const QBitArray &channelFlags, KoUpdater *progressUpdater) const; +}; + +#endif diff --git a/plugins/filters/guassianhighpass/guassianhighpass_filter.cpp b/plugins/filters/guassianhighpass/guassianhighpass_filter.cpp new file mode 100644 --- /dev/null +++ b/plugins/filters/guassianhighpass/guassianhighpass_filter.cpp @@ -0,0 +1,161 @@ +/* + * This file is part of Krita + * + * Copyright (c) 2019 Miguel Lopez + * + * 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 "guassianhighpass_filter.h" +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "kis_lod_transform.h" + +#include "wdg_guassianhighpass.h" +#include "ui_wdgguassianhighpass.h" +#include "KoColorSpaceTraits.h" +#include + + +KisGuassianHighPassFilter::KisGuassianHighPassFilter() : KisFilter(id(), FiltersCategoryEdgeDetectionId, i18n("&Guassian High Pass...")) +{ + setSupportsPainting(true); + setSupportsAdjustmentLayers(true); + setSupportsThreading(true); + setSupportsLevelOfDetail(false); + setColorSpaceIndependence(FULLY_INDEPENDENT); +} + +KisConfigWidget * KisGuassianHighPassFilter::createConfigurationWidget(QWidget* parent, const KisPaintDeviceSP) const +{ + return new KisWdgGuassianHighPass(parent); +} + +KisFilterConfigurationSP KisGuassianHighPassFilter::factoryConfiguration() const +{ + KisFilterConfigurationSP config = new KisFilterConfiguration(id().id(), 1); + config->setProperty("blurAmount", 1); + return config; +} + +void KisGuassianHighPassFilter::processImpl(KisPaintDeviceSP device, + const QRect& applyRect, + const KisFilterConfigurationSP _config, + KoUpdater* progressUpdater + ) const +{ + + QPointer filterUpdater = 0; + QPointer convolutionUpdater = 0; + QScopedPointer updater; + + if (progressUpdater) { + updater.reset(new KoProgressUpdater(progressUpdater)); + updater->start(100, i18n("Guassian High Pass")); + // Two sub-sub tasks that each go from 0 to 100. + convolutionUpdater = updater->startSubtask(); + filterUpdater = updater->startSubtask(); + } + + KisFilterConfigurationSP config = _config ? _config : new KisFilterConfiguration(id().id(), 1); + + QVariant value; + + KisLodTransformScalar t(device); + + const qreal blurAmount = t.scale(config->getProperty("blurAmount", value) ? value.toDouble() : 1.0); + + QBitArray channelFlags = config->channelFlags(); + KisGaussianKernel::applyGaussian(device, applyRect, + blurAmount, blurAmount, + channelFlags, + convolutionUpdater); + + qreal weights[2]; + qreal factor = 128; + + weights[0] = -factor; + weights[1] = 128; + + { + processRaw(device, applyRect, weights, factor, channelFlags, filterUpdater); + } +} + +void KisGuassianHighPassFilter::processRaw(KisPaintDeviceSP device, + const QRect &rect, + qreal weights[2], + qreal factor, + const QBitArray &channelFlags, + KoUpdater *progressUpdater) const +{ + const KoColorSpace *cs = device->colorSpace(); + const int pixelSize = cs->pixelSize(); + KoConvolutionOp * convolutionOp = cs->convolutionOp(); + KoColorTransformation * createInvertTransformation = cs->createInvertTransformation(); + KoMixColorsOp * mixColorsOp = cs->mixColorsOp(); + + quint8 *colors[2]; + colors[0] = new quint8[pixelSize]; + colors[1] = new quint8[pixelSize]; + + KisSequentialIteratorProgress dstIt(device, rect, progressUpdater); + + while (dstIt.nextPixel()) { + { + memcpy(colors[0], dstIt.oldRawData(), pixelSize); + memcpy(colors[1], dstIt.rawDataConst(), pixelSize); + convolutionOp->convolveColors(colors, weights, dstIt.rawData(), factor, 0, 2, channelFlags); + createInvertTransformation->transform(dstIt.rawDataConst(), dstIt.rawData(),1); + mixColorsOp->mixColors(dstIt.oldRawData(), 1, dstIt.rawData()); + } + } + + delete[] colors[0]; + delete[] colors[1]; +} + +QRect KisGuassianHighPassFilter::neededRect(const QRect & rect, const KisFilterConfigurationSP config, int lod) const +{ + KisLodTransformScalar t(lod); + + QVariant value; + const qreal blurAmount = t.scale(config->getProperty("blurAmount", value) ? value.toDouble() : 1.0); + + return rect.adjusted(-blurAmount * 2, -blurAmount * 2, blurAmount * 2, blurAmount * 2); +} + +QRect KisGuassianHighPassFilter::changedRect(const QRect & rect, const KisFilterConfigurationSP config, int lod) const +{ + KisLodTransformScalar t(lod); + + QVariant value; + const qreal blurAmount = t.scale(config->getProperty("blurAmount", value) ? value.toDouble() : 1.0); + + return rect.adjusted( -blurAmount, -blurAmount, blurAmount, blurAmount); +} diff --git a/plugins/filters/guassianhighpass/kritaguassianhighpassfilter.json b/plugins/filters/guassianhighpass/kritaguassianhighpassfilter.json new file mode 100644 --- /dev/null +++ b/plugins/filters/guassianhighpass/kritaguassianhighpassfilter.json @@ -0,0 +1,9 @@ +{ + "Id": "Edge Detection Filter", + "Type": "Service", + "X-KDE-Library": "kritaguassianhighpass", + "X-KDE-ServiceTypes": [ + "Krita/Filter" + ], + "X-Krita-Version": "40" +} diff --git a/plugins/filters/guassianhighpass/wdg_guassianhighpass.h b/plugins/filters/guassianhighpass/wdg_guassianhighpass.h new file mode 100644 --- /dev/null +++ b/plugins/filters/guassianhighpass/wdg_guassianhighpass.h @@ -0,0 +1,43 @@ +/* + * This file is part of Krita + * + * Copyright (c) 2019 Miguel Lopez + * + * 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_WDG_GUASSIANHIGHPASS_H_ +#define _KIS_WDG_GUASSIANHIGHPASS_H_ + +#include + +class Ui_WdgGuassianHighPass; + +class KisWdgGuassianHighPass : public KisConfigWidget +{ + Q_OBJECT +public: + KisWdgGuassianHighPass(QWidget * parent); + ~KisWdgGuassianHighPass() override; + inline const Ui_WdgGuassianHighPass* widget() const { + return m_widget; + } + void setConfiguration(const KisPropertiesConfigurationSP) override; + KisPropertiesConfigurationSP configuration() const override; +private: + Ui_WdgGuassianHighPass* m_widget; +}; + +#endif diff --git a/plugins/filters/guassianhighpass/wdg_guassianhighpass.cpp b/plugins/filters/guassianhighpass/wdg_guassianhighpass.cpp new file mode 100644 --- /dev/null +++ b/plugins/filters/guassianhighpass/wdg_guassianhighpass.cpp @@ -0,0 +1,57 @@ +/* + * This file is part of Krita + * + * Copyright (c) 2019 Miguel Lopez + * + * 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 "wdg_guassianhighpass.h" +#include +#include + +#include +#include +#include + +#include "ui_wdgguassianhighpass.h" + +KisWdgGuassianHighPass::KisWdgGuassianHighPass(QWidget * parent) : KisConfigWidget(parent) +{ + m_widget = new Ui_WdgGuassianHighPass(); + m_widget->setupUi(this); + + connect(widget()->doubleblurAmount, SIGNAL(valueChanged(double)), SIGNAL(sigConfigurationItemChanged())); +} + +KisWdgGuassianHighPass::~KisWdgGuassianHighPass() +{ + delete m_widget; +} + +void KisWdgGuassianHighPass::setConfiguration(const KisPropertiesConfigurationSP config) +{ + QVariant value; + widget()->doubleblurAmount->setValue((config->getProperty("blurAmount", value)) ? value.toDouble() : 1.0); +} + +KisPropertiesConfigurationSP KisWdgGuassianHighPass::configuration() const +{ + KisFilterConfigurationSP config = new KisFilterConfiguration("guassianhighpass", 1); + config->setProperty("blurAmount", widget()->doubleblurAmount->value()); + return config; +} + + diff --git a/plugins/filters/guassianhighpass/wdgguassianhighpass.ui b/plugins/filters/guassianhighpass/wdgguassianhighpass.ui new file mode 100644 --- /dev/null +++ b/plugins/filters/guassianhighpass/wdgguassianhighpass.ui @@ -0,0 +1,89 @@ + + + WdgGuassianHighPass + + + + 0 + 0 + 331 + 167 + + + + + + + + 0 + 0 + + + + Radius: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + false + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + 250.000000000000000 + + + 1.000000000000000 + + + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 20 + 21 + + + + + + + + + KisDoubleParseSpinBox + QDoubleSpinBox +
kis_double_parse_spin_box.h
+
+
+ + +