diff options
Diffstat (limited to 'src/imageplugins/oilpaint')
-rw-r--r-- | src/imageplugins/oilpaint/Makefile.am | 34 | ||||
-rw-r--r-- | src/imageplugins/oilpaint/digikamimageplugin_oilpaint.desktop | 51 | ||||
-rw-r--r-- | src/imageplugins/oilpaint/digikamimageplugin_oilpaint_ui.rc | 20 | ||||
-rw-r--r-- | src/imageplugins/oilpaint/imageeffect_oilpaint.cpp | 201 | ||||
-rw-r--r-- | src/imageplugins/oilpaint/imageeffect_oilpaint.h | 69 | ||||
-rw-r--r-- | src/imageplugins/oilpaint/imageplugin_oilpaint.cpp | 70 | ||||
-rw-r--r-- | src/imageplugins/oilpaint/imageplugin_oilpaint.h | 56 | ||||
-rw-r--r-- | src/imageplugins/oilpaint/oilpaint.cpp | 203 | ||||
-rw-r--r-- | src/imageplugins/oilpaint/oilpaint.h | 72 | ||||
-rw-r--r-- | src/imageplugins/oilpaint/oilpainttool.cpp | 208 | ||||
-rw-r--r-- | src/imageplugins/oilpaint/oilpainttool.h | 82 |
11 files changed, 1066 insertions, 0 deletions
diff --git a/src/imageplugins/oilpaint/Makefile.am b/src/imageplugins/oilpaint/Makefile.am new file mode 100644 index 00000000..f50d7408 --- /dev/null +++ b/src/imageplugins/oilpaint/Makefile.am @@ -0,0 +1,34 @@ +METASOURCES = AUTO + +INCLUDES = -I$(top_srcdir)/src/utilities/imageeditor/editor \ + -I$(top_srcdir)/src/utilities/imageeditor/canvas \ + -I$(top_srcdir)/src/libs/histogram \ + -I$(top_srcdir)/src/libs/levels \ + -I$(top_srcdir)/src/libs/curves \ + -I$(top_srcdir)/src/libs/whitebalance \ + -I$(top_srcdir)/src/libs/widgets/common \ + -I$(top_srcdir)/src/libs/widgets/iccprofiles \ + -I$(top_srcdir)/src/libs/widgets/imageplugins \ + -I$(top_srcdir)/src/libs/dialogs \ + -I$(top_srcdir)/src/libs/dimg \ + -I$(top_srcdir)/src/libs/dmetadata \ + -I$(top_srcdir)/src/libs/dimg/filters \ + -I$(top_srcdir)/src/digikam \ + $(LIBKDCRAW_CFLAGS) \ + $(all_includes) + +digikamimageplugin_oilpaint_la_SOURCES = imageplugin_oilpaint.cpp \ + oilpainttool.cpp oilpaint.cpp + +digikamimageplugin_oilpaint_la_LIBADD = $(LIB_TDEPARTS) \ + $(top_builddir)/src/digikam/libdigikam.la + +digikamimageplugin_oilpaint_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) -ltdecore -ltdeui $(LIB_TQT) -ltdefx -lkdcraw -ltdeio + +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/src/imageplugins/oilpaint/digikamimageplugin_oilpaint.desktop b/src/imageplugins/oilpaint/digikamimageplugin_oilpaint.desktop new file mode 100644 index 00000000..875c7f16 --- /dev/null +++ b/src/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 +X-TDE-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-TDE-Library=digikamimageplugin_oilpaint +author=Gilles Caulier, caulier dot gilles at gmail dot com diff --git a/src/imageplugins/oilpaint/digikamimageplugin_oilpaint_ui.rc b/src/imageplugins/oilpaint/digikamimageplugin_oilpaint_ui.rc new file mode 100644 index 00000000..864c09db --- /dev/null +++ b/src/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&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/src/imageplugins/oilpaint/imageeffect_oilpaint.cpp b/src/imageplugins/oilpaint/imageeffect_oilpaint.cpp new file mode 100644 index 00000000..da07be05 --- /dev/null +++ b/src/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. + * + * ============================================================ */ + +// TQt includes. + +#include <tqlabel.h> +#include <tqwhatsthis.h> +#include <tqimage.h> +#include <tqlayout.h> + +// KDE includes. + +#include <kcursor.h> +#include <tdelocale.h> +#include <tdeaboutdata.h> +#include <kiconloader.h> +#include <tdeapplication.h> +#include <kstandarddirs.h> +#include <knuminput.h> +#include <tdeconfig.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(TQWidget* parent) + : Digikam::CtrlPanelDlg(parent, i18n("Apply Oil Paint Effect"), + "oilpaint", false, false, true, + Digikam::ImagePannelWidget::SeparateViewAll) +{ + TQString whatsThis; + + TDEAboutData* about = new TDEAboutData("digikam", + I18N_NOOP("Oil Paint"), + digikam_version, + I18N_NOOP("An oil painting image effect plugin for digiKam."), + TDEAboutData::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); + + // ------------------------------------------------------------- + + TQWidget *gboxSettings = new TQWidget(m_imagePreviewWidget); + TQGridLayout* gridSettings = new TQGridLayout( gboxSettings, 3, 1, 0, spacingHint()); + + TQLabel *label1 = new TQLabel(i18n("Brush size:"), gboxSettings); + m_brushSizeInput = new KIntNumInput(gboxSettings); + m_brushSizeInput->setRange(1, 5, 1, true); + TQWhatsThis::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); + + // ------------------------------------------------------------- + + TQLabel *label2 = new TQLabel(i18n("Smooth:"), gboxSettings); + m_smoothInput = new KIntNumInput(gboxSettings); + m_smoothInput->setRange(10, 255, 1, true); + TQWhatsThis::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, TQ_SIGNAL(valueChanged (int)), + this, TQ_SLOT(slotTimer())); + + connect(m_smoothInput, TQ_SIGNAL(valueChanged (int)), + this, TQ_SLOT(slotTimer())); +} + +ImageEffect_OilPaint::~ImageEffect_OilPaint() +{ +} + +void ImageEffect_OilPaint::renderingFinished() +{ + m_brushSizeInput->setEnabled(true); + m_smoothInput->setEnabled(true); +} + +void ImageEffect_OilPaint::readUserSettings() +{ + TDEConfig* 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() +{ + TDEConfig* 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/src/imageplugins/oilpaint/imageeffect_oilpaint.h b/src/imageplugins/oilpaint/imageeffect_oilpaint.h new file mode 100644 index 00000000..527cc2ef --- /dev/null +++ b/src/imageplugins/oilpaint/imageeffect_oilpaint.h @@ -0,0 +1,69 @@ +/* ============================================================ + * + * 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 +{ + TQ_OBJECT + + +public: + + ImageEffect_OilPaint(TQWidget* 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/src/imageplugins/oilpaint/imageplugin_oilpaint.cpp b/src/imageplugins/oilpaint/imageplugin_oilpaint.cpp new file mode 100644 index 00000000..740e89fc --- /dev/null +++ b/src/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 <tdelocale.h> +#include <kgenericfactory.h> +#include <klibloader.h> +#include <tdeaction.h> +#include <kcursor.h> +#include <tdeapplication.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(TQObject *parent, const char*, const TQStringList&) + : Digikam::ImagePlugin(parent, "ImagePlugin_OilPaint") +{ + m_oilpaintAction = new TDEAction(i18n("Oil Paint..."), "oilpaint", 0, + this, TQ_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/src/imageplugins/oilpaint/imageplugin_oilpaint.h b/src/imageplugins/oilpaint/imageplugin_oilpaint.h new file mode 100644 index 00000000..032ee065 --- /dev/null +++ b/src/imageplugins/oilpaint/imageplugin_oilpaint.h @@ -0,0 +1,56 @@ +/* ============================================================ + * + * 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 TDEAction; + +class DIGIKAMIMAGEPLUGINS_EXPORT ImagePlugin_OilPaint : public Digikam::ImagePlugin +{ + TQ_OBJECT + + +public: + + ImagePlugin_OilPaint(TQObject *parent, const char* name, + const TQStringList &args); + ~ImagePlugin_OilPaint(); + + void setEnabledActions(bool enable); + +private slots: + + void slotOilPaint(); + +private: + + TDEAction *m_oilpaintAction; +}; + +#endif /* IMAGEPLUGIN_OILPAINT_H */ diff --git a/src/imageplugins/oilpaint/oilpaint.cpp b/src/imageplugins/oilpaint/oilpaint.cpp new file mode 100644 index 00000000..be9697fa --- /dev/null +++ b/src/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, TQObject *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/src/imageplugins/oilpaint/oilpaint.h b/src/imageplugins/oilpaint/oilpaint.h new file mode 100644 index 00000000..998522a5 --- /dev/null +++ b/src/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, TQObject *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/src/imageplugins/oilpaint/oilpainttool.cpp b/src/imageplugins/oilpaint/oilpainttool.cpp new file mode 100644 index 00000000..25bea302 --- /dev/null +++ b/src/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. + * + * ============================================================ */ + +// TQt includes. + +#include <tqimage.h> +#include <tqlabel.h> +#include <tqlayout.h> +#include <tqwhatsthis.h> + +// KDE includes. + +#include <tdeaboutdata.h> +#include <tdeapplication.h> +#include <tdeconfig.h> +#include <kcursor.h> +#include <kiconloader.h> +#include <tdelocale.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(TQObject* 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); + TQGridLayout* grid = new TQGridLayout( m_gboxSettings->plainPage(), 4, 1); + + TQLabel *label1 = new TQLabel(i18n("Brush size:"), m_gboxSettings->plainPage()); + m_brushSizeInput = new RIntNumInput(m_gboxSettings->plainPage()); + m_brushSizeInput->setRange(1, 5, 1); + m_brushSizeInput->setDefaultValue(1); + TQWhatsThis::add( m_brushSizeInput, i18n("<p>Set here the brush size to use for " + "simulating the oil painting.") ); + + // ------------------------------------------------------------- + + TQLabel *label2 = new TQLabel(i18n("Smooth:"), m_gboxSettings->plainPage()); + m_smoothInput = new RIntNumInput(m_gboxSettings->plainPage()); + m_smoothInput->setRange(10, 255, 1); + m_smoothInput->setDefaultValue(30); + TQWhatsThis::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, TQ_SIGNAL(valueChanged (int)), + // this, TQ_SLOT(slotTimer())); + // + // connect(m_smoothInput, TQ_SIGNAL(valueChanged (int)), + // this, TQ_SLOT(slotTimer())); +} + +OilPaintTool::~OilPaintTool() +{ +} + +void OilPaintTool::renderingFinished() +{ + m_brushSizeInput->setEnabled(true); + m_smoothInput->setEnabled(true); +} + +void OilPaintTool::readSettings() +{ + TDEConfig* 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() +{ + TDEConfig* 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/src/imageplugins/oilpaint/oilpainttool.h b/src/imageplugins/oilpaint/oilpainttool.h new file mode 100644 index 00000000..9c488a57 --- /dev/null +++ b/src/imageplugins/oilpaint/oilpainttool.h @@ -0,0 +1,82 @@ +/* ============================================================ + * + * 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 +{ + TQ_OBJECT + + +public: + + OilPaintTool(TQObject* 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 */ |