diff --git a/libs/ui/widgets/kis_gradient_chooser.h b/libs/ui/widgets/kis_gradient_chooser.h index d8888d331c..6f08b35765 100644 --- a/libs/ui/widgets/kis_gradient_chooser.h +++ b/libs/ui/widgets/kis_gradient_chooser.h @@ -1,80 +1,81 @@ /* * Copyright (c) 2004 Adrian Page * * 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_GRADIENT_CHOOSER_H_ #define KIS_GRADIENT_CHOOSER_H_ #include #include +#include class KoSegmentGradient; class KisViewManager; class QLabel; class QPushButton; class KisAutogradient; class KoResource; class KoResourceItemChooser; class KisCustomGradientDialog : public KoDialog { Q_OBJECT public: KisCustomGradientDialog(KoSegmentGradient* gradient, QWidget * parent, const char *name); private: KisAutogradient * m_page; }; -class KisGradientChooser : public QFrame +class KRITAUI_EXPORT KisGradientChooser : public QFrame { Q_OBJECT public: KisGradientChooser(QWidget *parent = 0, const char *name = 0); virtual ~KisGradientChooser(); /// Gets the currently selected resource /// @returns the selected resource, 0 is no resource is selected KoResource *currentResource(); void setCurrentResource(KoResource *resource); void setCurrentItem(int row, int column); Q_SIGNALS: /// Emitted when a resource was selected void resourceSelected(KoResource * resource); private Q_SLOTS: virtual void update(KoResource * resource); void addGradient(); void editGradient(); private: QLabel *m_lbName; KoResourceItemChooser * m_itemChooser; QPushButton* m_editGradient; }; #endif // KIS_GRADIENT_CHOOSER_H_ diff --git a/plugins/filters/CMakeLists.txt b/plugins/filters/CMakeLists.txt index 1121a0501e..16e9c72cc6 100644 --- a/plugins/filters/CMakeLists.txt +++ b/plugins/filters/CMakeLists.txt @@ -1,25 +1,26 @@ add_subdirectory( tests ) add_subdirectory( blur ) add_subdirectory( colors ) add_subdirectory( colorsfilters ) add_subdirectory( convolutionfilters ) add_subdirectory( embossfilter ) add_subdirectory( example ) add_subdirectory( fastcolortransfer ) add_subdirectory( imageenhancement ) add_subdirectory( noisefilter ) add_subdirectory( oilpaintfilter ) add_subdirectory( pixelizefilter ) add_subdirectory( raindropsfilter ) add_subdirectory( randompickfilter ) add_subdirectory( roundcorners ) add_subdirectory( smalltilesfilter ) add_subdirectory( sobelfilter ) add_subdirectory( unsharp ) add_subdirectory( wavefilter ) add_subdirectory( levelfilter ) add_subdirectory( dodgeburn ) add_subdirectory( phongbumpmap ) add_subdirectory( posterize ) add_subdirectory( indexcolors ) add_subdirectory( normalize ) +add_subdirectory( gradientmap ) diff --git a/plugins/filters/gradientmap/CMakeLists.txt b/plugins/filters/gradientmap/CMakeLists.txt new file mode 100644 index 0000000000..cceeb7734a --- /dev/null +++ b/plugins/filters/gradientmap/CMakeLists.txt @@ -0,0 +1,7 @@ +set(kritagradientmap_SOURCES gradientmap.cpp krita_gradient_map_color_transformation.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 ${CALLIGRA_PLUGIN_INSTALL_DIR}) diff --git a/plugins/filters/gradientmap/gradientmap.cpp b/plugins/filters/gradientmap/gradientmap.cpp new file mode 100644 index 0000000000..29be5b78f8 --- /dev/null +++ b/plugins/filters/gradientmap/gradientmap.cpp @@ -0,0 +1,116 @@ +/* + * 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 "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) +{ + 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) +{ +} + +KritaGradientMapFilterConfiguration* 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); + + return cfg; +} + +//----------------------------- + +void KritaGradientMapConfigWidget::setConfiguration(const KisPropertiesConfiguration* config) +{ + const KritaGradientMapFilterConfiguration* cfg = dynamic_cast (config); + Q_ASSERT(cfg); +} + +void KritaGradientMapConfigWidget::setView(KisViewManager *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 new file mode 100644 index 0000000000..812e4f55c2 --- /dev/null +++ b/plugins/filters/gradientmap/gradientmap.h @@ -0,0 +1,74 @@ +/* + * 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 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 new file mode 100644 index 0000000000..84982addf2 --- /dev/null +++ b/plugins/filters/gradientmap/krita_filter_gradient_map.cpp @@ -0,0 +1,49 @@ +/* + * 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 "kis_config_widget.h" +#include "filter/kis_color_transformation_filter.h" +#include "gradientmap.h" +#include "krita_gradient_map_color_transformation.h" + + +KritaFilterGradientMap::KritaFilterGradientMap() : KisColorTransformationFilter(id(), categoryMap(), i18n("&Gradient Map")) +{ + setColorSpaceIndependence(TO_LAB16); + setShowConfigurationWidget(true); + // don't support anything just yet because of thread safety problems + setSupportsPainting(false); + setSupportsAdjustmentLayers(false); + setSupportsThreading(false); +} + +KoColorTransformation* KritaFilterGradientMap::createTransformation(const KoColorSpace* cs, const KisFilterConfiguration* config) const +{ + auto gradient = static_cast(dynamic_cast(config)->gradient()); + + return new KritaGradientMapColorTransformation(gradient, cs); +} + +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 new file mode 100644 index 0000000000..4c57ff85e4 --- /dev/null +++ b/plugins/filters/gradientmap/krita_filter_gradient_map.h @@ -0,0 +1,41 @@ +/* + * 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 "kis_paint_device.h" +#include "filter/kis_filter.h" +#include "filter/kis_color_transformation_filter.h" + +class KritaFilterGradientMap : public KisColorTransformationFilter +{ +public: + KritaFilterGradientMap(); +public: + + virtual KoColorTransformation* createTransformation(const KoColorSpace* cs, const KisFilterConfiguration* config) const; + + static inline KoID id() { + return KoID("gradientmap", i18n("Gradient Map")); + } + + virtual KisConfigWidget* createConfigurationWidget(QWidget* parent, const KisPaintDeviceSP dev) const; +}; + diff --git a/plugins/filters/gradientmap/krita_gradient_map_color_transformation.cpp b/plugins/filters/gradientmap/krita_gradient_map_color_transformation.cpp new file mode 100644 index 0000000000..58fb387889 --- /dev/null +++ b/plugins/filters/gradientmap/krita_gradient_map_color_transformation.cpp @@ -0,0 +1,47 @@ +/* + * 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 new file mode 100644 index 0000000000..033c9d1e5a --- /dev/null +++ b/plugins/filters/gradientmap/krita_gradient_map_color_transformation.h @@ -0,0 +1,36 @@ +/* + * 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; +}; + diff --git a/plugins/filters/gradientmap/kritagradientmap.json b/plugins/filters/gradientmap/kritagradientmap.json new file mode 100644 index 0000000000..f93c3f8f99 --- /dev/null +++ b/plugins/filters/gradientmap/kritagradientmap.json @@ -0,0 +1,9 @@ +{ + "Id": "Gradient Map Filter", + "Type": "Service", + "X-KDE-Library": "kritagradientmap", + "X-KDE-ServiceTypes": [ + "Krita/Filter" + ], + "X-Krita-Version": "30" +} diff --git a/plugins/filters/gradientmap/wdg_gradientmap.ui b/plugins/filters/gradientmap/wdg_gradientmap.ui new file mode 100644 index 0000000000..a660db5ff9 --- /dev/null +++ b/plugins/filters/gradientmap/wdg_gradientmap.ui @@ -0,0 +1,39 @@ + + + WdgGradientMap + + + + 0 + 0 + 361 + 341 + + + + Gradient Map + + + + + + + 200 + 200 + + + + + + + + + KisGradientChooser + QFrame +
kis_gradient_chooser.h
+ 1 +
+
+ + +