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

The KisConvolutionPainter class applies a convolution kernel to a paint device. More...

#include <kis_convolution_painter.h>

+ Inheritance diagram for KisConvolutionPainter:

Public Types

enum  EnginePreference { NONE , SPATIAL , FFTW }
 
- Public Types inherited from KisPainter
enum  FillStyle {
  FillStyleNone , FillStyleForegroundColor , FillStyleBackgroundColor , FillStylePattern ,
  FillStyleGenerator
}
 This enum contains the styles with which we can fill things like polygons and ellipses. More...
 
enum  StrokeStyle { StrokeStyleNone , StrokeStyleBrush }
 The style of the brush stroke around polygons and so. More...
 

Public Member Functions

void applyMatrix (const KisConvolutionKernelSP kernel, const KisPaintDeviceSP src, QPoint srcPos, QPoint dstPos, QSize areaSize, KisConvolutionBorderOp borderOp=BORDER_REPEAT)
 
 KisConvolutionPainter ()
 
 KisConvolutionPainter (KisPaintDeviceSP device)
 
 KisConvolutionPainter (KisPaintDeviceSP device, EnginePreference enginePreference)
 
 KisConvolutionPainter (KisPaintDeviceSP device, KisSelectionSP selection)
 
bool needsTransaction (const KisConvolutionKernelSP kernel) const
 
void setEnginePreference (EnginePreference value)
 
- Public Member Functions inherited from KisPainter
void addDirtyRect (const QRect &r)
 
void addDirtyRects (const QVector< QRect > &rects)
 
bool antiAliasPolygonFill ()
 Return whether a polygon's filled area should be anti-aliased or not.
 
void applyDevice (const QRect &applyRect, const KisRenderedDab &dab, KisRandomAccessorSP dstIt, const KoColorSpace *srcColorSpace, KoCompositeOp::ParameterInfo &localParamInfo)
 
void applyDeviceWithSelection (const QRect &applyRect, const KisRenderedDab &dab, KisRandomAccessorSP dstIt, KisRandomConstAccessorSP maskIt, const KoColorSpace *srcColorSpace, KoCompositeOp::ParameterInfo &localParamInfo)
 
const KoColorbackgroundColor () const
 Returns the current background color.
 
void begin (KisPaintDeviceSP device)
 
void begin (KisPaintDeviceSP device, KisSelectionSP selection)
 
void beginTransaction (const KUndo2MagicString &transactionName=KUndo2MagicString(), int timedID=-1)
 Begin an undoable paint operation.
 
void bitBlt (const QPoint &pos, const KisPaintDeviceSP srcDev, const QRect &srcRect)
 
void bitBlt (qint32 dstX, qint32 dstY, const KisPaintDeviceSP srcDev, qint32 srcX, qint32 srcY, qint32 srcWidth, qint32 srcHeight)
 
void bitBltOldData (const QPoint &pos, const KisPaintDeviceSP srcDev, const QRect &srcRect)
 
void bitBltOldData (qint32 dstX, qint32 dstY, const KisPaintDeviceSP srcDev, qint32 srcX, qint32 srcY, qint32 srcWidth, qint32 srcHeight)
 
void bitBltWithFixedSelection (qint32 dstX, qint32 dstY, const KisPaintDeviceSP srcDev, const KisFixedPaintDeviceSP selection, qint32 selX, qint32 selY, qint32 srcX, qint32 srcY, qint32 srcWidth, qint32 srcHeight)
 
void bitBltWithFixedSelection (qint32 dstX, qint32 dstY, const KisPaintDeviceSP srcDev, const KisFixedPaintDeviceSP selection, qint32 srcWidth, qint32 srcHeight)
 
void bltFixed (const QPoint &pos, const KisFixedPaintDeviceSP srcDev, const QRect &srcRect)
 
void bltFixed (const QRect &rc, const QList< KisRenderedDab > allSrcDevices)
 
void bltFixed (qint32 dstX, qint32 dstY, const KisFixedPaintDeviceSP srcDev, qint32 srcX, qint32 srcY, qint32 srcWidth, qint32 srcHeight)
 
void bltFixedWithFixedSelection (qint32 dstX, qint32 dstY, const KisFixedPaintDeviceSP srcDev, const KisFixedPaintDeviceSP selection, qint32 selX, qint32 selY, qint32 srcX, qint32 srcY, quint32 srcWidth, quint32 srcHeight)
 
void bltFixedWithFixedSelection (qint32 dstX, qint32 dstY, const KisFixedPaintDeviceSP srcDev, const KisFixedPaintDeviceSP selection, quint32 srcWidth, quint32 srcHeight)
 
const QVector< QPair< QPointF, QPointF > > calculateAllMirroredPoints (const QPair< QPointF, QPointF > &pair)
 
const QVector< QPointF > calculateAllMirroredPoints (const QPointF &pos)
 
const QVector< QRect > calculateAllMirroredRects (const QRect &rc)
 
template<class T >
QVector< T > calculateMirroredObjects (const T &object)
 
QBitArray channelFlags ()
 
const KoCompositeOpcompositeOp (const KoColorSpace *srcCS)
 
QString compositeOpId ()
 Returns the current composite op Id.
 
void copyMirrorInformationFrom (const KisPainter *other)
 
void deleteTransaction ()
 
KisPaintDeviceSP device ()
 
const KisPaintDeviceSP device () const
 Returns the current paint device.
 
void drawDDALine (const QPointF &start, const QPointF &end)
 
void drawLine (const QPointF &start, const QPointF &end)
 
void drawLine (const QPointF &start, const QPointF &end, qreal width, bool antialias)
 
void drawPainterPath (const QPainterPath &path, const QPen &pen)
 
void drawPainterPath (const QPainterPath &path, const QPen &pen, const QRect &requestedRect)
 
void drawThickLine (const QPointF &start, const QPointF &end, int startWidth, int endWidth)
 
void drawWobblyLine (const QPointF &start, const QPointF &end)
 
void drawWuLine (const QPointF &start, const QPointF &end)
 
void end ()
 
KUndo2CommandendAndTakeTransaction ()
 
void endTransaction (KisPostExecutionUndoAdapter *undoAdapter)
 
void endTransaction (KisUndoAdapter *undoAdapter)
 Finish the undoable paint operation.
 
void fill (qint32 x, qint32 y, qint32 width, qint32 height, const KoColor &color)
 
void fillPainterPath (const QPainterPath &path)
 
void fillPainterPath (const QPainterPath &path, const QRect &requestedRect)
 
void fillPainterPathImpl (const QPainterPath &path, const QRect &requestedRect)
 
FillStyle fillStyle () const
 Returns the current fill style.
 
qreal flow () const
 
const KisFilterConfigurationSP generator () const
 
void getBezierCurvePoints (const QPointF &pos1, const QPointF &control1, const QPointF &control2, const QPointF &pos2, vQPointF &points) const
 
const KoAbstractGradientSP gradient () const
 
bool hasDirtyRegion () const
 
bool hasHorizontalMirroring () const
 
bool hasMirroring () const
 
bool hasVerticalMirroring () const
 
bool isOpacityUnit () const
 
 KisPainter ()
 Construct painter without a device.
 
 KisPainter (KisPaintDeviceSP device)
 Construct a painter, and begin painting on the device.
 
 KisPainter (KisPaintDeviceSP device, KisSelectionSP selection)
 Construct a painter, and begin painting on the device. All actions will be masked by the given selection.
 
void mirrorDab (Qt::Orientation direction, KisRenderedDab *dab, bool skipMirrorPixels=false) const
 
void mirrorRect (Qt::Orientation direction, QRect *rc) const
 
qreal opacityF () const
 Returns the opacity that is used in painting.
 
void paintAt (const KisPaintInformation &pos, KisDistanceInformation *savedDist)
 
void paintBezierCurve (const KisPaintInformation &pi1, const QPointF &control1, const QPointF &control2, const KisPaintInformation &pi2, KisDistanceInformation *currentDistance)
 
const KoColorpaintColor () const
 Returns the color that will be used to paint with.
 
void paintEllipse (const qreal x, const qreal y, const qreal w, const qreal h)
 
void paintEllipse (const QRectF &rect)
 
void paintLine (const KisPaintInformation &pi1, const KisPaintInformation &pi2, KisDistanceInformation *currentDistance)
 
KisPaintOppaintOp () const
 
void paintPainterPath (const QPainterPath &path)
 
void paintPolygon (const vQPointF &points)
 
void paintPolyline (const QVector< QPointF > &points, int index=0, int numPoints=-1)
 
void paintRect (const qreal x, const qreal y, const qreal w, const qreal h)
 
void paintRect (const QRectF &rect)
 
const KoPatternSP pattern () const
 Returns the currently set pattern.
 
QTransform patternTransform ()
 get the current transform on the pattern.
 
KisPaintOpPresetSP preset () const
 Return the paintop preset.
 
 Private (KisPainter *_q)
 
 Private (KisPainter *_q, const KoColorSpace *cs)
 
void putTransaction (KisTransaction *transaction)
 continue a transaction started somewhere else
 
void renderDabWithMirroringNonIncremental (QRect rc, KisPaintDeviceSP dab)
 
void renderMirrorMask (QRect rc, KisFixedPaintDeviceSP dab)
 
void renderMirrorMask (QRect rc, KisFixedPaintDeviceSP dab, KisFixedPaintDeviceSP mask)
 
void renderMirrorMask (QRect rc, KisPaintDeviceSP dab)
 
void renderMirrorMask (QRect rc, KisPaintDeviceSP dab, int sx, int sy, KisFixedPaintDeviceSP mask)
 
void renderMirrorMaskSafe (QRect rc, KisFixedPaintDeviceSP dab, bool preserveDab)
 
void renderMirrorMaskSafe (QRect rc, KisFixedPaintDeviceSP dab, KisFixedPaintDeviceSP mask, bool preserveDab)
 
void renderMirrorMaskSafe (QRect rc, KisPaintDeviceSP dab, int sx, int sy, KisFixedPaintDeviceSP mask, bool preserveMask)
 
void revertTransaction ()
 Cancel all the changes made by the painter.
 
KisRunnableStrokeJobsInterfacerunnableStrokeJobsInterface () const
 
KisSelectionSP selection ()
 
void setAntiAliasPolygonFill (bool antiAliasPolygonFill)
 Set whether a polygon's filled area should be anti-aliased or not. The default is true.
 
void setAverageOpacity (qreal averageOpacity)
 
void setBackgroundColor (const KoColor &color)
 
void setChannelFlags (QBitArray channelFlags)
 
void setColorConversionFlags (KoColorConversionTransformation::ConversionFlags conversionFlags)
 
void setCompositeOpId (const KoCompositeOp *op)
 
void setCompositeOpId (const QString &op)
 Set the composite op for this painter by string.
 
void setFillStyle (FillStyle fillStyle)
 Set the current style with which to fill.
 
void setFlow (qreal flow)
 
void setGenerator (KisFilterConfigurationSP generator)
 Set the current generator (a generator can be used to fill an area.
 
void setGradient (const KoAbstractGradientSP gradient)
 
void setMaskImageSize (qint32 width, qint32 height)
 
void setMirrorInformation (const QPointF &axesCenter, bool mirrorHorizontally, bool mirrorVertically)
 
void setOpacityF (qreal opacity)
 
void setOpacityToUnit ()
 
void setOpacityU8 (quint8 opacity)
 Set the opacity which is used in painting (like filling polygons)
 
void setOpacityUpdateAverage (qreal opacity)
 
void setPaintColor (const KoColor &color)
 
void setPaintOpPreset (KisPaintOpPresetSP preset, KisNodeSP node, KisImageSP image)
 
void setPattern (const KoPatternSP pattern)
 Set the current pattern.
 
void setPatternTransform (QTransform transform)
 Set the transform on the pattern.
 
void setProgress (KoUpdater *progressUpdater)
 
void setRenderingIntent (KoColorConversionTransformation::Intent intent)
 
void setRunnableStrokeJobsInterface (KisRunnableStrokeJobsInterface *interface)
 
void setSelection (KisSelectionSP selection)
 
void setStrokeStyle (StrokeStyle strokeStyle)
 Set the current brush stroke style.
 
StrokeStyle strokeStyle () const
 Returns the current brush stroke style.
 
QVector< QRect > takeDirtyRegion ()
 
KisTransactiontakeTransaction ()
 take transaction out of the reach of KisPainter
 
bool tryReduceSourceRect (const KisPaintDevice *srcDev, QRect *srcRect, qint32 *srcX, qint32 *srcY, qint32 *srcWidth, qint32 *srcHeight, qint32 *dstX, qint32 *dstY)
 
virtual ~KisPainter ()
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Static Public Member Functions

static bool supportsFFTW ()
 
- Static Public Member Functions inherited from KisPainter
static qreal blendAverageOpacity (qreal opacity, qreal averageOpacity)
 
static bool checkDeviceHasTransparency (KisPaintDeviceSP dev)
 
static KisPaintDeviceSP convertToAlphaAsAlpha (KisPaintDeviceSP src)
 
static KisPaintDeviceSP convertToAlphaAsGray (KisPaintDeviceSP src)
 
static KisPaintDeviceSP convertToAlphaAsPureAlpha (KisPaintDeviceSP src)
 
static void copyAreaOptimized (const QPoint &dstPt, KisPaintDeviceSP src, KisPaintDeviceSP dst, const QRect &originalSrcRect)
 
static void copyAreaOptimized (const QPoint &dstPt, KisPaintDeviceSP src, KisPaintDeviceSP dst, const QRect &originalSrcRect, KisSelectionSP selection)
 
static void copyAreaOptimizedOldData (const QPoint &dstPt, KisPaintDeviceSP src, KisPaintDeviceSP dst, const QRect &originalSrcRect)
 

Private Member Functions

template<class factory >
KisConvolutionWorker< factory > * createWorker (const KisConvolutionKernelSP kernel, KisPainter *painter, KoUpdater *progress)
 
bool useFFTImplementation (const KisConvolutionKernelSP kernel) const
 

Private Attributes

EnginePreference m_enginePreference
 

Friends

class KisConvolutionPainterTest
 

Additional Inherited Members

- Public Attributes inherited from KisPainter
bool antiAliasPolygonFill {true}
 
QPointF axesCenter
 
KoColor backgroundColor
 
const KoCompositeOpcachedCompositeOp {nullptr}
 
const KoColorSpacecachedSourceColorSpace {nullptr}
 
const KoColorSpacecolorSpace {nullptr}
 
QString compositeOpId
 
KoColorConversionTransformation::ConversionFlags conversionFlags {KoColorConversionTransformation::Empty}
 
KoColor customColor
 
KisPaintDeviceSP device
 
QVector< QRect > dirtyRects
 
QPointF duplicateOffset
 
QScopedPointer< KisRunnableStrokeJobsInterfacefakeRunnableStrokeJobsInterface
 
KisFillPainterfillPainter {nullptr}
 
FillStyle fillStyle {FillStyleNone}
 
KisFilterConfigurationSP generator
 
KoAbstractGradientSP gradient
 
bool isOpacityUnit {true}
 
qint32 maskImageHeight {255}
 
qint32 maskImageWidth {255}
 
QPainter * maskPainter {nullptr}
 
bool mirrorHorizontally {false}
 
bool mirrorVertically {false}
 
KoColor paintColor
 
KisPaintOppaintOp {nullptr}
 
KisPaintOpPresetSP paintOpPreset
 
KoCompositeOp::ParameterInfo paramInfo
 
KoPatternSP pattern
 
QTransform patternTransform
 
quint32 pixelSize {0}
 
KisPaintDeviceSP polygon
 
QImage polygonMaskImage
 
KoColorProfileprofile {nullptr}
 
KoUpdaterprogressUpdater {nullptr}
 
KisPainterq {nullptr}
 
KoColorConversionTransformation::Intent renderingIntent {KoColorConversionTransformation::IntentPerceptual}
 
KisRunnableStrokeJobsInterfacerunnableStrokeJobsInterface {nullptr}
 
KisSelectionSP selection
 
KisPaintLayersourceLayer {nullptr}
 
StrokeStyle strokeStyle {StrokeStyleBrush}
 
KisTransactiontransaction {nullptr}
 
- Public Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 
- Protected Member Functions inherited from KisPainter
void fillPolygon (const vQPointF &points, FillStyle fillStyle)
 Fill the polygon defined by points with the fillStyle.
 
void init ()
 Initialize, set everything to '0' or defaults.
 
KoUpdaterprogressUpdater ()
 

Detailed Description

The KisConvolutionPainter class applies a convolution kernel to a paint device.

Note: https://bugs.kde.org/show_bug.cgi?id=220310 shows that there's something here that we need to fix...

Definition at line 29 of file kis_convolution_painter.h.

Member Enumeration Documentation

◆ EnginePreference

Constructor & Destructor Documentation

◆ KisConvolutionPainter() [1/4]

KisConvolutionPainter::KisConvolutionPainter ( )

Definition at line 97 of file kis_convolution_painter.cc.

98 : KisPainter(),
100{
101}
EnginePreference m_enginePreference
KisPainter()
Construct painter without a device.

◆ KisConvolutionPainter() [2/4]

KisConvolutionPainter::KisConvolutionPainter ( KisPaintDeviceSP device)

Definition at line 103 of file kis_convolution_painter.cc.

106{
107}
KisPaintDeviceSP device

◆ KisConvolutionPainter() [3/4]

KisConvolutionPainter::KisConvolutionPainter ( KisPaintDeviceSP device,
KisSelectionSP selection )

Definition at line 109 of file kis_convolution_painter.cc.

112{
113}
KisSelectionSP selection

◆ KisConvolutionPainter() [4/4]

KisConvolutionPainter::KisConvolutionPainter ( KisPaintDeviceSP device,
EnginePreference enginePreference )

Definition at line 115 of file kis_convolution_painter.cc.

117 m_enginePreference(enginePreference)
118{
119}

Member Function Documentation

◆ applyMatrix()

void KisConvolutionPainter::applyMatrix ( const KisConvolutionKernelSP kernel,
const KisPaintDeviceSP src,
QPoint srcPos,
QPoint dstPos,
QSize areaSize,
KisConvolutionBorderOp borderOp = BORDER_REPEAT )

Convolve all channels in src using the specified kernel; there is only one kernel for all channels possible.

WARNING: The painter will read more pixels than you pass in areaSize. The actual processing area will be: QRect(x - kernel.width() / 2, y - kernel.height() / 2, w + 2 * (kernel.width() / 2), h + 2 * (kernel.height() / 2))

The border op decides what to do with pixels too close to the edge of the rect as defined above.

The channels flag determines which set out of color channels, alpha channels. channels we convolve.

Note that we do not (currently) support different kernels for different channels or channel types.

If you want to convolve a subset of the channels in a pixel, set those channels with KisPainter::setChannelFlags();

Force BORDER_IGNORE op for the wraparound mode, because the paint device has its own special iterators, which do everything for us.

We don't use defaultBounds->topLevelWrapRect(), because the main purpose of this wrapping is "getting expected results when applying to the layer". If a mask is bigger than the image, then it should be wrapped around the mask instead.

FIXME: Implementation can return empty destination device on faults and has no way to report this. This will cause a crash on sequential convolutions inside iterators.

o implementation should do it's work or assert otherwise (or report the issue somehow) o check other cases of the switch for the vulnerability

Definition at line 126 of file kis_convolution_painter.cc.

127{
133 if (src->defaultBounds()->wrapAroundMode() && src->supportsWraproundMode()) {
134 borderOp = BORDER_IGNORE;
135 }
136
137 // Determine whether we convolve border pixels, or not.
138 switch (borderOp) {
139 case BORDER_REPEAT: {
147 const QRect boundsRect = src->defaultBounds()->bounds();
148 const QRect requestedRect = QRect(srcPos, areaSize);
149 QRect dataRect = requestedRect | boundsRect;
150
152 dataRect = requestedRect | src->exactBounds();
153 }
154
165 if(dataRect.isValid()) {
167 worker = createWorker<RepeatIteratorFactory>(kernel, this, progressUpdater());
168 worker->execute(kernel, src, srcPos, dstPos, areaSize, dataRect);
169 delete worker;
170 }
171 break;
172 }
173 case BORDER_IGNORE:
174 default: {
176 worker = createWorker<StandardIteratorFactory>(kernel, this, progressUpdater());
177 worker->execute(kernel, src, srcPos, dstPos, areaSize, QRect());
178 delete worker;
179 }
180 }
181}
virtual void execute(const KisConvolutionKernelSP kernel, const KisPaintDeviceSP src, QPoint srcPos, QPoint dstPos, QSize areaSize, const QRect &dataRect)=0
KoUpdater * progressUpdater
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126
#define bounds(x, a, b)

References BORDER_IGNORE, BORDER_REPEAT, bounds, KisConvolutionWorker< _IteratorFactory_ >::execute(), KIS_SAFE_ASSERT_RECOVER, and KisPainter::progressUpdater.

◆ createWorker()

template<class factory >
KisConvolutionWorker< factory > * KisConvolutionPainter::createWorker ( const KisConvolutionKernelSP kernel,
KisPainter * painter,
KoUpdater * progress )
private

Definition at line 66 of file kis_convolution_painter.cc.

69{
71
72#ifdef HAVE_FFTW3
73 if (useFFTImplementation(kernel)) {
74 worker = new KisConvolutionWorkerFFT<factory>(painter, progress);
75 } else {
76 worker = new KisConvolutionWorkerSpatial<factory>(painter, progress);
77 }
78#else
79 Q_UNUSED(kernel);
80 worker = new KisConvolutionWorkerSpatial<factory>(painter, progress);
81#endif
82
83 return worker;
84}
bool useFFTImplementation(const KisConvolutionKernelSP kernel) const

References useFFTImplementation().

◆ needsTransaction()

bool KisConvolutionPainter::needsTransaction ( const KisConvolutionKernelSP kernel) const

The caller should ask if the painter needs an explicit transaction iff the source and destination devices coincide. Otherwise, the transaction is just not needed.

Definition at line 183 of file kis_convolution_painter.cc.

184{
185 return !useFFTImplementation(kernel);
186}

References useFFTImplementation().

◆ setEnginePreference()

void KisConvolutionPainter::setEnginePreference ( EnginePreference value)

Definition at line 121 of file kis_convolution_painter.cc.

122{
124}
float value(const T *src, size_t ch)

References m_enginePreference, and value().

◆ supportsFFTW()

bool KisConvolutionPainter::supportsFFTW ( )
static

Definition at line 87 of file kis_convolution_painter.cc.

88{
89#ifdef HAVE_FFTW3
90 return true;
91#else
92 return false;
93#endif
94}

◆ useFFTImplementation()

bool KisConvolutionPainter::useFFTImplementation ( const KisConvolutionKernelSP kernel) const
private

Definition at line 46 of file kis_convolution_painter.cc.

47{
48 bool result = false;
49
50#ifdef HAVE_FFTW3
51 #define THRESHOLD_SIZE 5
52
53 result =
56 (kernel->width() > THRESHOLD_SIZE ||
57 kernel->height() > THRESHOLD_SIZE));
58#else
59 Q_UNUSED(kernel);
60#endif
61
62 return result;
63}

References FFTW, KisConvolutionKernel::height(), m_enginePreference, NONE, and KisConvolutionKernel::width().

Friends And Related Symbol Documentation

◆ KisConvolutionPainterTest

friend class KisConvolutionPainterTest
friend

Definition at line 84 of file kis_convolution_painter.h.

Member Data Documentation

◆ m_enginePreference

EnginePreference KisConvolutionPainter::m_enginePreference
private

Definition at line 97 of file kis_convolution_painter.h.


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