summaryrefslogtreecommitdiffstats
path: root/src/imageplugins/filmgrain
diff options
context:
space:
mode:
Diffstat (limited to 'src/imageplugins/filmgrain')
-rw-r--r--src/imageplugins/filmgrain/Makefile.am34
-rw-r--r--src/imageplugins/filmgrain/digikamimageplugin_filmgrain.desktop52
-rw-r--r--src/imageplugins/filmgrain/digikamimageplugin_filmgrain_ui.rc20
-rw-r--r--src/imageplugins/filmgrain/filmgrain.cpp202
-rw-r--r--src/imageplugins/filmgrain/filmgrain.h58
-rw-r--r--src/imageplugins/filmgrain/filmgraintool.cpp195
-rw-r--r--src/imageplugins/filmgrain/filmgraintool.h83
-rw-r--r--src/imageplugins/filmgrain/imageeffect_filmgrain.cpp195
-rw-r--r--src/imageplugins/filmgrain/imageeffect_filmgrain.h74
-rw-r--r--src/imageplugins/filmgrain/imageplugin_filmgrain.cpp71
-rw-r--r--src/imageplugins/filmgrain/imageplugin_filmgrain.h57
11 files changed, 1041 insertions, 0 deletions
diff --git a/src/imageplugins/filmgrain/Makefile.am b/src/imageplugins/filmgrain/Makefile.am
new file mode 100644
index 00000000..c23c9d8e
--- /dev/null
+++ b/src/imageplugins/filmgrain/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_filmgrain_la_SOURCES = imageplugin_filmgrain.cpp \
+ filmgraintool.cpp filmgrain.cpp
+
+digikamimageplugin_filmgrain_la_LIBADD = $(LIB_TDEPARTS) \
+ $(top_builddir)/src/digikam/libdigikam.la
+
+digikamimageplugin_filmgrain_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) -ltdecore -ltdeui $(LIB_TQT) -ltdefx -lkdcraw -ltdeio
+
+kde_services_DATA = digikamimageplugin_filmgrain.desktop
+
+kde_module_LTLIBRARIES = digikamimageplugin_filmgrain.la
+
+rcdir = $(kde_datadir)/digikam
+rc_DATA = digikamimageplugin_filmgrain_ui.rc
+
diff --git a/src/imageplugins/filmgrain/digikamimageplugin_filmgrain.desktop b/src/imageplugins/filmgrain/digikamimageplugin_filmgrain.desktop
new file mode 100644
index 00000000..5ad6582b
--- /dev/null
+++ b/src/imageplugins/filmgrain/digikamimageplugin_filmgrain.desktop
@@ -0,0 +1,52 @@
+[Desktop Entry]
+Name=ImagePlugin_FilmGrain
+Name[bg]=Приставка за снимки - Филмово зърно
+Name[da]=Billedplugin_Filmkorn
+Name[el]=ΠρόσθετοΕικόνας_ΚόκκοςΦιλμ
+Name[fi]=Filmirakeet
+Name[hr]=Zrnatost
+Name[it]=PluginImmagini_GranaPellicola
+Name[nl]=Afbeeldingsplugin_Filmkorrel
+Name[sr]=Зрнаст филм
+Name[sr@Latn]=Zrnast film
+Name[sv]=Insticksprogram för filmkorn
+Name[tr]=ResimEklentisi_FilmTanecikleri
+Name[xx]=xxImagePlugin_FilmGrainxx
+
+Type=Service
+X-TDE-ServiceTypes=Digikam/ImagePlugin
+Encoding=UTF-8
+Comment=Film grain image effect plugin for digiKam
+Comment[bg]=Приставка на digiKam за наподобяване на филмово зърно
+Comment[ca]=Connector pel digiKam d'efecte d'imatge de gra de pel·lícula
+Comment[cs]=Efektový modul pro tvorbu filmového zrna pro digiKam
+Comment[da]=Plugin til filmkorn-effekt på billeder i Digikam
+Comment[de]=digiKam-Modul zum Erzeugen eines Effektes von körnigem Film
+Comment[el]=Πρόσθετο εφέ κόκκου φιλμ για το digiKam
+Comment[es]=Plugin para digiKam de efectos de imagen tipo grano fino de película
+Comment[et]=DigiKami teralisuse pildiefektiplugin
+Comment[fa]=وصلۀ جلوۀ تصویر خرده فیلم برای digiKam
+Comment[fi]=Filmikuvien rakeisuuden jäljittelijä
+Comment[gl]=Un plugin de digiKam para o efeito de grao de filme
+Comment[hr]=digiKam dodatak za efekt zrnatosti filma
+Comment[is]=Íforrit fyrir digiKam sem líkir eftir filmukornum
+Comment[it]=Plugin per l'effetto di grana della pellicola delle immagini per digiKam
+Comment[ja]=digiKam フィルム粒子効果プラグイン
+Comment[nds]=digiKam-Moduul för Effekten vun körnig Film
+Comment[nl]=Digikam-plugin voor filmkorrel
+Comment[pa]=ਡਿਜ਼ੀਕੈਮ ਲਈ ਫਿਲਮ ਗਰੇਨ ਚਿੱਤਰ ਪਰਭਾਵ ਪਲੱਗਇਨ
+Comment[pl]=Wtyczka do programu digiKam oferująca efekty zniekształceń
+Comment[pt]=Um 'plugin' do digiKam para o efeito de grão de filme
+Comment[pt_BR]=Um 'plugin' do digiKam para o efeito de grão de filme
+Comment[ru]=Модуль зернистости изображения для digiKam
+Comment[sk]=digiKam obrázkový plugin pre efekt filmového zrna
+Comment[sr]=digiKam-ов прикључак за ефекат зрнастости филма
+Comment[sr@Latn]=digiKam-ov priključak za efekat zrnastosti filma
+Comment[sv]=Digikam insticksprogram för filmkornsbildeffekt
+Comment[tr]=digiKam için film tanecikleri etkisi eklentisi
+Comment[uk]=Втулок digiKam для створення ефекту фільму на зображеннях
+Comment[vi]=Phần bổ sung hiệu ứng chạm mịn mặt màng ảnh cho digiKam
+Comment[xx]=xxFilm grain image effect plugin for digiKamxx
+
+X-TDE-Library=digikamimageplugin_filmgrain
+author=Gilles Caulier, caulier dot gilles at gmail dot com
diff --git a/src/imageplugins/filmgrain/digikamimageplugin_filmgrain_ui.rc b/src/imageplugins/filmgrain/digikamimageplugin_filmgrain_ui.rc
new file mode 100644
index 00000000..770c2dbd
--- /dev/null
+++ b/src/imageplugins/filmgrain/digikamimageplugin_filmgrain_ui.rc
@@ -0,0 +1,20 @@
+<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
+<kpartgui version="5" name="digikamimageplugin_filmgrain" >
+
+ <MenuBar>
+
+ <Menu name="Filters" ><text>F&amp;ilters</text>
+ <Action name="imageplugin_filmgrain" />
+ </Menu>
+
+ </MenuBar>
+
+ <ToolBar name="ToolBar" >
+ <text>Main Toolbar</text>
+ </ToolBar>
+
+ <ActionProperties>
+ <Action shortcut="" name="imageplugin_filmgrain" />
+ </ActionProperties>
+
+</kpartgui>
diff --git a/src/imageplugins/filmgrain/filmgrain.cpp b/src/imageplugins/filmgrain/filmgrain.cpp
new file mode 100644
index 00000000..57616eb9
--- /dev/null
+++ b/src/imageplugins/filmgrain/filmgrain.cpp
@@ -0,0 +1,202 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2005-05-25
+ * Description : FilmGrain threaded image filter.
+ *
+ * Copyright (C) 2005-2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ * Copyright (C) 2005-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.
+ *
+ * ============================================================ */
+
+// C++ includes.
+
+#include <cmath>
+#include <cstdlib>
+
+// TQt includes.
+
+#include <tqdatetime.h>
+
+// Local includes.
+
+#include "ddebug.h"
+#include "dimg.h"
+#include "dimggaussianblur.h"
+#include "imagecurves.h"
+#include "imagehistogram.h"
+#include "dimgimagefilters.h"
+#include "filmgrain.h"
+
+namespace DigikamFilmGrainImagesPlugin
+{
+
+FilmGrain::FilmGrain(Digikam::DImg *orgImage, TQObject *parent, int sensibility)
+ : Digikam::DImgThreadedFilter(orgImage, parent, "FilmGrain")
+{
+ m_sensibility = sensibility;
+ initFilter();
+}
+
+void FilmGrain::filterImage(void)
+{
+ filmgrainImage(&m_orgImage, m_sensibility);
+}
+
+// This method is based on the Simulate Film grain tutorial from GimpGuru.org web site
+// available at this url : http://www.gimpguru.org/Tutorials/FilmGrain
+
+void FilmGrain::filmgrainImage(Digikam::DImg *orgImage, int Sensibility)
+{
+ // Sensibility: 800..6400
+
+ if (Sensibility <= 0) return;
+
+ int Width = orgImage->width();
+ int Height = orgImage->height();
+ int bytesDepth = orgImage->bytesDepth();
+ bool sixteenBit = orgImage->sixteenBit();
+ uchar* data = orgImage->bits();
+
+ Digikam::DImg grain(Width, Height, sixteenBit); // Grain blured without curves adjustment.
+ Digikam::DImg mask(Width, Height, sixteenBit); // Grain mask with curves adjustment.
+ uchar* pGrainBits = grain.bits();
+ uchar* pMaskBits = mask.bits();
+ uchar* pOutBits = m_destImage.bits(); // Destination image with merged grain mask and original.
+
+ int Noise, Shade, nRand, component, progress;
+ uchar *ptr;
+ Digikam::DColor blendData, grainData, maskData, outData;
+
+ if (sixteenBit)
+ Noise = (Sensibility / 10 + 1) * 256 - 1;
+ else
+ Noise = Sensibility / 10;
+
+ // This value controls the shading pixel effect between original image and grain mask.
+ if (sixteenBit)
+ Shade = (52 + 1) * 256 - 1;
+ else
+ Shade = 52;
+
+ TQDateTime dt = TQDateTime::currentDateTime();
+ TQDateTime Y2000( TQDate(2000, 1, 1), TQTime(0, 0, 0) );
+ uint seed = (uint) dt.secsTo(Y2000);
+
+ // Make gray grain mask.
+
+ grainData.setSixteenBit(sixteenBit);
+
+ for (int x = 0; !m_cancel && x < Width; x++)
+ {
+ for (int y = 0; !m_cancel && y < Height; y++)
+ {
+ ptr = pGrainBits + x*bytesDepth + (y*Width*bytesDepth);
+
+ nRand = (rand_r(&seed) % Noise) - (Noise / 2);
+ if (sixteenBit)
+ component = CLAMP(32768 + nRand, 0, 65535);
+ else
+ component = CLAMP(128 + nRand, 0, 255);
+
+ grainData.setRed (component);
+ grainData.setGreen(component);
+ grainData.setBlue (component);
+ grainData.setAlpha(0);
+
+ grainData.setPixel(ptr);
+ }
+
+ // Update progress bar in dialog.
+ progress = (int) (((double)x * 25.0) / Width);
+
+ if (progress%5 == 0)
+ postProgress( progress );
+ }
+
+ // Smooth grain mask using gaussian blur with radius 1.
+ Digikam::DImgGaussianBlur(this, grain, grain, 25, 30, 1);
+
+ // Normally, film grain tends to be most noticeable in the midtones, and much less
+ // so in the shadows and highlights. Adjust histogram curve to adjust grain like this.
+
+ Digikam::ImageCurves *grainCurves = new Digikam::ImageCurves(sixteenBit);
+
+ // We modify only global luminosity of the grain.
+ if (sixteenBit)
+ {
+ grainCurves->setCurvePoint(Digikam::ImageHistogram::ValueChannel, 0, TQPoint(0, 0));
+ grainCurves->setCurvePoint(Digikam::ImageHistogram::ValueChannel, 8, TQPoint(32768, 32768));
+ grainCurves->setCurvePoint(Digikam::ImageHistogram::ValueChannel, 16, TQPoint(65535, 0));
+ }
+ else
+ {
+ grainCurves->setCurvePoint(Digikam::ImageHistogram::ValueChannel, 0, TQPoint(0, 0));
+ grainCurves->setCurvePoint(Digikam::ImageHistogram::ValueChannel, 8, TQPoint(128, 128));
+ grainCurves->setCurvePoint(Digikam::ImageHistogram::ValueChannel, 16, TQPoint(255, 0));
+ }
+
+ // Calculate curves and lut to apply on grain.
+ grainCurves->curvesCalculateCurve(Digikam::ImageHistogram::ValueChannel);
+ grainCurves->curvesLutSetup(Digikam::ImageHistogram::AlphaChannel);
+ grainCurves->curvesLutProcess(pGrainBits, pMaskBits, Width, Height);
+
+ grain.reset();
+ delete grainCurves;
+
+ // Update progress bar in dialog.
+ postProgress( 40 );
+
+ // Merge src image with grain using shade coefficient.
+
+ int alpha;
+ // get composer for default blending
+ Digikam::DColorComposer *composer = Digikam::DColorComposer::getComposer(Digikam::DColorComposer::PorterDuffNone);
+
+ for (int x = 0; !m_cancel && x < Width; x++)
+ {
+ for (int y = 0; !m_cancel && y < Height; y++)
+ {
+ int offset = x*bytesDepth + (y*Width*bytesDepth);
+
+ // read color from orig image
+ blendData.setColor(data + offset, sixteenBit);
+ // read color from mask
+ maskData.setColor(pMaskBits + offset, sixteenBit);
+ // set shade as alpha value - it will be used as source alpha when blending
+ maskData.setAlpha(Shade);
+
+ // compose, write result to blendData.
+ // Preserve alpha, do not blend it (taken from old algorithm - correct?)
+ alpha = blendData.alpha();
+ composer->compose(blendData, maskData);
+ blendData.setAlpha(alpha);
+
+ // write to destination
+ blendData.setPixel(pOutBits + offset);
+ }
+
+ // Update progress bar in dialog.
+ progress = (int) (50.0 + ((double)x * 50.0) / Width);
+
+ if (progress%5 == 0)
+ postProgress( progress );
+ }
+
+ delete composer;
+}
+
+} // NameSpace DigikamFilmGrainImagesPlugin
diff --git a/src/imageplugins/filmgrain/filmgrain.h b/src/imageplugins/filmgrain/filmgrain.h
new file mode 100644
index 00000000..42bcf03c
--- /dev/null
+++ b/src/imageplugins/filmgrain/filmgrain.h
@@ -0,0 +1,58 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2005-05-25
+ * Description : FilmGrain threaded image filter.
+ *
+ * Copyright (C) 2005-2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ * Copyright (C) 2005-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 FILMGRAIN_H
+#define FILMGRAIN_H
+
+// Digikam includes.
+
+#include "dimgthreadedfilter.h"
+
+namespace DigikamFilmGrainImagesPlugin
+{
+
+class FilmGrain : public Digikam::DImgThreadedFilter
+{
+
+public:
+
+ FilmGrain(Digikam::DImg *orgImage, TQObject *parent=0, int sensibility=12);
+
+ ~FilmGrain(){};
+
+private:
+
+ virtual void filterImage(void);
+
+ void filmgrainImage(Digikam::DImg *orgImage, int Sensibility);
+
+private:
+
+ int m_sensibility;
+};
+
+} // NameSpace DigikamFilmGrainImagesPlugin
+
+#endif /* FILMGRAIN_H */
diff --git a/src/imageplugins/filmgrain/filmgraintool.cpp b/src/imageplugins/filmgrain/filmgraintool.cpp
new file mode 100644
index 00000000..5799d814
--- /dev/null
+++ b/src/imageplugins/filmgrain/filmgraintool.cpp
@@ -0,0 +1,195 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2004-08-26
+ * Description : a digiKam image editor plugin for add film
+ * grain on an image.
+ *
+ * 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 <tqlcdnumber.h>
+#include <tqslider.h>
+#include <tqlayout.h>
+#include <tqimage.h>
+
+// KDE includes.
+
+#include <tdelocale.h>
+#include <tdeaboutdata.h>
+#include <kiconloader.h>
+#include <tdeapplication.h>
+#include <kstandarddirs.h>
+#include <tdeconfig.h>
+
+// Local includes.
+
+#include "daboutdata.h"
+#include "ddebug.h"
+#include "dimg.h"
+#include "imageiface.h"
+#include "imagepanelwidget.h"
+#include "editortoolsettings.h"
+#include "filmgrain.h"
+#include "filmgraintool.h"
+#include "filmgraintool.moc"
+
+using namespace Digikam;
+
+namespace DigikamFilmGrainImagesPlugin
+{
+
+FilmGrainTool::FilmGrainTool(TQObject* parent)
+ : EditorToolThreaded(parent)
+{
+ setName("filmgrain");
+ setToolName(i18n("Film Grain"));
+ setToolIcon(SmallIcon("filmgrain"));
+
+ // -------------------------------------------------------------
+
+ m_gboxSettings = new EditorToolSettings(EditorToolSettings::Default|
+ EditorToolSettings::Ok|
+ EditorToolSettings::Cancel|
+ EditorToolSettings::Try,
+ EditorToolSettings::PanIcon);
+
+ TQGridLayout* grid = new TQGridLayout( m_gboxSettings->plainPage(), 2, 1);
+ TQLabel *label1 = new TQLabel(i18n("Sensitivity (ISO):"), m_gboxSettings->plainPage());
+
+ m_sensibilitySlider = new TQSlider(2, 30, 1, 12, TQt::Horizontal, m_gboxSettings->plainPage());
+ m_sensibilitySlider->setTracking(false);
+ m_sensibilitySlider->setTickInterval(1);
+ m_sensibilitySlider->setTickmarks(TQSlider::Below);
+
+ m_sensibilityLCDValue = new TQLCDNumber(4, m_gboxSettings->plainPage());
+ m_sensibilityLCDValue->setSegmentStyle(TQLCDNumber::Flat);
+ m_sensibilityLCDValue->display(TQString::number(2400));
+ TQString whatsThis = i18n("<p>Set here the film ISO-sensitivity to "
+ "use for simulating the film graininess.");
+
+ TQWhatsThis::add(m_sensibilityLCDValue, whatsThis);
+ TQWhatsThis::add(m_sensibilitySlider, whatsThis);
+
+ grid->addMultiCellWidget(label1, 0, 0, 0, 1);
+ grid->addMultiCellWidget(m_sensibilitySlider, 1, 1, 0, 0);
+ grid->addMultiCellWidget(m_sensibilityLCDValue, 1, 1, 1, 1);
+ grid->setRowStretch(2, 10);
+ grid->setMargin(m_gboxSettings->spacingHint());
+ grid->setSpacing(m_gboxSettings->spacingHint());
+
+ setToolSettings(m_gboxSettings);
+
+ // -------------------------------------------------------------
+
+ m_previewWidget = new ImagePanelWidget(470, 350, "filmgrain Tool", m_gboxSettings->panIconView());
+
+ setToolView(m_previewWidget);
+ init();
+
+ // -------------------------------------------------------------
+
+ connect( m_sensibilitySlider, TQ_SIGNAL(valueChanged(int)),
+ this, TQ_SLOT(slotTimer()) );
+
+ // this connection is necessary to change the LCD display when
+ // the value is changed by single clicking on the slider
+ connect( m_sensibilitySlider, TQ_SIGNAL(valueChanged(int)),
+ this, TQ_SLOT(slotSliderMoved(int)) );
+
+ connect( m_sensibilitySlider, TQ_SIGNAL(sliderMoved(int)),
+ this, TQ_SLOT(slotSliderMoved(int)) );
+}
+
+FilmGrainTool::~FilmGrainTool()
+{
+}
+
+void FilmGrainTool::renderingFinished()
+{
+ m_sensibilitySlider->setEnabled(true);
+}
+
+void FilmGrainTool::readSettings()
+{
+ TDEConfig* config = kapp->config();
+ config->setGroup("filmgrain Tool");
+ m_sensibilitySlider->blockSignals(true);
+ m_sensibilitySlider->setValue(config->readNumEntry("SensitivityAjustment", 12));
+ m_sensibilitySlider->blockSignals(false);
+ slotSliderMoved(m_sensibilitySlider->value());
+}
+
+void FilmGrainTool::writeSettings()
+{
+ TDEConfig* config = kapp->config();
+ config->setGroup("filmgrain Tool");
+ config->writeEntry("SensitivityAjustment", m_sensibilitySlider->value());
+ m_previewWidget->writeSettings();
+ config->sync();
+}
+
+void FilmGrainTool::slotResetSettings()
+{
+ m_sensibilitySlider->blockSignals(true);
+ m_sensibilitySlider->setValue(12);
+ m_sensibilitySlider->blockSignals(false);
+}
+
+void FilmGrainTool::slotSliderMoved(int v)
+{
+ m_sensibilityLCDValue->display( TQString::number(400+200*v) );
+}
+
+void FilmGrainTool::prepareEffect()
+{
+ m_sensibilitySlider->setEnabled(false);
+
+ DImg image = m_previewWidget->getOriginalRegionImage();
+ int s = 400 + 200 * m_sensibilitySlider->value();
+
+ setFilter(dynamic_cast<DImgThreadedFilter*>(new FilmGrain(&image, this, s)));
+}
+
+void FilmGrainTool::prepareFinal()
+{
+ m_sensibilitySlider->setEnabled(false);
+
+ int s = 400 + 200 * m_sensibilitySlider->value();
+
+ ImageIface iface(0, 0);
+
+ setFilter(dynamic_cast<DImgThreadedFilter*>(new FilmGrain(iface.getOriginalImg(), this, s)));
+}
+
+void FilmGrainTool::putPreviewData()
+{
+ m_previewWidget->setPreviewImage(filter()->getTargetImage());
+}
+
+void FilmGrainTool::putFinalData()
+{
+ ImageIface iface(0, 0);
+ iface.putOriginalImage(i18n("Film Grain"), filter()->getTargetImage().bits());
+}
+
+} // NameSpace DigikamFilmGrainImagesPlugin
diff --git a/src/imageplugins/filmgrain/filmgraintool.h b/src/imageplugins/filmgrain/filmgraintool.h
new file mode 100644
index 00000000..1a179b53
--- /dev/null
+++ b/src/imageplugins/filmgrain/filmgraintool.h
@@ -0,0 +1,83 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2004-08-26
+ * Description : a digiKam image editor plugin for add film
+ * grain on an image.
+ *
+ * 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 FILMGRAINTOOL_H
+#define FILMGRAINTOOL_H
+
+// Digikam includes.
+
+#include "editortool.h"
+
+class TQSlider;
+class TQLCDNumber;
+
+namespace Digikam
+{
+class EditorToolSettings;
+class ImagePanelWidget;
+}
+
+namespace DigikamFilmGrainImagesPlugin
+{
+
+class FilmGrainTool : public Digikam::EditorToolThreaded
+{
+ TQ_OBJECT
+
+
+public:
+
+ FilmGrainTool(TQObject* parent);
+ ~FilmGrainTool();
+
+private slots:
+
+ void slotSliderMoved(int);
+ void slotResetSettings();
+
+private:
+
+ void readSettings();
+ void writeSettings();
+ void prepareEffect();
+ void prepareFinal();
+ void putPreviewData();
+ void putFinalData();
+ void renderingFinished();
+
+private:
+
+ TQSlider *m_sensibilitySlider;
+
+ TQLCDNumber *m_sensibilityLCDValue;
+
+ Digikam::ImagePanelWidget *m_previewWidget;
+
+ Digikam::EditorToolSettings *m_gboxSettings;
+};
+
+} // NameSpace DigikamFilmGrainImagesPlugin
+
+#endif /* FILMGRAINTOOL_H */
diff --git a/src/imageplugins/filmgrain/imageeffect_filmgrain.cpp b/src/imageplugins/filmgrain/imageeffect_filmgrain.cpp
new file mode 100644
index 00000000..e008095a
--- /dev/null
+++ b/src/imageplugins/filmgrain/imageeffect_filmgrain.cpp
@@ -0,0 +1,195 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2004-08-26
+ * Description : a digiKam image editor plugin for add film
+ * grain on an image.
+ *
+ * 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 <tqlcdnumber.h>
+#include <tqslider.h>
+#include <tqlayout.h>
+#include <tqimage.h>
+
+// KDE includes.
+
+#include <tdelocale.h>
+#include <tdeaboutdata.h>
+#include <kiconloader.h>
+#include <tdeapplication.h>
+#include <kstandarddirs.h>
+#include <tdeconfig.h>
+
+// Local includes.
+
+#include "version.h"
+#include "ddebug.h"
+#include "dimg.h"
+#include "imageiface.h"
+#include "imagewidget.h"
+#include "filmgrain.h"
+#include "imageeffect_filmgrain.h"
+#include "imageeffect_filmgrain.moc"
+
+namespace DigikamFilmGrainImagesPlugin
+{
+
+ImageEffect_FilmGrain::ImageEffect_FilmGrain(TQWidget* parent)
+ : Digikam::CtrlPanelDlg(parent, i18n("Add Film Grain to Photograph"),
+ "filmgrain", false, false, true,
+ Digikam::ImagePannelWidget::SeparateViewAll)
+{
+ TQString whatsThis;
+
+ TDEAboutData* about = new TDEAboutData("digikam",
+ I18N_NOOP("Film Grain"),
+ digikam_version,
+ I18N_NOOP("A digiKam image plugin to apply a film grain "
+ "effect to an image."),
+ TDEAboutData::License_GPL,
+ "(c) 2004-2005, Gilles Caulier\n"
+ "(c) 2006-2008, Gilles Caulier and Marcel Wiesweg",
+ 0,
+ "http://www.digikam.org");
+
+ about->addAuthor("Gilles Caulier", I18N_NOOP("Author and maintainer"),
+ "caulier dot gilles 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, 1, 1, 0, spacingHint());
+ TQLabel *label1 = new TQLabel(i18n("Sensitivity (ISO):"), gboxSettings);
+
+ m_sensibilitySlider = new TQSlider(2, 30, 1, 12, TQt::Horizontal, gboxSettings);
+ m_sensibilitySlider->setTracking ( false );
+ m_sensibilitySlider->setTickInterval(1);
+ m_sensibilitySlider->setTickmarks(TQSlider::Below);
+
+ m_sensibilityLCDValue = new TQLCDNumber (4, gboxSettings);
+ m_sensibilityLCDValue->setSegmentStyle ( TQLCDNumber::Flat );
+ m_sensibilityLCDValue->display( TQString::number(2400) );
+ whatsThis = i18n("<p>Set here the film ISO-sensitivity to use for simulating the film graininess.");
+
+ TQWhatsThis::add( m_sensibilityLCDValue, whatsThis);
+ TQWhatsThis::add( m_sensibilitySlider, whatsThis);
+
+ gridSettings->addMultiCellWidget(label1, 0, 0, 0, 1);
+ gridSettings->addMultiCellWidget(m_sensibilitySlider, 1, 1, 0, 0);
+ gridSettings->addMultiCellWidget(m_sensibilityLCDValue, 1, 1, 1, 1);
+
+ m_imagePreviewWidget->setUserAreaWidget(gboxSettings);
+
+ // -------------------------------------------------------------
+
+ connect( m_sensibilitySlider, TQ_SIGNAL(valueChanged(int)),
+ this, TQ_SLOT(slotTimer()) );
+
+ // this connection is necessary to change the LCD display when
+ // the value is changed by single clicking on the slider
+ connect( m_sensibilitySlider, TQ_SIGNAL(valueChanged(int)),
+ this, TQ_SLOT(slotSliderMoved(int)) );
+
+ connect( m_sensibilitySlider, TQ_SIGNAL(sliderMoved(int)),
+ this, TQ_SLOT(slotSliderMoved(int)) );
+}
+
+ImageEffect_FilmGrain::~ImageEffect_FilmGrain()
+{
+}
+
+void ImageEffect_FilmGrain::renderingFinished()
+{
+ m_sensibilitySlider->setEnabled(true);
+}
+
+void ImageEffect_FilmGrain::readUserSettings()
+{
+ TDEConfig* config = kapp->config();
+ config->setGroup("filmgrain Tool Dialog");
+ m_sensibilitySlider->blockSignals(true);
+ m_sensibilitySlider->setValue(config->readNumEntry("SensitivityAjustment", 12));
+ m_sensibilitySlider->blockSignals(false);
+ slotSliderMoved(m_sensibilitySlider->value());
+}
+
+void ImageEffect_FilmGrain::writeUserSettings()
+{
+ TDEConfig* config = kapp->config();
+ config->setGroup("filmgrain Tool Dialog");
+ config->writeEntry("SensitivityAjustment", m_sensibilitySlider->value());
+ config->sync();
+}
+
+void ImageEffect_FilmGrain::resetValues()
+{
+ m_sensibilitySlider->blockSignals(true);
+ m_sensibilitySlider->setValue(12);
+ m_sensibilitySlider->blockSignals(false);
+}
+
+void ImageEffect_FilmGrain::slotSliderMoved(int v)
+{
+ m_sensibilityLCDValue->display( TQString::number(400+200*v) );
+}
+
+void ImageEffect_FilmGrain::prepareEffect()
+{
+ m_sensibilitySlider->setEnabled(false);
+
+ Digikam::DImg image = m_imagePreviewWidget->getOriginalRegionImage();
+ int s = 400 + 200 * m_sensibilitySlider->value();
+
+ m_threadedFilter = dynamic_cast<Digikam::DImgThreadedFilter *>(new FilmGrain(&image, this, s));
+}
+
+void ImageEffect_FilmGrain::prepareFinal()
+{
+ m_sensibilitySlider->setEnabled(false);
+
+ int s = 400 + 200 * m_sensibilitySlider->value();
+
+ Digikam::ImageIface iface(0, 0);
+
+ m_threadedFilter = dynamic_cast<Digikam::DImgThreadedFilter *>(new FilmGrain(iface.getOriginalImg(), this, s));
+}
+
+void ImageEffect_FilmGrain::putPreviewData(void)
+{
+ m_imagePreviewWidget->setPreviewImage(m_threadedFilter->getTargetImage());
+}
+
+void ImageEffect_FilmGrain::putFinalData(void)
+{
+ Digikam::ImageIface iface(0, 0);
+ iface.putOriginalImage(i18n("Film Grain"), m_threadedFilter->getTargetImage().bits());
+}
+
+} // NameSpace DigikamFilmGrainImagesPlugin
+
diff --git a/src/imageplugins/filmgrain/imageeffect_filmgrain.h b/src/imageplugins/filmgrain/imageeffect_filmgrain.h
new file mode 100644
index 00000000..ba66e0a2
--- /dev/null
+++ b/src/imageplugins/filmgrain/imageeffect_filmgrain.h
@@ -0,0 +1,74 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2004-08-26
+ * Description : a digiKam image editor plugin for add film
+ * grain on an image.
+ *
+ * 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_FILMGRAIN_H
+#define IMAGEEFFECT_FILMGRAIN_H
+
+// Digikam includes.
+
+#include "ctrlpaneldlg.h"
+
+class TQSlider;
+class TQLCDNumber;
+
+namespace DigikamFilmGrainImagesPlugin
+{
+
+class ImageEffect_FilmGrain : public Digikam::CtrlPanelDlg
+{
+ TQ_OBJECT
+
+
+public:
+
+ ImageEffect_FilmGrain(TQWidget* parent);
+ ~ImageEffect_FilmGrain();
+
+private slots:
+
+ void slotSliderMoved(int);
+ void readUserSettings();
+
+private:
+
+ void writeUserSettings();
+ void resetValues();
+ void prepareEffect();
+ void prepareFinal();
+ void putPreviewData();
+ void putFinalData();
+ void renderingFinished();
+
+private:
+
+ TQSlider *m_sensibilitySlider;
+
+ TQLCDNumber *m_sensibilityLCDValue;
+};
+
+} // NameSpace DigikamFilmGrainImagesPlugin
+
+#endif /* IMAGEEFFECT_FILMGRAIN_H */
diff --git a/src/imageplugins/filmgrain/imageplugin_filmgrain.cpp b/src/imageplugins/filmgrain/imageplugin_filmgrain.cpp
new file mode 100644
index 00000000..efa2c35d
--- /dev/null
+++ b/src/imageplugins/filmgrain/imageplugin_filmgrain.cpp
@@ -0,0 +1,71 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2004-10-01
+ * Description : a digiKam image editor plugin for add film
+ * grain on an image.
+ *
+ * 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 "filmgraintool.h"
+#include "imageplugin_filmgrain.h"
+#include "imageplugin_filmgrain.moc"
+
+using namespace DigikamFilmGrainImagesPlugin;
+
+K_EXPORT_COMPONENT_FACTORY(digikamimageplugin_filmgrain,
+ KGenericFactory<ImagePlugin_FilmGrain>("digikamimageplugin_filmgrain"));
+
+ImagePlugin_FilmGrain::ImagePlugin_FilmGrain(TQObject *parent, const char*, const TQStringList &)
+ : Digikam::ImagePlugin(parent, "ImagePlugin_FilmGrain")
+{
+ m_filmgrainAction = new TDEAction(i18n("Add Film Grain..."), "filmgrain", 0,
+ this, TQ_SLOT(slotFilmGrain()),
+ actionCollection(), "imageplugin_filmgrain");
+
+ setXMLFile( "digikamimageplugin_filmgrain_ui.rc" );
+
+ DDebug() << "ImagePlugin_FilmGrain plugin loaded" << endl;
+}
+
+ImagePlugin_FilmGrain::~ImagePlugin_FilmGrain()
+{
+}
+
+void ImagePlugin_FilmGrain::setEnabledActions(bool enable)
+{
+ m_filmgrainAction->setEnabled(enable);
+}
+
+void ImagePlugin_FilmGrain::slotFilmGrain()
+{
+ FilmGrainTool *tool = new FilmGrainTool(this);
+ loadTool(tool);
+}
diff --git a/src/imageplugins/filmgrain/imageplugin_filmgrain.h b/src/imageplugins/filmgrain/imageplugin_filmgrain.h
new file mode 100644
index 00000000..495da122
--- /dev/null
+++ b/src/imageplugins/filmgrain/imageplugin_filmgrain.h
@@ -0,0 +1,57 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2004-10-01
+ * Description : a digiKam image editor plugin for add film
+ * grain on an image.
+ *
+ * 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_FILMGRAIN_H
+#define IMAGEPLUGIN_FILMGRAIN_H
+
+// Digikam includes.
+
+#include "imageplugin.h"
+#include "digikam_export.h"
+
+class TDEAction;
+
+class DIGIKAMIMAGEPLUGINS_EXPORT ImagePlugin_FilmGrain : public Digikam::ImagePlugin
+{
+ TQ_OBJECT
+
+
+public:
+
+ ImagePlugin_FilmGrain(TQObject *parent, const char* name,
+ const TQStringList &args);
+ ~ImagePlugin_FilmGrain();
+
+ void setEnabledActions(bool enable);
+
+private slots:
+
+ void slotFilmGrain();
+
+private:
+
+ TDEAction *m_filmgrainAction;
+};
+
+#endif /* IMAGEPLUGIN_FILMGRAIN_H */