Krita Source Code Documentation
Loading...
Searching...
No Matches
KisImagePatch Class Reference

#include <kis_image_patch.h>

Public Member Functions

void drawMe (QPainter &gc, const QRectF &dstRect, QPainter::RenderHints renderHints)
 
bool isValid ()
 
 KisImagePatch ()
 
 KisImagePatch (QRect imageRect, qint32 borderWidth, qreal scaleX, qreal scaleY)
 
QRect patchRect ()
 
void preScale (const QRectF &dstRect)
 
void setImage (QImage image)
 

Private Attributes

QImage m_image
 
QRectF m_interestRect
 
bool m_isScaled {false}
 
QRect m_patchRect
 
qreal m_scaleX {0.0}
 
qreal m_scaleY {0.0}
 

Detailed Description

Definition at line 17 of file kis_image_patch.h.

Constructor & Destructor Documentation

◆ KisImagePatch() [1/2]

KisImagePatch::KisImagePatch ( )

A default constructor initializing invalid patch

Definition at line 44 of file kis_image_patch.cpp.

45{
46}

◆ KisImagePatch() [2/2]

KisImagePatch::KisImagePatch ( QRect imageRect,
qint32 borderWidth,
qreal scaleX,
qreal scaleY )

Initializes a new patch with given values. Be careful, because the constructor does not fill QImage of the patch, as the patch rect is not known yet

See also
setImage

Definition at line 48 of file kis_image_patch.cpp.

50 : m_scaleX(scaleX)
51 , m_scaleY(scaleY)
52 , m_isScaled(false)
53{
54 // First we get unscaled rects
55 m_interestRect = QRectF(borderWidth, borderWidth,
56 imageRect.width(), imageRect.height());
57 m_patchRect = imageRect.adjusted(-borderWidth, -borderWidth,
58 borderWidth, borderWidth);
59 // And then we scale them
60 scaleRect(m_interestRect, scaleX, scaleY);
61 scaleRect(m_patchRect, scaleX, scaleY);
62
63 dbgRender << "A new patch has been created:";
64 dbgRender << ppVar(scaleX) << ppVar(scaleY);
67}
#define ppVar(var)
Definition kis_debug.h:155
#define dbgRender
Definition kis_debug.h:55
void scaleRect(QRectF &rc, qreal scaleX, qreal scaleY)

References dbgRender, m_interestRect, m_patchRect, ppVar, and scaleRect().

Member Function Documentation

◆ drawMe()

void KisImagePatch::drawMe ( QPainter & gc,
const QRectF & dstRect,
QPainter::RenderHints renderHints )

Draws an m_interestRect of the patch onto gc By the way it fits this rect into dstRect renderHints are directly transmitted to QPainter

Definition at line 109 of file kis_image_patch.cpp.

112{
113 gc.save();
114 gc.setCompositionMode(QPainter::CompositionMode_Source);
115 gc.setRenderHints(renderHints, true);
116 gc.drawImage(dstRect, m_image, m_interestRect);
117 gc.restore();
118
119#if 0
123 qreal scaleX = dstRect.width() / m_interestRect.width();
124 qreal scaleY = dstRect.height() / m_interestRect.height();
125 dbgRender << "## PATCH.DRAWME #####################";
126 dbgRender << ppVar(scaleX) << ppVar(scaleY);
129 dbgRender << ppVar(dstRect);
130 dbgRender << "## EODM #############################";
131#endif
132}

References dbgRender, m_image, m_interestRect, m_patchRect, and ppVar.

◆ isValid()

bool KisImagePatch::isValid ( )

Checks whether the patch can be used for drawing the image

Definition at line 104 of file kis_image_patch.cpp.

105{
106 return !m_image.isNull();
107}

References m_image.

◆ patchRect()

QRect KisImagePatch::patchRect ( )

Returns the rect of KisImage covered by the image of the patch (in KisImage pixels)

See also
m_patchRect

Definition at line 99 of file kis_image_patch.cpp.

100{
101 return m_patchRect;
102}

References m_patchRect.

◆ preScale()

void KisImagePatch::preScale ( const QRectF & dstRect)

prescale the patch image. Call after setImage(). This ensures that we use the QImage smoothscale method, not the QPainter scaling, which is far inferior.

Definition at line 75 of file kis_image_patch.cpp.

76{
77 if (m_isScaled) return;
78
79 qreal scaleX = dstRect.width() / m_interestRect.width();
80 qreal scaleY = dstRect.height() / m_interestRect.height();
81
82 QSize newImageSize = QSize(ceil(m_image.width() * scaleX),
83 ceil(m_image.height() * scaleY));
84 // Calculating new _aligned_ scale
85 scaleX = qreal(newImageSize.width()) / m_image.width();
86 scaleY = qreal(newImageSize.height()) / m_image.height();
87
88 m_scaleX *= scaleX;
89 m_scaleY *= scaleY;
90
91 scaleRect(m_interestRect, scaleX, scaleY);
92
93 m_image = m_image.scaled(newImageSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
94
95 m_isScaled = true;
96
97}

References m_image, m_interestRect, m_isScaled, m_scaleX, m_scaleY, and scaleRect().

◆ setImage()

void KisImagePatch::setImage ( QImage image)

Sets the image of the patch Should be called right after the constructor to finish initializing the object

Definition at line 69 of file kis_image_patch.cpp.

70{
71 m_image = image;
72 m_isScaled = false;
73}

References m_image, and m_isScaled.

Member Data Documentation

◆ m_image

QImage KisImagePatch::m_image
private

Definition at line 95 of file kis_image_patch.h.

◆ m_interestRect

QRectF KisImagePatch::m_interestRect
private

The rect that was requested during creation of the patch. It equals to patchRect without borders These borders are introduced for more accurate smooth scaling to reduce border effects (IN m_image PIXELS, relative to m_image's topLeft);

Definition at line 93 of file kis_image_patch.h.

◆ m_isScaled

bool KisImagePatch::m_isScaled {false}
private

Definition at line 96 of file kis_image_patch.h.

96{false};

◆ m_patchRect

QRect KisImagePatch::m_patchRect
private

The rect of KisImage covered by the image of the patch (in KisImage pixels)

Definition at line 82 of file kis_image_patch.h.

◆ m_scaleX

qreal KisImagePatch::m_scaleX {0.0}
private

The scale of the image stored in the patch

Definition at line 75 of file kis_image_patch.h.

75{0.0};

◆ m_scaleY

qreal KisImagePatch::m_scaleY {0.0}
private

Definition at line 76 of file kis_image_patch.h.

76{0.0};

The documentation for this class was generated from the following files: