File indexing completed on 2024-05-12 15:58:48
0001 /* 0002 * kis_warptransform_worker.h - part of Krita 0003 * 0004 * SPDX-FileCopyrightText: 2010 Marc Pegon <pe.marc@free.fr> 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef KIS_WARPTRANSFORM_WORKER_H 0010 #define KIS_WARPTRANSFORM_WORKER_H 0011 0012 #include "kis_types.h" 0013 #include "kritaimage_export.h" 0014 0015 #include <QImage> 0016 #include <QPolygon> 0017 #include <QPoint> 0018 #include <QPointF> 0019 #include <QRect> 0020 0021 #include <KoUpdater.h> 0022 0023 /** 0024 * Class to apply a transformation (affine, similitude, MLS) to a paintDevice 0025 * or a QImage according an original set of points p, a new set of points q, 0026 * and the constant alpha. 0027 * The algorithms are based a paper entitled "Image Deformation Using 0028 * Moving Least Squares", by Scott Schaefer (Texas A&M University), Travis 0029 * McPhail (Rice University) and Joe Warren (Rice University) 0030 */ 0031 0032 class KRITAIMAGE_EXPORT KisWarpTransformWorker : public QObject 0033 { 0034 Q_OBJECT 0035 0036 public: 0037 typedef enum WarpType_ {AFFINE_TRANSFORM = 0, SIMILITUDE_TRANSFORM, RIGID_TRANSFORM, N_MODES} WarpType; 0038 typedef enum WarpCalculation_ {GRID = 0, DRAW} WarpCalculation; 0039 0040 static QPointF affineTransformMath(QPointF v, QVector<QPointF> p, QVector<QPointF> q, qreal alpha); 0041 static QPointF similitudeTransformMath(QPointF v, QVector<QPointF> p, QVector<QPointF> q, qreal alpha); 0042 static QPointF rigidTransformMath(QPointF v, QVector<QPointF> p, QVector<QPointF> q, qreal alpha); 0043 0044 static QImage transformQImage(WarpType warpType, 0045 const QVector<QPointF> &origPoint, 0046 const QVector<QPointF> &transfPoint, 0047 qreal alpha, 0048 const QImage& srcImage, 0049 const QPointF &srcQImageOffset, 0050 QPointF *newOffset); 0051 0052 // Prepare the transformation on dev 0053 KisWarpTransformWorker(WarpType warpType, QVector<QPointF> origPoint, QVector<QPointF> transfPoint, qreal alpha, KoUpdater *progress); 0054 ~KisWarpTransformWorker() override; 0055 // Perform the prepared transformation 0056 void run(KisPaintDeviceSP srcDev, KisPaintDeviceSP dstDev); 0057 0058 QRect approxChangeRect(const QRect &rc); 0059 QRect approxNeedRect(const QRect &rc, const QRect &fullBounds); 0060 0061 private: 0062 struct FunctionTransformOp; 0063 typedef QPointF (*WarpMathFunction)(QPointF, QVector<QPointF>, QVector<QPointF>, qreal); 0064 0065 private: 0066 WarpMathFunction m_warpMathFunction; 0067 WarpCalculation m_warpCalc {GRID}; 0068 QVector<QPointF> m_origPoint; 0069 QVector<QPointF> m_transfPoint; 0070 qreal m_alpha {1.0}; 0071 KoUpdater *m_progress {0}; 0072 }; 0073 0074 #endif