Commit 07f0fd86 authored by Miguel Lopez's avatar Miguel Lopez Committed by Dmitry Kazakov

FEATURE: High Pass Filter

Implements basic version of high pass filter for Krita. More
versions may or may not to come to Krita from GIMP versions.
However, I decided not to do grayscale version as Krita already
have de-saturation filter which takes care of that part nicely.

Differential Revision: https://phabricator.kde.org/D20475
parent 68135ff0
......@@ -3,6 +3,7 @@ add_subdirectory( blur )
add_subdirectory( colors )
add_subdirectory( colorsfilters )
add_subdirectory( convolutionfilters )
add_subdirectory( guassianhighpass)
add_subdirectory( embossfilter )
add_subdirectory( example )
add_subdirectory( fastcolortransfer )
......
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})
/*
* This file is part of Krita
*
* Copyright (c) 2019 Miguel Lopez <reptillia39@live.com>
*
* 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 <kpluginfactory.h>
#include "guassianhighpass_filter.h"
#include <filter/kis_filter_registry.h>
K_PLUGIN_FACTORY_WITH_JSON(GuassianHighPassPluginFactory, "kritaguassianhighpassfilter.json", registerPlugin<GuassianHighPassPlugin>();)
GuassianHighPassPlugin::GuassianHighPassPlugin(QObject *parent, const QVariantList &)
: QObject(parent)
{
KisFilterRegistry::instance()->add(new KisGuassianHighPassFilter());
}
GuassianHighPassPlugin::~GuassianHighPassPlugin()
{
}
#include "guassianhighpass.moc"
/*
* This file is part of Krita
*
* Copyright (c) 2019 Miguel Lopez <reptillia39@live.com>
*
* 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 <QObject>
#include <QVariant>
class GuassianHighPassPlugin : public QObject
{
Q_OBJECT
public:
GuassianHighPassPlugin(QObject *parent, const QVariantList &);
~GuassianHighPassPlugin() override;
};
#endif
/*
* This file is part of Krita
*
* Copyright (c) 2019 Miguel Lopez <reptillia39@live.com>
*
* 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 <compositeops/KoVcMultiArchBuildSupport.h> //MSVC requires that Vc come first
#include "guassianhighpass_filter.h"
#include <QBitArray>
#include <KoColorSpace.h>
#include <KoChannelInfo.h>
#include <KoColor.h>
#include <kis_painter.h>
#include <kis_paint_device.h>
#include <kis_paint_layer.h>
#include <kis_group_layer.h>
#include <KoCompositeOps.h>
#include <kis_mask_generator.h>
#include <kis_gaussian_kernel.h>
#include <filter/kis_filter_category_ids.h>
#include <filter/kis_filter_configuration.h>
#include <kis_processing_information.h>
#include <KoProgressUpdater.h>
#include <KoUpdater.h>
#include <KoMixColorsOp.h>
#include <kis_paint_device.h>
#include "kis_lod_transform.h"
#include "wdg_guassianhighpass.h"
#include "ui_wdgguassianhighpass.h"
#include "KoColorSpaceTraits.h"
#include <KisSequentialIteratorProgress.h>
KisGuassianHighPassFilter::KisGuassianHighPassFilter() : KisFilter(id(), FiltersCategoryEdgeDetectionId, i18n("&Guassian High Pass..."))
{
setSupportsPainting(true);
setSupportsAdjustmentLayers(false);
setSupportsThreading(false);
setSupportsLevelOfDetail(false);
setColorSpaceIndependence(FULLY_INDEPENDENT);
}
KisConfigWidget * KisGuassianHighPassFilter::createConfigurationWidget(QWidget* parent, const KisPaintDeviceSP, bool /* useForMasks */) 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 *
) const
{
QPointer<KoUpdater> filterUpdater = 0;
QPointer<KoUpdater> convolutionUpdater = 0;
const QRect deviceBounds = device->defaultBounds()->bounds();
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();
KisPaintDeviceSP blur = new KisPaintDevice(*device);
KisGaussianKernel::applyGaussian(blur, applyRect,
blurAmount, blurAmount,
channelFlags,
convolutionUpdater);
KisPainter painter(device);
painter.setCompositeOp(blur->colorSpace()->compositeOp(COMPOSITE_GRAIN_EXTRACT));
painter.bitBlt(0, 0, blur, 0, 0, deviceBounds.width(), deviceBounds.height());
painter.end();
}
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);
}
/*
* This file is part of Krita
*
* Copyright (c) 2019 Miguel Lopez <reptillia39@live.com>
*
* 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 *
) const override;
static inline KoID id() {
return KoID("guassianhighpass", i18n("Guassian High Pass"));
}
KisConfigWidget * createConfigurationWidget(QWidget* parent, const KisPaintDeviceSP dev, bool useForMasks) 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:
};
#endif
{
"Id": "Edge Detection Filter",
"Type": "Service",
"X-KDE-Library": "kritaguassianhighpass",
"X-KDE-ServiceTypes": [
"Krita/Filter"
],
"X-Krita-Version": "40"
}
/*
* This file is part of Krita
*
* Copyright (c) 2019 Miguel Lopez <reptillia39@live.com>
*
* 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 <QLayout>
#include <QToolButton>
#include <filter/kis_filter.h>
#include <filter/kis_filter_configuration.h>
#include <kis_processing_information.h>
#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;
}
/*
* This file is part of Krita
*
* Copyright (c) 2019 Miguel Lopez <reptillia39@live.com>
*
* 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 <kis_config_widget.h>
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
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>WdgGuassianHighPass</class>
<widget class="QWidget" name="WdgGuassianHighPass">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>331</width>
<height>167</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="textLabel1">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Radius:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="2" rowspan="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="KisDoubleParseSpinBox" name="doubleblurAmount">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximum">
<double>250.000000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>21</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KisDoubleParseSpinBox</class>
<extends>QDoubleSpinBox</extends>
<header>kis_double_parse_spin_box.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
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