summaryrefslogtreecommitdiffstats
path: root/src/imageplugins/restoration
diff options
context:
space:
mode:
Diffstat (limited to 'src/imageplugins/restoration')
-rw-r--r--src/imageplugins/restoration/Makefile.am35
-rw-r--r--src/imageplugins/restoration/digikamimageplugin_restoration.desktop52
-rw-r--r--src/imageplugins/restoration/digikamimageplugin_restoration_ui.rc20
-rw-r--r--src/imageplugins/restoration/imageeffect_restoration.cpp349
-rw-r--r--src/imageplugins/restoration/imageeffect_restoration.h94
-rw-r--r--src/imageplugins/restoration/imageplugin_restoration.cpp71
-rw-r--r--src/imageplugins/restoration/imageplugin_restoration.h57
-rw-r--r--src/imageplugins/restoration/restorationtool.cpp356
-rw-r--r--src/imageplugins/restoration/restorationtool.h100
9 files changed, 1134 insertions, 0 deletions
diff --git a/src/imageplugins/restoration/Makefile.am b/src/imageplugins/restoration/Makefile.am
new file mode 100644
index 00000000..695609be
--- /dev/null
+++ b/src/imageplugins/restoration/Makefile.am
@@ -0,0 +1,35 @@
+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 \
+ -I$(top_srcdir)/src/libs/greycstoration \
+ $(LIBKDCRAW_CFLAGS) \
+ $(all_includes)
+
+digikamimageplugin_restoration_la_SOURCES = imageplugin_restoration.cpp \
+ restorationtool.cpp
+
+digikamimageplugin_restoration_la_LIBADD = $(LIB_TDEPARTS) \
+ $(top_builddir)/src/digikam/libdigikam.la
+
+digikamimageplugin_restoration_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) -no-undefined -ltdecore -ltdeui $(LIB_TQT) -ltdefx -lkdcraw -ltdeio
+
+kde_services_DATA = digikamimageplugin_restoration.desktop
+
+kde_module_LTLIBRARIES = digikamimageplugin_restoration.la
+
+rcdir = $(kde_datadir)/digikam
+rc_DATA = digikamimageplugin_restoration_ui.rc
+
diff --git a/src/imageplugins/restoration/digikamimageplugin_restoration.desktop b/src/imageplugins/restoration/digikamimageplugin_restoration.desktop
new file mode 100644
index 00000000..8d0e7bd8
--- /dev/null
+++ b/src/imageplugins/restoration/digikamimageplugin_restoration.desktop
@@ -0,0 +1,52 @@
+[Desktop Entry]
+Name=ImagePlugin_Restoration
+Name[bg]=Приставка за снимки - Възстановяване
+Name[da]=Plugin for billedrestaurering
+Name[el]=ΠρόσθετοΕικόνας_Αποκατάσταση
+Name[fi]=Restaurointi
+Name[hr]=Obnavljanje
+Name[it]=PluginImmagini_Restauro
+Name[ms]=ImagePlugin_Pemulihan
+Name[nl]=Afbeeldingsplugin_Restauratie
+Name[sr]=Рестаурација
+Name[sr@Latn]=Restauracija
+Name[sv]=Insticksprogram för bildrestaurering
+Name[tr]=ResimEklentisi_Onarım
+Name[xx]=xxImagePlugin_Restorationxx
+
+Type=Service
+X-TDE-ServiceTypes=Digikam/ImagePlugin
+Encoding=UTF-8
+Comment=digiKam plugin to restore a photograph
+Comment[bg]=Приставка на digiKam за възстановяване на снимки
+Comment[ca]=Connector pel digiKam per restaurar una fotografia
+Comment[da]=Digikam plugin til restaurering af et fotografi
+Comment[de]=digiKam-Modul zum Restaurieren eines Bildes
+Comment[el]=Πρόσθετο του digiKam για αποκατάσταση μιας φωτογραφίας
+Comment[es]=Plugin para digiKam para restaurar una fotografía
+Comment[et]=DigiKami foto restaureerimimise plugin
+Comment[fa]=وصلۀ digiKam برای ذخیرۀ یک عکس
+Comment[fi]=Korjaa kuvassa esiintyviä virheitä
+Comment[gl]=Un plugin de digiKam para restaurar unha fotografia
+Comment[hr]=digiKam dodatak za obnavljanje fotografije
+Comment[is]=Íforrit fyrir digiKam sem fjarlægir óhreinindi úr myndum
+Comment[it]=Plugin di digiKam per restaurare una fotografia
+Comment[ja]=digiKam 写真復元プラグイン
+Comment[nds]=digiKam-Moduul för't Wedderherstellen vun Fotos
+Comment[nl]=Digikam-plugin voor het herstellen van een foto
+Comment[pa]=ਇੱਕ ਫੋਟੋ ਮੁੜ-ਸਟੋਰ ਕਰਨ ਲਈ ਡਿਜ਼ੀਕੈਮ ਪਲੱਗਇਨ
+Comment[pl]=Wtyczka do programu digiKam umożliwiająca odrestaurowanie zdjęcia
+Comment[pt]=Um 'plugin' do digiKam para restaurar uma fotografia
+Comment[pt_BR]=Plugin digiKam para restaurar una fotografia
+Comment[ru]=Модуль digiKam для восстановления фотографий
+Comment[sk]=digiKam plugin pre obnovenie fotografie
+Comment[sr]=digiKam-ов прикључак за поправку фотографија
+Comment[sr@Latn]=digiKam-ov priključak za popravku fotografija
+Comment[sv]=Digikam insticksprogram för restaurering av ett fotografi
+Comment[tr]=Fotoğraf onarmak için digiKam eklentisi
+Comment[uk]=Втулок відновлення фотографій для digiKam
+Comment[vi]=Phần bổ sung xây dựng lại ảnh chụp như cũ cho digiKam
+Comment[xx]=xxdigiKam plugin to restore a photographxx
+
+X-TDE-Library=digikamimageplugin_restoration
+author=Gilles Caulier, caulier dot gilles at gmail dot com
diff --git a/src/imageplugins/restoration/digikamimageplugin_restoration_ui.rc b/src/imageplugins/restoration/digikamimageplugin_restoration_ui.rc
new file mode 100644
index 00000000..27185294
--- /dev/null
+++ b/src/imageplugins/restoration/digikamimageplugin_restoration_ui.rc
@@ -0,0 +1,20 @@
+<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
+<kpartgui version="5" name="digikamimageplugin_restoration" >
+
+ <MenuBar>
+
+ <Menu name="Enhance" ><text>Enh&amp;ance</text>
+ <Action name="imageplugin_restoration" />
+ </Menu>
+
+ </MenuBar>
+
+ <ToolBar name="ToolBar" >
+ <text>Main Toolbar</text>
+ </ToolBar>
+
+ <ActionProperties>
+ <Action shortcut="" name="imageplugin_restoration" />
+ </ActionProperties>
+
+</kpartgui>
diff --git a/src/imageplugins/restoration/imageeffect_restoration.cpp b/src/imageplugins/restoration/imageeffect_restoration.cpp
new file mode 100644
index 00000000..825ef23d
--- /dev/null
+++ b/src/imageplugins/restoration/imageeffect_restoration.cpp
@@ -0,0 +1,349 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2005-03-26
+ * Description : a digiKam image editor plugin to restore
+ * a photograph
+ *
+ * Copyright (C) 2005-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.
+ *
+ * ============================================================ */
+
+// TQt includes.
+
+#include <tqlabel.h>
+#include <tqtooltip.h>
+#include <tqwhatsthis.h>
+#include <tqlayout.h>
+#include <tqcombobox.h>
+#include <tqtabwidget.h>
+#include <tqfile.h>
+#include <tqimage.h>
+
+// KDE includes.
+
+#include <kurllabel.h>
+#include <tdelocale.h>
+#include <tdeaboutdata.h>
+#include <kiconloader.h>
+#include <tdeapplication.h>
+#include <tdefiledialog.h>
+#include <tdeglobalsettings.h>
+#include <kstandarddirs.h>
+#include <tdemessagebox.h>
+
+// Local includes.
+
+#include "version.h"
+#include "ddebug.h"
+#include "imageiface.h"
+#include "greycstorationsettings.h"
+#include "greycstorationwidget.h"
+#include "greycstorationiface.h"
+#include "imageeffect_restoration.h"
+#include "imageeffect_restoration.moc"
+
+namespace DigikamRestorationImagesPlugin
+{
+
+ImageEffect_Restoration::ImageEffect_Restoration(TQWidget* parent)
+ : Digikam::CtrlPanelDlg(parent, i18n("Photograph Restoration"),
+ "restoration", true, true, true,
+ Digikam::ImagePannelWidget::SeparateViewAll)
+{
+ TQString whatsThis;
+
+ // About data and help button.
+
+ TDEAboutData* about = new TDEAboutData("digikam",
+ I18N_NOOP("Photograph Restoration"),
+ digikam_version,
+ I18N_NOOP("A digiKam image plugin to restore a photograph."),
+ TDEAboutData::License_GPL,
+ "(c) 2005-2008, Gilles Caulier",
+ 0,
+ "http://www.digikam.org");
+
+ about->addAuthor("Gilles Caulier", I18N_NOOP("Author and maintainer"),
+ "caulier dot gilles at gmail dot com");
+
+ about->addAuthor("David Tschumperle", I18N_NOOP("CImg library"), 0,
+ "http://cimg.sourceforge.net");
+
+ about->addAuthor("Gerhard Kulzer", I18N_NOOP("Feedback and plugin polishing"),
+ "gerhard at kulzer.net");
+
+ setAboutData(about);
+
+ // -------------------------------------------------------------
+
+ m_mainTab = new TQTabWidget( m_imagePreviewWidget );
+
+ TQWidget* firstPage = new TQWidget( m_mainTab );
+ TQGridLayout* grid = new TQGridLayout( firstPage, 2, 2, spacingHint());
+ m_mainTab->addTab( firstPage, i18n("Preset") );
+
+ KURLLabel *cimgLogoLabel = new KURLLabel(firstPage);
+ cimgLogoLabel->setText(TQString());
+ cimgLogoLabel->setURL("http://cimg.sourceforge.net");
+ TDEGlobal::dirs()->addResourceType("logo-cimg", TDEGlobal::dirs()->kde_default("data") + "digikam/data");
+ TQString directory = TDEGlobal::dirs()->findResourceDir("logo-cimg", "logo-cimg.png");
+ cimgLogoLabel->setPixmap( TQPixmap( directory + "logo-cimg.png" ) );
+ TQToolTip::add(cimgLogoLabel, i18n("Visit CImg library website"));
+
+ TQLabel *typeLabel = new TQLabel(i18n("Filtering type:"), firstPage);
+ typeLabel->setAlignment ( TQt::AlignRight | TQt::AlignVCenter);
+ m_restorationTypeCB = new TQComboBox( false, firstPage );
+ m_restorationTypeCB->insertItem( i18n("None") );
+ m_restorationTypeCB->insertItem( i18n("Reduce Uniform Noise") );
+ m_restorationTypeCB->insertItem( i18n("Reduce JPEG Artefacts") );
+ m_restorationTypeCB->insertItem( i18n("Reduce Texturing") );
+ TQWhatsThis::add( m_restorationTypeCB, i18n("<p>Select the filter preset to use for photograph restoration:<p>"
+ "<b>None</b>: Most common values. Puts settings to default.<p>"
+ "<b>Reduce Uniform Noise</b>: reduce small image artifacts like sensor noise.<p>"
+ "<b>Reduce JPEG Artefacts</b>: reduce large image artifacts like JPEG compression mosaic.<p>"
+ "<b>Reduce Texturing</b>: reduce image artifacts like paper texture or Moire patterns "
+ "of a scanned image.<p>"));
+
+ grid->addMultiCellWidget(cimgLogoLabel, 0, 0, 1, 1);
+ grid->addMultiCellWidget(typeLabel, 1, 1, 0, 0);
+ grid->addMultiCellWidget(m_restorationTypeCB, 1, 1, 1, 1);
+ grid->setRowStretch(1, 10);
+
+ // -------------------------------------------------------------
+
+ m_settingsWidget = new Digikam::GreycstorationWidget( m_mainTab );
+ m_imagePreviewWidget->setUserAreaWidget(m_mainTab);
+
+ // -------------------------------------------------------------
+
+ connect(cimgLogoLabel, TQ_SIGNAL(leftClickedURL(const TQString&)),
+ this, TQ_SLOT(processCImgURL(const TQString&)));
+
+ connect(m_restorationTypeCB, TQ_SIGNAL(activated(int)),
+ this, TQ_SLOT(slotResetValues(int)));
+}
+
+ImageEffect_Restoration::~ImageEffect_Restoration()
+{
+}
+
+void ImageEffect_Restoration::renderingFinished()
+{
+ m_imagePreviewWidget->setEnable(true);
+ m_mainTab->setEnabled(true);
+}
+
+void ImageEffect_Restoration::readUserSettings()
+{
+ TDEConfig* config = kapp->config();
+ config->setGroup("restoration Tool Dialog");
+
+ Digikam::GreycstorationSettings settings;
+ settings.fastApprox = config->readBoolEntry("FastApprox", true);
+ settings.interp = config->readNumEntry("Interpolation",
+ Digikam::GreycstorationSettings::NearestNeighbor);
+ settings.amplitude = config->readDoubleNumEntry("Amplitude", 60.0);
+ settings.sharpness = config->readDoubleNumEntry("Sharpness", 0.7);
+ settings.anisotropy = config->readDoubleNumEntry("Anisotropy", 0.3);
+ settings.alpha = config->readDoubleNumEntry("Alpha", 0.6);
+ settings.sigma = config->readDoubleNumEntry("Sigma", 1.1);
+ settings.gaussPrec = config->readDoubleNumEntry("GaussPrec", 2.0);
+ settings.dl = config->readDoubleNumEntry("Dl", 0.8);
+ settings.da = config->readDoubleNumEntry("Da", 30.0);
+ settings.nbIter = config->readNumEntry("Iteration", 1);
+ settings.tile = config->readNumEntry("Tile", 512);
+ settings.btile = config->readNumEntry("BTile", 4);
+ m_settingsWidget->setSettings(settings);
+
+ int p = config->readNumEntry("Preset", NoPreset);
+ m_restorationTypeCB->setCurrentItem(p);
+ if (p == NoPreset)
+ m_settingsWidget->setEnabled(true);
+ else
+ m_settingsWidget->setEnabled(false);
+}
+
+void ImageEffect_Restoration::writeUserSettings()
+{
+ Digikam::GreycstorationSettings settings = m_settingsWidget->getSettings();
+ TDEConfig* config = kapp->config();
+ config->setGroup("restoration Tool Dialog");
+ config->writeEntry("Preset", m_restorationTypeCB->currentItem());
+ config->writeEntry("FastApprox", settings.fastApprox);
+ config->writeEntry("Interpolation", settings.interp);
+ config->writeEntry("Amplitude", settings.amplitude);
+ config->writeEntry("Sharpness", settings.sharpness);
+ config->writeEntry("Anisotropy", settings.anisotropy);
+ config->writeEntry("Alpha", settings.alpha);
+ config->writeEntry("Sigma", settings.sigma);
+ config->writeEntry("GaussPrec", settings.gaussPrec);
+ config->writeEntry("Dl", settings.dl);
+ config->writeEntry("Da", settings.da);
+ config->writeEntry("Iteration", settings.nbIter);
+ config->writeEntry("Tile", settings.tile);
+ config->writeEntry("BTile", settings.btile);
+ config->sync();
+}
+
+void ImageEffect_Restoration::slotResetValues(int i)
+{
+ if (i == NoPreset)
+ m_settingsWidget->setEnabled(true);
+ else
+ m_settingsWidget->setEnabled(false);
+
+ resetValues();
+}
+
+void ImageEffect_Restoration::resetValues()
+{
+ Digikam::GreycstorationSettings settings;
+ settings.setRestorationDefaultSettings();
+
+ switch(m_restorationTypeCB->currentItem())
+ {
+ case ReduceUniformNoise:
+ {
+ settings.amplitude = 40.0;
+ break;
+ }
+
+ case ReduceJPEGArtefacts:
+ {
+ settings.sharpness = 0.3;
+ settings.sigma = 1.0;
+ settings.amplitude = 100.0;
+ settings.nbIter = 2;
+ break;
+ }
+
+ case ReduceTexturing:
+ {
+ settings.sharpness = 0.5;
+ settings.sigma = 1.5;
+ settings.amplitude = 100.0;
+ settings.nbIter = 2;
+ break;
+ }
+ }
+
+ m_settingsWidget->setSettings(settings);
+}
+
+void ImageEffect_Restoration::processCImgURL(const TQString& url)
+{
+ TDEApplication::kApplication()->invokeBrowser(url);
+}
+
+void ImageEffect_Restoration::prepareEffect()
+{
+ m_mainTab->setEnabled(false);
+
+ Digikam::DImg previewImage = m_imagePreviewWidget->getOriginalRegionImage();
+
+ m_threadedFilter = dynamic_cast<Digikam::DImgThreadedFilter *>(
+ new Digikam::GreycstorationIface(
+ &previewImage, m_settingsWidget->getSettings(),
+ Digikam::GreycstorationIface::Restore,
+ 0, 0, 0, this));
+}
+
+void ImageEffect_Restoration::prepareFinal()
+{
+ m_mainTab->setEnabled(false);
+
+ Digikam::ImageIface iface(0, 0);
+ uchar *data = iface.getOriginalImage();
+ Digikam::DImg originalImage(iface.originalWidth(), iface.originalHeight(),
+ iface.originalSixteenBit(), iface.originalHasAlpha(), data);
+
+ m_threadedFilter = dynamic_cast<Digikam::DImgThreadedFilter *>(
+ new Digikam::GreycstorationIface(
+ &originalImage, m_settingsWidget->getSettings(),
+ Digikam::GreycstorationIface::Restore,
+ 0, 0, 0, this));
+
+ delete [] data;
+}
+
+void ImageEffect_Restoration::putPreviewData(void)
+{
+ Digikam::DImg imDest = m_threadedFilter->getTargetImage();
+ m_imagePreviewWidget->setPreviewImage(imDest);
+}
+
+void ImageEffect_Restoration::putFinalData(void)
+{
+ Digikam::ImageIface iface(0, 0);
+
+ iface.putOriginalImage(i18n("Restoration"),
+ m_threadedFilter->getTargetImage().bits());
+}
+
+void ImageEffect_Restoration::slotUser3()
+{
+ KURL loadRestorationFile = KFileDialog::getOpenURL(TDEGlobalSettings::documentPath(),
+ TQString( "*" ), this,
+ TQString( i18n("Photograph Restoration Settings File to Load")) );
+ if( loadRestorationFile.isEmpty() )
+ return;
+
+ TQFile file(loadRestorationFile.path());
+
+ if ( file.open(IO_ReadOnly) )
+ {
+ if (!m_settingsWidget->loadSettings(file, TQString("# Photograph Restoration Configuration File V2")))
+ {
+ KMessageBox::error(this,
+ i18n("\"%1\" is not a Photograph Restoration settings text file.")
+ .arg(loadRestorationFile.fileName()));
+ file.close();
+ return;
+ }
+
+ slotEffect();
+ }
+ else
+ KMessageBox::error(this, i18n("Cannot load settings from the Photograph Restoration text file."));
+
+ file.close();
+ m_restorationTypeCB->blockSignals(true);
+ m_restorationTypeCB->setCurrentItem(NoPreset);
+ m_restorationTypeCB->blockSignals(false);
+ m_settingsWidget->setEnabled(true);
+}
+
+void ImageEffect_Restoration::slotUser2()
+{
+ KURL saveRestorationFile = KFileDialog::getSaveURL(TDEGlobalSettings::documentPath(),
+ TQString( "*" ), this,
+ TQString( i18n("Photograph Restoration Settings File to Save")) );
+ if( saveRestorationFile.isEmpty() )
+ return;
+
+ TQFile file(saveRestorationFile.path());
+
+ if ( file.open(IO_WriteOnly) )
+ m_settingsWidget->saveSettings(file, TQString("# Photograph Restoration Configuration File V2"));
+ else
+ KMessageBox::error(this, i18n("Cannot save settings to the Photograph Restoration text file."));
+
+ file.close();
+}
+
+} // NameSpace DigikamRestorationImagesPlugin
+
diff --git a/src/imageplugins/restoration/imageeffect_restoration.h b/src/imageplugins/restoration/imageeffect_restoration.h
new file mode 100644
index 00000000..7c28bd92
--- /dev/null
+++ b/src/imageplugins/restoration/imageeffect_restoration.h
@@ -0,0 +1,94 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2005-03-26
+ * Description : a digiKam image editor plugin to restore
+ * a photograph
+ *
+ * Copyright (C) 2005-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 IMAGEEFFECT_RESTORATION_H
+#define IMAGEEFFECT_RESTORATION_H
+
+// TQt include.
+
+#include <tqstring.h>
+
+// Digikam includes.
+
+#include "ctrlpaneldlg.h"
+
+class TQComboBox;
+class TQTabWidget;
+
+namespace Digikam
+{
+class GreycstorationWidget;
+}
+
+namespace DigikamRestorationImagesPlugin
+{
+
+class ImageEffect_Restoration : public Digikam::CtrlPanelDlg
+{
+ TQ_OBJECT
+
+
+public:
+
+ ImageEffect_Restoration(TQWidget* parent);
+ ~ImageEffect_Restoration();
+
+private slots:
+
+ void slotUser2();
+ void slotUser3();
+ void processCImgURL(const TQString&);
+ void readUserSettings();
+ void slotResetValues(int);
+
+private:
+
+ void writeUserSettings();
+ void prepareEffect(void);
+ void prepareFinal(void);
+ void putPreviewData(void);
+ void putFinalData(void);
+ void resetValues(void);
+ void renderingFinished(void);
+
+private:
+
+ enum RestorationFilteringPreset
+ {
+ NoPreset=0,
+ ReduceUniformNoise,
+ ReduceJPEGArtefacts,
+ ReduceTexturing
+ };
+
+ TQTabWidget *m_mainTab;
+
+ TQComboBox *m_restorationTypeCB;
+
+ Digikam::GreycstorationWidget *m_settingsWidget;
+};
+
+} // NameSpace DigikamRestorationImagesPlugin
+
+#endif /* IMAGEEFFECT_RESTORATION_H */
diff --git a/src/imageplugins/restoration/imageplugin_restoration.cpp b/src/imageplugins/restoration/imageplugin_restoration.cpp
new file mode 100644
index 00000000..01cd52f7
--- /dev/null
+++ b/src/imageplugins/restoration/imageplugin_restoration.cpp
@@ -0,0 +1,71 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2005-03-26
+ * Description : a digiKam image editor plugin to restore
+ * a photograph
+ *
+ * Copyright (C) 2005-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 "restorationtool.h"
+#include "imageplugin_restoration.h"
+#include "imageplugin_restoration.moc"
+
+using namespace DigikamRestorationImagesPlugin;
+
+K_EXPORT_COMPONENT_FACTORY(digikamimageplugin_restoration,
+ KGenericFactory<ImagePlugin_Restoration>("digikamimageplugin_restoration"));
+
+ImagePlugin_Restoration::ImagePlugin_Restoration(TQObject *parent, const char*, const TQStringList &)
+ : Digikam::ImagePlugin(parent, "ImagePlugin_Restoration")
+{
+ m_restorationAction = new TDEAction(i18n("Restoration..."), "restoration", 0,
+ this, TQ_SLOT(slotRestoration()),
+ actionCollection(), "imageplugin_restoration");
+
+ setXMLFile( "digikamimageplugin_restoration_ui.rc" );
+
+ DDebug() << "ImagePlugin_Restoration plugin loaded" << endl;
+}
+
+ImagePlugin_Restoration::~ImagePlugin_Restoration()
+{
+}
+
+void ImagePlugin_Restoration::setEnabledActions(bool enable)
+{
+ m_restorationAction->setEnabled(enable);
+}
+
+void ImagePlugin_Restoration::slotRestoration()
+{
+ RestorationTool *tool = new RestorationTool(this);
+ loadTool(tool);
+}
diff --git a/src/imageplugins/restoration/imageplugin_restoration.h b/src/imageplugins/restoration/imageplugin_restoration.h
new file mode 100644
index 00000000..50ac8326
--- /dev/null
+++ b/src/imageplugins/restoration/imageplugin_restoration.h
@@ -0,0 +1,57 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2005-03-26
+ * Description : a digiKam image editor plugin to restore
+ * a photograph
+ *
+ * Copyright (C) 2005-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_RESTORATION_H
+#define IMAGEPLUGIN_RESTORATION_H
+
+// Digikam includes.
+
+#include "imageplugin.h"
+#include "digikam_export.h"
+
+class TDEAction;
+
+class DIGIKAMIMAGEPLUGINS_EXPORT ImagePlugin_Restoration : public Digikam::ImagePlugin
+{
+ TQ_OBJECT
+
+
+public:
+
+ ImagePlugin_Restoration(TQObject *parent, const char* name,
+ const TQStringList &args);
+ ~ImagePlugin_Restoration();
+
+ void setEnabledActions(bool enable);
+
+private slots:
+
+ void slotRestoration();
+
+private:
+
+ TDEAction *m_restorationAction;
+};
+
+#endif /* IMAGEPLUGIN_RESTORATION_H */
diff --git a/src/imageplugins/restoration/restorationtool.cpp b/src/imageplugins/restoration/restorationtool.cpp
new file mode 100644
index 00000000..a6896135
--- /dev/null
+++ b/src/imageplugins/restoration/restorationtool.cpp
@@ -0,0 +1,356 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2005-03-26
+ * Description : a digiKam image editor plugin to restore
+ * a photograph
+ *
+ * Copyright (C) 2005-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.
+ *
+ * ============================================================ */
+
+// TQt includes.
+
+#include <tqlabel.h>
+#include <tqtooltip.h>
+#include <tqwhatsthis.h>
+#include <tqlayout.h>
+#include <tqcombobox.h>
+#include <tqtabwidget.h>
+#include <tqfile.h>
+#include <tqimage.h>
+
+// KDE includes.
+
+#include <kurllabel.h>
+#include <tdelocale.h>
+#include <tdeaboutdata.h>
+#include <kiconloader.h>
+#include <tdeapplication.h>
+#include <tdefiledialog.h>
+#include <tdeglobalsettings.h>
+#include <kstandarddirs.h>
+#include <tdemessagebox.h>
+
+// Local includes.
+
+#include "daboutdata.h"
+#include "ddebug.h"
+#include "imageiface.h"
+#include "imagepanelwidget.h"
+#include "editortoolsettings.h"
+#include "greycstorationsettings.h"
+#include "greycstorationwidget.h"
+#include "greycstorationiface.h"
+#include "restorationtool.h"
+#include "restorationtool.moc"
+
+using namespace Digikam;
+
+namespace DigikamRestorationImagesPlugin
+{
+
+RestorationTool::RestorationTool(TQObject* parent)
+ : EditorToolThreaded(parent)
+{
+ setName("restoration");
+ setToolName(i18n("Restoration"));
+ setToolIcon(SmallIcon("restoration"));
+
+ // -------------------------------------------------------------
+
+ m_gboxSettings = new EditorToolSettings(EditorToolSettings::Default|
+ EditorToolSettings::Ok|
+ EditorToolSettings::Cancel|
+ EditorToolSettings::Load|
+ EditorToolSettings::SaveAs|
+ EditorToolSettings::Try,
+ EditorToolSettings::PanIcon);
+
+ TQGridLayout* gridSettings = new TQGridLayout(m_gboxSettings->plainPage(), 2, 1);
+ m_mainTab = new TQTabWidget( m_gboxSettings->plainPage() );
+
+ TQWidget* firstPage = new TQWidget( m_mainTab );
+ TQGridLayout* grid = new TQGridLayout(firstPage, 2, 2);
+ m_mainTab->addTab( firstPage, i18n("Preset") );
+
+ KURLLabel *cimgLogoLabel = new KURLLabel(firstPage);
+ cimgLogoLabel->setText(TQString());
+ cimgLogoLabel->setURL("http://cimg.sourceforge.net");
+ TDEGlobal::dirs()->addResourceType("logo-cimg", TDEGlobal::dirs()->kde_default("data") + "digikam/data");
+ TQString directory = TDEGlobal::dirs()->findResourceDir("logo-cimg", "logo-cimg.png");
+ cimgLogoLabel->setPixmap( TQPixmap( directory + "logo-cimg.png" ) );
+ TQToolTip::add(cimgLogoLabel, i18n("Visit CImg library website"));
+
+ TQLabel *typeLabel = new TQLabel(i18n("Filtering type:"), firstPage);
+ typeLabel->setAlignment ( TQt::AlignRight | TQt::AlignVCenter);
+ m_restorationTypeCB = new TQComboBox(false, firstPage);
+ m_restorationTypeCB->insertItem( i18n("None") );
+ m_restorationTypeCB->insertItem( i18n("Reduce Uniform Noise") );
+ m_restorationTypeCB->insertItem( i18n("Reduce JPEG Artefacts") );
+ m_restorationTypeCB->insertItem( i18n("Reduce Texturing") );
+ TQWhatsThis::add( m_restorationTypeCB, i18n("<p>Select the filter preset to use for photograph restoration:<p>"
+ "<b>None</b>: Most common values. Puts settings to default.<p>"
+ "<b>Reduce Uniform Noise</b>: reduce small image artifacts like sensor noise.<p>"
+ "<b>Reduce JPEG Artefacts</b>: reduce large image artifacts like JPEG compression mosaic.<p>"
+ "<b>Reduce Texturing</b>: reduce image artifacts like paper texture or Moire patterns "
+ "of a scanned image.<p>"));
+
+ grid->addMultiCellWidget(cimgLogoLabel, 0, 0, 1, 1);
+ grid->addMultiCellWidget(typeLabel, 1, 1, 0, 0);
+ grid->addMultiCellWidget(m_restorationTypeCB, 1, 1, 1, 1);
+ grid->setRowStretch(1, 10);
+ grid->setMargin(m_gboxSettings->spacingHint());
+ grid->setSpacing(m_gboxSettings->spacingHint());
+
+ m_settingsWidget = new GreycstorationWidget( m_mainTab );
+ gridSettings->addMultiCellWidget(m_mainTab, 0, 0, 1, 1);
+ gridSettings->addMultiCellWidget(new TQLabel(m_gboxSettings->plainPage()), 1, 1, 1, 1);
+ gridSettings->setMargin(m_gboxSettings->spacingHint());
+ gridSettings->setSpacing(m_gboxSettings->spacingHint());
+ gridSettings->setRowStretch(2, 10);
+
+ setToolSettings(m_gboxSettings);
+
+ // -------------------------------------------------------------
+
+ m_previewWidget = new ImagePanelWidget(470, 350, "restoration Tool", m_gboxSettings->panIconView());
+
+ setToolView(m_previewWidget);
+ init();
+
+ // -------------------------------------------------------------
+
+ connect(cimgLogoLabel, TQ_SIGNAL(leftClickedURL(const TQString&)),
+ this, TQ_SLOT(processCImgURL(const TQString&)));
+
+ connect(m_restorationTypeCB, TQ_SIGNAL(activated(int)),
+ this, TQ_SLOT(slotResetValues(int)));
+
+ // -------------------------------------------------------------
+
+ GreycstorationSettings defaults;
+ defaults.setRestorationDefaultSettings();
+ m_settingsWidget->setDefaultSettings(defaults);
+}
+
+RestorationTool::~RestorationTool()
+{
+}
+
+void RestorationTool::renderingFinished()
+{
+ m_previewWidget->setEnable(true);
+ m_mainTab->setEnabled(true);
+}
+
+void RestorationTool::readSettings()
+{
+ TDEConfig* config = kapp->config();
+ config->setGroup("restoration Tool");
+
+ GreycstorationSettings settings;
+ GreycstorationSettings defaults;
+ defaults.setRestorationDefaultSettings();
+
+ settings.fastApprox = config->readBoolEntry("FastApprox", defaults.fastApprox);
+ settings.interp = config->readNumEntry("Interpolation", defaults.interp);
+ settings.amplitude = config->readDoubleNumEntry("Amplitude", defaults.amplitude);
+ settings.sharpness = config->readDoubleNumEntry("Sharpness", defaults.sharpness);
+ settings.anisotropy = config->readDoubleNumEntry("Anisotropy", defaults.anisotropy);
+ settings.alpha = config->readDoubleNumEntry("Alpha", defaults.alpha);
+ settings.sigma = config->readDoubleNumEntry("Sigma", defaults.sigma);
+ settings.gaussPrec = config->readDoubleNumEntry("GaussPrec", defaults.gaussPrec);
+ settings.dl = config->readDoubleNumEntry("Dl", defaults.dl);
+ settings.da = config->readDoubleNumEntry("Da", defaults.da);
+ settings.nbIter = config->readNumEntry("Iteration", defaults.nbIter);
+ settings.tile = config->readNumEntry("Tile", defaults.tile);
+ settings.btile = config->readNumEntry("BTile", defaults.btile);
+ m_settingsWidget->setSettings(settings);
+
+ int p = config->readNumEntry("Preset", NoPreset);
+ m_restorationTypeCB->setCurrentItem(p);
+ if (p == NoPreset)
+ m_settingsWidget->setEnabled(true);
+ else
+ m_settingsWidget->setEnabled(false);
+}
+
+void RestorationTool::writeSettings()
+{
+ GreycstorationSettings settings = m_settingsWidget->getSettings();
+ TDEConfig* config = kapp->config();
+ config->setGroup("restoration Tool");
+ config->writeEntry("Preset", m_restorationTypeCB->currentItem());
+ config->writeEntry("FastApprox", settings.fastApprox);
+ config->writeEntry("Interpolation", settings.interp);
+ config->writeEntry("Amplitude", settings.amplitude);
+ config->writeEntry("Sharpness", settings.sharpness);
+ config->writeEntry("Anisotropy", settings.anisotropy);
+ config->writeEntry("Alpha", settings.alpha);
+ config->writeEntry("Sigma", settings.sigma);
+ config->writeEntry("GaussPrec", settings.gaussPrec);
+ config->writeEntry("Dl", settings.dl);
+ config->writeEntry("Da", settings.da);
+ config->writeEntry("Iteration", settings.nbIter);
+ config->writeEntry("Tile", settings.tile);
+ config->writeEntry("BTile", settings.btile);
+ m_previewWidget->writeSettings();
+ config->sync();
+}
+
+void RestorationTool::slotResetValues(int i)
+{
+ if (i == NoPreset)
+ m_settingsWidget->setEnabled(true);
+ else
+ m_settingsWidget->setEnabled(false);
+
+ slotResetSettings();
+}
+
+void RestorationTool::slotResetSettings()
+{
+ GreycstorationSettings settings;
+ settings.setRestorationDefaultSettings();
+
+ switch(m_restorationTypeCB->currentItem())
+ {
+ case ReduceUniformNoise:
+ {
+ settings.amplitude = 40.0;
+ break;
+ }
+
+ case ReduceJPEGArtefacts:
+ {
+ settings.sharpness = 0.3;
+ settings.sigma = 1.0;
+ settings.amplitude = 100.0;
+ settings.nbIter = 2;
+ break;
+ }
+
+ case ReduceTexturing:
+ {
+ settings.sharpness = 0.5;
+ settings.sigma = 1.5;
+ settings.amplitude = 100.0;
+ settings.nbIter = 2;
+ break;
+ }
+ }
+
+ m_settingsWidget->setSettings(settings);
+}
+
+void RestorationTool::processCImgURL(const TQString& url)
+{
+ TDEApplication::kApplication()->invokeBrowser(url);
+}
+
+void RestorationTool::prepareEffect()
+{
+ m_mainTab->setEnabled(false);
+
+ DImg previewImage = m_previewWidget->getOriginalRegionImage();
+
+ setFilter(dynamic_cast<DImgThreadedFilter*>(new GreycstorationIface(&previewImage,
+ m_settingsWidget->getSettings(), GreycstorationIface::Restore,
+ 0, 0, 0, this)));
+}
+
+void RestorationTool::prepareFinal()
+{
+ m_mainTab->setEnabled(false);
+
+ ImageIface iface(0, 0);
+ uchar *data = iface.getOriginalImage();
+ DImg originalImage(iface.originalWidth(), iface.originalHeight(),
+ iface.originalSixteenBit(), iface.originalHasAlpha(), data);
+
+ setFilter(dynamic_cast<DImgThreadedFilter*>(new GreycstorationIface(&originalImage,
+ m_settingsWidget->getSettings(), GreycstorationIface::Restore,
+ 0, 0, 0, this)));
+
+ delete [] data;
+}
+
+void RestorationTool::putPreviewData()
+{
+ DImg imDest = filter()->getTargetImage();
+ m_previewWidget->setPreviewImage(imDest);
+}
+
+void RestorationTool::putFinalData()
+{
+ ImageIface iface(0, 0);
+ iface.putOriginalImage(i18n("Restoration"), filter()->getTargetImage().bits());
+}
+
+void RestorationTool::slotLoadSettings()
+{
+ KURL loadRestorationFile = KFileDialog::getOpenURL(TDEGlobalSettings::documentPath(),
+ TQString( "*" ), kapp->activeWindow(),
+ TQString( i18n("Photograph Restoration Settings File to Load")) );
+ if( loadRestorationFile.isEmpty() )
+ return;
+
+ TQFile file(loadRestorationFile.path());
+
+ if ( file.open(IO_ReadOnly) )
+ {
+ if (!m_settingsWidget->loadSettings(file, TQString("# Photograph Restoration Configuration File V2")))
+ {
+ KMessageBox::error(kapp->activeWindow(),
+ i18n("\"%1\" is not a Photograph Restoration settings text file.")
+ .arg(loadRestorationFile.fileName()));
+ file.close();
+ return;
+ }
+
+ slotEffect();
+ }
+ else
+ KMessageBox::error(kapp->activeWindow(), i18n("Cannot load settings from the Photograph Restoration text file."));
+
+ file.close();
+ m_restorationTypeCB->blockSignals(true);
+ m_restorationTypeCB->setCurrentItem(NoPreset);
+ m_restorationTypeCB->blockSignals(false);
+ m_settingsWidget->setEnabled(true);
+}
+
+void RestorationTool::slotSaveAsSettings()
+{
+ KURL saveRestorationFile = KFileDialog::getSaveURL(TDEGlobalSettings::documentPath(),
+ TQString( "*" ), kapp->activeWindow(),
+ TQString( i18n("Photograph Restoration Settings File to Save")) );
+ if( saveRestorationFile.isEmpty() )
+ return;
+
+ TQFile file(saveRestorationFile.path());
+
+ if ( file.open(IO_WriteOnly) )
+ m_settingsWidget->saveSettings(file, TQString("# Photograph Restoration Configuration File V2"));
+ else
+ KMessageBox::error(kapp->activeWindow(), i18n("Cannot save settings to the Photograph Restoration text file."));
+
+ file.close();
+}
+
+} // NameSpace DigikamRestorationImagesPlugin
+
diff --git a/src/imageplugins/restoration/restorationtool.h b/src/imageplugins/restoration/restorationtool.h
new file mode 100644
index 00000000..6242a2b6
--- /dev/null
+++ b/src/imageplugins/restoration/restorationtool.h
@@ -0,0 +1,100 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2005-03-26
+ * Description : a digiKam image editor plugin to restore
+ * a photograph
+ *
+ * Copyright (C) 2005-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 RESTORATIONTOOL_H
+#define RESTORATIONTOOL_H
+
+// TQt includes.
+
+#include <tqstring.h>
+
+// Digikam includes.
+
+#include "editortool.h"
+
+class TQComboBox;
+class TQTabWidget;
+
+namespace Digikam
+{
+class GreycstorationWidget;
+class EditorToolSettings;
+class ImagePanelWidget;
+}
+
+namespace DigikamRestorationImagesPlugin
+{
+
+class RestorationTool : public Digikam::EditorToolThreaded
+{
+ TQ_OBJECT
+
+
+public:
+
+ RestorationTool(TQObject* parent);
+ ~RestorationTool();
+
+private slots:
+
+ void slotSaveAsSettings();
+ void slotLoadSettings();
+ void slotResetSettings();
+ void processCImgURL(const TQString&);
+ void slotResetValues(int);
+
+private:
+
+ void readSettings();
+ void writeSettings();
+ void prepareEffect();
+ void prepareFinal();
+ void putPreviewData();
+ void putFinalData();
+ void renderingFinished();
+
+private:
+
+ enum RestorationFilteringPreset
+ {
+ NoPreset=0,
+ ReduceUniformNoise,
+ ReduceJPEGArtefacts,
+ ReduceTexturing
+ };
+
+ TQTabWidget *m_mainTab;
+
+ TQComboBox *m_restorationTypeCB;
+
+ Digikam::GreycstorationWidget *m_settingsWidget;
+
+ Digikam::ImagePanelWidget *m_previewWidget;
+
+ Digikam::EditorToolSettings *m_gboxSettings;
+};
+
+} // NameSpace DigikamRestorationImagesPlugin
+
+#endif /* RESTORATIONTOOL_H */