20#include "kis_perspectivetransform_worker.h"
22#include "kis_iterators_pixel.h"
23#include "kis_paint_device.h"
24#include "kis_perspective_math.h"
25#include "kis_progress_display_interface.h"
26#include "kis_random_sub_accessor.h"
27#include "kis_selection.h"
29KisPerspectiveTransformWorker::KisPerspectiveTransformWorker(KisPaintDeviceSP dev,
const KisPoint& topLeft,
const KisPoint& topRight,
const KisPoint& bottomLeft,
const KisPoint& bottomRight, KisProgressDisplayInterface *progress)
30 : KisProgressSubject(), m_dev(dev), m_cancelRequested(false), m_progress(progress)
34 if(m_dev->hasSelection())
35 m_r = m_dev->selection()->selectedExactRect();
37 m_r = m_dev->exactBounds();
40 kdDebug() <<
"r = " << m_r << endl;
42 double* b = KisPerspectiveMath::computeMatrixTransfoToPerspective(topLeft, topRight, bottomLeft, bottomRight, m_r);
43 for(
int i = 0; i < 3; i++)
45 for(
int j = 0; j < 3; j++)
47 kdDebug() <<
"sol[" << 3*i+j <<
"]=" << b[3*i+j] << endl;
48 m_matrix[i][j] = b[3*i+j];
55KisPerspectiveTransformWorker::~KisPerspectiveTransformWorker()
61 return sqrt(p.x() * p.x() + p.y() * p.y() );
64void KisPerspectiveTransformWorker::run()
66 kdDebug() <<
"r = " << m_r << endl;
69 if(m_dev->hasSelection())
71 m_r = m_dev->selection()->selectedExactRect();
75 m_r = m_dev->exactBounds();
79 kdDebug() <<
"r = " << m_r << endl;
80 KisRectIteratorPixel dstIt = m_dev->createRectIterator(m_r.x(), m_r.y(), m_r.width(), m_r.height(),
true);
81 KisPaintDeviceSP srcdev =
new KisPaintDevice(*m_dev.data());
83 KisRandomSubAccessorPixel srcAcc = srcdev->createRandomSubAccessor();
86 m_progress->setSubject(
this,
true,
true);
87 m_lastProgressReport = 0;
89 m_progressTotalSteps = m_r.width() * m_r.height();
93 if(dstIt.isSelected())
96 double sf = ( dstIt.x() * m_matrix[2][0] + dstIt.y() * m_matrix[2][1] + 1.0);
97 sf = (sf == 0.) ? 1. : 1./sf;
98 p.setX( ( dstIt.x() * m_matrix[0][0] + dstIt.y() * m_matrix[0][1] + m_matrix[0][2] ) * sf );
99 p.setY( ( dstIt.x() * m_matrix[1][0] + dstIt.y() * m_matrix[1][1] + m_matrix[1][2] ) * sf );
102 srcAcc.sampledOldRawData( dstIt.
rawData() );
110 if(m_lastProgressReport != (m_progressStep * 100) / m_progressTotalSteps)
112 m_lastProgressReport = (m_progressStep * 100) / m_progressTotalSteps;
113 emit notifyProgress(m_lastProgressReport);
115 if (m_cancelRequested) {
A double-based point class that can return it's coordinates approximated to integers.
TQ_UINT8 * rawData() const
returns a pointer to the pixel data. Do NOT interpret the data - leave that to a colorstrategy
bool isDone() const
returns true when iterators has reached the end