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

#include <kis_sketch_paintop.h>

+ Inheritance diagram for KisSketchPaintOp:

Public Member Functions

 KisSketchPaintOp (const KisPaintOpSettingsSP settings, KisPainter *painter, KisNodeSP node, KisImageSP image)
 
void paintLine (const KisPaintInformation &pi1, const KisPaintInformation &pi2, KisDistanceInformation *currentDistance) override
 
 ~KisSketchPaintOp () override
 
- Public Member Functions inherited from KisPaintOp
virtual bool canPaint () const
 
virtual std::pair< int, bool > doAsynchronousUpdate (QVector< KisRunnableStrokeJobData * > &jobs)
 
 KisPaintOp (KisPainter *painter)
 
void paintAt (const KisPaintInformation &info, KisDistanceInformation *currentDistance)
 
virtual void paintBezierCurve (const KisPaintInformation &pi1, const QPointF &control1, const QPointF &control2, const KisPaintInformation &pi2, KisDistanceInformation *currentDistance)
 
 Private (KisPaintOp *_q)
 
void updateSpacing (const KisPaintInformation &info, KisDistanceInformation &currentDistance) const
 
void updateTiming (const KisPaintInformation &info, KisDistanceInformation &currentDistance) const
 
virtual ~KisPaintOp ()
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 
- Public Member Functions inherited from KisShared
bool deref ()
 
bool ref ()
 
int refCount ()
 
QAtomicInt * sharedWeakReference ()
 

Static Public Member Functions

static QList< KoResourceLoadResultprepareLinkedResources (const KisPaintOpSettingsSP settings, KisResourcesInterfaceSP resourcesInterface)
 
- Static Public Member Functions inherited from KisPaintOp
static void splitCoordinate (qreal coordinate, qint32 *whole, qreal *fraction)
 

Protected Member Functions

KisSpacingInformation paintAt (const KisPaintInformation &info) override
 
KisSpacingInformation updateSpacingImpl (const KisPaintInformation &info) const override
 
KisTimingInformation updateTimingImpl (const KisPaintInformation &info) const override
 
- Protected Member Functions inherited from KisPaintOp
KisFixedPaintDeviceSP cachedDab ()
 
KisFixedPaintDeviceSP cachedDab (const KoColorSpace *cs)
 
KisPainterpainter () const
 
KisPaintDeviceSP source () const
 
- Protected Member Functions inherited from KisShared
 KisShared ()
 
 ~KisShared ()
 

Private Member Functions

void doPaintLine (const KisPaintInformation &pi1, const KisPaintInformation &pi2)
 
void drawConnection (const QPointF &start, const QPointF &end, double lineWidth)
 
void updateBrushMask (const KisPaintInformation &info, qreal scale, qreal rotation)
 

Private Attributes

KisAirbrushOptionData m_airbrushOption
 
KisBrushSP m_brush
 
QRectF m_brushBoundingBox
 
KisBrushOptionProperties m_brushOption
 
int m_count {0}
 
KisPaintDeviceSP m_dab
 
KisDabCachem_dabCache {nullptr}
 
KisDensityOption m_densityOption
 
QPointF m_hotSpot
 
KisLineWidthOption m_lineWidthOption
 
KisFixedPaintDeviceSP m_maskDab
 
KisOffsetScaleOption m_offsetScaleOption
 
KisOpacityOption m_opacityOption
 
KisPainterm_painter {nullptr}
 
QVector< QPointF > m_points
 
qreal m_radius {1.0}
 
KisRateOption m_rateOption
 
KisRotationOption m_rotationOption
 
KisSizeOption m_sizeOption
 
KisSketchOpOptionData m_sketchProperties
 

Additional Inherited Members

- Public Attributes inherited from KisPaintOp
KisFixedPaintDeviceSP dab
 
bool fanCornersEnabled {false}
 
qreal fanCornersStep {1.0}
 
KisPainterpainter {nullptr}
 
KisPaintOpq {nullptr}
 
- Public Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Detailed Description

Definition at line 27 of file kis_sketch_paintop.h.

Constructor & Destructor Documentation

◆ KisSketchPaintOp()

KisSketchPaintOp::KisSketchPaintOp ( const KisPaintOpSettingsSP settings,
KisPainter * painter,
KisNodeSP node,
KisImageSP image )

Definition at line 54 of file kis_sketch_paintop.cpp.

56 , m_opacityOption(settings.data(), node)
57 , m_sizeOption(settings.data())
58 , m_rotationOption(settings.data())
59 , m_rateOption(settings.data())
60 , m_densityOption(settings.data())
61 , m_lineWidthOption(settings.data())
62 , m_offsetScaleOption(settings.data())
63{
64 Q_UNUSED(image);
65 Q_UNUSED(node);
66
67 m_airbrushOption.read(settings.data());
68 m_sketchProperties.read(settings.data());
69 m_brushOption.readOptionSetting(settings, settings->resourcesInterface(), settings->canvasResourcesInterface());
70
73
74 m_painter = 0;
75 m_count = 0;
76}
The KisDabCache class provides caching for dabs into the brush paintop.
void readOptionSetting(KisPropertiesConfigurationPointer settings, KisResourcesInterfaceSP resourcesInterface, KoCanvasResourcesInterfaceSP canvasResourcesInterface)
KisOffsetScaleOption m_offsetScaleOption
KisRotationOption m_rotationOption
KisDensityOption m_densityOption
KisDabCache * m_dabCache
KisSizeOption m_sizeOption
KisRateOption m_rateOption
KisOpacityOption m_opacityOption
KisSketchOpOptionData m_sketchProperties
KisAirbrushOptionData m_airbrushOption
KisBrushOptionProperties m_brushOption
KisLineWidthOption m_lineWidthOption
bool read(const KisPropertiesConfiguration *setting)
KisPainter * painter
KisPaintOp(KisPainter *painter)
bool read(const KisPropertiesConfiguration *setting)

References KisBrushOptionProperties::brush(), KisSharedPtr< T >::data(), m_airbrushOption, m_brush, m_brushOption, m_count, m_dabCache, m_painter, m_sketchProperties, KisAirbrushOptionData::read(), KisSketchOpOptionData::read(), and KisPaintopPropertiesCanvasResourcesBase::readOptionSetting().

◆ ~KisSketchPaintOp()

KisSketchPaintOp::~KisSketchPaintOp ( )
override

Definition at line 78 of file kis_sketch_paintop.cpp.

79{
80 delete m_painter;
81 delete m_dabCache;
82}

References m_dabCache, and m_painter.

Member Function Documentation

◆ doPaintLine()

void KisSketchPaintOp::doPaintLine ( const KisPaintInformation & pi1,
const KisPaintInformation & pi2 )
private

Since the order of calculation of function parameters is not defined by C++ standard, we should generate values in an external code snippet which has a definite order of execution.

Definition at line 138 of file kis_sketch_paintop.cpp.

139{
140 if (!m_brush || !painter()) return;
141
142 if (!m_dab) {
145 m_painter->setPaintColor(painter()->paintColor());
146 }
147 else {
148 m_dab->clear();
149 }
150
151 QPointF prevMouse = pi1.pos();
152 QPointF mousePosition = pi2.pos();
153 m_points.append(mousePosition);
154
155
156 const qreal lodAdditionalScale = KisLodTransform::lodToScale(painter()->device());
157 const qreal scale = lodAdditionalScale * m_sizeOption.apply(pi2);
158 if ((scale * m_brush->width()) <= 0.01 || (scale * m_brush->height()) <= 0.01) return;
159
160 const qreal currentLineWidth = qMax(0.9, lodAdditionalScale * m_lineWidthOption.apply(pi2) * m_sketchProperties.lineWidth);
161
162 const qreal currentOffsetScale = m_offsetScaleOption.apply(pi2) * m_sketchProperties.offset * 0.01;
163 const double rotation = m_rotationOption.apply(pi2);
164 const double currentProbability = m_densityOption.apply(pi2) * m_sketchProperties.probability;
165
166 // shaded: does not draw this line, chrome does, fur does
168 drawConnection(prevMouse, mousePosition, currentLineWidth);
169 }
170
171
172 qreal thresholdDistance = 0.0;
173
174 // update the mask for simple mode only once
175 // determine the radius
177 updateBrushMask(pi2, 1.0, 0.0);
178 //m_radius = qMax(m_maskDab->bounds().width(),m_maskDab->bounds().height()) * 0.5;
179 m_radius = 0.5 * qMax(m_brush->width(), m_brush->height());
180 }
181
183 updateBrushMask(pi2, scale, rotation);
184 m_radius = qMax(m_maskDab->bounds().width(), m_maskDab->bounds().height()) * 0.5;
185 thresholdDistance = pow(m_radius, 2);
186 }
187
189 // update the radius according scale in simple mode
190 thresholdDistance = pow(m_radius * scale, 2);
191 }
192
193 // determine density
194 const qreal density = thresholdDistance * currentProbability;
195
196 // probability behaviour
197 qreal probability = 1.0 - currentProbability;
198
199 QColor painterColor = painter()->paintColor().toQColor();
200 QColor randomColor;
201 KoColor color(m_dab->colorSpace());
202
203 int w = m_maskDab->bounds().width();
204 quint8 opacityU8 = 0;
205 quint8 * pixel;
206 qreal distance;
207 QPoint positionInMask;
208 QPointF diff;
209
210 int size = m_points.size();
211 // MAIN LOOP
212 for (int i = 0; i < size; i++) {
213 diff = m_points.at(i) - mousePosition;
214 distance = diff.x() * diff.x() + diff.y() * diff.y();
215
216 // circle test
217 bool makeConnection = false;
219 if (distance < thresholdDistance) {
220 makeConnection = true;
221 }
222 // mask test
223 }
224 else {
225 if (m_brushBoundingBox.contains(m_points.at(i))) {
226 positionInMask = (diff + m_hotSpot).toPoint();
227 uint pos = ((positionInMask.y() * w + positionInMask.x()) * m_maskDab->pixelSize());
228 if (pos < m_maskDab->allocatedPixels() * m_maskDab->pixelSize()) {
229 pixel = m_maskDab->data() + pos;
230 opacityU8 = m_maskDab->colorSpace()->opacityU8(pixel);
231 if (opacityU8 != 0) {
232 makeConnection = true;
233 }
234 }
235 }
236
237 }
238
239 if (!makeConnection) {
240 // check next point
241 continue;
242 }
243
245 probability = distance / density;
246 }
247
248 KisRandomSourceSP randomSource = pi2.randomSource();
249
250 // density check
251 if (randomSource->generateNormalized() >= probability) {
252 QPointF offsetPt = diff * currentOffsetScale;
253
261 qreal r1 = randomSource->generateNormalized();
262 qreal r2 = randomSource->generateNormalized();
263 qreal r3 = randomSource->generateNormalized();
264
265 // some color transformation per line goes here
266 randomColor.setRgbF(r1 * painterColor.redF(),
267 r2 * painterColor.greenF(),
268 r3 * painterColor.blueF());
269 color.fromQColor(randomColor);
270 m_painter->setPaintColor(color);
271 }
272
273 // distance based opacity
274 qreal opacity = OPACITY_OPAQUE_F;
276 // TODO: check if the formula is correct, do we actually
277 // need rounding here?
278 opacity *= qRound((1.0 - (distance / thresholdDistance)));
279 }
280
282 opacity *= randomSource->generateNormalized();
283 }
284
285 m_painter->setOpacityF(opacity);
286
288 drawConnection(mousePosition + offsetPt, m_points.at(i) - offsetPt, currentLineWidth);
289 }
290 else {
291 drawConnection(mousePosition + offsetPt, mousePosition - offsetPt, currentLineWidth);
292 }
293
294
295
296 }
297 }// end of MAIN LOOP
298
299 m_count++;
300
301 QRect rc = m_dab->extent();
303
304 painter()->bitBlt(rc.x(), rc.y(), m_dab, rc.x(), rc.y(), rc.width(), rc.height());
306}
QPointF r2
QPointF r1
QPointF r3
const qreal OPACITY_OPAQUE_F
qreal distance(const QPointF &p1, const QPointF &p2)
unsigned int uint
const KoColorSpace * colorSpace() const
static qreal lodToScale(int levelOfDetail)
void apply(KisPainter *painter, const KisPaintInformation &info) const
virtual void clear()
KisPaintDeviceSP createCompositionSourceDevice() const
QRect extent() const
const KoColorSpace * colorSpace() const
KisRandomSourceSP randomSource() const
const QPointF & pos() const
KoColor paintColor
void renderMirrorMask(QRect rc, KisFixedPaintDeviceSP dab)
void setOpacityF(qreal opacity)
void bitBlt(qint32 dstX, qint32 dstY, const KisPaintDeviceSP srcDev, qint32 srcX, qint32 srcY, qint32 srcWidth, qint32 srcHeight)
void setPaintColor(const KoColor &color)
qreal generateNormalized() const
qreal apply(const KisPaintInformation &info) const
void drawConnection(const QPointF &start, const QPointF &end, double lineWidth)
KisFixedPaintDeviceSP m_maskDab
void updateBrushMask(const KisPaintInformation &info, qreal scale, qreal rotation)
KisPaintDeviceSP m_dab
QVector< QPointF > m_points
qreal apply(const KisPaintInformation &info) const
virtual quint8 opacityU8(const quint8 *pixel) const =0
void toQColor(QColor *c) const
a convenience method for the above.
Definition KoColor.cpp:198
int size(const Forest< T > &forest)
Definition KisForest.h:1232
KisPaintDeviceSP source() const

References KisRotationOption::apply(), KisStandardOption< Data >::apply(), KisOpacityOption::apply(), KisPainter::bitBlt(), KisFixedPaintDevice::bounds(), KisPaintDevice::clear(), KisFixedPaintDevice::colorSpace(), KisPaintDevice::colorSpace(), KisPaintDevice::createCompositionSourceDevice(), KisFixedPaintDevice::data(), distance(), KisSketchOpOptionData::distanceDensity, KisSketchOpOptionData::distanceOpacity, drawConnection(), KisPaintDevice::extent(), KoColor::fromQColor(), KisRandomSource::generateNormalized(), KisSketchOpOptionData::lineWidth, KisLodTransformBase::lodToScale(), m_brush, m_brushBoundingBox, m_count, m_dab, m_densityOption, m_hotSpot, m_lineWidthOption, m_maskDab, m_offsetScaleOption, m_opacityOption, m_painter, m_points, m_radius, m_rotationOption, m_sizeOption, m_sketchProperties, KisSketchOpOptionData::magnetify, KisSketchOpOptionData::makeConnection, KisSketchOpOptionData::offset, OPACITY_OPAQUE_F, KoColorSpace::opacityU8(), KisPainter::paintColor, KisPaintOp::painter, KisFixedPaintDevice::pixelSize(), KisPaintInformation::pos(), KisSketchOpOptionData::probability, r1, r2, r3, KisSketchOpOptionData::randomOpacity, KisSketchOpOptionData::randomRGB, KisPaintInformation::randomSource(), KisPainter::renderMirrorMask(), KisPainter::setOpacityF(), KisPainter::setPaintColor(), KisSketchOpOptionData::simpleMode, KisPaintOp::source(), KoColor::toQColor(), and updateBrushMask().

◆ drawConnection()

void KisSketchPaintOp::drawConnection ( const QPointF & start,
const QPointF & end,
double lineWidth )
private

Definition at line 90 of file kis_sketch_paintop.cpp.

91{
92 //Both drawWuLine() and the drawDDALine produce nicer 1px lines than the drawLine()
94 if (lineWidth == 1.0) {
95 m_painter->drawWuLine(start, end);
96 }
97 else {
98 m_painter->drawLine(start, end, lineWidth, true);
99 }
100 }
101 else {
102 if (lineWidth == 1.0) {
103 m_painter->drawDDALine(start, end);
104 }
105 else {
106 m_painter->drawLine(start, end, lineWidth, false);
107 }
108 }
109}
void drawDDALine(const QPointF &start, const QPointF &end)
void drawWuLine(const QPointF &start, const QPointF &end)
void drawLine(const QPointF &start, const QPointF &end)

References KisSketchOpOptionData::antiAliasing, KisPainter::drawDDALine(), KisPainter::drawLine(), KisPainter::drawWuLine(), m_painter, and m_sketchProperties.

◆ paintAt()

KisSpacingInformation KisSketchPaintOp::paintAt ( const KisPaintInformation & info)
overrideprotectedvirtual

The implementation of painting of a dab and updating spacing. This does NOT need to update the timing information.

Implements KisPaintOp.

Definition at line 310 of file kis_sketch_paintop.cpp.

311{
312 doPaintLine(info, info);
313 return updateSpacingImpl(info);
314}
KisSpacingInformation updateSpacingImpl(const KisPaintInformation &info) const override
void doPaintLine(const KisPaintInformation &pi1, const KisPaintInformation &pi2)

References doPaintLine(), and updateSpacingImpl().

◆ paintLine()

void KisSketchPaintOp::paintLine ( const KisPaintInformation & pi1,
const KisPaintInformation & pi2,
KisDistanceInformation * currentDistance )
overridevirtual

Draw a line between pos1 and pos2 using the currently set brush and color. If savedDist is less than zero, the brush is painted at pos1 before being painted along the line using the spacing setting.

Returns
the drag distance, that is the remains of the distance between p1 and p2 not covered because the currently set brush has a spacing greater than that distance.

Reimplemented from KisPaintOp.

Definition at line 126 of file kis_sketch_paintop.cpp.

128{
129 // Use superclass behavior for lines of zero length. Otherwise, airbrushing can happen faster
130 // than it is supposed to.
131 if (pi1.pos() == pi2.pos()) {
132 KisPaintOp::paintLine(pi1, pi2, currentDistance);
133 }
134 else {
135 doPaintLine(pi1, pi2);
136 }
137}
virtual void paintLine(const KisPaintInformation &pi1, const KisPaintInformation &pi2, KisDistanceInformation *currentDistance)

References doPaintLine(), KisPaintOp::paintLine(), and KisPaintInformation::pos().

◆ prepareLinkedResources()

QList< KoResourceLoadResult > KisSketchPaintOp::prepareLinkedResources ( const KisPaintOpSettingsSP settings,
KisResourcesInterfaceSP resourcesInterface )
static

Definition at line 84 of file kis_sketch_paintop.cpp.

85{
86 KisBrushOptionProperties brushOption;
87 return brushOption.prepareLinkedResources(settings, resourcesInterface);
88}
QList< KoResourceLoadResult > prepareLinkedResources(const KisPropertiesConfigurationPointer settings, KisResourcesInterfaceSP resourcesInterface) const

References KisPaintopPropertiesCanvasResourcesBase::prepareLinkedResources().

◆ updateBrushMask()

void KisSketchPaintOp::updateBrushMask ( const KisPaintInformation & info,
qreal scale,
qreal rotation )
private

Definition at line 111 of file kis_sketch_paintop.cpp.

112{
113 QRect dstRect;
115 painter()->paintColor(),
116 info.pos(),
117 KisDabShape(scale, 1.0, rotation),
118 info, 1.0,
119 &dstRect);
120
121 m_brushBoundingBox = dstRect;
122 m_hotSpot = QPointF(0.5 * m_brushBoundingBox.width(),
123 0.5 * m_brushBoundingBox.height());
124}
KisFixedPaintDeviceSP fetchDab(const KoColorSpace *cs, KisColorSource *colorSource, const QPointF &cursorPoint, KisDabShape const &, const KisPaintInformation &info, qreal softnessFactor, QRect *dstDabRect, qreal lightnessStrength=1.0)

References KisPaintDevice::colorSpace(), KisDabCache::fetchDab(), m_brushBoundingBox, m_dab, m_dabCache, m_hotSpot, m_maskDab, KisPaintOp::painter, and KisPaintInformation::pos().

◆ updateSpacingImpl()

KisSpacingInformation KisSketchPaintOp::updateSpacingImpl ( const KisPaintInformation & info) const
overrideprotectedvirtual

Implementation of a spacing update

Implements KisPaintOp.

Definition at line 316 of file kis_sketch_paintop.cpp.

317{
318 return KisPaintOpPluginUtils::effectiveSpacing(0.0, 0.0, true, 0.0, false, 0.0, false, 0.0,
320 &m_airbrushOption, nullptr, info);
321}
KisSpacingInformation effectiveSpacing(qreal dabWidth, qreal dabHeight, bool isotropicSpacing, qreal rotation, bool axesFlipped, qreal spacingVal, bool autoSpacingActive, qreal autoSpacingCoeff, qreal lodScale, const KisAirbrushOptionData *airbrushOption, const KisSpacingOption *spacingOption, const KisPaintInformation &pi)

References KisPaintOpPluginUtils::effectiveSpacing(), KisLodTransformBase::lodToScale(), m_airbrushOption, and KisPaintOp::painter.

◆ updateTimingImpl()

KisTimingInformation KisSketchPaintOp::updateTimingImpl ( const KisPaintInformation & info) const
overrideprotectedvirtual

Implementation of a timing update. The default implementation always disables timing. This is suitable for paintops that do not support airbrushing.

Reimplemented from KisPaintOp.

Definition at line 323 of file kis_sketch_paintop.cpp.

324{
326}
KisTimingInformation effectiveTiming(const KisAirbrushOptionData *airbrushOption, const KisRateOption *rateOption, const KisPaintInformation &pi)

References KisPaintOpPluginUtils::effectiveTiming(), m_airbrushOption, and m_rateOption.

Member Data Documentation

◆ m_airbrushOption

KisAirbrushOptionData KisSketchPaintOp::m_airbrushOption
private

Definition at line 65 of file kis_sketch_paintop.h.

◆ m_brush

KisBrushSP KisSketchPaintOp::m_brush
private

Definition at line 73 of file kis_sketch_paintop.h.

◆ m_brushBoundingBox

QRectF KisSketchPaintOp::m_brushBoundingBox
private

Definition at line 52 of file kis_sketch_paintop.h.

◆ m_brushOption

KisBrushOptionProperties KisSketchPaintOp::m_brushOption
private

Definition at line 67 of file kis_sketch_paintop.h.

◆ m_count

int KisSketchPaintOp::m_count {0}
private

Definition at line 71 of file kis_sketch_paintop.h.

71{0};

◆ m_dab

KisPaintDeviceSP KisSketchPaintOp::m_dab
private

Definition at line 48 of file kis_sketch_paintop.h.

◆ m_dabCache

KisDabCache* KisSketchPaintOp::m_dabCache {nullptr}
private

Definition at line 74 of file kis_sketch_paintop.h.

74{nullptr};

◆ m_densityOption

KisDensityOption KisSketchPaintOp::m_densityOption
private

Definition at line 62 of file kis_sketch_paintop.h.

◆ m_hotSpot

QPointF KisSketchPaintOp::m_hotSpot
private

Definition at line 53 of file kis_sketch_paintop.h.

◆ m_lineWidthOption

KisLineWidthOption KisSketchPaintOp::m_lineWidthOption
private

Definition at line 63 of file kis_sketch_paintop.h.

◆ m_maskDab

KisFixedPaintDeviceSP KisSketchPaintOp::m_maskDab
private

Definition at line 51 of file kis_sketch_paintop.h.

◆ m_offsetScaleOption

KisOffsetScaleOption KisSketchPaintOp::m_offsetScaleOption
private

Definition at line 64 of file kis_sketch_paintop.h.

◆ m_opacityOption

KisOpacityOption KisSketchPaintOp::m_opacityOption
private

Definition at line 58 of file kis_sketch_paintop.h.

◆ m_painter

KisPainter* KisSketchPaintOp::m_painter {nullptr}
private

Definition at line 72 of file kis_sketch_paintop.h.

72{nullptr};

◆ m_points

QVector<QPointF> KisSketchPaintOp::m_points
private

Definition at line 70 of file kis_sketch_paintop.h.

◆ m_radius

qreal KisSketchPaintOp::m_radius {1.0}
private

Definition at line 56 of file kis_sketch_paintop.h.

56{1.0};

◆ m_rateOption

KisRateOption KisSketchPaintOp::m_rateOption
private

Definition at line 61 of file kis_sketch_paintop.h.

◆ m_rotationOption

KisRotationOption KisSketchPaintOp::m_rotationOption
private

Definition at line 60 of file kis_sketch_paintop.h.

◆ m_sizeOption

KisSizeOption KisSketchPaintOp::m_sizeOption
private

Definition at line 59 of file kis_sketch_paintop.h.

◆ m_sketchProperties

KisSketchOpOptionData KisSketchPaintOp::m_sketchProperties
private

Definition at line 68 of file kis_sketch_paintop.h.


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