diff options
Diffstat (limited to 'src/imageplugins/sheartool')
-rw-r--r-- | src/imageplugins/sheartool/Makefile.am | 33 | ||||
-rw-r--r-- | src/imageplugins/sheartool/digikamimageplugin_sheartool.desktop | 53 | ||||
-rw-r--r-- | src/imageplugins/sheartool/digikamimageplugin_sheartool_ui.rc | 20 | ||||
-rw-r--r-- | src/imageplugins/sheartool/imageeffect_sheartool.cpp | 322 | ||||
-rw-r--r-- | src/imageplugins/sheartool/imageeffect_sheartool.h | 82 | ||||
-rw-r--r-- | src/imageplugins/sheartool/imageplugin_sheartool.cpp | 69 | ||||
-rw-r--r-- | src/imageplugins/sheartool/imageplugin_sheartool.h | 56 | ||||
-rw-r--r-- | src/imageplugins/sheartool/shear.cpp | 185 | ||||
-rw-r--r-- | src/imageplugins/sheartool/shear.h | 84 | ||||
-rw-r--r-- | src/imageplugins/sheartool/sheartool.cpp | 331 | ||||
-rw-r--r-- | src/imageplugins/sheartool/sheartool.h | 96 |
11 files changed, 1331 insertions, 0 deletions
diff --git a/src/imageplugins/sheartool/Makefile.am b/src/imageplugins/sheartool/Makefile.am new file mode 100644 index 00000000..a601b8a5 --- /dev/null +++ b/src/imageplugins/sheartool/Makefile.am @@ -0,0 +1,33 @@ +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_sheartool_la_SOURCES = imageplugin_sheartool.cpp shear.cpp \ + sheartool.cpp + +digikamimageplugin_sheartool_la_LIBADD = $(LIB_TDEPARTS) \ + $(top_builddir)/src/digikam/libdigikam.la + +digikamimageplugin_sheartool_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) -ltdecore -ltdeui $(LIB_TQT) -ltdefx -lkdcraw -ltdeio + +kde_services_DATA = digikamimageplugin_sheartool.desktop + +kde_module_LTLIBRARIES = digikamimageplugin_sheartool.la + +rcdir = $(kde_datadir)/digikam +rc_DATA = digikamimageplugin_sheartool_ui.rc diff --git a/src/imageplugins/sheartool/digikamimageplugin_sheartool.desktop b/src/imageplugins/sheartool/digikamimageplugin_sheartool.desktop new file mode 100644 index 00000000..8884ef27 --- /dev/null +++ b/src/imageplugins/sheartool/digikamimageplugin_sheartool.desktop @@ -0,0 +1,53 @@ +[Desktop Entry] +Name=ImagePlugin_ShearTool +Name[bg]=Приставка за снимки - Инструмент за изрязване +Name[da]=Billedplugin_Forskydningsværktøj +Name[el]=ΠρόσθετοΕικόνας_ΕργαλείοΣτρέβλωσης +Name[fi]=Väännin +Name[hr]=Smicanje +Name[it]=PluginImmagini_DistorsioneCurvilinea +Name[ms]=ImagePlugin_AlatanPemotong +Name[nl]=Afbeeldingsplugin_SchuinTrekken +Name[sr]=Алат за искошавање +Name[sr@Latn]=Alat za iskošavanje +Name[sv]=Insticksprogram med skjuvningsverktyg +Name[tr]=ResimEklentisi_EğmeAracı +Name[xx]=xxImagePlugin_ShearToolxx + +Type=Service +X-TDE-ServiceTypes=Digikam/ImagePlugin +Encoding=UTF-8 +Comment=Shear tool plugin for digiKam +Comment[bg]=Приставка на digiKam с инструмент за изрязване на снимки +Comment[ca]=Connector pel digiKam d'eina per retallar +Comment[da]=Forskydningsværktøjs-plugin for Digikam +Comment[de]=digiKam-Modul zum Scheren eines Bildes +Comment[el]=Πρόσθετο εργαλείο στρέβλωσης για το digiKam +Comment[es]=Plugin para digiKam con herramientas para cizallar una imagen +Comment[et]=DigiKami pildinihkeplugin +Comment[fa]=وصلۀ ابزار چیدن برای digiKam +Comment[fi]=Vääntää kuvaa vaaka- ja pystysuunnassa +Comment[gl]=Un plugin de digiKam para inclinar unha imaxe +Comment[hr]=digiKam dodatak za smicanje +Comment[is]=Íforrit fyrir digiKam sem snýr upp á myndir +Comment[it]=Plugin per lo strumento di distorsione curvilinea per digiKam +Comment[ja]=digiKam 剪断変形プラグイン +Comment[ms]=Templat plugin pemotong untuk digiKam +Comment[nds]=digiKam-Warktüüchmoduul för't Scheren +Comment[nl]=Digikam-plugin voor het schuintrekken van afbeeldingen +Comment[pa]=ਡਿਜ਼ੀਕੈਮ ਲਈ ਸ਼ੀਅਰ ਸੰਦ ਪਲੱਗਇਨ +Comment[pl]=Wtyczka do programu digiKam umożliwiająca pochylenie obrazu +Comment[pt]=Um 'plugin' do digiKam para inclinar uma imagem +Comment[pt_BR]=Um 'plugin' do digiKam para inclinar uma imagem +Comment[ru]=Модуль сдвига фрагментов для digiKam +Comment[sk]=digiKam plugin pre orezanie obrázku +Comment[sr]=digiKam-ов прикључак за искошавање +Comment[sr@Latn]=digiKam-ov priključak za iskošavanje +Comment[sv]=Digikam insticksprogram med skjuvningsverktyg +Comment[tr]=digiKam için eğme aracı eklentisi +Comment[uk]=Втулок засобу перекошення для digiKam +Comment[vi]=Phần bổ sung công cụ kéo cắt cho digiKam +Comment[xx]=xxShear tool plugin for digiKamxx + +X-TDE-Library=digikamimageplugin_sheartool +author=Gilles Caulier, caulier dot gilles at gmail dot com diff --git a/src/imageplugins/sheartool/digikamimageplugin_sheartool_ui.rc b/src/imageplugins/sheartool/digikamimageplugin_sheartool_ui.rc new file mode 100644 index 00000000..0a2cf60a --- /dev/null +++ b/src/imageplugins/sheartool/digikamimageplugin_sheartool_ui.rc @@ -0,0 +1,20 @@ +<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd"> +<kpartgui version="4" name="digikamimageplugin_sheartool" > + + <MenuBar> + + <Menu name="Transform" ><text>Tra&nsform</text> + <Action name="imageplugin_sheartool" /> + </Menu> + + </MenuBar> + + <ToolBar name="ToolBar" > + <text>Main Toolbar</text> + </ToolBar> + + <ActionProperties> + <Action shortcut="" name="imageplugin_sheartool" /> + </ActionProperties> + +</kpartgui> diff --git a/src/imageplugins/sheartool/imageeffect_sheartool.cpp b/src/imageplugins/sheartool/imageeffect_sheartool.cpp new file mode 100644 index 00000000..e65bd91b --- /dev/null +++ b/src/imageplugins/sheartool/imageeffect_sheartool.cpp @@ -0,0 +1,322 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2004-12-23 + * Description : a plugin to shear 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. + * + * ============================================================ */ + +// TQt includes. + +#include <tqlabel.h> +#include <tqcheckbox.h> +#include <tqwhatsthis.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 <knuminput.h> +#include <kseparator.h> +#include <kcursor.h> +#include <tdeconfig.h> + +// Local includes. + +#include "version.h" +#include "ddebug.h" +#include "dimg.h" +#include "imageiface.h" +#include "imagewidget.h" +#include "sheartool.h" +#include "imageeffect_sheartool.h" +#include "imageeffect_sheartool.moc" + +namespace DigikamShearToolImagesPlugin +{ + +ImageEffect_ShearTool::ImageEffect_ShearTool(TQWidget* parent) + : Digikam::ImageGuideDlg(parent, i18n("Shear Tool"), "sheartool", + false, true, true, + Digikam::ImageGuideWidget::HVGuideMode) +{ + // No need Abort button action. + showButton(User1, false); + + TQString whatsThis; + + // About data and help button. + + TDEAboutData* about = new TDEAboutData("digikam", + I18N_NOOP("Shear Tool"), + digikam_version, + I18N_NOOP("A digiKam image plugin to shear an image."), + TDEAboutData::License_GPL, + "(c) 2004-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("Pieter Z. Voloshyn", I18N_NOOP("Shear algorithm"), + "pieter dot voloshyn at gmail dot com"); + + setAboutData(about); + + TQWhatsThis::add( m_imagePreviewWidget, i18n("<p>This is the shearing image operation preview. " + "If you move the mouse cursor on this preview, " + "a vertical and horizontal dashed line will be drawn " + "to guide you in adjusting the shearing correction. " + "Release the left mouse button to freeze the dashed " + "line's position.")); + + // ------------------------------------------------------------- + + TQString temp; + Digikam::ImageIface iface(0, 0); + + TQWidget *gboxSettings = new TQWidget(plainPage()); + TQGridLayout* gridSettings = new TQGridLayout( gboxSettings, 11, 2, spacingHint()); + + TQLabel *label1 = new TQLabel(i18n("New width:"), gboxSettings); + m_newWidthLabel = new TQLabel(temp.setNum( iface.originalWidth()) + i18n(" px"), gboxSettings); + m_newWidthLabel->setAlignment( AlignBottom | AlignRight ); + + TQLabel *label2 = new TQLabel(i18n("New height:"), gboxSettings); + m_newHeightLabel = new TQLabel(temp.setNum( iface.originalHeight()) + i18n(" px"), gboxSettings); + m_newHeightLabel->setAlignment( AlignBottom | AlignRight ); + + gridSettings->addMultiCellWidget(label1, 0, 0, 0, 0); + gridSettings->addMultiCellWidget(m_newWidthLabel, 0, 0, 1, 2); + gridSettings->addMultiCellWidget(label2, 1, 1, 0, 0); + gridSettings->addMultiCellWidget(m_newHeightLabel, 1, 1, 1, 2); + + KSeparator *line = new KSeparator(Horizontal, gboxSettings); + gridSettings->addMultiCellWidget(line, 2, 2, 0, 2); + + TQLabel *label3 = new TQLabel(i18n("Main horizontal angle:"), gboxSettings); + m_mainHAngleInput = new KIntNumInput(gboxSettings); + m_mainHAngleInput->setRange(-45, 45, 1, true); + m_mainHAngleInput->setValue(0); + TQWhatsThis::add( m_mainHAngleInput, i18n("<p>The main horizontal shearing angle, in degrees.")); + gridSettings->addMultiCellWidget(label3, 3, 3, 0, 2); + gridSettings->addMultiCellWidget(m_mainHAngleInput, 4, 4, 0, 2); + + TQLabel *label4 = new TQLabel(i18n("Fine horizontal angle:"), gboxSettings); + m_fineHAngleInput = new KDoubleNumInput(gboxSettings); + m_fineHAngleInput->setRange(-5.0, 5.0, 0.01, true); + m_fineHAngleInput->setValue(0); + TQWhatsThis::add( m_fineHAngleInput, i18n("<p>This value in degrees will be added to main horizontal angle value " + "to set fine adjustments.")); + gridSettings->addMultiCellWidget(label4, 5, 5, 0, 2); + gridSettings->addMultiCellWidget(m_fineHAngleInput, 6, 6, 0, 2); + + TQLabel *label5 = new TQLabel(i18n("Main vertical angle:"), gboxSettings); + m_mainVAngleInput = new KIntNumInput(gboxSettings); + m_mainVAngleInput->setRange(-45, 45, 1, true); + m_mainVAngleInput->setValue(0); + TQWhatsThis::add( m_mainVAngleInput, i18n("<p>The main vertical shearing angle, in degrees.")); + gridSettings->addMultiCellWidget(label5, 7, 7, 0, 0); + gridSettings->addMultiCellWidget(m_mainVAngleInput, 8, 8, 0, 2); + + TQLabel *label6 = new TQLabel(i18n("Fine vertical angle:"), gboxSettings); + m_fineVAngleInput = new KDoubleNumInput(gboxSettings); + m_fineVAngleInput->setRange(-5.0, 5.0, 0.01, true); + m_fineVAngleInput->setValue(0); + TQWhatsThis::add( m_fineVAngleInput, i18n("<p>This value in degrees will be added to main vertical angle value " + "to set fine adjustments.")); + gridSettings->addMultiCellWidget(label6, 9, 9, 0, 2); + gridSettings->addMultiCellWidget(m_fineVAngleInput, 10, 10, 0, 2); + + m_antialiasInput = new TQCheckBox(i18n("Anti-Aliasing"), gboxSettings); + TQWhatsThis::add( m_antialiasInput, i18n("<p>Enable this option to apply the anti-aliasing filter " + "to the sheared image. " + "To smooth the target image, it will be blurred a little.")); + gridSettings->addMultiCellWidget(m_antialiasInput, 11, 11, 0, 2); + + setUserAreaWidget(gboxSettings); + + // ------------------------------------------------------------- + + connect(m_mainHAngleInput, TQ_SIGNAL(valueChanged (int)), + this, TQ_SLOT(slotTimer())); + + connect(m_fineHAngleInput, TQ_SIGNAL(valueChanged (double)), + this, TQ_SLOT(slotTimer())); + + connect(m_mainVAngleInput, TQ_SIGNAL(valueChanged (int)), + this, TQ_SLOT(slotTimer())); + + connect(m_fineVAngleInput, TQ_SIGNAL(valueChanged (double)), + this, TQ_SLOT(slotTimer())); + + connect(m_antialiasInput, TQ_SIGNAL(toggled (bool)), + this, TQ_SLOT(slotEffect())); +} + +ImageEffect_ShearTool::~ImageEffect_ShearTool() +{ +} + +void ImageEffect_ShearTool::readUserSettings(void) +{ + TDEConfig *config = kapp->config(); + config->setGroup("sheartool Tool Dialog"); + m_mainHAngleInput->setValue(config->readNumEntry("Main HAngle", 0)); + m_mainVAngleInput->setValue(config->readNumEntry("Main VAngle", 0)); + m_fineHAngleInput->setValue(config->readDoubleNumEntry("Fine HAngle", 0.0)); + m_fineVAngleInput->setValue(config->readDoubleNumEntry("Fine VAngle", 0.0)); + m_antialiasInput->setChecked(config->readBoolEntry("Anti Aliasing", true)); + slotEffect(); +} + +void ImageEffect_ShearTool::writeUserSettings(void) +{ + TDEConfig *config = kapp->config(); + config->setGroup("sheartool Tool Dialog"); + config->writeEntry("Main HAngle", m_mainHAngleInput->value()); + config->writeEntry("Main VAngle", m_mainVAngleInput->value()); + config->writeEntry("Fine HAngle", m_fineHAngleInput->value()); + config->writeEntry("Fine VAngle", m_fineVAngleInput->value()); + config->writeEntry("Anti Aliasing", m_antialiasInput->isChecked()); + config->sync(); +} + +void ImageEffect_ShearTool::resetValues() +{ + m_mainHAngleInput->blockSignals(true); + m_mainVAngleInput->blockSignals(true); + m_fineHAngleInput->blockSignals(true); + m_fineVAngleInput->blockSignals(true); + m_antialiasInput->blockSignals(true); + m_mainHAngleInput->setValue(0); + m_mainVAngleInput->setValue(0); + m_fineHAngleInput->setValue(0.0); + m_fineVAngleInput->setValue(0.0); + m_antialiasInput->setChecked(true); + m_mainHAngleInput->blockSignals(false); + m_mainVAngleInput->blockSignals(false); + m_fineHAngleInput->blockSignals(false); + m_fineVAngleInput->blockSignals(false); + m_antialiasInput->blockSignals(false); +} + +void ImageEffect_ShearTool::prepareEffect() +{ + kapp->setOverrideCursor( KCursor::waitCursor() ); + m_mainHAngleInput->setEnabled(false); + m_mainVAngleInput->setEnabled(false); + m_fineHAngleInput->setEnabled(false); + m_fineVAngleInput->setEnabled(false); + m_antialiasInput->setEnabled(false); + + float hAngle = m_mainHAngleInput->value() + m_fineHAngleInput->value(); + float vAngle = m_mainVAngleInput->value() + m_fineVAngleInput->value(); + bool antialiasing = m_antialiasInput->isChecked(); + TQColor background = paletteBackgroundColor().rgb(); + + Digikam::ImageIface* iface = m_imagePreviewWidget->imageIface(); + int orgW = iface->originalWidth(); + int orgH = iface->originalHeight(); + + uchar *data = iface->getPreviewImage(); + Digikam::DImg image(iface->previewWidth(), iface->previewHeight(), iface->previewSixteenBit(), + iface->previewHasAlpha(), data); + delete [] data; + + m_threadedFilter = dynamic_cast<Digikam::DImgThreadedFilter *>( + new ShearTool(&image, this, hAngle, vAngle, antialiasing, background, orgW, orgH)); +} + +void ImageEffect_ShearTool::prepareFinal() +{ + m_mainHAngleInput->setEnabled(false); + m_mainVAngleInput->setEnabled(false); + m_fineHAngleInput->setEnabled(false); + m_fineVAngleInput->setEnabled(false); + m_antialiasInput->setEnabled(false); + + float hAngle = m_mainHAngleInput->value() + m_fineHAngleInput->value(); + float vAngle = m_mainVAngleInput->value() + m_fineVAngleInput->value(); + bool antialiasing = m_antialiasInput->isChecked(); + TQColor background = TQt::black; + + Digikam::ImageIface iface(0, 0); + int orgW = iface.originalWidth(); + int orgH = iface.originalHeight(); + + uchar *data = iface.getOriginalImage(); + Digikam::DImg orgImage(orgW, orgH, iface.originalSixteenBit(), + iface.originalHasAlpha(), data); + delete [] data; + + m_threadedFilter = dynamic_cast<Digikam::DImgThreadedFilter *>( + new ShearTool(&orgImage, this, hAngle, vAngle, antialiasing, background, orgW, orgH)); +} + +void ImageEffect_ShearTool::putPreviewData(void) +{ + Digikam::ImageIface* iface = m_imagePreviewWidget->imageIface(); + int w = iface->previewWidth(); + int h = iface->previewHeight(); + + Digikam::DImg imTemp = m_threadedFilter->getTargetImage().smoothScale(w, h, TQSize::ScaleMin); + Digikam::DImg imDest( w, h, m_threadedFilter->getTargetImage().sixteenBit(), + m_threadedFilter->getTargetImage().hasAlpha() ); + + imDest.fill( Digikam::DColor(paletteBackgroundColor().rgb(), + m_threadedFilter->getTargetImage().sixteenBit()) ); + imDest.bitBltImage(&imTemp, (w-imTemp.width())/2, (h-imTemp.height())/2); + + iface->putPreviewImage((imDest.smoothScale(iface->previewWidth(), + iface->previewHeight())).bits()); + + m_imagePreviewWidget->updatePreview(); + TQSize newSize = dynamic_cast<ShearTool *>(m_threadedFilter)->getNewSize(); + TQString temp; + m_newWidthLabel->setText(temp.setNum( newSize.width()) + i18n(" px") ); + m_newHeightLabel->setText(temp.setNum( newSize.height()) + i18n(" px") ); +} + +void ImageEffect_ShearTool::putFinalData(void) +{ + Digikam::ImageIface iface(0, 0); + Digikam::DImg targetImage = m_threadedFilter->getTargetImage(); + iface.putOriginalImage(i18n("Shear Tool"), + targetImage.bits(), + targetImage.width(), targetImage.height()); +} + +void ImageEffect_ShearTool::renderingFinished() +{ + m_mainHAngleInput->setEnabled(true); + m_mainVAngleInput->setEnabled(true); + m_fineHAngleInput->setEnabled(true); + m_fineVAngleInput->setEnabled(true); + m_antialiasInput->setEnabled(true); + kapp->restoreOverrideCursor(); +} + +} // NameSpace DigikamShearToolImagesPlugin + diff --git a/src/imageplugins/sheartool/imageeffect_sheartool.h b/src/imageplugins/sheartool/imageeffect_sheartool.h new file mode 100644 index 00000000..311b4e0d --- /dev/null +++ b/src/imageplugins/sheartool/imageeffect_sheartool.h @@ -0,0 +1,82 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2004-12-23 + * Description : a plugin to shear 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 IMAGEEFFECT_SHEARTOOL_H +#define IMAGEEFFECT_SHEARTOOL_H + +// Local includes. + +#include "imageguidedlg.h" + +class TQFrame; +class TQPushButton; +class TQCheckBox; +class TQLabel; + +class KIntNumInput; +class KDoubleNumInput; + +namespace DigikamShearToolImagesPlugin +{ + +class ImageEffect_ShearTool : public Digikam::ImageGuideDlg +{ + TQ_OBJECT + + +public: + + ImageEffect_ShearTool(TQWidget* parent); + ~ImageEffect_ShearTool(); + +private slots: + + void readUserSettings(void); + +protected: + + void writeUserSettings(void); + void prepareEffect(void); + void prepareFinal(void); + void putPreviewData(void); + void putFinalData(void); + void resetValues(void); + void renderingFinished(void); + +private: + + TQLabel *m_newWidthLabel; + TQLabel *m_newHeightLabel; + + TQCheckBox *m_antialiasInput; + + KIntNumInput *m_mainHAngleInput; + KIntNumInput *m_mainVAngleInput; + + KDoubleNumInput *m_fineHAngleInput; + KDoubleNumInput *m_fineVAngleInput; +}; + +} // NameSpace DigikamShearToolImagesPlugin + +#endif /* IMAGEEFFECT_SHEARTOOL_H */ diff --git a/src/imageplugins/sheartool/imageplugin_sheartool.cpp b/src/imageplugins/sheartool/imageplugin_sheartool.cpp new file mode 100644 index 00000000..34030899 --- /dev/null +++ b/src/imageplugins/sheartool/imageplugin_sheartool.cpp @@ -0,0 +1,69 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2004-12-23 + * Description : a plugin to shear 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> + +// Local includes. + +#include "ddebug.h" +#include "sheartool.h" +#include "imageplugin_sheartool.h" +#include "imageplugin_sheartool.moc" + +using namespace DigikamShearToolImagesPlugin; + +K_EXPORT_COMPONENT_FACTORY(digikamimageplugin_sheartool, + KGenericFactory<ImagePlugin_ShearTool>("digikamimageplugin_sheartool")); + +ImagePlugin_ShearTool::ImagePlugin_ShearTool(TQObject *parent, const char*, const TQStringList &) + : Digikam::ImagePlugin(parent, "ImagePlugin_ShearTool") +{ + m_sheartoolAction = new TDEAction(i18n("Shear..."), "shear", 0, + this, TQ_SLOT(slotShearTool()), + actionCollection(), "imageplugin_sheartool"); + + setXMLFile("digikamimageplugin_sheartool_ui.rc"); + + DDebug() << "ImagePlugin_ShearTool plugin loaded" << endl; +} + +ImagePlugin_ShearTool::~ImagePlugin_ShearTool() +{ +} + +void ImagePlugin_ShearTool::setEnabledActions(bool enable) +{ + m_sheartoolAction->setEnabled(enable); +} + +void ImagePlugin_ShearTool::slotShearTool() +{ + ShearTool *tool = new ShearTool(this); + loadTool(tool); +} diff --git a/src/imageplugins/sheartool/imageplugin_sheartool.h b/src/imageplugins/sheartool/imageplugin_sheartool.h new file mode 100644 index 00000000..2423a1b1 --- /dev/null +++ b/src/imageplugins/sheartool/imageplugin_sheartool.h @@ -0,0 +1,56 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2004-12-23 + * Description : a plugin to shear 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_SHEARTOOL_H +#define IMAGEPLUGIN_SHEARTOOL_H + +// Digikam includes. + +#include "imageplugin.h" +#include "digikam_export.h" + +class TDEAction; + +class DIGIKAMIMAGEPLUGINS_EXPORT ImagePlugin_ShearTool : public Digikam::ImagePlugin +{ + TQ_OBJECT + + +public: + + ImagePlugin_ShearTool(TQObject *parent, const char* name, + const TQStringList &args); + ~ImagePlugin_ShearTool(); + + void setEnabledActions(bool enable); + +private slots: + + void slotShearTool(); + +private: + + TDEAction *m_sheartoolAction; +}; + +#endif /* IMAGEPLUGIN_SHEARTOOL_H */ diff --git a/src/imageplugins/sheartool/shear.cpp b/src/imageplugins/sheartool/shear.cpp new file mode 100644 index 00000000..29af5390 --- /dev/null +++ b/src/imageplugins/sheartool/shear.cpp @@ -0,0 +1,185 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2005-07-18 + * Description : Shear threaded image filter. + * + * Copyright (C) 2005-2008 by Gilles Caulier <caulier dot gilles at gmail dot com> + * + * Original Shear algorithms copyrighted 2005 by + * Pieter Z. Voloshyn <pieter dot voloshyn at gmail dot com>. + * + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; + * either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * ============================================================ */ + +// Degrees to radian convertion coeff (PI/180). To optimize computation. +#define DEG2RAD 0.017453292519943 + +// C++ includes. + +#include <cmath> +#include <cstdlib> + +// Local includes. + +#include "dimg.h" +#include "dimgimagefilters.h" +#include "shear.h" + +namespace DigikamShearToolImagesPlugin +{ + +Shear::Shear(Digikam::DImg *orgImage, TQObject *parent, float hAngle, float vAngle, + bool antialiasing, TQColor backgroundColor, int orgW, int orgH) + : Digikam::DImgThreadedFilter(orgImage, parent, "sheartool") +{ + m_hAngle = hAngle; + m_vAngle = vAngle; + m_orgW = orgW; + m_orgH = orgH; + m_antiAlias = antialiasing; + m_backgroundColor = backgroundColor; + + initFilter(); +} + +void Shear::filterImage(void) +{ + int progress; + int x, y, p = 0, pt; + int new_width, new_height; + double nx, ny, dx, dy; + double horz_factor, vert_factor; + double horz_add, vert_add; + double horz_beta_angle, vert_beta_angle; + + int nWidth = m_orgImage.width(); + int nHeight = m_orgImage.height(); + + uchar *pBits = m_orgImage.bits(); + unsigned short *pBits16 = (unsigned short*)m_orgImage.bits(); + + // get beta ( complementary ) angle for horizontal and vertical angles + horz_beta_angle = ( ( ( m_hAngle < 0.0 ) ? 180.0 : 90.0 ) - m_hAngle ) * DEG2RAD; + vert_beta_angle = ( ( ( m_vAngle < 0.0 ) ? 180.0 : 90.0 ) - m_vAngle ) * DEG2RAD; + + // get new distance for width and height values + horz_add = nHeight * ( ( m_hAngle < 0.0 ) ? sin( horz_beta_angle ) : cos( horz_beta_angle ) ); + vert_add = nWidth * ( ( m_vAngle < 0.0 ) ? sin( vert_beta_angle ) : cos( vert_beta_angle ) ); + + // get absolute values for the distances + horz_add = fabs( horz_add ); + vert_add = fabs( vert_add ); + + // get new image size ( original size + distance ) + new_width = (int)horz_add + nWidth; + new_height = (int)vert_add + nHeight; + + // get scale factor for width and height + horz_factor = horz_add / new_height; + vert_factor = vert_add / new_width; + + // if horizontal angle is greater than zero... + // else, initial distance is equal to maximum distance ( in negative form ) + if( m_hAngle > 0.0 ) + { + // initial distance is zero and scale is negative ( to decrease ) + dx = 0; + horz_factor *= -1.0; + } + else + { + dx = -horz_add; + } + + // if vertical angle is greater than zero... + // else, initial distance is equal to maximum distance ( in negative form ) + if( m_vAngle > 0.0 ) + { + // initial distance is zero and scale is negative ( to decrease ) + dy = 0; + vert_factor *= -1.0; + } + else + { + dy = -vert_add; + } + + // allocates a new image with the new size + + bool sixteenBit = m_orgImage.sixteenBit(); + + m_destImage = Digikam::DImg(new_width, new_height, sixteenBit, m_orgImage.hasAlpha()); + m_destImage.fill( Digikam::DColor(m_backgroundColor.rgb(), sixteenBit) ); + + uchar *pResBits = m_destImage.bits(); + unsigned short *pResBits16 = (unsigned short *)m_destImage.bits(); + + Digikam::DImgImageFilters filters; + + for( y = 0; y < new_height; y++) + { + for( x = 0; x < new_width; x++, p += 4 ) + { + // get new positions + nx = x + dx + y * horz_factor; + ny = y + dy + x * vert_factor; + + // if is inside the source image + if (isInside (nWidth, nHeight, ROUND( nx ), ROUND( ny ))) + { + if( m_antiAlias ) + { + if (!sixteenBit) + filters.pixelAntiAliasing(pBits, nWidth, nHeight, nx, ny, + &pResBits[p+3], &pResBits[p+2], + &pResBits[p+1], &pResBits[p]); + else + filters.pixelAntiAliasing16(pBits16, nWidth, nHeight, nx, ny, + &pResBits16[p+3], &pResBits16[p+2], + &pResBits16[p+1], &pResBits16[p]); + } + else + { + pt = setPosition (nWidth, ROUND( nx ), ROUND( ny )); + + for (int z = 0 ; z < 4 ; z++) + { + if (!sixteenBit) + pResBits[p+z] = pBits[pt+z]; + else + pResBits16[p+z] = pBits16[pt+z]; + } + } + } + } + + // Update the progress bar in dialog. + progress = (int)(((double)y * 100.0) / new_height); + if (progress%5 == 0) + postProgress( progress ); + } + + // To compute the rotated destination image size using original image dimensions. + int W = (int)(fabs(m_orgH * ( ( m_hAngle < 0.0 ) ? sin( horz_beta_angle ) : cos( horz_beta_angle ))))+ + m_orgW; + int H = (int)(fabs(m_orgW * ( ( m_vAngle < 0.0 ) ? sin( vert_beta_angle ) : cos( vert_beta_angle ))))+ + m_orgH; + + m_newSize.setWidth(W); + m_newSize.setHeight(H); +} + +} // NameSpace DigikamShearToolImagesPlugin diff --git a/src/imageplugins/sheartool/shear.h b/src/imageplugins/sheartool/shear.h new file mode 100644 index 00000000..480d1084 --- /dev/null +++ b/src/imageplugins/sheartool/shear.h @@ -0,0 +1,84 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2005-07-18 + * Description : Shear threaded image filter. + * + * 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 SHEAR_H +#define SHEAR_H + +// TQt includes. + +#include <tqsize.h> +#include <tqcolor.h> + +// Digikam includes. + +#include "dimgthreadedfilter.h" + +namespace DigikamShearToolImagesPlugin +{ + +class Shear : public Digikam::DImgThreadedFilter +{ + +public: + + Shear(Digikam::DImg *orgImage, TQObject *parent=0, float hAngle=0.0, float vAngle=0.0, + bool antialiasing=true, TQColor backgroundColor=TQt::black, int orgW=0, int orgH=0); + + ~Shear(){}; + + TQSize getNewSize(void){ return m_newSize; }; + +private: + + virtual void filterImage(void); + + inline int setPosition (int Width, int X, int Y) + { + return (Y *Width*4 + 4*X); + }; + + inline bool isInside (int Width, int Height, int X, int Y) + { + bool bIsWOk = ((X < 0) ? false : (X >= Width ) ? false : true); + bool bIsHOk = ((Y < 0) ? false : (Y >= Height) ? false : true); + return (bIsWOk && bIsHOk); + }; + +private: + + bool m_antiAlias; + + int m_orgW; + int m_orgH; + + float m_hAngle; + float m_vAngle; + + TQColor m_backgroundColor; + + TQSize m_newSize; +}; + +} // NameSpace DigikamShearToolImagesPlugin + +#endif /* SHEAR_H */ diff --git a/src/imageplugins/sheartool/sheartool.cpp b/src/imageplugins/sheartool/sheartool.cpp new file mode 100644 index 00000000..9f65b6d3 --- /dev/null +++ b/src/imageplugins/sheartool/sheartool.cpp @@ -0,0 +1,331 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2004-12-23 + * Description : a plugin to shear 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. + * + * ============================================================ */ + +// TQt includes. + +#include <tqcheckbox.h> +#include <tqimage.h> +#include <tqlabel.h> +#include <tqlayout.h> +#include <tqwhatsthis.h> + +// KDE includes. + +#include <tdeaboutdata.h> +#include <tdeapplication.h> +#include <tdeconfig.h> +#include <kcursor.h> +#include <kiconloader.h> +#include <tdelocale.h> +#include <kseparator.h> +#include <kstandarddirs.h> + +// LibKDcraw includes. + +#include <libkdcraw/rnuminput.h> + +// Local includes. + +#include "daboutdata.h" +#include "ddebug.h" +#include "dimg.h" +#include "editortoolsettings.h" +#include "imageiface.h" +#include "imagewidget.h" +#include "shear.h" +#include "sheartool.h" +#include "sheartool.moc" + +using namespace KDcrawIface; +using namespace Digikam; + +namespace DigikamShearToolImagesPlugin +{ + +ShearTool::ShearTool(TQObject* parent) + : EditorToolThreaded(parent) +{ + setName("sheartool"); + setToolName(i18n("Shear Tool")); + setToolIcon(SmallIcon("sheartool")); + + m_previewWidget = new ImageWidget("sheartool Tool", 0, + i18n("<p>This is the shear operation preview. " + "If you move the mouse cursor on this preview, " + "a vertical and horizontal dashed line will be drawn " + "to guide you in adjusting the shear correction. " + "Release the left mouse button to freeze the dashed " + "line's position."), + false, ImageGuideWidget::HVGuideMode); + + setToolView(m_previewWidget); + + // ------------------------------------------------------------- + + TQString temp; + Digikam::ImageIface iface(0, 0); + + m_gboxSettings = new EditorToolSettings(EditorToolSettings::Default| + EditorToolSettings::Ok| + EditorToolSettings::Cancel, + EditorToolSettings::ColorGuide); + TQGridLayout* grid = new TQGridLayout(m_gboxSettings->plainPage(), 12, 2); + + TQLabel *label1 = new TQLabel(i18n("New width:"), m_gboxSettings->plainPage()); + m_newWidthLabel = new TQLabel(temp.setNum( iface.originalWidth()) + i18n(" px"), m_gboxSettings->plainPage()); + m_newWidthLabel->setAlignment( AlignBottom | AlignRight ); + + TQLabel *label2 = new TQLabel(i18n("New height:"), m_gboxSettings->plainPage()); + m_newHeightLabel = new TQLabel(temp.setNum( iface.originalHeight()) + i18n(" px"), m_gboxSettings->plainPage()); + m_newHeightLabel->setAlignment( AlignBottom | AlignRight ); + + KSeparator *line = new KSeparator(Horizontal, m_gboxSettings->plainPage()); + + TQLabel *label3 = new TQLabel(i18n("Main horizontal angle:"), m_gboxSettings->plainPage()); + m_mainHAngleInput = new RIntNumInput(m_gboxSettings->plainPage()); + m_mainHAngleInput->setRange(-45, 45, 1); + m_mainHAngleInput->setDefaultValue(0); + TQWhatsThis::add( m_mainHAngleInput, i18n("<p>The main horizontal shearing angle, in degrees.")); + + TQLabel *label4 = new TQLabel(i18n("Fine horizontal angle:"), m_gboxSettings->plainPage()); + m_fineHAngleInput = new RDoubleNumInput(m_gboxSettings->plainPage()); + m_fineHAngleInput->setRange(-5.0, 5.0, 0.01); + m_fineHAngleInput->setDefaultValue(0); + TQWhatsThis::add( m_fineHAngleInput, i18n("<p>This value in degrees will be added to main horizontal angle value " + "to set fine adjustments.")); + + TQLabel *label5 = new TQLabel(i18n("Main vertical angle:"), m_gboxSettings->plainPage()); + m_mainVAngleInput = new RIntNumInput(m_gboxSettings->plainPage()); + m_mainVAngleInput->setRange(-45, 45, 1); + m_mainVAngleInput->setDefaultValue(0); + TQWhatsThis::add( m_mainVAngleInput, i18n("<p>The main vertical shearing angle, in degrees.")); + + TQLabel *label6 = new TQLabel(i18n("Fine vertical angle:"), m_gboxSettings->plainPage()); + m_fineVAngleInput = new RDoubleNumInput(m_gboxSettings->plainPage()); + m_fineVAngleInput->setRange(-5.0, 5.0, 0.01); + m_fineVAngleInput->setDefaultValue(0); + TQWhatsThis::add( m_fineVAngleInput, i18n("<p>This value in degrees will be added to main vertical angle value " + "to set fine adjustments.")); + + m_antialiasInput = new TQCheckBox(i18n("Anti-Aliasing"), m_gboxSettings->plainPage()); + TQWhatsThis::add( m_antialiasInput, i18n("<p>Enable this option to apply the anti-aliasing filter " + "to the sheared image. " + "To smooth the target image, it will be blurred a little.")); + + grid->addMultiCellWidget(label1, 0, 0, 0, 0); + grid->addMultiCellWidget(m_newWidthLabel, 0, 0, 1, 2); + grid->addMultiCellWidget(label2, 1, 1, 0, 0); + grid->addMultiCellWidget(m_newHeightLabel, 1, 1, 1, 2); + grid->addMultiCellWidget(line, 2, 2, 0, 2); + grid->addMultiCellWidget(label3, 3, 3, 0, 2); + grid->addMultiCellWidget(m_mainHAngleInput, 4, 4, 0, 2); + grid->addMultiCellWidget(label4, 5, 5, 0, 2); + grid->addMultiCellWidget(m_fineHAngleInput, 6, 6, 0, 2); + grid->addMultiCellWidget(label5, 7, 7, 0, 0); + grid->addMultiCellWidget(m_mainVAngleInput, 8, 8, 0, 2); + grid->addMultiCellWidget(label6, 9, 9, 0, 2); + grid->addMultiCellWidget(m_fineVAngleInput, 10, 10, 0, 2); + grid->addMultiCellWidget(m_antialiasInput, 11, 11, 0, 2); + grid->setRowStretch(12, 10); + grid->setMargin(m_gboxSettings->spacingHint()); + grid->setSpacing(m_gboxSettings->spacingHint()); + + setToolSettings(m_gboxSettings); + init(); + + // ------------------------------------------------------------- + + connect(m_mainHAngleInput, TQ_SIGNAL(valueChanged(int)), + this, TQ_SLOT(slotTimer())); + + connect(m_fineHAngleInput, TQ_SIGNAL(valueChanged(double)), + this, TQ_SLOT(slotTimer())); + + connect(m_mainVAngleInput, TQ_SIGNAL(valueChanged(int)), + this, TQ_SLOT(slotTimer())); + + connect(m_fineVAngleInput, TQ_SIGNAL(valueChanged(double)), + this, TQ_SLOT(slotTimer())); + + connect(m_antialiasInput, TQ_SIGNAL(toggled(bool)), + this, TQ_SLOT(slotEffect())); + + connect(m_gboxSettings, TQ_SIGNAL(signalColorGuideChanged()), + this, TQ_SLOT(slotColorGuideChanged())); +} + +ShearTool::~ShearTool() +{ +} + +void ShearTool::slotColorGuideChanged() +{ + m_previewWidget->slotChangeGuideColor(m_gboxSettings->guideColor()); + m_previewWidget->slotChangeGuideSize(m_gboxSettings->guideSize()); +} + +void ShearTool::readSettings() +{ + TDEConfig *config = kapp->config(); + config->setGroup("sheartool Tool"); + m_mainHAngleInput->setValue(config->readNumEntry("Main HAngle", m_mainHAngleInput->defaultValue())); + m_mainVAngleInput->setValue(config->readNumEntry("Main VAngle", m_mainVAngleInput->defaultValue())); + m_fineHAngleInput->setValue(config->readDoubleNumEntry("Fine HAngle", m_fineHAngleInput->defaultValue())); + m_fineVAngleInput->setValue(config->readDoubleNumEntry("Fine VAngle", m_fineVAngleInput->defaultValue())); + m_antialiasInput->setChecked(config->readBoolEntry("Anti Aliasing", true)); + m_gboxSettings->setGuideColor(config->readColorEntry("Guide Color", &TQt::red)); + m_gboxSettings->setGuideSize(config->readNumEntry("Guide Width", 1)); + + slotColorGuideChanged(); + slotEffect(); +} + +void ShearTool::writeSettings() +{ + TDEConfig *config = kapp->config(); + config->setGroup("sheartool Tool"); + config->writeEntry("Main HAngle", m_mainHAngleInput->value()); + config->writeEntry("Main VAngle", m_mainVAngleInput->value()); + config->writeEntry("Fine HAngle", m_fineHAngleInput->value()); + config->writeEntry("Fine VAngle", m_fineVAngleInput->value()); + config->writeEntry("Anti Aliasing", m_antialiasInput->isChecked()); + config->writeEntry("Guide Color", m_gboxSettings->guideColor()); + config->writeEntry("Guide Width", m_gboxSettings->guideSize()); + m_previewWidget->writeSettings(); + config->sync(); +} + +void ShearTool::slotResetSettings() +{ + m_mainHAngleInput->blockSignals(true); + m_mainVAngleInput->blockSignals(true); + m_fineHAngleInput->blockSignals(true); + m_fineVAngleInput->blockSignals(true); + m_antialiasInput->blockSignals(true); + + m_mainHAngleInput->slotReset(); + m_mainVAngleInput->slotReset(); + m_fineHAngleInput->slotReset(); + m_fineVAngleInput->slotReset(); + m_antialiasInput->setChecked(true); + + m_mainHAngleInput->blockSignals(false); + m_mainVAngleInput->blockSignals(false); + m_fineHAngleInput->blockSignals(false); + m_fineVAngleInput->blockSignals(false); + m_antialiasInput->blockSignals(false); +} + +void ShearTool::prepareEffect() +{ + kapp->setOverrideCursor( KCursor::waitCursor() ); + m_mainHAngleInput->setEnabled(false); + m_mainVAngleInput->setEnabled(false); + m_fineHAngleInput->setEnabled(false); + m_fineVAngleInput->setEnabled(false); + m_antialiasInput->setEnabled(false); + + float hAngle = m_mainHAngleInput->value() + m_fineHAngleInput->value(); + float vAngle = m_mainVAngleInput->value() + m_fineVAngleInput->value(); + bool antialiasing = m_antialiasInput->isChecked(); + TQColor background = m_previewWidget->paletteBackgroundColor().rgb(); + ImageIface* iface = m_previewWidget->imageIface(); + int orgW = iface->originalWidth(); + int orgH = iface->originalHeight(); + uchar *data = iface->getPreviewImage(); + DImg image(iface->previewWidth(), iface->previewHeight(), iface->previewSixteenBit(), + iface->previewHasAlpha(), data); + delete [] data; + + setFilter(dynamic_cast<DImgThreadedFilter*>(new Shear(&image, this, hAngle, vAngle, antialiasing, + background, orgW, orgH))); +} + +void ShearTool::prepareFinal() +{ + m_mainHAngleInput->setEnabled(false); + m_mainVAngleInput->setEnabled(false); + m_fineHAngleInput->setEnabled(false); + m_fineVAngleInput->setEnabled(false); + m_antialiasInput->setEnabled(false); + + float hAngle = m_mainHAngleInput->value() + m_fineHAngleInput->value(); + float vAngle = m_mainVAngleInput->value() + m_fineVAngleInput->value(); + bool antialiasing = m_antialiasInput->isChecked(); + TQColor background = TQt::black; + + ImageIface iface(0, 0); + int orgW = iface.originalWidth(); + int orgH = iface.originalHeight(); + + uchar *data = iface.getOriginalImage(); + DImg orgImage(orgW, orgH, iface.originalSixteenBit(), iface.originalHasAlpha(), data); + delete [] data; + + setFilter(dynamic_cast<DImgThreadedFilter*>(new Shear(&orgImage, this, hAngle, vAngle, antialiasing, + background, orgW, orgH))); +} + +void ShearTool::putPreviewData() +{ + ImageIface* iface = m_previewWidget->imageIface(); + int w = iface->previewWidth(); + int h = iface->previewHeight(); + DImg imTemp = filter()->getTargetImage().smoothScale(w, h, TQSize::ScaleMin); + DImg imDest( w, h, filter()->getTargetImage().sixteenBit(), + filter()->getTargetImage().hasAlpha() ); + + imDest.fill(DColor(m_previewWidget->paletteBackgroundColor().rgb(), + filter()->getTargetImage().sixteenBit()) ); + imDest.bitBltImage(&imTemp, (w-imTemp.width())/2, (h-imTemp.height())/2); + + iface->putPreviewImage((imDest.smoothScale(iface->previewWidth(), + iface->previewHeight())).bits()); + + m_previewWidget->updatePreview(); + TQSize newSize = dynamic_cast<Shear*>(filter())->getNewSize(); + TQString temp; + m_newWidthLabel->setText(temp.setNum( newSize.width()) + i18n(" px") ); + m_newHeightLabel->setText(temp.setNum( newSize.height()) + i18n(" px") ); +} + +void ShearTool::putFinalData() +{ + ImageIface iface(0, 0); + DImg targetImage = filter()->getTargetImage(); + iface.putOriginalImage(i18n("Shear Tool"), + targetImage.bits(), + targetImage.width(), targetImage.height()); +} + +void ShearTool::renderingFinished() +{ + m_mainHAngleInput->setEnabled(true); + m_mainVAngleInput->setEnabled(true); + m_fineHAngleInput->setEnabled(true); + m_fineVAngleInput->setEnabled(true); + m_antialiasInput->setEnabled(true); + kapp->restoreOverrideCursor(); +} + +} // NameSpace DigikamShearToolImagesPlugin diff --git a/src/imageplugins/sheartool/sheartool.h b/src/imageplugins/sheartool/sheartool.h new file mode 100644 index 00000000..1c8161b4 --- /dev/null +++ b/src/imageplugins/sheartool/sheartool.h @@ -0,0 +1,96 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2004-12-23 + * Description : a plugin to shear 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 SHEARTOOL_H +#define SHEARTOOL_H + +// Local includes. + +#include "editortool.h" + +class TQFrame; +class TQPushButton; +class TQCheckBox; +class TQLabel; + +namespace KDcrawIface +{ +class RIntNumInput; +class RDoubleNumInput; +} + +namespace Digikam +{ +class EditorToolSettings; +class ImageWidget; +} + +namespace DigikamShearToolImagesPlugin +{ + +class ShearTool : public Digikam::EditorToolThreaded +{ + TQ_OBJECT + + +public: + + ShearTool(TQObject* parent); + ~ShearTool(); + +private slots: + + void slotResetSettings(); + void slotColorGuideChanged(); + +private: + + void readSettings(); + void writeSettings(); + void prepareEffect(); + void prepareFinal(); + void putPreviewData(); + void putFinalData(); + void renderingFinished(); + +private: + + TQLabel *m_newWidthLabel; + TQLabel *m_newHeightLabel; + + TQCheckBox *m_antialiasInput; + + KDcrawIface::RIntNumInput *m_mainHAngleInput; + KDcrawIface::RIntNumInput *m_mainVAngleInput; + + KDcrawIface::RDoubleNumInput *m_fineHAngleInput; + KDcrawIface::RDoubleNumInput *m_fineVAngleInput; + + Digikam::ImageWidget *m_previewWidget; + + Digikam::EditorToolSettings *m_gboxSettings; +}; + +} // NameSpace DigikamShearToolImagesPlugin + +#endif /* SHEARTOOL_H */ |