summaryrefslogtreecommitdiffstats
path: root/digikam/imageplugins/oilpaint
diff options
context:
space:
mode:
Diffstat (limited to 'digikam/imageplugins/oilpaint')
-rw-r--r--digikam/imageplugins/oilpaint/Makefile.am34
-rw-r--r--digikam/imageplugins/oilpaint/digikamimageplugin_oilpaint.desktop51
-rw-r--r--digikam/imageplugins/oilpaint/digikamimageplugin_oilpaint_ui.rc20
-rw-r--r--digikam/imageplugins/oilpaint/imageeffect_oilpaint.cpp201
-rw-r--r--digikam/imageplugins/oilpaint/imageeffect_oilpaint.h68
-rw-r--r--digikam/imageplugins/oilpaint/imageplugin_oilpaint.cpp70
-rw-r--r--digikam/imageplugins/oilpaint/imageplugin_oilpaint.h55
-rw-r--r--digikam/imageplugins/oilpaint/oilpaint.cpp203
-rw-r--r--digikam/imageplugins/oilpaint/oilpaint.h72
-rw-r--r--digikam/imageplugins/oilpaint/oilpainttool.cpp208
-rw-r--r--digikam/imageplugins/oilpaint/oilpainttool.h81
11 files changed, 1063 insertions, 0 deletions
diff --git a/digikam/imageplugins/oilpaint/Makefile.am b/digikam/imageplugins/oilpaint/Makefile.am
new file mode 100644
index 0000000..1b5c503
--- /dev/null
+++ b/digikam/imageplugins/oilpaint/Makefile.am
@@ -0,0 +1,34 @@
+METASOURCES = AUTO
+
+INCLUDES = -I$(top_srcdir)/digikam/utilities/imageeditor/editor \
+ -I$(top_srcdir)/digikam/utilities/imageeditor/canvas \
+ -I$(top_srcdir)/digikam/libs/histogram \
+ -I$(top_srcdir)/digikam/libs/levels \
+ -I$(top_srcdir)/digikam/libs/curves \
+ -I$(top_srcdir)/digikam/libs/whitebalance \
+ -I$(top_srcdir)/digikam/libs/widgets/common \
+ -I$(top_srcdir)/digikam/libs/widgets/iccprofiles \
+ -I$(top_srcdir)/digikam/libs/widgets/imageplugins \
+ -I$(top_srcdir)/digikam/libs/dialogs \
+ -I$(top_srcdir)/digikam/libs/dimg \
+ -I$(top_srcdir)/digikam/libs/dmetadata \
+ -I$(top_srcdir)/digikam/libs/dimg/filters \
+ -I$(top_srcdir)/digikam/digikam \
+ $(LIBKDCRAW_CFLAGS) \
+ $(all_includes)
+
+digikamimageplugin_oilpaint_la_SOURCES = imageplugin_oilpaint.cpp \
+ oilpainttool.cpp oilpaint.cpp
+
+digikamimageplugin_oilpaint_la_LIBADD = $(LIB_KPARTS) \
+ $(top_builddir)/digikam/digikam/libdigikam.la
+
+digikamimageplugin_oilpaint_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries)
+
+kde_services_DATA = digikamimageplugin_oilpaint.desktop
+
+kde_module_LTLIBRARIES = digikamimageplugin_oilpaint.la
+
+rcdir = $(kde_datadir)/digikam
+rc_DATA = digikamimageplugin_oilpaint_ui.rc
+
diff --git a/digikam/imageplugins/oilpaint/digikamimageplugin_oilpaint.desktop b/digikam/imageplugins/oilpaint/digikamimageplugin_oilpaint.desktop
new file mode 100644
index 0000000..a9a84d2
--- /dev/null
+++ b/digikam/imageplugins/oilpaint/digikamimageplugin_oilpaint.desktop
@@ -0,0 +1,51 @@
+[Desktop Entry]
+Name=ImagePlugin_OilPaint
+Name[bg]=Приставка за снимки - Маслени бои
+Name[da]=Billedplugin_Oliemaling
+Name[el]=ΠρόσθετοΕικόνας_Ελαιογραφίας
+Name[fi]=Öljyvärimaalaus
+Name[hr]=Uljana slika
+Name[it]=PluginImmagini_PitturaAOlio
+Name[nl]=Afbeeldingsplugin_Olieverf
+Name[sr]=Слика у уљу
+Name[sr@Latn]=Slika u ulju
+Name[sv]=Insticksprogram för oljemålning
+Name[tr]=ResimEklentisi_YağlıBoya
+Name[xx]=xxImagePlugin_OilPaintxx
+Type=Service
+ServiceTypes=Digikam/ImagePlugin
+Encoding=UTF-8
+Comment=Oil paint image effect plugin for digiKam
+Comment[bg]=Приставка на digiKam за наподобяване на картина с маслени бои
+Comment[ca]=Connector pel digiKam d'efecte de pintura a l'oli
+Comment[da]=Plugin med oliemalingeffekt på billeder i Digikam
+Comment[de]=digiKam-Modul zum Erzeugen eines Ölgemäldeeffektes
+Comment[el]=Πρόσθετο ελαιογραφίας για το digiKam
+Comment[es]=Plugin para digiKam con efectos de pintura al óleo
+Comment[et]=DigiKami õlimaali pildiefektiplugin
+Comment[fa]=وصلۀ جلوۀ تصویر رنگ روغن برای digiKam
+Comment[fi]=Jäljittelee öljyvärimaalausta
+Comment[gl]=Un plugin de digiKam para simular unha pintura ao óleo
+Comment[hr]=digiKam dodatak za efekt uljane slike
+Comment[is]=Íforrit fyrir digiKam sem líkir eftir olíumálun
+Comment[it]=Plugin per l'effetto di pittura a olio delle immagini per digiKam
+Comment[ja]=digiKam 油絵効果プラグイン
+Comment[ms]=Plugin kesan imej cat minyak untuk digiKam
+Comment[nds]=digiKam-Moduul för Öölbildeffekten
+Comment[nl]=Digikam-plugin voor olieverfafbeeldingen
+Comment[pa]=ਡਿਜ਼ੀਕੈਮ ਲਈ ਤੇਲ ਪੇਂਟ ਚਿੱਤਰ ਪਰਭਾਵ ਪਲੱਗਇਨ
+Comment[pl]=Wtyczka do programu digiKam zmniejszająca szum
+Comment[pt]=Um 'plugin' do digiKam para simular uma pintura a óleo
+Comment[pt_BR]=Plugin de efeito de condensar cor da imagem
+Comment[ru]=Модуль эффект "маслянной краски" для digiKam
+Comment[sk]=digiKam plugin pre efekt olejomaľby
+Comment[sr]=digiKam-ов прикључак за ефекат слике у уљу
+Comment[sr@Latn]=digiKam-ov priključak za efekat slike u ulju
+Comment[sv]=Digikam insticksprogram för oljemålningsbildeffekt
+Comment[tr]=digiKam için resmi yağlıboyaya benzetme eklentisi
+Comment[uk]=Втулок створення ефекту олійних фарб для digiKam
+Comment[vi]=Phần bổ sung hiệu ứng ảnh sơn dầu cho digiKam
+Comment[xx]=xxOil paint image effect plugin for digiKamxx
+
+X-KDE-Library=digikamimageplugin_oilpaint
+author=Gilles Caulier, caulier dot gilles at gmail dot com
diff --git a/digikam/imageplugins/oilpaint/digikamimageplugin_oilpaint_ui.rc b/digikam/imageplugins/oilpaint/digikamimageplugin_oilpaint_ui.rc
new file mode 100644
index 0000000..864c09d
--- /dev/null
+++ b/digikam/imageplugins/oilpaint/digikamimageplugin_oilpaint_ui.rc
@@ -0,0 +1,20 @@
+<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
+<kpartgui version="5" name="digikamimageplugin_oilpaint" >
+
+ <MenuBar>
+
+ <Menu name="Filters" ><text>F&amp;ilters</text>
+ <Action name="imageplugin_oilpaint" />
+ </Menu>
+
+ </MenuBar>
+
+ <ToolBar name="ToolBar" >
+ <text>Main Toolbar</text>
+ </ToolBar>
+
+ <ActionProperties>
+ <Action shortcut="" name="imageplugin_oilpaint" />
+ </ActionProperties>
+
+</kpartgui>
diff --git a/digikam/imageplugins/oilpaint/imageeffect_oilpaint.cpp b/digikam/imageplugins/oilpaint/imageeffect_oilpaint.cpp
new file mode 100644
index 0000000..bbe7308
--- /dev/null
+++ b/digikam/imageplugins/oilpaint/imageeffect_oilpaint.cpp
@@ -0,0 +1,201 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2004-08-25
+ * Description : a plugin to simulate Oil Painting
+ *
+ * Copyright (C) 2004-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ * Copyright (C) 2006-2008 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
+ *
+ * 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, 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.
+ *
+ * ============================================================ */
+
+// Qt includes.
+
+#include <qlabel.h>
+#include <qwhatsthis.h>
+#include <qimage.h>
+#include <qlayout.h>
+
+// KDE includes.
+
+#include <kcursor.h>
+#include <klocale.h>
+#include <kaboutdata.h>
+#include <kiconloader.h>
+#include <kapplication.h>
+#include <kstandarddirs.h>
+#include <knuminput.h>
+#include <kconfig.h>
+
+// Local includes.
+
+#include "version.h"
+#include "ddebug.h"
+#include "dimg.h"
+#include "imageiface.h"
+#include "imagewidget.h"
+#include "oilpaint.h"
+#include "imageeffect_oilpaint.h"
+#include "imageeffect_oilpaint.moc"
+
+namespace DigikamOilPaintImagesPlugin
+{
+
+ImageEffect_OilPaint::ImageEffect_OilPaint(QWidget* parent)
+ : Digikam::CtrlPanelDlg(parent, i18n("Apply Oil Paint Effect"),
+ "oilpaint", false, false, true,
+ Digikam::ImagePannelWidget::SeparateViewAll)
+{
+ QString whatsThis;
+
+ KAboutData* about = new KAboutData("digikam",
+ I18N_NOOP("Oil Paint"),
+ digikam_version,
+ I18N_NOOP("An oil painting image effect plugin for digiKam."),
+ KAboutData::License_GPL,
+ "(c) 2004-2005, Gilles Caulier\n"
+ "(c) 2006-2008, Gilles Caulier and Marcel Wiesweg",
+ 0,
+ "http://wwww.digikam.org");
+
+ about->addAuthor("Gilles Caulier", I18N_NOOP("Author and maintainer"),
+ "caulier dot gilles at gmail dot com");
+
+ about->addAuthor("Pieter Z. Voloshyn", I18N_NOOP("Oil paint algorithm"),
+ "pieter dot voloshyn at gmail dot com");
+
+ about->addAuthor("Marcel Wiesweg", I18N_NOOP("Developer"),
+ "marcel dot wiesweg at gmx dot de");
+
+ setAboutData(about);
+
+ // -------------------------------------------------------------
+
+ QWidget *gboxSettings = new QWidget(m_imagePreviewWidget);
+ QGridLayout* gridSettings = new QGridLayout( gboxSettings, 3, 1, 0, spacingHint());
+
+ QLabel *label1 = new QLabel(i18n("Brush size:"), gboxSettings);
+ m_brushSizeInput = new KIntNumInput(gboxSettings);
+ m_brushSizeInput->setRange(1, 5, 1, true);
+ QWhatsThis::add( m_brushSizeInput, i18n("<p>Set here the brush size to use for "
+ "simulating the oil painting.") );
+
+ gridSettings->addMultiCellWidget(label1, 0, 0, 0, 1);
+ gridSettings->addMultiCellWidget(m_brushSizeInput, 1, 1, 0, 1);
+
+ // -------------------------------------------------------------
+
+ QLabel *label2 = new QLabel(i18n("Smooth:"), gboxSettings);
+ m_smoothInput = new KIntNumInput(gboxSettings);
+ m_smoothInput->setRange(10, 255, 1, true);
+ QWhatsThis::add( m_smoothInput, i18n("<p>This value controls the smoothing effect "
+ "of the brush under the canvas.") );
+
+ gridSettings->addMultiCellWidget(label2, 2, 2, 0, 1);
+ gridSettings->addMultiCellWidget(m_smoothInput, 3, 3, 0, 1);
+
+ m_imagePreviewWidget->setUserAreaWidget(gboxSettings);
+
+ // -------------------------------------------------------------
+
+ connect(m_brushSizeInput, SIGNAL(valueChanged (int)),
+ this, SLOT(slotTimer()));
+
+ connect(m_smoothInput, SIGNAL(valueChanged (int)),
+ this, SLOT(slotTimer()));
+}
+
+ImageEffect_OilPaint::~ImageEffect_OilPaint()
+{
+}
+
+void ImageEffect_OilPaint::renderingFinished()
+{
+ m_brushSizeInput->setEnabled(true);
+ m_smoothInput->setEnabled(true);
+}
+
+void ImageEffect_OilPaint::readUserSettings()
+{
+ KConfig* config = kapp->config();
+ config->setGroup("oilpaint Tool Dialog");
+ m_brushSizeInput->blockSignals(true);
+ m_smoothInput->blockSignals(true);
+ m_brushSizeInput->setValue(config->readNumEntry("BrushSize", 1));
+ m_smoothInput->setValue(config->readNumEntry("SmoothAjustment", 30));
+ m_brushSizeInput->blockSignals(false);
+ m_smoothInput->blockSignals(false);
+}
+
+void ImageEffect_OilPaint::writeUserSettings()
+{
+ KConfig* config = kapp->config();
+ config->setGroup("oilpaint Tool Dialog");
+ config->writeEntry("BrushSize", m_brushSizeInput->value());
+ config->writeEntry("SmoothAjustment", m_smoothInput->value());
+ config->sync();
+}
+
+void ImageEffect_OilPaint::resetValues()
+{
+ m_brushSizeInput->blockSignals(true);
+ m_smoothInput->blockSignals(true);
+ m_brushSizeInput->setValue(1);
+ m_smoothInput->setValue(30);
+ m_brushSizeInput->blockSignals(false);
+ m_smoothInput->blockSignals(false);
+}
+
+void ImageEffect_OilPaint::prepareEffect()
+{
+ m_brushSizeInput->setEnabled(false);
+ m_smoothInput->setEnabled(false);
+
+ Digikam::DImg image = m_imagePreviewWidget->getOriginalRegionImage();
+
+ int b = m_brushSizeInput->value();
+ int s = m_smoothInput->value();
+
+ m_threadedFilter = dynamic_cast<Digikam::DImgThreadedFilter *>(new OilPaint(&image, this, b, s));
+}
+
+void ImageEffect_OilPaint::prepareFinal()
+{
+ m_brushSizeInput->setEnabled(false);
+ m_smoothInput->setEnabled(false);
+
+ int b = m_brushSizeInput->value();
+ int s = m_smoothInput->value();
+
+ Digikam::ImageIface iface(0, 0);
+ m_threadedFilter = dynamic_cast<Digikam::DImgThreadedFilter *>(new OilPaint(iface.getOriginalImg(), this, b, s));
+}
+
+void ImageEffect_OilPaint::putPreviewData(void)
+{
+ m_imagePreviewWidget->setPreviewImage(m_threadedFilter->getTargetImage());
+}
+
+void ImageEffect_OilPaint::putFinalData(void)
+{
+ Digikam::ImageIface iface(0, 0);
+
+ iface.putOriginalImage(i18n("Oil Paint"),
+ m_threadedFilter->getTargetImage().bits());
+}
+
+} // NameSpace DigikamOilPaintImagesPlugin
+
diff --git a/digikam/imageplugins/oilpaint/imageeffect_oilpaint.h b/digikam/imageplugins/oilpaint/imageeffect_oilpaint.h
new file mode 100644
index 0000000..76c4122
--- /dev/null
+++ b/digikam/imageplugins/oilpaint/imageeffect_oilpaint.h
@@ -0,0 +1,68 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2004-08-25
+ * Description : a plugin to simulate Oil Painting
+ *
+ * Copyright (C) 2004-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ * Copyright (C) 2006-2008 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
+ *
+ * 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, 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.
+ *
+ * ============================================================ */
+
+#ifndef IMAGEEFFECT_OILPAINT_H
+#define IMAGEEFFECT_OILPAINT_H
+
+// Digikam includes.
+
+#include "ctrlpaneldlg.h"
+
+class KIntNumInput;
+
+namespace DigikamOilPaintImagesPlugin
+{
+
+class ImageEffect_OilPaint : public Digikam::CtrlPanelDlg
+{
+ Q_OBJECT
+
+public:
+
+ ImageEffect_OilPaint(QWidget* parent);
+ ~ImageEffect_OilPaint();
+
+private slots:
+
+ void readUserSettings();
+
+private:
+
+ void writeUserSettings();
+ void resetValues();
+ void prepareEffect();
+ void prepareFinal();
+ void putPreviewData();
+ void putFinalData();
+ void renderingFinished();
+
+private:
+
+ KIntNumInput *m_brushSizeInput;
+ KIntNumInput *m_smoothInput;
+};
+
+} // NameSpace DigikamOilPaintImagesPlugin
+
+#endif /* IMAGEEFFECT_OILPAINT_H */
diff --git a/digikam/imageplugins/oilpaint/imageplugin_oilpaint.cpp b/digikam/imageplugins/oilpaint/imageplugin_oilpaint.cpp
new file mode 100644
index 0000000..d84efea
--- /dev/null
+++ b/digikam/imageplugins/oilpaint/imageplugin_oilpaint.cpp
@@ -0,0 +1,70 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2004-08-25
+ * Description : a plugin to simulate Oil Painting
+ *
+ * Copyright (C) 2004-2008 by Gilles Caulier <caulier dot gilles at gmail dot 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, 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.
+ *
+ * ============================================================ */
+
+// KDE includes.
+
+#include <klocale.h>
+#include <kgenericfactory.h>
+#include <klibloader.h>
+#include <kaction.h>
+#include <kcursor.h>
+#include <kapplication.h>
+
+// Local includes.
+
+#include "ddebug.h"
+#include "oilpainttool.h"
+#include "imageplugin_oilpaint.h"
+#include "imageplugin_oilpaint.moc"
+
+using namespace DigikamOilPaintImagesPlugin;
+
+K_EXPORT_COMPONENT_FACTORY(digikamimageplugin_oilpaint,
+ KGenericFactory<ImagePlugin_OilPaint>("digikamimageplugin_oilpaint"));
+
+ImagePlugin_OilPaint::ImagePlugin_OilPaint(QObject *parent, const char*, const QStringList&)
+ : Digikam::ImagePlugin(parent, "ImagePlugin_OilPaint")
+{
+ m_oilpaintAction = new KAction(i18n("Oil Paint..."), "oilpaint", 0,
+ this, SLOT(slotOilPaint()),
+ actionCollection(), "imageplugin_oilpaint");
+
+ setXMLFile( "digikamimageplugin_oilpaint_ui.rc" );
+
+ DDebug() << "ImagePlugin_OilPaint plugin loaded" << endl;
+}
+
+ImagePlugin_OilPaint::~ImagePlugin_OilPaint()
+{
+}
+
+void ImagePlugin_OilPaint::setEnabledActions(bool enable)
+{
+ m_oilpaintAction->setEnabled(enable);
+}
+
+void ImagePlugin_OilPaint::slotOilPaint()
+{
+ OilPaintTool *tool = new OilPaintTool(this);
+ loadTool(tool);
+}
diff --git a/digikam/imageplugins/oilpaint/imageplugin_oilpaint.h b/digikam/imageplugins/oilpaint/imageplugin_oilpaint.h
new file mode 100644
index 0000000..d7d8958
--- /dev/null
+++ b/digikam/imageplugins/oilpaint/imageplugin_oilpaint.h
@@ -0,0 +1,55 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2004-08-25
+ * Description : a plugin to simulate Oil Painting
+ *
+ * Copyright (C) 2004-2008 by Gilles Caulier <caulier dot gilles at gmail dot 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, 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.
+ *
+ * ============================================================ */
+
+#ifndef IMAGEPLUGIN_OILPAINT_H
+#define IMAGEPLUGIN_OILPAINT_H
+
+// Digikam includes.
+
+#include "imageplugin.h"
+#include "digikam_export.h"
+
+class KAction;
+
+class DIGIKAMIMAGEPLUGINS_EXPORT ImagePlugin_OilPaint : public Digikam::ImagePlugin
+{
+ Q_OBJECT
+
+public:
+
+ ImagePlugin_OilPaint(QObject *parent, const char* name,
+ const QStringList &args);
+ ~ImagePlugin_OilPaint();
+
+ void setEnabledActions(bool enable);
+
+private slots:
+
+ void slotOilPaint();
+
+private:
+
+ KAction *m_oilpaintAction;
+};
+
+#endif /* IMAGEPLUGIN_OILPAINT_H */
diff --git a/digikam/imageplugins/oilpaint/oilpaint.cpp b/digikam/imageplugins/oilpaint/oilpaint.cpp
new file mode 100644
index 0000000..b17b240
--- /dev/null
+++ b/digikam/imageplugins/oilpaint/oilpaint.cpp
@@ -0,0 +1,203 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2005-05-25
+ * Description : Oil Painting threaded image filter.
+ *
+ * Copyright (C) 2005-2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ * Copyright (C) 2006-2007 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
+ *
+ * Original OilPaint algorithm copyrighted 2004 by
+ * Pieter Z. Voloshyn <pieter dot voloshyn at gmail dot 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, 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.
+ *
+ * ============================================================ */
+
+// C++ includes.
+
+#include <cmath>
+#include <cstdlib>
+
+// Local includes.
+
+#include "ddebug.h"
+#include "dimg.h"
+#include "dimggaussianblur.h"
+#include "dimgimagefilters.h"
+#include "oilpaint.h"
+
+namespace DigikamOilPaintImagesPlugin
+{
+
+OilPaint::OilPaint(Digikam::DImg *orgImage, QObject *parent, int brushSize, int smoothness)
+ : Digikam::DImgThreadedFilter(orgImage, parent, "OilPaint")
+{
+ m_brushSize = brushSize;
+ m_smoothness = smoothness;
+ initFilter();
+}
+
+void OilPaint::filterImage(void)
+{
+ oilpaintImage(m_orgImage, m_destImage, m_brushSize, m_smoothness);
+}
+
+// This method have been ported from Pieter Z. Voloshyn algorithm code.
+
+/* Function to apply the OilPaint effect.
+ *
+ * data => The image data in RGBA mode.
+ * w => Width of image.
+ * h => Height of image.
+ * BrushSize => Brush size.
+ * Smoothness => Smooth value.
+ *
+ * Theory => Using MostFrequentColor function we take the main color in
+ * a matrix and simply write at the original position.
+ */
+
+void OilPaint::oilpaintImage(Digikam::DImg &orgImage, Digikam::DImg &destImage, int BrushSize, int Smoothness)
+{
+ int progress;
+ Digikam::DColor mostFrequentColor;
+ int w,h;
+
+ mostFrequentColor.setSixteenBit(orgImage.sixteenBit());
+ w = (int)orgImage.width();
+ h = (int)orgImage.height();
+ uchar *dest = destImage.bits();
+ int bytesDepth = orgImage.bytesDepth();
+ uchar *dptr;
+
+ // Allocate some arrays to be used.
+ // Do this here once for all to save a few million new / delete operations
+ m_intensityCount = new uchar[Smoothness + 1];
+ m_averageColorR = new uint[Smoothness + 1];
+ m_averageColorG = new uint[Smoothness + 1];
+ m_averageColorB = new uint[Smoothness + 1];
+
+ for (int h2 = 0; !m_cancel && (h2 < h); h2++)
+ {
+ for (int w2 = 0; !m_cancel && (w2 < w); w2++)
+ {
+ mostFrequentColor = MostFrequentColor(orgImage, w2, h2, BrushSize, Smoothness);
+ dptr = dest + w2*bytesDepth + (w*h2*bytesDepth);
+ mostFrequentColor.setPixel(dptr);
+ }
+
+ progress = (int) (((double)h2 * 100.0) / h);
+ if ( progress%5 == 0 )
+ postProgress( progress );
+ }
+
+ // free all the arrays
+ delete [] m_intensityCount;
+ delete [] m_averageColorR;
+ delete [] m_averageColorG;
+ delete [] m_averageColorB;
+}
+
+// This method have been ported from Pieter Z. Voloshyn algorithm code.
+
+/* Function to determine the most frequent color in a matrix
+ *
+ * Bits => Bits array
+ * Width => Image width
+ * Height => Image height
+ * X => Position horizontal
+ * Y => Position vertical
+ * Radius => Is the radius of the matrix to be analized
+ * Intensity => Intensity to calcule
+ *
+ * Theory => This function creates a matrix with the analized pixel in
+ * the center of this matrix and find the most frequenty color
+ */
+
+Digikam::DColor OilPaint::MostFrequentColor(Digikam::DImg &src, int X, int Y, int Radius, int Intensity)
+{
+ int i, w, h, I, Width, Height;
+ uint red, green, blue;
+
+ uchar *dest = src.bits();
+ int bytesDepth = src.bytesDepth();
+ uchar *sptr;
+ bool sixteenBit = src.sixteenBit();
+
+ Digikam::DColor mostFrequentColor;
+
+ double Scale = Intensity / (sixteenBit ? 65535.0 : 255.0);
+ Width = (int)src.width();
+ Height = (int)src.height();
+
+ // Erase the array
+ memset(m_intensityCount, 0, (Intensity + 1) * sizeof (uchar));
+
+ for (w = X - Radius; w <= X + Radius; w++)
+ {
+ for (h = Y - Radius; h <= Y + Radius; h++)
+ {
+ // This condition helps to identify when a point doesn't exist
+
+ if ((w >= 0) && (w < Width) && (h >= 0) && (h < Height))
+ {
+ sptr = dest + w*bytesDepth + (Width*h*bytesDepth);
+ Digikam::DColor color(sptr, sixteenBit);
+ red = (uint)color.red();
+ green = (uint)color.green();
+ blue = (uint)color.blue();
+
+ I = lround(GetIntensity (red, green, blue) * Scale);
+ m_intensityCount[I]++;
+
+ if (m_intensityCount[I] == 1)
+ {
+ m_averageColorR[I] = red;
+ m_averageColorG[I] = green;
+ m_averageColorB[I] = blue;
+ }
+ else
+ {
+ m_averageColorR[I] += red;
+ m_averageColorG[I] += green;
+ m_averageColorB[I] += blue;
+ }
+ }
+ }
+ }
+
+ I = 0;
+ int MaxInstance = 0;
+
+ for (i = 0 ; i <= Intensity ; i++)
+ {
+ if (m_intensityCount[i] > MaxInstance)
+ {
+ I = i;
+ MaxInstance = m_intensityCount[i];
+ }
+ }
+
+ // get Alpha channel value from original (unchanged)
+ mostFrequentColor = src.getPixelColor(X, Y);
+
+ // Overwrite RGB values to destination.
+ mostFrequentColor.setRed(m_averageColorR[I] / MaxInstance);
+ mostFrequentColor.setGreen(m_averageColorG[I] / MaxInstance);
+ mostFrequentColor.setBlue(m_averageColorB[I] / MaxInstance);
+
+ return mostFrequentColor;
+}
+
+} // NameSpace DigikamOilPaintImagesPlugin
diff --git a/digikam/imageplugins/oilpaint/oilpaint.h b/digikam/imageplugins/oilpaint/oilpaint.h
new file mode 100644
index 0000000..b69c6d0
--- /dev/null
+++ b/digikam/imageplugins/oilpaint/oilpaint.h
@@ -0,0 +1,72 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2005-05-25
+ * Description : Oil Painting threaded image filter.
+ *
+ * Copyright (C) 2005-2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ * Copyright (C) 2006-2007 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
+ *
+ * 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, 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.
+ *
+ * ============================================================ */
+
+#ifndef OILPAINT_H
+#define OILPAINT_H
+
+// Digikam includes.
+
+#include "dimgthreadedfilter.h"
+
+namespace DigikamOilPaintImagesPlugin
+{
+
+class OilPaint : public Digikam::DImgThreadedFilter
+{
+
+public:
+
+ OilPaint(Digikam::DImg *orgImage, QObject *parent=0, int brushSize=1, int smoothness=30);
+
+ ~OilPaint(){};
+
+private:
+
+ virtual void filterImage(void);
+
+ void oilpaintImage(Digikam::DImg &orgImage, Digikam::DImg &destImage, int BrushSize, int Smoothness);
+
+ Digikam::DColor MostFrequentColor (Digikam::DImg &src,
+ int X, int Y, int Radius, int Intensity);
+
+ // Function to calculate the color intensity and return the luminance (Y)
+ // component of YIQ color model.
+ inline double GetIntensity(uint Red, uint Green, uint Blue)
+ { return Red * 0.3 + Green * 0.59 + Blue * 0.11; };
+
+private:
+
+ uchar *m_intensityCount;
+
+ int m_brushSize;
+ int m_smoothness;
+
+ uint *m_averageColorR;
+ uint *m_averageColorG;
+ uint *m_averageColorB;
+};
+
+} // NameSpace DigikamOilPaintImagesPlugin
+
+#endif /* OILPAINT_H */
diff --git a/digikam/imageplugins/oilpaint/oilpainttool.cpp b/digikam/imageplugins/oilpaint/oilpainttool.cpp
new file mode 100644
index 0000000..7d166d2
--- /dev/null
+++ b/digikam/imageplugins/oilpaint/oilpainttool.cpp
@@ -0,0 +1,208 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2004-08-25
+ * Description : a plugin to simulate Oil Painting
+ *
+ * Copyright (C) 2004-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ * Copyright (C) 2006-2008 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
+ *
+ * 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, 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.
+ *
+ * ============================================================ */
+
+// Qt includes.
+
+#include <qimage.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qwhatsthis.h>
+
+// KDE includes.
+
+#include <kaboutdata.h>
+#include <kapplication.h>
+#include <kconfig.h>
+#include <kcursor.h>
+#include <kiconloader.h>
+#include <klocale.h>
+#include <kstandarddirs.h>
+
+// LibKDcraw includes.
+
+#include <libkdcraw/rnuminput.h>
+
+// Local includes.
+
+#include "daboutdata.h"
+#include "ddebug.h"
+#include "dimg.h"
+#include "imageiface.h"
+#include "imagepanelwidget.h"
+#include "editortoolsettings.h"
+#include "oilpaint.h"
+#include "oilpainttool.h"
+#include "oilpainttool.moc"
+
+using namespace KDcrawIface;
+using namespace Digikam;
+
+namespace DigikamOilPaintImagesPlugin
+{
+
+OilPaintTool::OilPaintTool(QObject* parent)
+ : EditorToolThreaded(parent)
+{
+ setName("oilpaint");
+ setToolName(i18n("Oil Paint"));
+ setToolIcon(SmallIcon("oilpaint"));
+
+ // -------------------------------------------------------------
+
+ m_gboxSettings = new EditorToolSettings(EditorToolSettings::Default|
+ EditorToolSettings::Ok|
+ EditorToolSettings::Cancel|
+ EditorToolSettings::Try,
+ EditorToolSettings::PanIcon);
+ QGridLayout* grid = new QGridLayout( m_gboxSettings->plainPage(), 4, 1);
+
+ QLabel *label1 = new QLabel(i18n("Brush size:"), m_gboxSettings->plainPage());
+ m_brushSizeInput = new RIntNumInput(m_gboxSettings->plainPage());
+ m_brushSizeInput->setRange(1, 5, 1);
+ m_brushSizeInput->setDefaultValue(1);
+ QWhatsThis::add( m_brushSizeInput, i18n("<p>Set here the brush size to use for "
+ "simulating the oil painting.") );
+
+ // -------------------------------------------------------------
+
+ QLabel *label2 = new QLabel(i18n("Smooth:"), m_gboxSettings->plainPage());
+ m_smoothInput = new RIntNumInput(m_gboxSettings->plainPage());
+ m_smoothInput->setRange(10, 255, 1);
+ m_smoothInput->setDefaultValue(30);
+ QWhatsThis::add( m_smoothInput, i18n("<p>This value controls the smoothing effect "
+ "of the brush under the canvas.") );
+
+
+ grid->addMultiCellWidget(label1, 0, 0, 0, 1);
+ grid->addMultiCellWidget(m_brushSizeInput, 1, 1, 0, 1);
+ grid->addMultiCellWidget(label2, 2, 2, 0, 1);
+ grid->addMultiCellWidget(m_smoothInput, 3, 3, 0, 1);
+ grid->setRowStretch(4, 10);
+ grid->setMargin(m_gboxSettings->spacingHint());
+ grid->setSpacing(m_gboxSettings->spacingHint());
+
+ setToolSettings(m_gboxSettings);
+
+ // -------------------------------------------------------------
+
+ m_previewWidget = new ImagePanelWidget(470, 350, "oilpaint Tool", m_gboxSettings->panIconView());
+
+ setToolView(m_previewWidget);
+ init();
+
+ // -------------------------------------------------------------
+
+ // this filter is relative slow, so we should use the try button instead right now
+
+ // connect(m_brushSizeInput, SIGNAL(valueChanged (int)),
+ // this, SLOT(slotTimer()));
+ //
+ // connect(m_smoothInput, SIGNAL(valueChanged (int)),
+ // this, SLOT(slotTimer()));
+}
+
+OilPaintTool::~OilPaintTool()
+{
+}
+
+void OilPaintTool::renderingFinished()
+{
+ m_brushSizeInput->setEnabled(true);
+ m_smoothInput->setEnabled(true);
+}
+
+void OilPaintTool::readSettings()
+{
+ KConfig* config = kapp->config();
+ config->setGroup("oilpaint Tool");
+ m_brushSizeInput->blockSignals(true);
+ m_smoothInput->blockSignals(true);
+
+ m_brushSizeInput->setValue(config->readNumEntry("BrushSize", m_brushSizeInput->defaultValue()));
+ m_smoothInput->setValue(config->readNumEntry("SmoothAjustment", m_smoothInput->defaultValue()));
+
+ m_brushSizeInput->blockSignals(false);
+ m_smoothInput->blockSignals(false);
+}
+
+void OilPaintTool::writeSettings()
+{
+ KConfig* config = kapp->config();
+ config->setGroup("oilpaint Tool");
+ config->writeEntry("BrushSize", m_brushSizeInput->value());
+ config->writeEntry("SmoothAjustment", m_smoothInput->value());
+ m_previewWidget->writeSettings();
+ config->sync();
+}
+
+void OilPaintTool::slotResetSettings()
+{
+ m_brushSizeInput->blockSignals(true);
+ m_smoothInput->blockSignals(true);
+
+ m_brushSizeInput->slotReset();
+ m_smoothInput->slotReset();
+
+ m_brushSizeInput->blockSignals(false);
+ m_smoothInput->blockSignals(false);
+}
+
+void OilPaintTool::prepareEffect()
+{
+ m_brushSizeInput->setEnabled(false);
+ m_smoothInput->setEnabled(false);
+
+ DImg image = m_previewWidget->getOriginalRegionImage();
+
+ int b = m_brushSizeInput->value();
+ int s = m_smoothInput->value();
+
+ setFilter(dynamic_cast<DImgThreadedFilter*>(new OilPaint(&image, this, b, s)));
+}
+
+void OilPaintTool::prepareFinal()
+{
+ m_brushSizeInput->setEnabled(false);
+ m_smoothInput->setEnabled(false);
+
+ int b = m_brushSizeInput->value();
+ int s = m_smoothInput->value();
+
+ ImageIface iface(0, 0);
+ setFilter(dynamic_cast<DImgThreadedFilter*>(new OilPaint(iface.getOriginalImg(), this, b, s)));
+}
+
+void OilPaintTool::putPreviewData()
+{
+ m_previewWidget->setPreviewImage(filter()->getTargetImage());
+}
+
+void OilPaintTool::putFinalData()
+{
+ ImageIface iface(0, 0);
+ iface.putOriginalImage(i18n("Oil Paint"), filter()->getTargetImage().bits());
+}
+
+} // NameSpace DigikamOilPaintImagesPlugin
+
diff --git a/digikam/imageplugins/oilpaint/oilpainttool.h b/digikam/imageplugins/oilpaint/oilpainttool.h
new file mode 100644
index 0000000..1c6d774
--- /dev/null
+++ b/digikam/imageplugins/oilpaint/oilpainttool.h
@@ -0,0 +1,81 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2004-08-25
+ * Description : a plugin to simulate Oil Painting
+ *
+ * Copyright (C) 2004-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ * Copyright (C) 2006-2008 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
+ *
+ * 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, 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.
+ *
+ * ============================================================ */
+
+#ifndef OILPAINTTOOL_H
+#define OILPAINTTOOL_H
+
+// Digikam includes.
+
+#include "editortool.h"
+
+namespace KDcrawIface
+{
+class RIntNumInput;
+}
+
+namespace Digikam
+{
+class EditorToolSettings;
+class ImagePanelWidget;
+}
+
+namespace DigikamOilPaintImagesPlugin
+{
+
+class OilPaintTool : public Digikam::EditorToolThreaded
+{
+ Q_OBJECT
+
+public:
+
+ OilPaintTool(QObject* parent);
+ ~OilPaintTool();
+
+private slots:
+
+ void slotResetSettings();
+
+private:
+
+ void readSettings();
+ void writeSettings();
+ void prepareEffect();
+ void prepareFinal();
+ void putPreviewData();
+ void putFinalData();
+ void renderingFinished();
+
+private:
+
+ KDcrawIface::RIntNumInput *m_brushSizeInput;
+ KDcrawIface::RIntNumInput *m_smoothInput;
+
+ Digikam::ImagePanelWidget *m_previewWidget;
+
+ Digikam::EditorToolSettings *m_gboxSettings;
+};
+
+} // NameSpace DigikamOilPaintImagesPlugin
+
+#endif /* OILPAINTTOOL_H */