diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2024-11-22 18:41:30 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2024-11-22 18:41:30 +0900 |
commit | ee0d99607c14cb63d3ebdb3a970b508949fa8219 (patch) | |
tree | 94ac1efedb94cb38bf6879ba0610fe75b554216b /src/imageplugins/inpainting | |
parent | 4adff739380e4ae9f30e443ee95644f184456869 (diff) | |
download | digikam-ee0d99607c14cb63d3ebdb3a970b508949fa8219.tar.gz digikam-ee0d99607c14cb63d3ebdb3a970b508949fa8219.zip |
Rename 'digikam' folder to 'src'
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'src/imageplugins/inpainting')
-rw-r--r-- | src/imageplugins/inpainting/Makefile.am | 34 | ||||
-rw-r--r-- | src/imageplugins/inpainting/digikamimageplugin_inpainting.desktop | 49 | ||||
-rw-r--r-- | src/imageplugins/inpainting/digikamimageplugin_inpainting_ui.rc | 20 | ||||
-rw-r--r-- | src/imageplugins/inpainting/imageeffect_inpainting.cpp | 466 | ||||
-rw-r--r-- | src/imageplugins/inpainting/imageeffect_inpainting.h | 116 | ||||
-rw-r--r-- | src/imageplugins/inpainting/imageplugin_inpainting.cpp | 97 | ||||
-rw-r--r-- | src/imageplugins/inpainting/imageplugin_inpainting.h | 57 | ||||
-rw-r--r-- | src/imageplugins/inpainting/inpaintingtool.cpp | 430 | ||||
-rw-r--r-- | src/imageplugins/inpainting/inpaintingtool.h | 133 |
9 files changed, 1402 insertions, 0 deletions
diff --git a/src/imageplugins/inpainting/Makefile.am b/src/imageplugins/inpainting/Makefile.am new file mode 100644 index 00000000..243253a8 --- /dev/null +++ b/src/imageplugins/inpainting/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 \ + -I$(top_srcdir)/src/libs/greycstoration \ + $(LIBKDCRAW_CFLAGS) \ + $(all_includes) + +digikamimageplugin_inpainting_la_SOURCES = imageplugin_inpainting.cpp \ + inpaintingtool.cpp + +digikamimageplugin_inpainting_la_LIBADD = $(LIB_TDEPARTS) \ + $(top_builddir)/src/digikam/libdigikam.la + +digikamimageplugin_inpainting_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) -no-undefined -ltdecore -ltdeui $(LIB_TQT) -ltdefx -lkdcraw -ltdeio + +kde_services_DATA = digikamimageplugin_inpainting.desktop + +kde_module_LTLIBRARIES = digikamimageplugin_inpainting.la + +rcdir = $(kde_datadir)/digikam +rc_DATA = digikamimageplugin_inpainting_ui.rc diff --git a/src/imageplugins/inpainting/digikamimageplugin_inpainting.desktop b/src/imageplugins/inpainting/digikamimageplugin_inpainting.desktop new file mode 100644 index 00000000..09f891a7 --- /dev/null +++ b/src/imageplugins/inpainting/digikamimageplugin_inpainting.desktop @@ -0,0 +1,49 @@ +[Desktop Entry] +Name=ImagePlugin_InPainting +Name[bg]=Приставка за снимка - Дорисуване +Name[da]=Plugin til indfyldning +Name[el]=ΠρόσθετοΕικόνας_Αποζωγραφισμός +Name[hr]=Bojanje +Name[it]=PluginImmagini_Reintegrazione +Name[nl]=Afbeeldingsplugin_Inkleuren +Name[sr]=Пребојавање +Name[sr@Latn]=Prebojavanje +Name[sv]=Insticksprogram för ifyllnad +Name[tr]=ResimEklentisi_InPainting +Name[xx]=xxImagePlugin_InPaintingxx + +Type=Service +X-TDE-ServiceTypes=Digikam/ImagePlugin +Encoding=UTF-8 +Comment=digiKam plugin to inpaint a photograph +Comment[bg]=Приставка на digiKam за дорисуване на повредени или липсващи области от снимки +Comment[ca]=Connector pel digiKam per repintar una fotografia +Comment[da]=Digikam plugin til at indfylde i et fotografi +Comment[de]=digiKam-Modul zur Korrektur von Bildfehlern durch Inpainting +Comment[el]=Πρόσθετο αποζωγραφισμού μιας φωτογραφίας μέσα για το digiKam +Comment[es]=Plugin para digiKam repintar una parte de una fotografía +Comment[et]=DigiKami foto objektide kaotamise plugin +Comment[fa]=وصلۀ digiKam برای کشیدن یک عکس +Comment[gl]=Un plugin de digiKam para pintar por dentro unha fotografia +Comment[hr]=digiKam dodatak za bojanje u fotografiji +Comment[is]=Íforrit fyrir digiKam til að fjarlægja óæskilega hluti úr mynd +Comment[it]=Plugin di digiKam per reintegrare una fotografia +Comment[ja]=digiKam 写真修復プラグイン +Comment[nds]=digiKam-Moduul för de Bildkorrektuur dör Övermalen +Comment[nl]=Digikam-plugin voor het inkleuren van een foto +Comment[pa]=ਇੱਕ ਫੋਟੋ-ਗਰਾਫ਼ ਇਨ-ਪੇਂਟ ਲਈ ਡਿਜ਼ੀਕੈਮ ਪਲੱਗਇਨ +Comment[pl]=Wtyczka do programu digiKam umożliwiająca zamalowanie fragmentów zdjęcia +Comment[pt]=Um 'plugin' do digiKam para pintar por dentro uma fotografia +Comment[pt_BR]=Um 'plugin' do digiKam para pintar por dentro uma fotografia +Comment[ru]=Модуль подрисовки фотографий для digiKam +Comment[sk]=digiKam plugin na odstránenie artefaktov +Comment[sr]=digiKam-ов прикључак за пребојавање фотографије +Comment[sr@Latn]=digiKam-ov priključak za prebojavanje fotografije +Comment[sv]=Digikam insticksprogram för att fylla i ett fotografi +Comment[tr]=TDE Fotoğraf Yöneticisi +Comment[uk]=Втулок малювання на фотографіях для digiKam +Comment[vi]=Phần bổ sung sơn vào ảnh chụp cho digiKam +Comment[xx]=xxdigiKam plugin to inpaint a photographxx + +X-TDE-Library=digikamimageplugin_inpainting +author=Gilles Caulier, caulier dot gilles at gmail dot com diff --git a/src/imageplugins/inpainting/digikamimageplugin_inpainting_ui.rc b/src/imageplugins/inpainting/digikamimageplugin_inpainting_ui.rc new file mode 100644 index 00000000..a4c13901 --- /dev/null +++ b/src/imageplugins/inpainting/digikamimageplugin_inpainting_ui.rc @@ -0,0 +1,20 @@ +<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd"> +<kpartgui version="5" name="digikamimageplugin_inpainting" > + + <MenuBar> + + <Menu name="Enhance" ><text>Enh&ance</text> + <Action name="imageplugin_inpainting" /> + </Menu> + + </MenuBar> + + <ToolBar name="ToolBar" > + <text>Main Toolbar</text> + </ToolBar> + + <ActionProperties> + <Action name="imageplugin_inpainting" /> + </ActionProperties> + +</kpartgui> diff --git a/src/imageplugins/inpainting/imageeffect_inpainting.cpp b/src/imageplugins/inpainting/imageeffect_inpainting.cpp new file mode 100644 index 00000000..d7f2f5fe --- /dev/null +++ b/src/imageplugins/inpainting/imageeffect_inpainting.cpp @@ -0,0 +1,466 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2005-03-30 + * Description : a digiKam image editor plugin to inpaint + * 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. + * + * ============================================================ */ + +// C++ include. + +#include <cstdio> +#include <cmath> +#include <cstring> + +// TQt includes. + +#include <tqvgroupbox.h> +#include <tqlabel.h> +#include <tqpushbutton.h> +#include <tqtooltip.h> +#include <tqwhatsthis.h> +#include <tqlayout.h> +#include <tqframe.h> +#include <tqcheckbox.h> +#include <tqcombobox.h> +#include <tqtabwidget.h> +#include <tqtimer.h> +#include <tqevent.h> +#include <tqpixmap.h> +#include <tqpainter.h> +#include <tqbrush.h> +#include <tqfile.h> + +// KDE includes. + +#include <kcursor.h> +#include <kurllabel.h> +#include <tdelocale.h> +#include <tdeaboutdata.h> +#include <khelpmenu.h> +#include <kiconloader.h> +#include <tdeapplication.h> +#include <tdepopupmenu.h> +#include <tdefiledialog.h> +#include <kstandarddirs.h> +#include <kprogress.h> +#include <tdemessagebox.h> +#include <knuminput.h> +#include <tdeglobalsettings.h> +#include <kpassivepopup.h> + +// Local includes. + +#include "version.h" +#include "ddebug.h" +#include "imageiface.h" +#include "greycstorationsettings.h" +#include "greycstorationwidget.h" +#include "greycstorationiface.h" +#include "imageeffect_inpainting.h" +#include "imageeffect_inpainting.moc" + +namespace DigikamInPaintingImagesPlugin +{ + +class InPaintingPassivePopup : public KPassivePopup +{ +public: + + InPaintingPassivePopup(TQWidget* parent) : KPassivePopup(parent), m_parent(parent) {} + +protected: + + virtual void positionSelf() { move(m_parent->x() + 30, m_parent->y() + 30); } + +private: + + TQWidget* m_parent; +}; + +//------------------------------------------------------------------------------------------ + +void ImageEffect_InPainting::inPainting(TQWidget* parent) +{ + // -- check if we actually have a selection -------------------- + + Digikam::ImageIface iface(0, 0); + + int w = iface.selectedWidth(); + int h = iface.selectedHeight(); + + if (!w || !h) + { + InPaintingPassivePopup* popup = new InPaintingPassivePopup(parent); + popup->setView(i18n("Inpainting Photograph Tool"), + i18n("You need to select a region to inpaint to use " + "this tool")); + popup->setAutoDelete(true); + popup->setTimeout(2500); + popup->show(); + return; + } + + // -- run the dlg ---------------------------------------------- + + ImageEffect_InPainting_Dialog dlg(parent); + dlg.exec(); +} + +//------------------------------------------------------------------------------------------ + +ImageEffect_InPainting_Dialog::ImageEffect_InPainting_Dialog(TQWidget* parent) + : Digikam::ImageGuideDlg(parent, i18n("Photograph Inpainting"), + "inpainting", true, true, false, + Digikam::ImageGuideWidget::HVGuideMode, + 0, true, true, true) +{ + m_isComputed = false; + TQString whatsThis; + + TDEAboutData* about = new TDEAboutData("digikam", + I18N_NOOP("Photograph Inpainting"), + digikam_version, + I18N_NOOP("A digiKam image plugin to inpaint 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); + + // ------------------------------------------------------------- + + TQWidget *gboxSettings = new TQWidget(plainPage()); + TQGridLayout* gridSettings = new TQGridLayout(gboxSettings, 2, 1, spacingHint()); + m_mainTab = new TQTabWidget( gboxSettings ); + + TQWidget* firstPage = new TQWidget( m_mainTab ); + TQGridLayout* grid = new TQGridLayout( firstPage, 2, 2, marginHint(), 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_inpaintingTypeCB = new TQComboBox( false, firstPage ); + m_inpaintingTypeCB->insertItem( i18n("None") ); + m_inpaintingTypeCB->insertItem( i18n("Remove Small Artefact") ); + m_inpaintingTypeCB->insertItem( i18n("Remove Medium Artefact") ); + m_inpaintingTypeCB->insertItem( i18n("Remove Large Artefact") ); + TQWhatsThis::add( m_inpaintingTypeCB, i18n("<p>Select the filter preset to use for photograph restoration:<p>" + "<b>None</b>: Most common values. Puts settings to default.<p>" + "<b>Remove Small Artefact</b>: inpaint small image artefact like image glitch.<p>" + "<b>Remove Medium Artefact</b>: inpaint medium image artefact.<p>" + "<b>Remove Large Artefact</b>: inpaint image artefact like unwanted object.<p>")); + + grid->addMultiCellWidget(cimgLogoLabel, 0, 0, 1, 1); + grid->addMultiCellWidget(typeLabel, 1, 1, 0, 0); + grid->addMultiCellWidget(m_inpaintingTypeCB, 1, 1, 1, 1); + grid->setRowStretch(1, 10); + + // ------------------------------------------------------------- + + m_settingsWidget = new Digikam::GreycstorationWidget(m_mainTab); + + gridSettings->addMultiCellWidget(m_mainTab, 0, 0, 1, 1); + gridSettings->addMultiCellWidget(new TQLabel(gboxSettings), 1, 1, 1, 1); + setUserAreaWidget(gboxSettings); + + // ------------------------------------------------------------- + + connect(cimgLogoLabel, TQ_SIGNAL(leftClickedURL(const TQString&)), + this, TQ_SLOT(processCImgURL(const TQString&))); + + connect(m_inpaintingTypeCB, TQ_SIGNAL(activated(int)), + this, TQ_SLOT(slotResetValues(int))); +} + +ImageEffect_InPainting_Dialog::~ImageEffect_InPainting_Dialog() +{ +} + +void ImageEffect_InPainting_Dialog::renderingFinished() +{ + m_mainTab->setEnabled(true); +} + +void ImageEffect_InPainting_Dialog::readUserSettings() +{ + TDEConfig* config = kapp->config(); + config->setGroup("inpainting Tool Dialog"); + + Digikam::GreycstorationSettings settings; + settings.fastApprox = config->readBoolEntry("FastApprox", true); + settings.interp = config->readNumEntry("Interpolation", + Digikam::GreycstorationSettings::NearestNeighbor); + settings.amplitude = config->readDoubleNumEntry("Amplitude", 20.0); + settings.sharpness = config->readDoubleNumEntry("Sharpness", 0.3); + settings.anisotropy = config->readDoubleNumEntry("Anisotropy", 1.0); + settings.alpha = config->readDoubleNumEntry("Alpha", 0.8); + settings.sigma = config->readDoubleNumEntry("Sigma", 2.0); + 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", 30); + settings.tile = config->readNumEntry("Tile", 512); + settings.btile = config->readNumEntry("BTile", 4); + m_settingsWidget->setSettings(settings); + + int p = config->readNumEntry("Preset", NoPreset); + m_inpaintingTypeCB->setCurrentItem(p); + if (p == NoPreset) + m_settingsWidget->setEnabled(true); + else + m_settingsWidget->setEnabled(false); +} + +void ImageEffect_InPainting_Dialog::writeUserSettings() +{ + Digikam::GreycstorationSettings settings = m_settingsWidget->getSettings(); + TDEConfig* config = kapp->config(); + config->setGroup("inpainting Tool Dialog"); + config->writeEntry("Preset", m_inpaintingTypeCB->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_InPainting_Dialog::slotResetValues(int i) +{ + if (i == NoPreset) + m_settingsWidget->setEnabled(true); + else + m_settingsWidget->setEnabled(false); + + resetValues(); +} + +void ImageEffect_InPainting_Dialog::resetValues() +{ + Digikam::GreycstorationSettings settings; + settings.setInpaintingDefaultSettings(); + + switch(m_inpaintingTypeCB->currentItem()) + { + case RemoveSmallArtefact: + // We use default settings here. + break; + + case RemoveMediumArtefact: + { + settings.amplitude = 50.0; + settings.nbIter = 50; + break; + } + + case RemoveLargeArtefact: + { + settings.amplitude = 100.0; + settings.nbIter = 100; + break; + } + } + + m_settingsWidget->setSettings(settings); +} + +void ImageEffect_InPainting_Dialog::processCImgURL(const TQString& url) +{ + TDEApplication::kApplication()->invokeBrowser(url); +} + +void ImageEffect_InPainting_Dialog::prepareEffect() +{ + m_mainTab->setEnabled(false); + + Digikam::ImageIface iface(0, 0); + uchar *data = iface.getOriginalImage(); + m_originalImage = Digikam::DImg(iface.originalWidth(), iface.originalHeight(), + iface.originalSixteenBit(), iface.originalHasAlpha(), data); + delete [] data; + + // Selected area from the image and mask creation: + // + // We optimize the computation time to use the current selected area in image editor + // and to create an inpainting mask with it. Because inpainting is done by interpolation + // neighboor pixels which can be located far from the selected area, we need to ajust the + // mask size in according with the parameter algorithms, especially 'amplitude'. + // Mask size is computed like this : + // + // (image_size_x + 2*amplitude , image_size_y + 2*amplitude) + + + TQRect selectionRect = TQRect(iface.selectedXOrg(), iface.selectedYOrg(), + iface.selectedWidth(), iface.selectedHeight()); + + TQPixmap inPaintingMask(iface.originalWidth(), iface.originalHeight()); + inPaintingMask.fill(TQt::black); + TQPainter p(&inPaintingMask); + p.fillRect( selectionRect, TQBrush(TQt::white) ); + p.end(); + + Digikam::GreycstorationSettings settings = m_settingsWidget->getSettings(); + + int x1 = (int)(selectionRect.left() - 2*settings.amplitude); + int y1 = (int)(selectionRect.top() - 2*settings.amplitude); + int x2 = (int)(selectionRect.right() + 2*settings.amplitude); + int y2 = (int)(selectionRect.bottom() + 2*settings.amplitude); + m_maskRect = TQRect(x1, y1, x2-x1, y2-y1); + + // Mask area normalization. + // We need to check if mask area is out of image size else inpainting give strange results. + + if (m_maskRect.left() < 0) m_maskRect.setLeft(0); + if (m_maskRect.top() < 0) m_maskRect.setTop(0); + if (m_maskRect.right() > iface.originalWidth()) m_maskRect.setRight(iface.originalWidth()); + if (m_maskRect.bottom() > iface.originalHeight()) m_maskRect.setBottom(iface.originalHeight()); + + m_maskImage = inPaintingMask.convertToImage().copy(m_maskRect); + m_cropImage = m_originalImage.copy(m_maskRect); + + m_threadedFilter = dynamic_cast<Digikam::DImgThreadedFilter *>( + new Digikam::GreycstorationIface( + &m_cropImage, + settings, + Digikam::GreycstorationIface::InPainting, + 0, 0, + m_maskImage, this)); +} + +void ImageEffect_InPainting_Dialog::prepareFinal() +{ + if (!m_isComputed) + { + setProgressVisible(true); + prepareEffect(); + } + else + { + putFinalData(); + kapp->restoreOverrideCursor(); + accept(); + } +} + +void ImageEffect_InPainting_Dialog::putPreviewData() +{ + Digikam::ImageIface* iface = m_imagePreviewWidget->imageIface(); + Digikam::GreycstorationSettings settings = m_settingsWidget->getSettings(); + + m_cropImage = m_threadedFilter->getTargetImage(); + TQRect cropSel((int)(2*settings.amplitude), (int)(2*settings.amplitude), + iface->selectedWidth(), iface->selectedHeight()); + Digikam::DImg imDest = m_cropImage.copy(cropSel); + + iface->putPreviewImage((imDest.smoothScale(iface->previewWidth(), + iface->previewHeight())).bits()); + m_imagePreviewWidget->updatePreview(); + m_isComputed = true; +} + +void ImageEffect_InPainting_Dialog::putFinalData(void) +{ + Digikam::ImageIface iface(0, 0); + + if (!m_isComputed) + m_cropImage = m_threadedFilter->getTargetImage(); + + m_originalImage.bitBltImage(&m_cropImage, m_maskRect.left(), m_maskRect.top()); + + iface.putOriginalImage(i18n("InPainting"), m_originalImage.bits()); +} + +void ImageEffect_InPainting_Dialog::slotUser3() +{ + KURL loadInpaintingFile = KFileDialog::getOpenURL(TDEGlobalSettings::documentPath(), + TQString( "*" ), this, + TQString( i18n("Photograph Inpainting Settings File to Load")) ); + if( loadInpaintingFile.isEmpty() ) + return; + + TQFile file(loadInpaintingFile.path()); + + if ( file.open(IO_ReadOnly) ) + { + if (!m_settingsWidget->loadSettings(file, TQString("# Photograph Inpainting Configuration File V2"))) + { + KMessageBox::error(this, + i18n("\"%1\" is not a Photograph Inpainting settings text file.") + .arg(loadInpaintingFile.fileName())); + file.close(); + return; + } + } + else + KMessageBox::error(this, i18n("Cannot load settings from the Photograph Inpainting text file.")); + + file.close(); + m_inpaintingTypeCB->blockSignals(true); + m_inpaintingTypeCB->setCurrentItem(NoPreset); + m_inpaintingTypeCB->blockSignals(false); + m_settingsWidget->setEnabled(true); +} + +void ImageEffect_InPainting_Dialog::slotUser2() +{ + KURL saveRestorationFile = KFileDialog::getSaveURL(TDEGlobalSettings::documentPath(), + TQString( "*" ), this, + TQString( i18n("Photograph Inpainting Settings File to Save")) ); + if( saveRestorationFile.isEmpty() ) + return; + + TQFile file(saveRestorationFile.path()); + + if ( file.open(IO_WriteOnly) ) + m_settingsWidget->saveSettings(file, TQString("# Photograph Inpainting Configuration File V2")); + else + KMessageBox::error(this, i18n("Cannot save settings to the Photograph Inpainting text file.")); + + file.close(); +} + +} // NameSpace DigikamInPaintingImagesPlugin + diff --git a/src/imageplugins/inpainting/imageeffect_inpainting.h b/src/imageplugins/inpainting/imageeffect_inpainting.h new file mode 100644 index 00000000..542e9504 --- /dev/null +++ b/src/imageplugins/inpainting/imageeffect_inpainting.h @@ -0,0 +1,116 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2005-03-30 + * Description : a digiKam image editor plugin to inpaint + * 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_INPAINTING_H +#define IMAGEEFFECT_INPAINTING_H + +// TQt include. + +#include <tqimage.h> +#include <tqrect.h> +#include <tqstring.h> + +// Digikam includes. + +#include "dimg.h" +#include "imageguidedlg.h" + +class TQTabWidget; +class TQComboBox; + +namespace Digikam +{ +class GreycstorationWidget; +} + +namespace DigikamInPaintingImagesPlugin +{ + +class ImageEffect_InPainting +{ +public: + + static void inPainting(TQWidget *parent); +}; + +//----------------------------------------------------------- + +class ImageEffect_InPainting_Dialog : public Digikam::ImageGuideDlg +{ + TQ_OBJECT + + +public: + + ImageEffect_InPainting_Dialog(TQWidget* parent); + ~ImageEffect_InPainting_Dialog(); + +private slots: + + void slotUser2(); + void slotUser3(); + void readUserSettings(); + void processCImgURL(const TQString&); + void slotResetValues(int); + +private: + + void writeUserSettings(); + void resetValues(); + void prepareEffect(); + void prepareFinal(); + void putPreviewData(); + void putFinalData(); + void renderingFinished(); + +private: + + enum InPaintingFilteringPreset + { + NoPreset=0, + RemoveSmallArtefact, + RemoveMediumArtefact, + RemoveLargeArtefact + }; + + bool m_isComputed; + + TQRect m_maskRect; + + TQImage m_maskImage; + + TQComboBox *m_inpaintingTypeCB; + + TQTabWidget *m_mainTab; + + Digikam::DImg m_originalImage; + Digikam::DImg m_cropImage; + + Digikam::GreycstorationWidget *m_settingsWidget; +}; + +} // NameSpace DigikamInPaintingImagesPlugin + +#endif /* IMAGEEFFECT_INPAINTING_H */ diff --git a/src/imageplugins/inpainting/imageplugin_inpainting.cpp b/src/imageplugins/inpainting/imageplugin_inpainting.cpp new file mode 100644 index 00000000..2c1e30f3 --- /dev/null +++ b/src/imageplugins/inpainting/imageplugin_inpainting.cpp @@ -0,0 +1,97 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2005-03-30 + * Description : a digiKam image editor plugin to inpaint + * a photograph + * + * Copyright (C) 2005-2009 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 "imageiface.h" +#include "inpaintingtool.h" +#include "imageplugin_inpainting.h" +#include "imageplugin_inpainting.moc" + +using namespace DigikamInPaintingImagesPlugin; +using namespace Digikam; + +K_EXPORT_COMPONENT_FACTORY(digikamimageplugin_inpainting, + KGenericFactory<ImagePlugin_InPainting>("digikamimageplugin_inpainting")); + +ImagePlugin_InPainting::ImagePlugin_InPainting(TQObject *parent, const char*, const TQStringList &) + : Digikam::ImagePlugin(parent, "ImagePlugin_InPainting") +{ + m_inPaintingAction = new TDEAction(i18n("Inpainting..."), "inpainting", + CTRL+Key_E, + this, TQ_SLOT(slotInPainting()), + actionCollection(), "imageplugin_inpainting"); + + m_inPaintingAction->setWhatsThis( i18n( "This filter can be used to inpaint a part in a photo. " + "Select a region to inpaint to use this option.") ); + + setXMLFile( "digikamimageplugin_inpainting_ui.rc" ); + + DDebug() << "ImagePlugin_InPainting plugin loaded" << endl; +} + +ImagePlugin_InPainting::~ImagePlugin_InPainting() +{ +} + +void ImagePlugin_InPainting::setEnabledActions(bool enable) +{ + m_inPaintingAction->setEnabled(enable); +} + +void ImagePlugin_InPainting::slotInPainting() +{ + + ImageIface iface(0, 0); + + int w = iface.selectedWidth(); + int h = iface.selectedHeight(); + + if (!w || !h) + { + InPaintingPassivePopup* popup = new InPaintingPassivePopup(kapp->activeWindow()); + popup->setView(i18n("Inpainting Photograph Tool"), + i18n("You need to select a region to inpaint to use " + "this tool")); + popup->setAutoDelete(true); + popup->setTimeout(2500); + popup->show(); + return; + } + + // -- run the dlg ---------------------------------------------- + + InPaintingTool *tool = new InPaintingTool(this); + loadTool(tool); +} diff --git a/src/imageplugins/inpainting/imageplugin_inpainting.h b/src/imageplugins/inpainting/imageplugin_inpainting.h new file mode 100644 index 00000000..fb2b1f5c --- /dev/null +++ b/src/imageplugins/inpainting/imageplugin_inpainting.h @@ -0,0 +1,57 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2005-03-30 + * Description : a digiKam image editor plugin to inpaint + * a photograph + * + * Copyright (C) 2005-2009 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_INPAINTING_H +#define IMAGEPLUGIN_INPAINTING_H + +// Digikam includes. + +#include "imageplugin.h" +#include "digikam_export.h" + +class TDEAction; + +class DIGIKAMIMAGEPLUGINS_EXPORT ImagePlugin_InPainting : public Digikam::ImagePlugin +{ + TQ_OBJECT + + +public: + + ImagePlugin_InPainting(TQObject *parent, const char* name, + const TQStringList &args); + ~ImagePlugin_InPainting(); + + void setEnabledActions(bool enable); + +private slots: + + void slotInPainting(); + +private: + + TDEAction *m_inPaintingAction; +}; + +#endif /* IMAGEPLUGIN_INPAINTING_H */ diff --git a/src/imageplugins/inpainting/inpaintingtool.cpp b/src/imageplugins/inpainting/inpaintingtool.cpp new file mode 100644 index 00000000..2ada52bf --- /dev/null +++ b/src/imageplugins/inpainting/inpaintingtool.cpp @@ -0,0 +1,430 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2005-03-30 + * Description : a digiKam image editor plugin to inpaint + * a photograph + * + * Copyright (C) 2005-2009 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. + * + * ============================================================ */ + +// C++ includes. + +#include <cstdio> +#include <cmath> +#include <cstring> + +// TQt includes. + +#include <tqbrush.h> +#include <tqcheckbox.h> +#include <tqcombobox.h> +#include <tqevent.h> +#include <tqfile.h> +#include <tqframe.h> +#include <tqlabel.h> +#include <tqlayout.h> +#include <tqpainter.h> +#include <tqpixmap.h> +#include <tqpushbutton.h> +#include <tqtabwidget.h> +#include <tqtimer.h> +#include <tqtooltip.h> +#include <tqvgroupbox.h> +#include <tqwhatsthis.h> + +// KDE includes. + +#include <tdeaboutdata.h> +#include <tdeapplication.h> +#include <kcursor.h> +#include <tdefiledialog.h> +#include <tdeglobalsettings.h> +#include <khelpmenu.h> +#include <kiconloader.h> +#include <tdelocale.h> +#include <tdemessagebox.h> +#include <tdepopupmenu.h> +#include <kprogress.h> +#include <kstandarddirs.h> +#include <kurllabel.h> + +// Local includes. + +#include "daboutdata.h" +#include "ddebug.h" +#include "dimgthreadedfilter.h" +#include "imageiface.h" +#include "imagewidget.h" +#include "editortoolsettings.h" +#include "greycstorationsettings.h" +#include "greycstorationwidget.h" +#include "greycstorationiface.h" +#include "inpaintingtool.h" +#include "inpaintingtool.moc" + +using namespace Digikam; + +namespace DigikamInPaintingImagesPlugin +{ + +InPaintingTool::InPaintingTool(TQObject* parent) + : EditorToolThreaded(parent) +{ + setName("inpainting"); + setToolName(i18n("Inpainting")); + setToolIcon(SmallIcon("inpainting")); + + m_isComputed = false; + + m_previewWidget = new ImageWidget("inpainting Tool", 0, + i18n("<p>Here you can see the image selection preview with " + "inpainting applied."), + true, ImageGuideWidget::HVGuideMode, false, true); + setToolView(m_previewWidget); + + // ------------------------------------------------------------- + + m_gboxSettings = new EditorToolSettings(EditorToolSettings::Default| + EditorToolSettings::Try| + EditorToolSettings::Load| + EditorToolSettings::SaveAs| + EditorToolSettings::Ok| + EditorToolSettings::Cancel); + 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_inpaintingTypeCB = new TQComboBox( false, firstPage ); + m_inpaintingTypeCB->insertItem( i18n("None") ); + m_inpaintingTypeCB->insertItem( i18n("Remove Small Artefact") ); + m_inpaintingTypeCB->insertItem( i18n("Remove Medium Artefact") ); + m_inpaintingTypeCB->insertItem( i18n("Remove Large Artefact") ); + TQWhatsThis::add( m_inpaintingTypeCB, i18n("<p>Select the filter preset to use for photograph restoration:<p>" + "<b>None</b>: Most common values. Puts settings to default.<p>" + "<b>Remove Small Artefact</b>: inpaint small image artefact like image glitch.<p>" + "<b>Remove Medium Artefact</b>: inpaint medium image artefact.<p>" + "<b>Remove Large Artefact</b>: inpaint image artefact like unwanted object.<p>")); + + grid->addMultiCellWidget(cimgLogoLabel, 0, 0, 1, 1); + grid->addMultiCellWidget(typeLabel, 1, 1, 0, 0); + grid->addMultiCellWidget(m_inpaintingTypeCB, 1, 1, 1, 1); + grid->setMargin(m_gboxSettings->spacingHint()); + grid->setSpacing(m_gboxSettings->spacingHint()); + grid->setRowStretch(1, 10); + + // ------------------------------------------------------------- + + 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(1, 10); + + setToolSettings(m_gboxSettings); + init(); + + // ------------------------------------------------------------- + + connect(cimgLogoLabel, TQ_SIGNAL(leftClickedURL(const TQString&)), + this, TQ_SLOT(processCImgURL(const TQString&))); + + connect(m_inpaintingTypeCB, TQ_SIGNAL(activated(int)), + this, TQ_SLOT(slotResetValues(int))); + + // ------------------------------------------------------------- + + GreycstorationSettings defaults; + defaults.setInpaintingDefaultSettings(); + m_settingsWidget->setDefaultSettings(defaults); +} + +InPaintingTool::~InPaintingTool() +{ +} + +void InPaintingTool::renderingFinished() +{ + m_mainTab->setEnabled(true); +} + +void InPaintingTool::readSettings() +{ + TDEConfig* config = kapp->config(); + config->setGroup("inpainting Tool"); + + GreycstorationSettings settings; + GreycstorationSettings defaults; + defaults.setInpaintingDefaultSettings(); + + 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_inpaintingTypeCB->setCurrentItem(p); + if (p == NoPreset) + m_settingsWidget->setEnabled(true); + else + m_settingsWidget->setEnabled(false); +} + +void InPaintingTool::writeSettings() +{ + GreycstorationSettings settings = m_settingsWidget->getSettings(); + TDEConfig* config = kapp->config(); + config->setGroup("inpainting Tool"); + config->writeEntry("Preset", m_inpaintingTypeCB->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 InPaintingTool::slotResetValues(int i) +{ + if (i == NoPreset) + m_settingsWidget->setEnabled(true); + else + m_settingsWidget->setEnabled(false); + + slotResetSettings(); +} + +void InPaintingTool::slotResetSettings() +{ + GreycstorationSettings settings; + settings.setInpaintingDefaultSettings(); + + switch(m_inpaintingTypeCB->currentItem()) + { + case RemoveSmallArtefact: + // We use default settings here. + break; + + case RemoveMediumArtefact: + { + settings.amplitude = 50.0; + settings.nbIter = 50; + break; + } + + case RemoveLargeArtefact: + { + settings.amplitude = 100.0; + settings.nbIter = 100; + break; + } + } + + m_settingsWidget->setSettings(settings); +} + +void InPaintingTool::processCImgURL(const TQString& url) +{ + TDEApplication::kApplication()->invokeBrowser(url); +} + +void InPaintingTool::prepareEffect() +{ + m_mainTab->setEnabled(false); + + ImageIface iface(0, 0); + uchar *data = iface.getOriginalImage(); + m_originalImage = DImg(iface.originalWidth(), iface.originalHeight(), + iface.originalSixteenBit(), iface.originalHasAlpha(), data); + delete [] data; + + // Selected area from the image and mask creation: + // + // We optimize the computation time to use the current selected area in image editor + // and to create an inpainting mask with it. Because inpainting is done by interpolation + // neighboor pixels which can be located far from the selected area, we need to ajust the + // mask size in according with the parameter algorithms, especially 'amplitude'. + // Mask size is computed like this : + // + // (image_size_x + 2*amplitude , image_size_y + 2*amplitude) + + + TQRect selectionRect = TQRect(iface.selectedXOrg(), iface.selectedYOrg(), + iface.selectedWidth(), iface.selectedHeight()); + + TQPixmap inPaintingMask(iface.originalWidth(), iface.originalHeight()); + inPaintingMask.fill(TQt::black); + TQPainter p(&inPaintingMask); + p.fillRect( selectionRect, TQBrush(TQt::white) ); + p.end(); + + GreycstorationSettings settings = m_settingsWidget->getSettings(); + + int x1 = (int)(selectionRect.left() - 2*settings.amplitude); + int y1 = (int)(selectionRect.top() - 2*settings.amplitude); + int x2 = (int)(selectionRect.right() + 2*settings.amplitude); + int y2 = (int)(selectionRect.bottom() + 2*settings.amplitude); + m_maskRect = TQRect(x1, y1, x2-x1, y2-y1); + + // Mask area normalization. + // We need to check if mask area is out of image size else inpainting give strange results. + + if (m_maskRect.left() < 0) m_maskRect.setLeft(0); + if (m_maskRect.top() < 0) m_maskRect.setTop(0); + if (m_maskRect.right() > iface.originalWidth()) m_maskRect.setRight(iface.originalWidth()); + if (m_maskRect.bottom() > iface.originalHeight()) m_maskRect.setBottom(iface.originalHeight()); + + m_maskImage = inPaintingMask.convertToImage().copy(m_maskRect); + m_cropImage = m_originalImage.copy(m_maskRect); + + setFilter(dynamic_cast<DImgThreadedFilter*>( + new GreycstorationIface( + &m_cropImage, + settings, + GreycstorationIface::InPainting, + 0, 0, + m_maskImage, this))); +} + +void InPaintingTool::prepareFinal() +{ + if (!m_isComputed) + { + prepareEffect(); + } + else + { + Digikam::DImgThreadedFilter::EventData *eventData = new Digikam::DImgThreadedFilter::EventData(); + eventData->progress = 100; + eventData->starting = false; + eventData->success = true; + TQApplication::postEvent(this, new TQCustomEvent(TQEvent::User, eventData)); + } +} + +void InPaintingTool::putPreviewData() +{ + ImageIface* iface = m_previewWidget->imageIface(); + GreycstorationSettings settings = m_settingsWidget->getSettings(); + + m_cropImage = filter()->getTargetImage(); + TQRect cropSel((int)(2*settings.amplitude), (int)(2*settings.amplitude), + iface->selectedWidth(), iface->selectedHeight()); + DImg imDest = m_cropImage.copy(cropSel); + + iface->putPreviewImage((imDest.smoothScale(iface->previewWidth(), + iface->previewHeight())).bits()); + m_previewWidget->updatePreview(); + m_isComputed = true; +} + +void InPaintingTool::putFinalData() +{ + ImageIface iface(0, 0); + + if (!m_isComputed) + m_cropImage = filter()->getTargetImage(); + + m_originalImage.bitBltImage(&m_cropImage, m_maskRect.left(), m_maskRect.top()); + + iface.putOriginalImage(i18n("InPainting"), m_originalImage.bits()); +} + +void InPaintingTool::slotLoadSettings() +{ + KURL loadInpaintingFile = KFileDialog::getOpenURL(TDEGlobalSettings::documentPath(), + TQString( "*" ), kapp->activeWindow(), + TQString( i18n("Photograph Inpainting Settings File to Load")) ); + if( loadInpaintingFile.isEmpty() ) + return; + + TQFile file(loadInpaintingFile.path()); + + if ( file.open(IO_ReadOnly) ) + { + if (!m_settingsWidget->loadSettings(file, TQString("# Photograph Inpainting Configuration File V2"))) + { + KMessageBox::error(kapp->activeWindow(), + i18n("\"%1\" is not a Photograph Inpainting settings text file.") + .arg(loadInpaintingFile.fileName())); + file.close(); + return; + } + } + else + KMessageBox::error(kapp->activeWindow(), i18n("Cannot load settings from the Photograph Inpainting text file.")); + + file.close(); + m_inpaintingTypeCB->blockSignals(true); + m_inpaintingTypeCB->setCurrentItem(NoPreset); + m_inpaintingTypeCB->blockSignals(false); + m_settingsWidget->setEnabled(true); +} + +void InPaintingTool::slotSaveAsSettings() +{ + KURL saveRestorationFile = KFileDialog::getSaveURL(TDEGlobalSettings::documentPath(), + TQString( "*" ), kapp->activeWindow(), + TQString( i18n("Photograph Inpainting Settings File to Save")) ); + if( saveRestorationFile.isEmpty() ) + return; + + TQFile file(saveRestorationFile.path()); + + if ( file.open(IO_WriteOnly) ) + m_settingsWidget->saveSettings(file, TQString("# Photograph Inpainting Configuration File V2")); + else + KMessageBox::error(kapp->activeWindow(), i18n("Cannot save settings to the Photograph Inpainting text file.")); + + file.close(); +} + +} // NameSpace DigikamInPaintingImagesPlugin diff --git a/src/imageplugins/inpainting/inpaintingtool.h b/src/imageplugins/inpainting/inpaintingtool.h new file mode 100644 index 00000000..44202c5d --- /dev/null +++ b/src/imageplugins/inpainting/inpaintingtool.h @@ -0,0 +1,133 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2005-03-30 + * Description : a digiKam image editor plugin to inpaint + * a photograph + * + * Copyright (C) 2005-2009 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 INPAINTINGTOOL_H +#define INPAINTINGTOOL_H + +// TQt includes. + +#include <tqimage.h> +#include <tqrect.h> +#include <tqstring.h> + +// KDE includes. + +#include <kpassivepopup.h> + +// Digikam includes. + +#include "dimg.h" +#include "editortool.h" + +class TQTabWidget; +class TQComboBox; + +namespace Digikam +{ +class GreycstorationWidget; +class ImageWidget; +class EditorToolSettings; +} + +namespace DigikamInPaintingImagesPlugin +{ + +class InPaintingPassivePopup : public KPassivePopup +{ +public: + + InPaintingPassivePopup(TQWidget* parent) : KPassivePopup(parent), m_parent(parent) {} + +protected: + + virtual void positionSelf() { move(m_parent->x() + 30, m_parent->y() + 30); } + +private: + + TQWidget* m_parent; +}; + +//----------------------------------------------------------- + +class InPaintingTool : public Digikam::EditorToolThreaded +{ + TQ_OBJECT + + +public: + + InPaintingTool(TQObject* parent); + ~InPaintingTool(); + +private slots: + + void processCImgURL(const TQString&); + void slotResetValues(int); + void slotResetSettings(); + void slotSaveAsSettings(); + void slotLoadSettings(); + +private: + + void readSettings(); + void writeSettings(); + void prepareEffect(); + void prepareFinal(); + void putPreviewData(); + void putFinalData(); + void renderingFinished(); + +private: + + enum InPaintingFilteringPreset + { + NoPreset=0, + RemoveSmallArtefact, + RemoveMediumArtefact, + RemoveLargeArtefact + }; + + bool m_isComputed; + + TQRect m_maskRect; + + TQImage m_maskImage; + + TQComboBox *m_inpaintingTypeCB; + + TQTabWidget *m_mainTab; + + Digikam::DImg m_originalImage; + Digikam::DImg m_cropImage; + + Digikam::GreycstorationWidget *m_settingsWidget; + + Digikam::ImageWidget *m_previewWidget; + + Digikam::EditorToolSettings *m_gboxSettings; +}; + +} // NameSpace DigikamInPaintingImagesPlugin + +#endif /* INPAINTINGTOOL_H */ |