Krita Source Code Documentation
Loading...
Searching...
No Matches
GridIterationTools::PaintDevicePolygonOp Struct Reference

#include <kis_grid_interpolation_tools.h>

Public Member Functions

void copyPreviousRects ()
 
void fastCopyArea (QRect areaToCopy)
 
void fastCopyArea (QRect areaToCopy, bool lazy)
 
void finalize ()
 
void operator() (const QPolygonF &srcPolygon, const QPolygonF &dstPolygon)
 
void operator() (const QPolygonF &srcPolygon, const QPolygonF &dstPolygon, const QPolygonF &clipDstPolygon)
 
 PaintDevicePolygonOp (KisPaintDeviceSP srcDev, KisPaintDeviceSP dstDev)
 
void setCanMergeRects (bool newCanMergeRects)
 

Public Attributes

KisPaintDeviceSP m_dstDev
 
const qreal m_epsilon {0.001}
 
KisPaintDeviceSP m_srcDev
 

Private Attributes

bool m_canMergeRects {true}
 
QVector< QRect > m_rectsToCopy
 

Detailed Description

Definition at line 169 of file kis_grid_interpolation_tools.h.

Constructor & Destructor Documentation

◆ PaintDevicePolygonOp()

GridIterationTools::PaintDevicePolygonOp::PaintDevicePolygonOp ( KisPaintDeviceSP srcDev,
KisPaintDeviceSP dstDev )
inline

Member Function Documentation

◆ copyPreviousRects()

void GridIterationTools::PaintDevicePolygonOp::copyPreviousRects ( )
inline

Definition at line 303 of file kis_grid_interpolation_tools.h.

303 {
305
306 for (QVector<QRect>::iterator it = m_rectsToCopy.begin(); it < end; it++) {
307 QRect areaToCopy = *it;
308 fastCopyArea(areaToCopy.adjusted(0, 0, 1, 1), false);
309 }
311 }
static QVector< QRect >::iterator mergeSparseRects(QVector< QRect >::iterator beginIt, QVector< QRect >::iterator endIt)
merge a set of rectangles into a smaller set of bigger rectangles

References fastCopyArea(), m_rectsToCopy, and KisRegion::mergeSparseRects().

◆ fastCopyArea() [1/2]

void GridIterationTools::PaintDevicePolygonOp::fastCopyArea ( QRect areaToCopy)
inline

◆ fastCopyArea() [2/2]

void GridIterationTools::PaintDevicePolygonOp::fastCopyArea ( QRect areaToCopy,
bool lazy )
inline

Definition at line 178 of file kis_grid_interpolation_tools.h.

178 {
179#ifdef DEBUG_PAINTING_POLYGONS
180
181 QRect boundRect = areaToCopy;
182 KisSequentialIterator dstIt(m_dstDev, boundRect);
183 KisSequentialIterator srcIt(m_srcDev, boundRect);
184
185 // this can possibly be optimized with scanlining the polygon
186 // (use intersectLineConvexPolygon to get a line at every height)
187 // but it doesn't matter much because in the vast majority of cases
188 // it should go straight to the rect area copying
189
190 while (dstIt.nextPixel() && srcIt.nextPixel()) {
191 memcpy(dstIt.rawData(), srcIt.oldRawData(), m_dstDev->pixelSize());
192 QColor color = m_debugColor;
193 color.setHsl(KisAlgebra2D::wrapValue(m_debugColor.hslHue() + 20, 0, 360), m_debugColor.hslSaturation(), m_debugColor.lightness());
194 m_dstDev->colorSpace()->fromQColor(color, dstIt.rawData());
195 }
196 return;
197#endif
198 if (lazy) {
199 m_rectsToCopy.append(areaToCopy.adjusted(0, 0, -1, -1));
200 } else {
201 KisPainter::copyAreaOptimized(areaToCopy.topLeft(), m_srcDev, m_dstDev, areaToCopy);
202 }
203 }
quint32 pixelSize() const
const KoColorSpace * colorSpace() const
static void copyAreaOptimized(const QPoint &dstPt, KisPaintDeviceSP src, KisPaintDeviceSP dst, const QRect &originalSrcRect)
virtual void fromQColor(const QColor &color, quint8 *dst) const =0
T wrapValue(T value, T wrapBounds)

References KisPaintDevice::colorSpace(), KisPainter::copyAreaOptimized(), KoColorSpace::fromQColor(), m_dstDev, m_rectsToCopy, m_srcDev, KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::nextPixel(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::oldRawData(), KisPaintDevice::pixelSize(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::rawData(), and KisAlgebra2D::wrapValue().

◆ finalize()

void GridIterationTools::PaintDevicePolygonOp::finalize ( )
inline

◆ operator()() [1/2]

void GridIterationTools::PaintDevicePolygonOp::operator() ( const QPolygonF & srcPolygon,
const QPolygonF & dstPolygon )
inline

Definition at line 205 of file kis_grid_interpolation_tools.h.

205 {
206 operator() (srcPolygon, dstPolygon, dstPolygon);
207 }
void operator()(const QPolygonF &srcPolygon, const QPolygonF &dstPolygon)

References operator()().

◆ operator()() [2/2]

void GridIterationTools::PaintDevicePolygonOp::operator() ( const QPolygonF & srcPolygon,
const QPolygonF & dstPolygon,
const QPolygonF & clipDstPolygon )
inline

We need to make sure that the destination polygon is not too small, otherwise even small rounding will send the src-accessor into infinity

Definition at line 209 of file kis_grid_interpolation_tools.h.

209 {
210#ifdef DEBUG_PAINTING_POLYGONS
211 //m_rectId++;
212#endif
213 QRect boundRect = clipDstPolygon.boundingRect().toAlignedRect();
214 if (boundRect.isEmpty()) return;
215
216 bool samePolygon = (m_dstDev->colorSpace() == m_srcDev->colorSpace())
217 && KisAlgebra2D::fuzzyPointCompare(srcPolygon, dstPolygon, m_epsilon)
218 && KisAlgebra2D::fuzzyPointCompare(srcPolygon, clipDstPolygon, m_epsilon);
219
220 if (samePolygon && KisAlgebra2D::isPolygonPixelAlignedRect(dstPolygon, m_epsilon)) {
221 QRect boundRect = dstPolygon.boundingRect().toAlignedRect();
222 fastCopyArea(boundRect);
223 return;
224 }
225
226
227 // provess previous rects so they are all processed
228 // in the same order as without any performance improvements
229 // (according to the grid processing order)
231
232
233 KisSequentialIterator dstIt(m_dstDev, boundRect);
235
236 KisFourPointInterpolatorBackward interp(srcPolygon, dstPolygon);
237#ifdef DEBUG_PAINTING_POLYGONS
238 int pixelId = 0;
239#endif
240
246 if (interp.isValid(0.1)) {
247 int y = boundRect.top();
248 interp.setY(y);
249
250 while (dstIt.nextPixel()) {
251 int newY = dstIt.y();
252
253 if (y != newY) {
254 y = newY;
255 interp.setY(y);
256 }
257
258 QPointF srcPoint(dstIt.x(), y);
259
260 if (clipDstPolygon.containsPoint(srcPoint, Qt::OddEvenFill)) {
261
262 interp.setX(srcPoint.x());
263 QPointF dstPoint = interp.getValue();
264
265 // brain-blowing part:
266 //
267 // since the interpolator does the inverted
268 // transformation we read data from "dstPoint"
269 // (which is non-transformed) and write it into
270 // "srcPoint" (which is transformed position)
271
272 srcAcc->moveTo(dstPoint);
273 quint8* rawData = dstIt.rawData();
274 srcAcc->sampledOldRawData(rawData);
275#ifdef DEBUG_PAINTING_POLYGONS
276 QColor color = m_debugColor;
277 color.setHsl(KisAlgebra2D::wrapValue(m_debugColor.hslHue() + m_rectId, 0, 360), m_debugColor.hslSaturation(), qBound(0, m_debugColor.lightness() - 50 - pixelId, 100));
278 pixelId++;
279 m_dstDev->colorSpace()->fromQColor(color, rawData);
280#endif
281 }
282 }
283
284 } else {
285 srcAcc->moveTo(interp.fallbackSourcePoint());
286
287 while (dstIt.nextPixel()) {
288 QPointF srcPoint(dstIt.x(), dstIt.y());
289
290 if (clipDstPolygon.containsPoint(srcPoint, Qt::OddEvenFill)) {
291 srcAcc->sampledOldRawData(dstIt.rawData());
292#ifdef DEBUG_PAINTING_POLYGONS
293 QColor color = m_debugColor;
294 color.setHsl(KisAlgebra2D::wrapValue(m_debugColor.hslHue() + m_rectId, 0, 360), m_debugColor.hslSaturation(), qBound(0, m_debugColor.lightness() + 50, 100));
295 m_dstDev->colorSpace()->fromQColor(color, dstIt.rawData());
296#endif
297 }
298 }
299 }
300
301 }
QPointF dstPoint
KisRandomSubAccessorSP createRandomSubAccessor() const
void sampledOldRawData(quint8 *dst)
void moveTo(qreal x, qreal y)
qreal interp(qreal r, qreal a, qreal b)
private functions
bool isPolygonPixelAlignedRect(const Polygon &poly, Difference tolerance)
bool fuzzyPointCompare(const QPointF &p1, const QPointF &p2)

References KisPaintDevice::colorSpace(), copyPreviousRects(), KisPaintDevice::createRandomSubAccessor(), dstPoint, fastCopyArea(), KoColorSpace::fromQColor(), KisAlgebra2D::fuzzyPointCompare(), interp(), KisAlgebra2D::isPolygonPixelAlignedRect(), m_dstDev, m_epsilon, m_srcDev, KisRandomSubAccessor::moveTo(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::nextPixel(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::rawData(), KisRandomSubAccessor::sampledOldRawData(), KisAlgebra2D::wrapValue(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::x(), and KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::y().

◆ setCanMergeRects()

void GridIterationTools::PaintDevicePolygonOp::setCanMergeRects ( bool newCanMergeRects)
inline

Definition at line 317 of file kis_grid_interpolation_tools.h.

317 {
318 m_canMergeRects = newCanMergeRects;
319 }

References m_canMergeRects.

Member Data Documentation

◆ m_canMergeRects

bool GridIterationTools::PaintDevicePolygonOp::m_canMergeRects {true}
private

Definition at line 334 of file kis_grid_interpolation_tools.h.

334{true};

◆ m_dstDev

KisPaintDeviceSP GridIterationTools::PaintDevicePolygonOp::m_dstDev

Definition at line 322 of file kis_grid_interpolation_tools.h.

◆ m_epsilon

const qreal GridIterationTools::PaintDevicePolygonOp::m_epsilon {0.001}

Definition at line 323 of file kis_grid_interpolation_tools.h.

323{0.001};

◆ m_rectsToCopy

QVector<QRect> GridIterationTools::PaintDevicePolygonOp::m_rectsToCopy
private

Definition at line 335 of file kis_grid_interpolation_tools.h.

◆ m_srcDev

KisPaintDeviceSP GridIterationTools::PaintDevicePolygonOp::m_srcDev

Definition at line 321 of file kis_grid_interpolation_tools.h.


The documentation for this struct was generated from the following file: