diff --git a/plugins/filters/gradientmap/CMakeLists.txt b/plugins/filters/gradientmap/CMakeLists.txt index 45841ff50c..2cda03575a 100644 --- a/plugins/filters/gradientmap/CMakeLists.txt +++ b/plugins/filters/gradientmap/CMakeLists.txt @@ -1,7 +1,8 @@ -set(kritagradientmap_SOURCES gradientmap.cpp krita_gradient_map_color_transformation.cpp krita_filter_gradient_map.cpp) +set(kritagradientmap_SOURCES gradientmap.cpp +krita_filter_gradient_map.cpp) ki18n_wrap_ui(kritagradientmap_SOURCES wdg_gradientmap.ui) add_library(kritagradientmap MODULE ${kritagradientmap_SOURCES}) target_link_libraries(kritagradientmap kritaui) install(TARGETS kritagradientmap DESTINATION ${KRITA_PLUGIN_INSTALL_DIR}) diff --git a/plugins/filters/gradientmap/gradientmap.cpp b/plugins/filters/gradientmap/gradientmap.cpp index 37b01d46d8..c8a6eefa47 100644 --- a/plugins/filters/gradientmap/gradientmap.cpp +++ b/plugins/filters/gradientmap/gradientmap.cpp @@ -1,120 +1,92 @@ /* * This file is part of the KDE project * * Copyright (c) 2016 Spencer Brown * 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 "QObject" #include "gradientmap.h" #include #include #include "krita_filter_gradient_map.h" -#include "krita_gradient_map_color_transformation.h" +#include "KoResourceServerProvider.h" #include "kis_config_widget.h" K_PLUGIN_FACTORY_WITH_JSON(KritaGradientMapFactory, "kritagradientmap.json", registerPlugin();) KritaGradientMapConfigWidget::KritaGradientMapConfigWidget(QWidget *parent, KisPaintDeviceSP dev, Qt::WFlags f) : KisConfigWidget(parent, f) { Q_UNUSED(dev) m_page = new WdgGradientMap(this); QHBoxLayout *l = new QHBoxLayout(this); Q_CHECK_PTR(l); l->addWidget(m_page); l->setContentsMargins(0, 0, 0, 0); connect(m_page->gradientchooser, SIGNAL(resourceSelected(KoResource*)), SIGNAL(sigConfigurationItemChanged())); } KritaGradientMapConfigWidget::~KritaGradientMapConfigWidget() { delete m_page; } void KritaGradientMapConfigWidget::gradientResourceChanged(KoResource* gradient) { Q_UNUSED(gradient) } -KritaGradientMapFilterConfiguration* KritaGradientMapConfigWidget::configuration() const +KisFilterConfiguration* KritaGradientMapConfigWidget::configuration() const { - KritaGradientMapFilterConfiguration* cfg = new KritaGradientMapFilterConfiguration(); - const KoResource* gradient; - if (!(gradient = m_page->gradientchooser->currentResource())) - { - m_page->gradientchooser->setCurrentItem(0, 0); - gradient = m_page->gradientchooser->currentResource(); - } - cfg->setGradient(gradient); + KisFilterConfiguration* cfg = new KisFilterConfiguration("gradientmap", 1); + QString gradientName; + gradientName = m_page->gradientchooser->currentResource()->name(); + cfg->setProperty("gradientName", gradientName); return cfg; } //----------------------------- void KritaGradientMapConfigWidget::setConfiguration(const KisPropertiesConfiguration* config) { - const KritaGradientMapFilterConfiguration* cfg = dynamic_cast (config); - Q_ASSERT(cfg); - Q_UNUSED(cfg); + m_page->gradientchooser->setCurrentResource(KoResourceServerProvider::instance()->gradientServer(false)->resourceByName(config->getString("gradientName"))); + Q_ASSERT(config); + Q_UNUSED(config); } void KritaGradientMapConfigWidget::setView(KisViewManager *view) { Q_UNUSED(view) } - -//----------------------------- - -KritaGradientMapFilterConfiguration::KritaGradientMapFilterConfiguration() - : KisColorTransformationConfiguration("gradientmap", 1) -{ - -} - -KritaGradientMapFilterConfiguration::~KritaGradientMapFilterConfiguration() -{ -} - -void KritaGradientMapFilterConfiguration::setGradient(const KoResource* gradient) -{ - m_gradient = gradient; -} - -const KoResource* KritaGradientMapFilterConfiguration::gradient() const -{ - return m_gradient; -} - -//----------------------------- - +//------------------------------ KritaGradientMap::KritaGradientMap(QObject *parent, const QVariantList &) : QObject(parent) { KisFilterRegistry::instance()->add(KisFilterSP(new KritaFilterGradientMap())); } KritaGradientMap::~KritaGradientMap() { } //----------------------------- #include "gradientmap.moc" diff --git a/plugins/filters/gradientmap/gradientmap.h b/plugins/filters/gradientmap/gradientmap.h index 812e4f55c2..78c6f7aa62 100644 --- a/plugins/filters/gradientmap/gradientmap.h +++ b/plugins/filters/gradientmap/gradientmap.h @@ -1,74 +1,60 @@ /* * This file is part of Krita * * Copyright (c) 2016 Spencer Brown * * 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. */ #pragma once #include "QObject" #include "ui_wdg_gradientmap.h" #include "kis_properties_configuration.h" #include "filter/kis_color_transformation_configuration.h" #include "kis_config_widget.h" class WdgGradientMap : public QWidget, public Ui::WdgGradientMap { Q_OBJECT public: WdgGradientMap(QWidget *parent) : QWidget(parent) { setupUi(this); } }; -class KritaGradientMapFilterConfiguration : public KisColorTransformationConfiguration -{ -public: - KritaGradientMapFilterConfiguration(); - virtual ~KritaGradientMapFilterConfiguration(); - - virtual void setGradient(const KoResource* gradient); - - virtual const KoResource* gradient() const; - -private: - KoResource const* m_gradient; -}; - class KritaGradientMapConfigWidget : public KisConfigWidget { Q_OBJECT public: KritaGradientMapConfigWidget(QWidget *parent, KisPaintDeviceSP dev, Qt::WFlags f = 0); virtual ~KritaGradientMapConfigWidget(); - virtual KritaGradientMapFilterConfiguration* configuration() const; + virtual KisFilterConfiguration *configuration() const; virtual void setConfiguration(const KisPropertiesConfiguration* config); WdgGradientMap * m_page; void setView(KisViewManager *view); void gradientResourceChanged(KoResource *gradient); }; class KritaGradientMap : public QObject { Q_OBJECT public: KritaGradientMap(QObject *parent, const QVariantList &); virtual ~KritaGradientMap(); }; diff --git a/plugins/filters/gradientmap/krita_filter_gradient_map.cpp b/plugins/filters/gradientmap/krita_filter_gradient_map.cpp index 84982addf2..44b7b081ff 100644 --- a/plugins/filters/gradientmap/krita_filter_gradient_map.cpp +++ b/plugins/filters/gradientmap/krita_filter_gradient_map.cpp @@ -1,49 +1,99 @@ /* * This file is part of the KDE project * * Copyright (c) 2016 Spencer Brown * 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 "krita_filter_gradient_map.h" -#include "KoColorSpace.h" +#include +#include + +#include +#include +#include + #include "kis_config_widget.h" -#include "filter/kis_color_transformation_filter.h" +#include +#include +#include +#include #include "gradientmap.h" -#include "krita_gradient_map_color_transformation.h" + +#include -KritaFilterGradientMap::KritaFilterGradientMap() : KisColorTransformationFilter(id(), categoryMap(), i18n("&Gradient Map")) +KritaFilterGradientMap::KritaFilterGradientMap() : KisFilter(id(), categoryMap(), i18n("&Gradient Map")) { - setColorSpaceIndependence(TO_LAB16); + setColorSpaceIndependence(FULLY_INDEPENDENT); setShowConfigurationWidget(true); // don't support anything just yet because of thread safety problems - setSupportsPainting(false); - setSupportsAdjustmentLayers(false); - setSupportsThreading(false); + setSupportsLevelOfDetail(true); + setSupportsPainting(true); + setSupportsAdjustmentLayers(true); + setSupportsThreading(true); } -KoColorTransformation* KritaFilterGradientMap::createTransformation(const KoColorSpace* cs, const KisFilterConfiguration* config) const +void KritaFilterGradientMap::processImpl(KisPaintDeviceSP device, + const QRect& applyRect, + const KisFilterConfiguration *config, + KoUpdater *progressUpdater) const { - auto gradient = static_cast(dynamic_cast(config)->gradient()); + Q_ASSERT(!device.isNull()); + + if (progressUpdater) { + progressUpdater->setRange(0, applyRect.height() * applyRect.width()); + } + + KoAbstractGradient *gradient = KoResourceServerProvider::instance()->gradientServer(false)->resourceByName(config->getString("gradientName")); + + KoColorSet *gradientCache = new KoColorSet(); + for (int i=0; i<256; i++) { + KoColor gc; + gradient->colorAt(gc, ((qreal)i/255.0)); + KoColorSetEntry col; + col.color = gc; + gradientCache->add(col); + } - return new KritaGradientMapColorTransformation(gradient, cs); + KoColor outColor(Qt::white, device->colorSpace()); + KisSequentialIterator it(device, applyRect); + int p = 0; + quint8 grey; + const int pixelSize = device->colorSpace()->pixelSize(); + do { + grey = device->colorSpace()->intensity8(it.oldRawData()); + outColor = gradientCache->getColor((quint32)grey).color; + outColor.convertTo(device->colorSpace()); + memcpy(it.rawData(), outColor.data(), pixelSize); + if (progressUpdater) progressUpdater->setValue(p++); + + } while (it.nextPixel()); + +} + +KisFilterConfiguration *KritaFilterGradientMap::factoryConfiguration(const KisPaintDeviceSP) const +{ + KisFilterConfiguration *config = new KisFilterConfiguration("gradientmap", 1); + KoAbstractGradient *gradient = KoResourceServerProvider::instance()->gradientServer(false)->resources().first(); + config->setProperty("gradientName", gradient->name()); + return config; } KisConfigWidget * KritaFilterGradientMap::createConfigurationWidget(QWidget * parent, const KisPaintDeviceSP dev) const { return new KritaGradientMapConfigWidget(parent, dev); } diff --git a/plugins/filters/gradientmap/krita_filter_gradient_map.h b/plugins/filters/gradientmap/krita_filter_gradient_map.h index 4c57ff85e4..a4e87b8ced 100644 --- a/plugins/filters/gradientmap/krita_filter_gradient_map.h +++ b/plugins/filters/gradientmap/krita_filter_gradient_map.h @@ -1,41 +1,53 @@ /* * This file is part of Krita * * Copyright (c) 2016 Spencer Brown * * 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. */ -#pragma once +#ifndef KIS_GRADIENT_MAP_H +#define KIS_GRADIENT_MAP_H -#include "kis_paint_device.h" -#include "filter/kis_filter.h" -#include "filter/kis_color_transformation_filter.h" +#include +#include +#include +#include +#include +#include +#include -class KritaFilterGradientMap : public KisColorTransformationFilter +class KritaFilterGradientMap : public KisFilter { public: KritaFilterGradientMap(); public: - virtual KoColorTransformation* createTransformation(const KoColorSpace* cs, const KisFilterConfiguration* config) const; static inline KoID id() { return KoID("gradientmap", i18n("Gradient Map")); } + virtual void processImpl(KisPaintDeviceSP device, + const QRect& applyRect, + const KisFilterConfiguration* config, + KoUpdater *progressUpdater) const; + + virtual KisFilterConfiguration *factoryConfiguration(const KisPaintDeviceSP) const; + virtual KisConfigWidget* createConfigurationWidget(QWidget* parent, const KisPaintDeviceSP dev) const; }; +#endif diff --git a/plugins/filters/gradientmap/krita_gradient_map_color_transformation.cpp b/plugins/filters/gradientmap/krita_gradient_map_color_transformation.cpp deleted file mode 100644 index 58fb387889..0000000000 --- a/plugins/filters/gradientmap/krita_gradient_map_color_transformation.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * This file is part of the KDE project - * - * Copyright (c) 2016 Spencer Brown - * 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 "krita_gradient_map_color_transformation.h" -#include "KoColor.h" -#include "KoColorSpaceMaths.h" - -KritaGradientMapColorTransformation::KritaGradientMapColorTransformation(const KoAbstractGradient * gradient, const KoColorSpace * cs) - : m_gradient(gradient), - m_colorSpace(cs), - m_psize(cs->pixelSize()) -{ -} - -void KritaGradientMapColorTransformation::transform(const quint8 * src, quint8 * dst, qint32 nPixels) const -{ - quint16 srcPixel[4]; - qreal grey; - KoColor outColor(m_colorSpace); - - while (nPixels--) - { - m_colorSpace->toLabA16(src,reinterpret_cast(srcPixel),1); - grey = qreal(srcPixel[0]) / KoColorSpaceMathsTraits::max; - m_gradient->colorAt(outColor, grey); - memcpy(dst, outColor.data(), m_psize); - src += m_psize; - dst += m_psize; - } -} - diff --git a/plugins/filters/gradientmap/krita_gradient_map_color_transformation.h b/plugins/filters/gradientmap/krita_gradient_map_color_transformation.h deleted file mode 100644 index 033c9d1e5a..0000000000 --- a/plugins/filters/gradientmap/krita_gradient_map_color_transformation.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of Krita - * - * Copyright (c) 2016 Spencer Brown - * - * 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. - */ - -#pragma once - -#include "KoColorTransformation.h" -#include "KoAbstractGradient.h" - -class KritaGradientMapColorTransformation : public KoColorTransformation -{ -public: - KritaGradientMapColorTransformation(const KoAbstractGradient * gradient, const KoColorSpace* cs); - virtual void transform(const quint8* src, quint8* dst, qint32 nPixels) const; -private: - const KoAbstractGradient* m_gradient; - const KoColorSpace* m_colorSpace; - const size_t m_psize; -}; -