[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [calligra/krita-gsoc-filters-sahil] krita/plugins: Implementing Color Balance Filter
From: Sahil Nagpal <nagpal.sahil01 () gmail ! com>
Date: 2013-07-11 20:05:09
Message-ID: E1UxN6z-0004Xv-Dv () scm ! kde ! org
[Download RAW message or body]
Git commit a16fb91dab9e6cce93b79a8ad26fb1aebd8245c1 by Sahil Nagpal.
Committed on 11/07/2013 at 20:03.
Pushed by sahilnagpal into branch 'krita-gsoc-filters-sahil'.
Implementing Color Balance Filter
M +2 -0 krita/plugins/colorspaces/extensions/CMakeLists.txt
M +5 -0 krita/plugins/colorspaces/extensions/extensions_plugin.cc
A +180 -0 krita/plugins/colorspaces/extensions/kis_color_balance_midtones_adjustment.cpp \
[License: LGPL (v2)] A +37 -0 \
krita/plugins/colorspaces/extensions/kis_color_balance_midtones_adjustment.h \
[License: LGPL (v2)] A +174 -0 \
krita/plugins/colorspaces/extensions/kis_color_balance_shadows_adjustment.cpp \
[License: LGPL (v2)] A +38 -0 \
krita/plugins/colorspaces/extensions/kis_color_balance_shadows_adjustment.h \
[License: LGPL (v2)] M +2 -0 \
krita/plugins/filters/colorsfilters/CMakeLists.txt M +2 -0 \
krita/plugins/filters/colorsfilters/colorsfilters.cpp A +146 -0 \
krita/plugins/filters/colorsfilters/kis_color_balance_filter.cpp [License: LGPL \
(v2)] A +77 -0 krita/plugins/filters/colorsfilters/kis_color_balance_filter.h \
[License: LGPL (v2)] A +311 -0 \
krita/plugins/filters/colorsfilters/wdg_color_balance.ui
http://commits.kde.org/calligra/a16fb91dab9e6cce93b79a8ad26fb1aebd8245c1
diff --git a/krita/plugins/colorspaces/extensions/CMakeLists.txt \
b/krita/plugins/colorspaces/extensions/CMakeLists.txt index 3c197c4..c6c072e 100644
--- a/krita/plugins/colorspaces/extensions/CMakeLists.txt
+++ b/krita/plugins/colorspaces/extensions/CMakeLists.txt
@@ -7,6 +7,8 @@ kis_dodgeshadows_adjustment.cpp
kis_burnhighlights_adjustment.cpp
kis_burnmidtones_adjustment.cpp
kis_burnshadows_adjustment.cpp
+kis_color_balance_midtones_adjustment.cpp
+kis_color_balance_shadows_adjustment.cpp
)
kde4_add_plugin( krita_colorspaces_extensions ${extensions_plugin_PART_SRCS} )
diff --git a/krita/plugins/colorspaces/extensions/extensions_plugin.cc \
b/krita/plugins/colorspaces/extensions/extensions_plugin.cc index b4eab40..e216783 \
100644
--- a/krita/plugins/colorspaces/extensions/extensions_plugin.cc
+++ b/krita/plugins/colorspaces/extensions/extensions_plugin.cc
@@ -30,6 +30,8 @@
#include "kis_burnmidtones_adjustment.h"
#include "kis_burnhighlights_adjustment.h"
#include "kis_burnshadows_adjustment.h"
+#include "kis_color_balance_midtones_adjustment.h"
+#include "kis_color_balance_shadows_adjustment.h"
K_PLUGIN_FACTORY(ExtensionsPluginFactory, registerPlugin<ExtensionsPlugin>();)
@@ -47,6 +49,9 @@ ExtensionsPlugin::ExtensionsPlugin(QObject *parent, const \
QVariantList &)
KoColorTransformationFactoryRegistry::addColorTransformationFactory(new \
KisBurnMidtonesAdjustmentFactory);
KoColorTransformationFactoryRegistry::addColorTransformationFactory(new \
KisBurnHighlightsAdjustmentFactory);
KoColorTransformationFactoryRegistry::addColorTransformationFactory(new \
KisBurnShadowsAdjustmentFactory); +
+ KoColorTransformationFactoryRegistry::addColorTransformationFactory(new \
KisColorBalanceMidtonesAdjustmentFactory); + \
KoColorTransformationFactoryRegistry::addColorTransformationFactory(new \
KisColorBalanceShadowsAdjustmentFactory); }
ExtensionsPlugin::~ExtensionsPlugin()
diff --git a/krita/plugins/colorspaces/extensions/kis_color_balance_midtones_adjustment.cpp \
b/krita/plugins/colorspaces/extensions/kis_color_balance_midtones_adjustment.cpp new \
file mode 100644 index 0000000..15b4c89
--- /dev/null
+++ b/krita/plugins/colorspaces/extensions/kis_color_balance_midtones_adjustment.cpp
@@ -0,0 +1,180 @@
+/*
+ * Copyright (c) 2013 Sahil Nagpal <nagpal.sahil01@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+*/
+
+#include "kis_color_balance_midtones_adjustment.h"
+#include <KoConfig.h>
+
+#include <kis_debug.h>
+#include <klocale.h>
+
+#include <KoColorConversions.h>
+#include <KoColorModelStandardIds.h>
+#include <KoColorSpace.h>
+#include <KoColorSpaceTraits.h>
+#include <KoColorTransformation.h>
+#include <KoID.h>
+#include <kis_hsv_adjustment.h>
+
+
+#define SCALE_TO_FLOAT( v ) KoColorSpaceMaths< _channel_type_, float>::scaleToA( v )
+#define SCALE_FROM_FLOAT( v ) KoColorSpaceMaths< float, _channel_type_>::scaleToA( \
v ) +
+template<typename _channel_type_>
+class KisColorBalanceMidtonesAdjustment : public KoColorTransformation
+{
+ typedef KoBgrTraits<_channel_type_> RGBTrait;
+ typedef typename RGBTrait::Pixel RGBPixel;
+
+public:
+ KisColorBalanceMidtonesAdjustment(){};
+
+void transform(const quint8 *srcU8, quint8 *dstU8, qint32 nPixels) const
+{
+ const RGBPixel* src = reinterpret_cast<const RGBPixel*>(srcU8);
+ RGBPixel* dst = reinterpret_cast<RGBPixel*>(dstU8);
+ float value_red, value_green, value_blue, hue, saturation, lightness, a = 0.25, \
b = 0.333, scale = 0.7; +
+ while(nPixels > 0) {
+
+ float red = SCALE_TO_FLOAT(src->red);
+ float green = SCALE_TO_FLOAT(src->green);
+ float blue = SCALE_TO_FLOAT(src->blue);
+ RGBToHSL(red, green, blue, &hue, &saturation, &lightness);
+
+ float midtones_red = m_cyan_red;
+ midtones_red *=CLAMP ((lightness - b) / a + 0.5, 0.0, 1.0) * CLAMP \
((lightness + b - 1) /-a + 0.5, 0.0, 1.0) * scale; +
+ float midtones_green = m_magenta_green;
+ midtones_green *=CLAMP ((lightness - b) / a + 0.5, 0.0, 1.0) * CLAMP \
((lightness + b - 1) /-a + 0.5, 0.0, 1.0) * scale; +
+ float midtones_blue = m_yellow_blue;
+ midtones_blue *=CLAMP ((lightness - b) / a + 0.5, 0.0, 1.0) * CLAMP \
((lightness + b - 1) /-a + 0.5, 0.0, 1.0) * scale; +\
+ midtones_red += red;
+ midtones_green += green;
+ midtones_blue += blue;
+ value_red = CLAMP(midtones_red,0.0 ,1.0);
+ value_green = CLAMP(midtones_green,0.0, 1.0);
+ value_blue = CLAMP(midtones_blue, 0.0, 1.0);
+
+ if(m_preserve)
+ {
+ float h1, s1, l1, h2, s2, l2, r, g, bl;
+ RGBToHSL(SCALE_TO_FLOAT(src->red), SCALE_TO_FLOAT(src->green), \
SCALE_TO_FLOAT(src->blue), &h1, &s1, &l1); + RGBToHSL(value_red, \
value_green, value_blue, &h2, &s2, &l2); + l2 = l1;
+
+ HSLToRGB(h2, s2, l2, &r, &g, &bl);
+ value_red = r;
+ value_green = g;
+ value_blue = bl;
+ }
+ dst->red = SCALE_FROM_FLOAT(value_red);
+ dst->green = SCALE_FROM_FLOAT(value_green);
+ dst->blue = SCALE_FROM_FLOAT(value_blue);
+ dst->alpha = src->alpha;
+
+ --nPixels;
+ ++src;
+ ++dst;
+ }
+}
+
+
+virtual QList<QString> parameters() const
+{
+ QList<QString> list;
+ list << "cyan_red" << "magenta_green" << "yellow_blue" << "preserve_luminosity";
+ return list;
+}
+
+virtual int parameterId(const QString& name) const
+{
+ if (name == "cyan_red")
+ return 0;
+ else if(name == "magenta_green")
+ return 1;
+ else if(name == "yellow_blue")
+ return 2;
+ else if(name == "preserve_luminosity")
+ return 3;
+ return -1;
+}
+
+ virtual void setParameter(int id, const QVariant& parameter)
+ {
+ switch(id)
+ {
+ case 0:
+ m_cyan_red = parameter.toDouble();
+ break;
+ case 1:
+ m_magenta_green = parameter.toDouble();
+ break;
+ case 2:
+ m_yellow_blue = parameter.toDouble();
+ break;
+ case 3:
+ m_preserve = parameter.toBool();
+ break;
+ default:
+ ;
+ }
+ }
+private:
+
+ double m_cyan_red, m_magenta_green, m_yellow_blue;
+ bool m_preserve;
+};
+
+ KisColorBalanceMidtonesAdjustmentFactory::KisColorBalanceMidtonesAdjustmentFactory()
+ : KoColorTransformationFactory("BalanceMidtones", i18n("ColorBalanceMidtones \
Adjustment")) +{
+}
+
+QList< QPair< KoID, KoID > > \
KisColorBalanceMidtonesAdjustmentFactory::supportedModels() const +{
+ QList< QPair< KoID, KoID > > l;
+ l.append(QPair< KoID, KoID >(RGBAColorModelID , Integer8BitsColorDepthID));
+ l.append(QPair< KoID, KoID >(RGBAColorModelID , Integer16BitsColorDepthID));
+ l.append(QPair< KoID, KoID >(RGBAColorModelID , Float32BitsColorDepthID));
+ return l;
+}
+
+KoColorTransformation* \
KisColorBalanceMidtonesAdjustmentFactory::createTransformation(const KoColorSpace* \
colorSpace, QHash<QString, QVariant> parameters) const +{
+ KoColorTransformation * adj;
+ if (colorSpace->colorModelId() != RGBAColorModelID) {
+ kError() << "Unsupported color space " << colorSpace->id() << " in \
KisColorBalanceMidtonesAdjustment::createTransformation"; + return 0;
+ }
+ if (colorSpace->colorDepthId() == Float32BitsColorDepthID) {
+ adj = new KisColorBalanceMidtonesAdjustment< float >();
+ } else if (colorSpace->colorDepthId() == Integer16BitsColorDepthID) {
+ adj = new KisColorBalanceMidtonesAdjustment< quint16 >();
+ } else if (colorSpace->colorDepthId() == Integer8BitsColorDepthID) {
+ adj = new KisColorBalanceMidtonesAdjustment< quint8 >();
+ } else {
+ kError() << "Unsupported color space " << colorSpace->id() << " in \
KisColorBalanceMidtonesAdjustment::createTransformation"; + return 0;
+ }
+ adj->setParameters(parameters);
+ return adj;
+
+}
diff --git a/krita/plugins/colorspaces/extensions/kis_color_balance_midtones_adjustment.h \
b/krita/plugins/colorspaces/extensions/kis_color_balance_midtones_adjustment.h new \
file mode 100644 index 0000000..df2f540
--- /dev/null
+++ b/krita/plugins/colorspaces/extensions/kis_color_balance_midtones_adjustment.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2013 Sahil Nagpal <nagpal.sahil01@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+*/
+
+#ifndef _KIS_COLOR_BALANCE_MIDTONES_ADJUSTMENT_H_
+#define _KIS_COLOR_BALANCE_MIDTONES_ADJUSTMENT_H_
+
+#include "KoColorTransformationFactory.h"
+
+class KisColorBalanceMidtonesAdjustmentFactory : public KoColorTransformationFactory
+{
+public:
+
+ KisColorBalanceMidtonesAdjustmentFactory();
+
+ virtual QList< QPair< KoID, KoID > > supportedModels() const;
+
+ virtual KoColorTransformation* createTransformation(const KoColorSpace* \
colorSpace, QHash<QString, QVariant> parameters) const; +
+};
+
+#endif
diff --git a/krita/plugins/colorspaces/extensions/kis_color_balance_shadows_adjustment.cpp \
b/krita/plugins/colorspaces/extensions/kis_color_balance_shadows_adjustment.cpp new \
file mode 100644 index 0000000..270dfe2
--- /dev/null
+++ b/krita/plugins/colorspaces/extensions/kis_color_balance_shadows_adjustment.cpp
@@ -0,0 +1,174 @@
+/*
+ * Copyright (c) 2013 Sahil Nagpal <nagpal.sahil01@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+*/
+
+#include "kis_color_balance_shadows_adjustment.h"
+#include <KoConfig.h>
+
+#include <kis_debug.h>
+#include <klocale.h>
+
+#include <KoColorConversions.h>
+#include <KoColorModelStandardIds.h>
+#include <KoColorSpace.h>
+#include <KoColorSpaceTraits.h>
+#include <KoColorTransformation.h>
+#include <KoID.h>
+#include <kis_hsv_adjustment.h>
+
+
+#define SCALE_TO_FLOAT( v ) KoColorSpaceMaths< _channel_type_, float>::scaleToA( v )
+#define SCALE_FROM_FLOAT( v ) KoColorSpaceMaths< float, _channel_type_>::scaleToA( \
v ) +
+template<typename _channel_type_>
+class KisColorBalanceShadowsAdjustment : public KoColorTransformation
+{
+ typedef KoBgrTraits<_channel_type_> RGBTrait;
+ typedef typename RGBTrait::Pixel RGBPixel;
+
+public:
+ KisColorBalanceShadowsAdjustment(){};
+
+void transform(const quint8 *srcU8, quint8 *dstU8, qint32 nPixels) const
+{
+ const RGBPixel* src = reinterpret_cast<const RGBPixel*>(srcU8);
+ RGBPixel* dst = reinterpret_cast<RGBPixel*>(dstU8);
+ float value_red, value_green, value_blue, a = 0.25, b = 0.333, scale = 0.7, h, \
s, v; +
+ while(nPixels > 0) {
+
+ RGBToHSL(SCALE_TO_FLOAT(src->red), SCALE_TO_FLOAT(src->green), \
SCALE_TO_FLOAT(src->blue), &h, &s, &v); + float shadows_red = cyan_red, \
shadows_green = magenta_green, shadows_blue = yellow_blue; +
+ shadows_red *= CLAMP ((v - b) / -a + 0.5, 0, 1) * scale;
+ shadows_green *= CLAMP ((v - b) / -a + 0.5, 0, 1) * scale;
+ shadows_blue *= CLAMP ((v - b) / -a + 0.5, 0, 1) * scale;
+
+ value_red = SCALE_TO_FLOAT(src->red);
+ value_red += CLAMP(shadows_red, 0, 1.0);
+ value_green = SCALE_TO_FLOAT(src->green);
+ value_green += CLAMP(shadows_green,0.0 ,1.0);
+ value_blue = SCALE_TO_FLOAT(src->blue);
+ value_blue += CLAMP(shadows_blue, 0.0, 1.0);
+
+ if(m_preserve)
+ {
+ float h1, s1, l1, h2, s2, l2, r, g, bl;
+ RGBToHSL(SCALE_TO_FLOAT(src->red), SCALE_TO_FLOAT(src->green), \
SCALE_TO_FLOAT(src->blue), &h1, &s1, &l1); + RGBToHSL(value_red, \
value_green, value_blue, &h2, &s2, &l2); + l2 = l1;
+
+ HSLToRGB(h2, s2, l2, &r, &g, &bl);
+ value_red = r;
+ value_green = g;
+ value_blue = bl;
+ }
+
+ dst->red = SCALE_FROM_FLOAT (value_red);
+ dst->green = SCALE_FROM_FLOAT(value_green);
+ dst->blue = SCALE_FROM_FLOAT(value_blue);
+ dst->alpha = src->alpha;
+
+ --nPixels;
+ ++src;
+ ++dst;
+ }
+}
+
+
+virtual QList<QString> parameters() const
+{
+ QList<QString> list;
+ list << "cyan_red" << "magenta_green" << "yellow_blue" << "preserve_luminosity";
+ return list;
+}
+
+virtual int parameterId(const QString& name) const
+{
+ if (name == "cyan_red")
+ return 0;
+ else if(name == "magenta_green")
+ return 1;
+ else if(name == "yellow_blue")
+ return 2;
+ else if(name == "preserve_luminosity")
+ return 3;
+ return -1;
+}
+
+virtual void setParameter(int id, const QVariant& parameter)
+{
+ switch(id)
+ {
+ case 0:
+ cyan_red = parameter.toDouble();
+ break;
+ case 1:
+ magenta_green = parameter.toDouble();
+ break;
+ case 2:
+ yellow_blue = parameter.toDouble();
+ break;
+ case 3:
+ m_preserve = parameter.toBool();
+ break;
+ default:
+ ;
+ }
+}
+private:
+
+ double cyan_red, magenta_green, yellow_blue;
+ bool m_preserve;
+};
+
+ KisColorBalanceShadowsAdjustmentFactory::KisColorBalanceShadowsAdjustmentFactory()
+ : KoColorTransformationFactory("BalanceShadows", i18n("ColorBalanceShadows \
Adjustment")) +{
+}
+
+QList< QPair< KoID, KoID > > \
KisColorBalanceShadowsAdjustmentFactory::supportedModels() const +{
+ QList< QPair< KoID, KoID > > l;
+ l.append(QPair< KoID, KoID >(RGBAColorModelID , Integer8BitsColorDepthID));
+ l.append(QPair< KoID, KoID >(RGBAColorModelID , Integer16BitsColorDepthID));
+ l.append(QPair< KoID, KoID >(RGBAColorModelID , Float32BitsColorDepthID));
+ return l;
+}
+
+KoColorTransformation* \
KisColorBalanceShadowsAdjustmentFactory::createTransformation(const KoColorSpace* \
colorSpace, QHash<QString, QVariant> parameters) const +{
+ KoColorTransformation * adj;
+ if (colorSpace->colorModelId() != RGBAColorModelID) {
+ kError() << "Unsupported color space " << colorSpace->id() << " in \
KisColorBalanceShadowsAdjustment::createTransformation"; + return 0;
+ }
+ if (colorSpace->colorDepthId() == Float32BitsColorDepthID) {
+ adj = new KisColorBalanceShadowsAdjustment< float >();
+ } else if (colorSpace->colorDepthId() == Integer16BitsColorDepthID) {
+ adj = new KisColorBalanceShadowsAdjustment< quint16 >();
+ } else if (colorSpace->colorDepthId() == Integer8BitsColorDepthID) {
+ adj = new KisColorBalanceShadowsAdjustment< quint8 >();
+ } else {
+ kError() << "Unsupported color space " << colorSpace->id() << " in \
KisColorBalanceShadowsAdjustment::createTransformation"; + return 0;
+ }
+ adj->setParameters(parameters);
+ return adj;
+
+}
diff --git a/krita/plugins/colorspaces/extensions/kis_color_balance_shadows_adjustment.h \
b/krita/plugins/colorspaces/extensions/kis_color_balance_shadows_adjustment.h new \
file mode 100644 index 0000000..18b98b5
--- /dev/null
+++ b/krita/plugins/colorspaces/extensions/kis_color_balance_shadows_adjustment.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2013 Sahil Nagpal <nagpal.sahil01@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+*/
+
+#ifndef _KIS_COLOR_BALANCE_SHADOWS_ADJUSTMENT_H_
+#define _KIS_COLOR_BALANCE_SHADOWS_ADJUSTMENT_H_
+
+#include "KoColorTransformationFactory.h"
+
+class KisColorBalanceShadowsAdjustmentFactory : public KoColorTransformationFactory
+{
+public:
+
+ KisColorBalanceShadowsAdjustmentFactory();
+
+ virtual QList< QPair< KoID, KoID > > supportedModels() const;
+
+ virtual KoColorTransformation* createTransformation(const KoColorSpace* \
colorSpace, QHash<QString, QVariant> parameters) const; +
+};
+
+#endif
+
diff --git a/krita/plugins/filters/colorsfilters/CMakeLists.txt \
b/krita/plugins/filters/colorsfilters/CMakeLists.txt index f37a11b..acc726b 100644
--- a/krita/plugins/filters/colorsfilters/CMakeLists.txt
+++ b/krita/plugins/filters/colorsfilters/CMakeLists.txt
@@ -5,10 +5,12 @@ set(kritacolorsfilters_PART_SRCS
kis_hsv_adjustment_filter.cpp
kis_perchannel_filter.cpp
kis_brightness_contrast_filter.cpp
+ kis_color_balance_filter.cpp
)
kde4_add_ui_files(kritacolorsfilters_PART_SRCS
wdg_perchannel.ui
+ wdg_color_balance.ui
wdg_brightness_contrast.ui
wdg_hsv_adjustment.ui
)
diff --git a/krita/plugins/filters/colorsfilters/colorsfilters.cpp \
b/krita/plugins/filters/colorsfilters/colorsfilters.cpp index 54fd60e..a4d958c 100644
--- a/krita/plugins/filters/colorsfilters/colorsfilters.cpp
+++ b/krita/plugins/filters/colorsfilters/colorsfilters.cpp
@@ -53,6 +53,7 @@
#include "kis_hsv_adjustment_filter.h"
#include "kis_brightness_contrast_filter.h"
#include "kis_perchannel_filter.h"
+#include "kis_color_balance_filter.h"
#include "filter/kis_filter_registry.h"
#include <kis_painter.h>
#include <KoProgressUpdater.h>
@@ -73,6 +74,7 @@ ColorsFilters::ColorsFilters(QObject *parent, const QVariantList &)
manager->add(new KisPerChannelFilter());
manager->add(new KisDesaturateFilter());
manager->add(new KisHSVAdjustmentFilter());
+ manager->add(new KisColorBalanceFilter());
}
diff --git a/krita/plugins/filters/colorsfilters/kis_color_balance_filter.cpp \
b/krita/plugins/filters/colorsfilters/kis_color_balance_filter.cpp new file mode \
100644 index 0000000..a62294a
--- /dev/null
+++ b/krita/plugins/filters/colorsfilters/kis_color_balance_filter.cpp
@@ -0,0 +1,146 @@
+/*
+ * Copyright (c) 2013 Sahil Nagpal <nagpal.sahil01@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+*/
+
+#include "kis_color_balance_filter.h"
+#include <KoProgressUpdater.h>
+#include "filter/kis_filter_configuration.h"
+#include "kis_selection.h"
+#include "kis_paint_device.h"
+#include "kis_processing_information.h"
+
+KisColorBalanceFilter::KisColorBalanceFilter()
+ : KisColorTransformationFilter(id(), categoryAdjust(), i18n("&Color Balance.."))
+{
+ setShortcut(KShortcut(QKeySequence(Qt::CTRL + Qt::Key_C)));
+ setSupportsPainting(true);
+ setSupportsIncrementalPainting(false);
+}
+
+KisConfigWidget * KisColorBalanceFilter::createConfigurationWidget(QWidget* parent, \
const KisPaintDeviceSP dev) const +{
+ Q_UNUSED(dev);
+ return new KisColorBalanceConfigWidget(parent);
+}
+
+KoColorTransformation * KisColorBalanceFilter::createTransformation(const \
KoColorSpace* cs, const KisFilterConfiguration* config) const +{
+ QHash<QString, QVariant> params;
+ QString suffix = "Midtones";
+ if (config) {
+ params["cyan_red"] = config->getInt("cyan_red", 0);
+ params["magenta_green"] = config->getInt("magenta_green", 0);
+ params["yellow_blue"] = config->getInt("yellow_blue", 0);
+ params["preserve_luminosity"] = config->getBool("preserve_luminosity", \
true); + int type = config->getInt("type", KisColorBalanceFilter::MIDTONES);
+ switch(type)
+ {
+ case KisColorBalanceFilter::HIGHLIGHTS:
+ suffix = "Highlights";
+ break;
+ case KisColorBalanceFilter::SHADOWS:
+ suffix = "Shadows";
+ break;
+ default: break;
+ }
+ }
+ return cs->createColorTransformation("Balance" + suffix , params);
+}
+
+KisFilterConfiguration* KisColorBalanceFilter::factoryConfiguration(const \
KisPaintDeviceSP) const +{
+ KisFilterConfiguration* config = new KisFilterConfiguration(id().id(), 0);
+ config->setProperty("cyan_red", 0);
+ config->setProperty("yellow_green", 0);
+ config->setProperty("magenta_blue", 0);
+ config->setProperty("preserve_luminosity", true);
+ return config;
+}
+
+KisColorBalanceConfigWidget::KisColorBalanceConfigWidget(QWidget* parent) : \
KisConfigWidget(parent) +{
+ m_page = new Ui_Form();
+ m_page->setupUi(this);
+ m_page->cyanRedSlider->setMaximum(100);
+ m_page->cyanRedSlider->setMinimum(-100);
+ m_page->cyanRedSpinbox->setMaximum(100);
+ m_page->cyanRedSpinbox->setMinimum(-100);
+ m_page->yellowBlueSlider->setMaximum(100);
+ m_page->yellowBlueSlider->setMinimum(-100);
+ m_page->yellowBlueSpinbox->setMaximum(100);
+ m_page->yellowBlueSpinbox->setMinimum(-100);
+ m_page->magentaGreenSlider->setMaximum(100);
+ m_page->magentaGreenSlider->setMinimum(-100);
+ m_page->magentaGreenSpinbox->setMaximum(100);
+ m_page->magentaGreenSpinbox->setMinimum(-100);
+
+ connect(m_page->radioButtonMidtones, SIGNAL(toggled(bool)), \
SIGNAL(sigConfigurationItemChanged())); + connect(m_page->radioButtonHighlights, \
SIGNAL(toggled(bool)), SIGNAL(sigConfigurationItemChanged())); + \
connect(m_page->radioButtonShadows, SIGNAL(toggled(bool)), \
SIGNAL(sigConfigurationItemChanged())); + \
+ connect(m_page->cyanRedSlider, SIGNAL(valueChanged(int)), \
SIGNAL(sigConfigurationItemChanged())); + connect(m_page->magentaGreenSlider, \
SIGNAL(valueChanged(int)), SIGNAL(sigConfigurationItemChanged())); + \
connect(m_page->yellowBlueSlider, SIGNAL(valueChanged(int)), \
SIGNAL(sigConfigurationItemChanged())); + connect(m_page->chkPreserve, \
SIGNAL(toggled(bool)), SIGNAL(sigConfigurationItemChanged())); +}
+
+KisColorBalanceConfigWidget::~KisColorBalanceConfigWidget()
+{
+ delete m_page;
+}
+
+KisPropertiesConfiguration * KisColorBalanceConfigWidget::configuration() const
+{
+ KisFilterConfiguration* c = new \
KisFilterConfiguration(KisColorBalanceFilter::id().id(), 0); + int type = 0;
+ if(m_page->radioButtonHighlights->isChecked()) {
+ type = KisColorBalanceFilter::HIGHLIGHTS;
+ } else if(m_page->radioButtonShadows->isChecked()) {
+ type = KisColorBalanceFilter::SHADOWS;
+ } else {
+ type = KisColorBalanceFilter::MIDTONES;
+ }
+ c->setProperty("type", type);
+ c->setProperty("cyan_red", m_page->cyanRedSlider->value() / 100.0);
+ c->setProperty("magenta_green", m_page->magentaGreenSlider->value() / 100.0);
+ c->setProperty("yellow_blue", m_page->yellowBlueSlider->value() / 100.0);
+ c->setProperty("preserve_luminosity", m_page->chkPreserve->isChecked());
+ return c;
+}
+
+void KisColorBalanceConfigWidget::setConfiguration(const KisPropertiesConfiguration \
* config) +{
+ int type = config->getInt("type", KisColorBalanceFilter::MIDTONES);
+ switch(type)
+ {
+ case KisColorBalanceFilter::HIGHLIGHTS:
+ m_page->radioButtonHighlights->setChecked(true);
+ break;
+ case KisColorBalanceFilter::SHADOWS:
+ m_page->radioButtonShadows->setChecked(true);
+ break;
+ default:
+ case KisColorBalanceFilter::MIDTONES:
+ m_page->radioButtonMidtones->setChecked(true);
+ break;
+ }
+ m_page->cyanRedSlider->setValue( config->getDouble("cyan_red", 0));
+ m_page->magentaGreenSlider->setValue( config->getDouble("magenta_green", 0));
+ m_page->yellowBlueSlider->setValue( config->getDouble("yellow_blue", 0));
+ m_page->chkPreserve->setChecked(config->getBool("preserve_luminosity", true));
+}
diff --git a/krita/plugins/filters/colorsfilters/kis_color_balance_filter.h \
b/krita/plugins/filters/colorsfilters/kis_color_balance_filter.h new file mode 100644
index 0000000..778bc0c
--- /dev/null
+++ b/krita/plugins/filters/colorsfilters/kis_color_balance_filter.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2013 Sahil Nagpal <nagpal.sahil01@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+*/
+
+#ifndef _KIS_COLOR_BALANCE_FILTER_H_
+#define _KIS_COLOR_BALANCE_FILTER_H_
+
+#include <QList>
+#include "filter/kis_filter.h"
+#include "kis_config_widget.h"
+#include "ui_wdg_color_balance.h"
+#include "filter/kis_color_transformation_filter.h"
+
+
+class QWidget;
+class KoColorTransformation;
+
+class KisColorBalanceFilter : public KisColorTransformationFilter
+{
+
+public:
+
+ KisColorBalanceFilter();
+public:
+ enum Type {
+ SHADOWS,
+ MIDTONES,
+ HIGHLIGHTS
+ };
+
+public:
+
+ virtual KisConfigWidget * createConfigurationWidget(QWidget* parent, const \
KisPaintDeviceSP dev) const; +
+ using KisFilter::process;
+
+ virtual KoColorTransformation* createTransformation(const KoColorSpace* cs, \
const KisFilterConfiguration* config) const; +
+ static inline KoID id() {
+ return KoID("colorbalance", i18n("Color Balance.."));
+ }
+
+ virtual KisFilterConfiguration * factoryConfiguration(const KisPaintDeviceSP) \
const; +
+};
+
+class KisColorBalanceConfigWidget : public KisConfigWidget
+{
+
+ Q_OBJECT
+
+public:
+ KisColorBalanceConfigWidget(QWidget * parent);
+ virtual ~KisColorBalanceConfigWidget();
+
+ virtual KisPropertiesConfiguration * configuration() const;
+ virtual void setConfiguration(const KisPropertiesConfiguration* config);
+ Ui_Form * m_page;
+ QString m_id;
+};
+
+#endif
diff --git a/krita/plugins/filters/colorsfilters/wdg_color_balance.ui \
b/krita/plugins/filters/colorsfilters/wdg_color_balance.ui new file mode 100644
index 0000000..7641e24
--- /dev/null
+++ b/krita/plugins/filters/colorsfilters/wdg_color_balance.ui
@@ -0,0 +1,311 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Form</class>
+ <widget class="QWidget" name="Form">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>385</width>
+ <height>249</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <widget class="QLabel" name="label_2">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>161</width>
+ <height>16</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Select Range to Adjust</string>
+ </property>
+ </widget>
+ <widget class="QRadioButton" name="radioButtonShadows">
+ <property name="geometry">
+ <rect>
+ <x>7</x>
+ <y>20</y>
+ <width>81</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Shadows</string>
+ </property>
+ </widget>
+ <widget class="QRadioButton" name="radioButtonMidtones">
+ <property name="geometry">
+ <rect>
+ <x>94</x>
+ <y>20</y>
+ <width>80</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Midtones</string>
+ </property>
+ </widget>
+ <widget class="QRadioButton" name="radioButtonHighlights">
+ <property name="geometry">
+ <rect>
+ <x>180</x>
+ <y>20</y>
+ <width>86</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Highlights</string>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label_3">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>40</y>
+ <width>141</width>
+ <height>20</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Adjust Color Levels</string>
+ </property>
+ </widget>
+ <widget class="QWidget" name="layoutWidget">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>60</y>
+ <width>351</width>
+ <height>121</height>
+ </rect>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QLabel" name="label_cyan">
+ <property name="layoutDirection">
+ <enum>Qt::RightToLeft</enum>
+ </property>
+ <property name="text">
+ <string> Cyan</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QSlider" name="cyanRedSlider">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_red">
+ <property name="text">
+ <string>Red </string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QSpinBox" name="cyanRedSpinbox"/>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="QLabel" name="label_magenta">
+ <property name="enabled">
+ <bool>true</bool>
+ </property>
+ <property name="layoutDirection">
+ <enum>Qt::RightToLeft</enum>
+ </property>
+ <property name="text">
+ <string>Magenta</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QSlider" name="magentaGreenSlider">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_green">
+ <property name="text">
+ <string>Green</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QSpinBox" name="magentaGreenSpinbox"/>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
+ <item>
+ <widget class="QLabel" name="label_yellow">
+ <property name="layoutDirection">
+ <enum>Qt::RightToLeft</enum>
+ </property>
+ <property name="text">
+ <string> Yellow</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QSlider" name="yellowBlueSlider">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_blue">
+ <property name="text">
+ <string>Blue </string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QSpinBox" name="yellowBlueSpinbox"/>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QCheckBox" name="chkPreserve">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>190</y>
+ <width>151</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Preserve Luminosity</string>
+ </property>
+ </widget>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>cyanRedSlider</sender>
+ <signal>valueChanged(int)</signal>
+ <receiver>cyanRedSpinbox</receiver>
+ <slot>setValue(int)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>91</x>
+ <y>73</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>222</x>
+ <y>80</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>cyanRedSpinbox</sender>
+ <signal>valueChanged(int)</signal>
+ <receiver>cyanRedSlider</receiver>
+ <slot>setValue(int)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>210</x>
+ <y>64</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>130</x>
+ <y>71</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>magentaGreenSlider</sender>
+ <signal>valueChanged(int)</signal>
+ <receiver>magentaGreenSpinbox</receiver>
+ <slot>setValue(int)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>149</x>
+ <y>110</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>233</x>
+ <y>114</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>magentaGreenSpinbox</sender>
+ <signal>valueChanged(int)</signal>
+ <receiver>magentaGreenSlider</receiver>
+ <slot>setValue(int)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>218</x>
+ <y>101</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>121</x>
+ <y>99</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>yellowBlueSlider</sender>
+ <signal>valueChanged(int)</signal>
+ <receiver>yellowBlueSpinbox</receiver>
+ <slot>setValue(int)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>108</x>
+ <y>142</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>227</x>
+ <y>145</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>yellowBlueSpinbox</sender>
+ <signal>valueChanged(int)</signal>
+ <receiver>yellowBlueSlider</receiver>
+ <slot>setValue(int)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>218</x>
+ <y>130</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>143</x>
+ <y>131</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic