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

#include <deform_brush.h>

Public Member Functions

 DeformBrush ()
 
QPointF hotSpot (qreal scale, qreal rotation)
 
void initDeformAction ()
 
KisFixedPaintDeviceSP paintMask (KisFixedPaintDeviceSP dab, KisPaintDeviceSP layer, KisRandomSourceSP randomSource, qreal scale, qreal rotation, QPointF pos, qreal subPixelX, qreal subPixelY, int dabX, int dabY)
 
void setProperties (KisDeformOptionData *properties)
 
void setSizeProperties (KisBrushSizeOptionData *properties)
 
 ~DeformBrush ()
 

Private Member Functions

void debugColor (const quint8 *data, KoColorSpace *cs)
 
qreal maskHeight (qreal scale)
 
qreal maskWidth (qreal scale)
 
qreal norme (qreal x, qreal y)
 
bool setupAction (DeformModes mode, const QPointF &pos, QTransform const &rotation)
 

Private Attributes

int m_counter {1}
 
DeformBasem_deformAction {0}
 
bool m_firstPaint {false}
 
QRectF m_maskRect
 
qreal m_prevX {0.0}
 
qreal m_prevY {0.0}
 
KisDeformOptionDatam_properties {0}
 
KisBrushSizeOptionDatam_sizeProperties {0}
 
KisRandomSubAccessorSP m_srcAcc
 

Detailed Description

Definition at line 179 of file deform_brush.h.

Constructor & Destructor Documentation

◆ DeformBrush()

DeformBrush::DeformBrush ( )

Definition at line 28 of file deform_brush.cpp.

29{
30 m_firstPaint = false;
31 m_counter = 1;
33}
DeformBase * m_deformAction

References m_counter, m_deformAction, and m_firstPaint.

◆ ~DeformBrush()

DeformBrush::~DeformBrush ( )

Definition at line 35 of file deform_brush.cpp.

36{
37 delete m_deformAction;
38}

References m_deformAction.

Member Function Documentation

◆ debugColor()

void DeformBrush::debugColor ( const quint8 * data,
KoColorSpace * cs )
private

Definition at line 265 of file deform_brush.cpp.

266{
267 QColor rgbcolor;
268 cs->toQColor(data, &rgbcolor);
269 dbgPlugins << "RGBA: ("
270 << rgbcolor.red()
271 << ", " << rgbcolor.green()
272 << ", " << rgbcolor.blue()
273 << ", " << rgbcolor.alpha() << ")";
274}
virtual void toQColor(const quint8 *src, QColor *c) const =0
#define dbgPlugins
Definition kis_debug.h:51

References dbgPlugins, and KoColorSpace::toQColor().

◆ hotSpot()

QPointF DeformBrush::hotSpot ( qreal scale,
qreal rotation )

Definition at line 276 of file deform_brush.cpp.

277{
278 qreal fWidth = maskWidth(scale);
279 qreal fHeight = maskHeight(scale);
280
281 QTransform m;
282 m.reset();
283 m.rotate(-rotation);
284
285 m_maskRect = QRect(0, 0, fWidth, fHeight);
286 m_maskRect.translate(-m_maskRect.center());
287 m_maskRect = m.mapRect(m_maskRect);
288 m_maskRect.translate(-m_maskRect.topLeft());
289 return m_maskRect.center();
290}
QRectF m_maskRect
qreal maskHeight(qreal scale)
qreal maskWidth(qreal scale)

References m_maskRect, maskHeight(), and maskWidth().

◆ initDeformAction()

void DeformBrush::initDeformAction ( )

Definition at line 40 of file deform_brush.cpp.

41{
43
44 switch (mode) {
45 case GROW:
46 case SHRINK: {
48 break;
49 }
50 case SWIRL_CW:
51 case SWIRL_CCW: {
53 break;
54 }
55
56 case MOVE: {
58 static_cast<DeformMove*>(m_deformAction)->setFactor(m_properties->deformAmount);
59 break;
60 }
61 case LENS_IN:
62 case LENS_OUT: {
64 static_cast<DeformLens*>(m_deformAction)->setLensFactor(m_properties->deformAmount, 0.0);
65 static_cast<DeformLens*>(m_deformAction)->setMode(mode == LENS_OUT);
66 break;
67 }
68 case DEFORM_COLOR: {
70 static_cast<DeformColor*>(m_deformAction)->setFactor(m_properties->deformAmount);
71 break;
72 }
73 default: {
75 break;
76 }
77 }
78}
@ DEFORM_COLOR
@ SWIRL_CCW
KisDeformOptionData * m_properties
Randomly disturb the pixels.
Inverse lens distortion.
Inverse move.
Inverse weighted rotation - swirlCW&&swirlCWW.
Inverse weighted inverse scaling - grow&shrink.

References DEFORM_COLOR, KisDeformOptionData::deformAction, KisDeformOptionData::deformAmount, GROW, LENS_IN, LENS_OUT, m_deformAction, m_properties, MOVE, SHRINK, SWIRL_CCW, and SWIRL_CW.

◆ maskHeight()

qreal DeformBrush::maskHeight ( qreal scale)
inlineprivate

◆ maskWidth()

qreal DeformBrush::maskWidth ( qreal scale)
inlineprivate

Definition at line 205 of file deform_brush.h.

205 {
207 }

References KisBrushSizeOptionData::brushDiameter, and m_sizeProperties.

◆ norme()

qreal DeformBrush::norme ( qreal x,
qreal y )
inlineprivate

Definition at line 213 of file deform_brush.h.

◆ paintMask()

KisFixedPaintDeviceSP DeformBrush::paintMask ( KisFixedPaintDeviceSP dab,
KisPaintDeviceSP layer,
KisRandomSourceSP randomSource,
qreal scale,
qreal rotation,
QPointF pos,
qreal subPixelX,
qreal subPixelY,
int dabX,
int dabY )

Definition at line 157 of file deform_brush.cpp.

163{
165 KisCrossDeviceColorSampler colorSampler(layer, dab);
166
167 qreal fWidth = maskWidth(scale);
168 qreal fHeight = maskHeight(scale);
169
170 int dstWidth = qRound(m_maskRect.width());
171 int dstHeight = qRound(m_maskRect.height());
172
173 // clear
174 if (dab->bounds().width() != dstWidth || dab->bounds().height() != dstHeight) {
175 dab->setRect(m_maskRect.toRect());
177 }
178
179 qreal const centerX = dstWidth * 0.5 + subPixelX;
180 qreal const centerY = dstHeight * 0.5 + subPixelY;
181
182 qreal const majorAxis = 2.0 / fWidth;
183 qreal const minorAxis = 2.0 / fHeight;
184
185 qreal distance;
186
187 QTransform forwardRotationMatrix;
188 forwardRotationMatrix.rotate(rotation);
189 QTransform reverseRotationMatrix;
190 reverseRotationMatrix.rotate(-rotation);
191
192 // if can't paint, stop
194 pos, forwardRotationMatrix))
195 {
196 return 0;
197 }
198
199 mask->setRect(dab->bounds());
201 quint8* maskPointer = mask->data();
202 qint8 maskPixelSize = mask->pixelSize();
203
204 quint8* dabPointer = dab->data();
205 int dabPixelSize = dab->colorSpace()->pixelSize();
206
207 for (int y = 0; y < dstHeight; y++) {
208 for (int x = 0; x < dstWidth; x++) {
209 qreal maskX = x - centerX;
210 qreal maskY = y - centerY;
211 forwardRotationMatrix.map(maskX, maskY, &maskX, &maskY);
212 distance = norme(maskX * majorAxis, maskY * minorAxis);
213
214 if (distance > 1.0) {
215 // leave there OPACITY TRANSPARENT pixel (default pixel)
216
217 colorSampler.sampleOldColor(x + dabX, y + dabY, dabPointer);
218 dabPointer += dabPixelSize;
219
220 *maskPointer = OPACITY_TRANSPARENT_U8;
221 maskPointer += maskPixelSize;
222 continue;
223 }
224
225 if (m_sizeProperties->brushDensity != 1.0) {
226 if (m_sizeProperties->brushDensity < randomSource->generateNormalized()) {
227 dabPointer += dabPixelSize;
228 *maskPointer = OPACITY_TRANSPARENT_U8;
229 maskPointer += maskPixelSize;
230 continue;
231 }
232 }
233
234 m_deformAction->transform(&maskX, &maskY, distance, randomSource);
235 reverseRotationMatrix.map(maskX, maskY, &maskX, &maskY);
236
237 maskX += pos.x();
238 maskY += pos.y();
239
241 maskX = qRound(maskX);
242 maskY = qRound(maskY);
243 }
244
246 colorSampler.sampleOldColor(maskX, maskY, dabPointer);
247 }
248 else {
249 colorSampler.sampleColor(maskX, maskY, dabPointer);
250 }
251
252 dabPointer += dabPixelSize;
253
254 *maskPointer = OPACITY_OPAQUE_U8;
255 maskPointer += maskPixelSize;
256
257 }
258 }
259 m_counter++;
260
261 return mask;
262
263}
const quint8 OPACITY_TRANSPARENT_U8
const quint8 OPACITY_OPAQUE_U8
qreal distance(const QPointF &p1, const QPointF &p2)
virtual void transform(qreal *x, qreal *y, qreal distance, KisRandomSourceSP randomSource)
bool setupAction(DeformModes mode, const QPointF &pos, QTransform const &rotation)
qreal norme(qreal x, qreal y)
void setRect(const QRect &rc)
const KoColorSpace * colorSpace() const
qreal generateNormalized() const
virtual quint32 pixelSize() const =0
static KoColorSpaceRegistry * instance()

References KisFixedPaintDevice::bounds(), KisBrushSizeOptionData::brushDensity, KisFixedPaintDevice::colorSpace(), KisFixedPaintDevice::data(), KisDeformOptionData::deformAction, KisDeformOptionData::deformUseBilinear, KisDeformOptionData::deformUseOldData, distance(), KisRandomSource::generateNormalized(), KoColorSpaceRegistry::instance(), KisFixedPaintDevice::lazyGrowBufferWithoutInitialization(), m_counter, m_deformAction, m_maskRect, m_properties, m_sizeProperties, maskHeight(), maskWidth(), norme(), OPACITY_OPAQUE_U8, OPACITY_TRANSPARENT_U8, KisFixedPaintDevice::pixelSize(), KoColorSpace::pixelSize(), KisCrossDeviceColorSamplerImpl< Traits >::sampleColor(), KisCrossDeviceColorSamplerImpl< Traits >::sampleOldColor(), KisFixedPaintDevice::setRect(), setupAction(), and DeformBase::transform().

◆ setProperties()

void DeformBrush::setProperties ( KisDeformOptionData * properties)
inline

Definition at line 193 of file deform_brush.h.

193 {
194 m_properties = properties;
195 }

References m_properties.

◆ setSizeProperties()

void DeformBrush::setSizeProperties ( KisBrushSizeOptionData * properties)
inline

Definition at line 190 of file deform_brush.h.

190 {
191 m_sizeProperties = properties;
192 }

References m_sizeProperties.

◆ setupAction()

bool DeformBrush::setupAction ( DeformModes mode,
const QPointF & pos,
QTransform const & rotation )
private

Definition at line 80 of file deform_brush.cpp.

82{
83
84 switch (mode) {
85 case GROW:
86 case SHRINK: {
87 // grow or shrink, the sign decide
88 qreal sign = (mode == GROW) ? 1.0 : -1.0;
89 qreal factor;
91 factor = (1.0 + sign * (m_counter * m_counter / 100.0));
92 }
93 else {
94 factor = (1.0 + sign * (m_properties->deformAmount));
95 }
96 DeformScale* deformScale = dynamic_cast<DeformScale*>(m_deformAction);
97 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(deformScale, false);
98 deformScale->setFactor(factor);
99 break;
100 }
101 case SWIRL_CW:
102 case SWIRL_CCW: {
103 // CW or CCW, the sign decide
104 qreal sign = (mode == SWIRL_CW) ? 1.0 : -1.0;
105 qreal factor;
107 factor = m_counter * sign * degToRad;
108 }
109 else {
110 factor = (360 * m_properties->deformAmount * 0.5) * sign * degToRad;
111 }
112 DeformRotation* deformRotation = dynamic_cast<DeformRotation*>(m_deformAction);
113 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(deformRotation, false);
114 deformRotation->setAlpha(factor);
115 break;
116 }
117 case MOVE: {
118 if (m_firstPaint == false) {
119 m_prevX = pos.x();
120 m_prevY = pos.y();
121 DeformMove* deformMove = static_cast<DeformMove*>(m_deformAction);
122 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(deformMove, false);
123 deformMove->setDistance(0.0, 0.0);
124 m_firstPaint = true;
125 return false;
126 }
127 else {
128 qreal xDistance = pos.x() - m_prevX;
129 qreal yDistance = pos.y() - m_prevY;
130 rotation.map(xDistance, yDistance, &xDistance, &yDistance);
131 DeformMove* deformMove = static_cast<DeformMove*>(m_deformAction);
132 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(deformMove, false);
133 deformMove->setDistance(xDistance, yDistance);
134 m_prevX = pos.x();
135 m_prevY = pos.y();
136 }
137 break;
138 }
139 case LENS_IN:
140 case LENS_OUT: {
141 DeformLens* deformLens = static_cast<DeformLens*>(m_deformAction);
142 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(deformLens, false);
144 break;
145 }
146 case DEFORM_COLOR: {
147 // no run-time setup
148 break;
149 }
150 default: {
151 break;
152 }
153 }
154 return true;
155}
void setMaxDistance(qreal maxX, qreal maxY)
void setDistance(qreal dx, qreal dy)
void setAlpha(qreal alpha)
void setFactor(qreal factor)
const qreal degToRad
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129

References KisBrushSizeOptionData::brushDiameter, DEFORM_COLOR, KisDeformOptionData::deformAmount, KisDeformOptionData::deformUseCounter, degToRad, GROW, KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, LENS_IN, LENS_OUT, m_counter, m_deformAction, m_firstPaint, m_prevX, m_prevY, m_properties, m_sizeProperties, MOVE, DeformRotation::setAlpha(), DeformMove::setDistance(), DeformScale::setFactor(), DeformLens::setMaxDistance(), SHRINK, sign(), SWIRL_CCW, and SWIRL_CW.

Member Data Documentation

◆ m_counter

int DeformBrush::m_counter {1}
private

Definition at line 222 of file deform_brush.h.

222{1}; // taken from the constructor

◆ m_deformAction

DeformBase* DeformBrush::m_deformAction {0}
private

Definition at line 226 of file deform_brush.h.

226{0};

◆ m_firstPaint

bool DeformBrush::m_firstPaint {false}
private

Definition at line 220 of file deform_brush.h.

220{false};

◆ m_maskRect

QRectF DeformBrush::m_maskRect
private

Definition at line 224 of file deform_brush.h.

◆ m_prevX

qreal DeformBrush::m_prevX {0.0}
private

Definition at line 221 of file deform_brush.h.

221{0.0}, m_prevY {0.0};

◆ m_prevY

qreal DeformBrush::m_prevY {0.0}
private

Definition at line 221 of file deform_brush.h.

221{0.0}, m_prevY {0.0};

◆ m_properties

KisDeformOptionData* DeformBrush::m_properties {0}
private

Definition at line 228 of file deform_brush.h.

228{0};

◆ m_sizeProperties

KisBrushSizeOptionData* DeformBrush::m_sizeProperties {0}
private

Definition at line 229 of file deform_brush.h.

229{0};

◆ m_srcAcc

KisRandomSubAccessorSP DeformBrush::m_srcAcc
private

Definition at line 219 of file deform_brush.h.


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