All pastes #1336463 Raw Edit

Digikam Perspective Inverse Tran

public diff v1 · immutable
#1336463 ·published 2009-02-13 21:38 UTC
rendered paste body
Index: imageplugins/perspective/perspectivewidget.h===================================================================--- imageplugins/perspective/perspectivewidget.h	(Revision 925640)+++ imageplugins/perspective/perspectivewidget.h	(Arbeitskopie)@@ -85,6 +85,7 @@      void slotChangeGuideColor(const QColor &color);     void slotChangeGuideSize(int size);+    void slotInverseTransformationChanged(bool isEnabled);  signals: @@ -126,6 +127,7 @@     bool                 m_antiAlias;     bool                 m_drawWhileMoving;     bool                 m_drawGrid;+    bool                 m_inverseTransformation;      uint                *m_data;     int                  m_w;Index: imageplugins/perspective/perspectivetool.cpp===================================================================--- imageplugins/perspective/perspectivetool.cpp	(Revision 925640)+++ imageplugins/perspective/perspectivetool.cpp	(Arbeitskopie)@@ -125,6 +125,7 @@     KSeparator *line2         = new KSeparator (Qt::Horizontal, m_gboxSettings->plainPage());     m_drawWhileMovingCheckBox = new QCheckBox(i18n("Draw preview while moving"), m_gboxSettings->plainPage());     m_drawGridCheckBox        = new QCheckBox(i18n("Draw grid"), m_gboxSettings->plainPage());+    m_inverseTransformation   = new QCheckBox(i18n("Inverse transformation"), m_gboxSettings->plainPage());      // ------------------------------------------------------------- @@ -160,13 +161,14 @@     gridLayout->addWidget(line2,                        8, 0, 1, 3);     gridLayout->addWidget(m_drawWhileMovingCheckBox,    9, 0, 1, 3);     gridLayout->addWidget(m_drawGridCheckBox,          10, 0, 1, 3);-    gridLayout->addWidget(label7,                      11, 0, 1, 1);-    gridLayout->addWidget(m_guideColorBt,              11, 2, 1, 1);-    gridLayout->addWidget(space,                       12, 0, 1, 3);-    gridLayout->addWidget(label8,                      13, 0, 1, 1);-    gridLayout->addWidget(m_guideSize,                 13, 2, 1, 1);+    gridLayout->addWidget(m_inverseTransformation,     11, 0, 1, 3);+    gridLayout->addWidget(label7,                      12, 0, 1, 1);+    gridLayout->addWidget(m_guideColorBt,              12, 2, 1, 1);+    gridLayout->addWidget(space,                       13, 0, 1, 3);+    gridLayout->addWidget(label8,                      14, 0, 1, 1);+    gridLayout->addWidget(m_guideSize,                 14, 2, 1, 1);     gridLayout->setColumnStretch(1, 10);-    gridLayout->setRowStretch(14, 10);+    gridLayout->setRowStretch(15, 10);      setToolSettings(m_gboxSettings);     init();@@ -187,6 +189,7 @@      connect(m_guideSize, SIGNAL(valueChanged(int)),             m_previewWidget, SLOT(slotChangeGuideSize(int)));+    connect(m_inverseTransformation, SIGNAL(toggled(bool)), m_previewWidget, SLOT(slotInverseTransformationChanged(bool))); }  PerspectiveTool::~PerspectiveTool()@@ -202,6 +205,7 @@     m_drawGridCheckBox->setChecked(group.readEntry("Draw Grid", false));     m_guideColorBt->setColor(group.readEntry("Guide Color", defaultGuideColor));     m_guideSize->setValue(group.readEntry("Guide Width", 1));+    m_inverseTransformation->setChecked(group.readEntry("Inverse Transformation", false));     m_previewWidget->slotToggleDrawWhileMoving(m_drawWhileMovingCheckBox->isChecked());     m_previewWidget->slotToggleDrawGrid(m_drawGridCheckBox->isChecked());     m_previewWidget->slotChangeGuideColor(m_guideColorBt->color());@@ -216,6 +220,7 @@     group.writeEntry("Draw Grid", m_drawGridCheckBox->isChecked());     group.writeEntry("Guide Color", m_guideColorBt->color());     group.writeEntry("Guide Width", m_guideSize->value());+    group.writeEntry("Inverse Transformation", m_inverseTransformation->isChecked());     config->sync(); } Index: imageplugins/perspective/perspectivetool.h===================================================================--- imageplugins/perspective/perspectivetool.h	(Revision 925640)+++ imageplugins/perspective/perspectivetool.h	(Arbeitskopie)@@ -80,6 +80,7 @@      QCheckBox                   *m_drawWhileMovingCheckBox;     QCheckBox                   *m_drawGridCheckBox;+    QCheckBox                   *m_inverseTransformation;      QSpinBox                    *m_guideSize; Index: imageplugins/perspective/perspectivewidget.cpp===================================================================--- imageplugins/perspective/perspectivewidget.cpp	(Revision 925640)+++ imageplugins/perspective/perspectivewidget.cpp	(Arbeitskopie)@@ -73,6 +73,7 @@      m_drawGrid        = false;     m_drawWhileMoving = true;+    m_inverseTransformation = false;     m_currentResizing = ResizingNone;     m_guideColor      = Qt::red;     m_guideSize       = 1;@@ -210,6 +211,12 @@                               targetImg.bits(), targetImg.width(), targetImg.height()); } +void PerspectiveWidget::slotInverseTransformationChanged(bool isEnabled) {+    m_inverseTransformation = isEnabled;+    updatePixmap();+    repaint();+}+ void PerspectiveWidget::slotToggleAntiAliasing(bool a) {     m_antiAlias = a;@@ -276,8 +283,17 @@      m_pixmap->fill(palette().color(QPalette::Background)); +    if(m_inverseTransformation) {+        m_transformedCenter = buildPerspective(QPoint(0, 0), QPoint(m_w, m_h),+                                               m_topLeftPoint, m_topRightPoint,+                                               m_bottomLeftPoint, m_bottomRightPoint);+      +	m_iface->putPreviewImage(m_previewImage.bits());+        m_iface->paint(m_pixmap, m_rect.x(), m_rect.y(),+                       m_rect.width(), m_rect.height());     // if we are resizing with the mouse, compute and draw only if drawWhileMoving is set-    if (m_currentResizing == ResizingNone || m_drawWhileMoving)+    }+    else if ((m_currentResizing == ResizingNone || m_drawWhileMoving))     {         // Create preview image @@ -456,9 +472,22 @@     transform.scale    (scalex, scaley);     transform.multiply (matrix); -    // Compute perspective transformation to image if image data containers exist.-    if (orgImage && destImage)+    if(orgImage && destImage) {+      if(m_inverseTransformation) {+	Matrix inverseTransform = transform;+	inverseTransform.invert();+	+	//Transform the matrix so it puts the result into the getTargetSize() rectangle+	Matrix transformIntoBounds;+	transformIntoBounds.scale(double(getTargetSize().width()) / double(orgImage->width()), double(getTargetSize().height()) / double(orgImage->height()));+	transformIntoBounds.translate(getTargetSize().left(), getTargetSize().top());+	inverseTransform.multiply(transformIntoBounds);+        transformAffine(orgImage, destImage, inverseTransform, background);+      }else{+	// Compute perspective transformation to image if image data containers exist.         transformAffine(orgImage, destImage, transform, background);+      }+    }      // Calculate the grid array points.     double newX, newY;@@ -757,7 +786,7 @@                                         m_w-1, 0 );                 QRegion unsableArea(unsablePoints); -                if ( unsableArea.contains(pm) ) return;+                if ( unsableArea.contains(pm) && !m_inverseTransformation ) return;                  m_topLeftPoint = pm - m_rect.topLeft();                 setCursor( Qt::SizeFDiagCursor );@@ -775,7 +804,7 @@                                         m_w-1, m_h-1);                 QRegion unsableArea(unsablePoints); -                if ( unsableArea.contains(pm) ) return;+                if ( unsableArea.contains(pm) && !m_inverseTransformation ) return;                  m_topRightPoint = pm - m_rect.topLeft();                 setCursor( Qt::SizeBDiagCursor );@@ -793,7 +822,7 @@                                         0, 0);                 QRegion unsableArea(unsablePoints); -                if ( unsableArea.contains(pm) ) return;+                if ( unsableArea.contains(pm) && !m_inverseTransformation ) return;                  m_bottomLeftPoint = pm - m_rect.topLeft();                 setCursor( Qt::SizeBDiagCursor );@@ -811,7 +840,7 @@                                         0, m_w-1);                 QRegion unsableArea(unsablePoints); -                if ( unsableArea.contains(pm) ) return;+                if ( unsableArea.contains(pm) && !m_inverseTransformation ) return;                  m_bottomRightPoint = pm - m_rect.topLeft();                 setCursor( Qt::SizeFDiagCursor );