Krita Source Code Documentation
Loading...
Searching...
No Matches
KoFilterEffect Class Referenceabstract

#include <KoFilterEffect.h>

+ Inheritance diagram for KoFilterEffect:

Public Member Functions

void addInput (const QString &input)
 Adds a new input at the end of the input list.
 
QRectF filterRect () const
 Returns the region this filter is applied to in bounding box units.
 
QRectF filterRectForBoundingRect (const QRectF &boundingRect) const
 Returns the region this filter is applied to for the given bounding rect.
 
QString id () const
 Returns the unique id of the filter.
 
QList< QString > inputs () const
 
void insertInput (int index, const QString &input)
 Inserts an input at the given position in the input list.
 
 KoFilterEffect (const QString &id, const QString &name)
 
virtual bool load (const QDomElement &element, const KoFilterEffectLoadingContext &context)=0
 
int maximalInputCount () const
 
QString name () const
 Returns the user visible name of the filter.
 
QString output () const
 Returns the name of the output image.
 
 Private ()
 
virtual QImage processImage (const QImage &image, const KoFilterEffectRenderContext &context) const =0
 
virtual QImage processImages (const QList< QImage > &images, const KoFilterEffectRenderContext &context) const
 
void removeInput (int index)
 Removes an input from the given position in the input list.
 
int requiredInputCount () const
 
virtual void save (KoXmlWriter &writer)=0
 
void setFilterRect (const QRectF &filterRect)
 Sets the region the filter is applied to in bounding box units.
 
void setInput (int index, const QString &input)
 Sets an existing input to a new value.
 
void setOutput (const QString &output)
 
virtual ~KoFilterEffect ()
 

Public Attributes

QRectF filterRect
 
QString id
 
QList< QString > inputs
 
int maximalInputCount
 
QString name
 
QString output
 
int requiredInputCount
 

Protected Member Functions

void saveCommonAttributes (KoXmlWriter &writer)
 
void setMaximalInputCount (int count)
 Sets the maximal number of input images.
 
void setRequiredInputCount (int count)
 Sets the required number of input images.
 

Private Attributes

Private *const d
 
- Private Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Additional Inherited Members

- Private Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Detailed Description

This is the base for filter effect (blur, invert...) that can be applied on a shape. All sizes and coordinates of the filter effect are stored in object bounding box coordinates, where (0,0) refers to the top-left corner of a shapes bounding rect and (1,1) refers to the bottom-right corner. When loading, a transformation matrix is given to convert from user space coordinates. Another transformation matrix is given via the render context to convert back to user space coordinates when applying the effect. Using object bounding box coordinates internally makes it easy to share effects between shapes or even between users via the filter effect resources.

Definition at line 15 of file KoFilterEffect.cpp.

Constructor & Destructor Documentation

◆ KoFilterEffect()

KoFilterEffect::KoFilterEffect ( const QString & id,
const QString & name )

Definition at line 35 of file KoFilterEffect.cpp.

36 : d(new Private)
37{
38 d->id = id;
39 d->name = name;
40}
Private *const d

References d, id, and name.

◆ ~KoFilterEffect()

KoFilterEffect::~KoFilterEffect ( )
virtual

Definition at line 42 of file KoFilterEffect.cpp.

43{
44 delete d;
45}

References d.

Member Function Documentation

◆ addInput()

void KoFilterEffect::addInput ( const QString & input)

Adds a new input at the end of the input list.

Definition at line 81 of file KoFilterEffect.cpp.

82{
83 if (d->inputs.count() < d->maximalInputCount)
84 d->inputs.append(input);
85}

References d.

◆ filterRect()

QRectF KoFilterEffect::filterRect ( ) const

Returns the region this filter is applied to in bounding box units.

◆ filterRectForBoundingRect()

QRectF KoFilterEffect::filterRectForBoundingRect ( const QRectF & boundingRect) const

Returns the region this filter is applied to for the given bounding rect.

Definition at line 67 of file KoFilterEffect.cpp.

68{
69 qreal x = boundingRect.x() + d->filterRect.x() * boundingRect.width();
70 qreal y = boundingRect.y() + d->filterRect.y() * boundingRect.height();
71 qreal w = d->filterRect.width() * boundingRect.width();
72 qreal h = d->filterRect.height() * boundingRect.height();
73 return QRectF(x, y, w, h);
74}

References d.

◆ id()

QString KoFilterEffect::id ( ) const

Returns the unique id of the filter.

◆ inputs()

QList< QString > KoFilterEffect::inputs ( ) const

Returns list of named input images of this filter effect.

These names identify the input images for this filter effect. These can be one of the keywords SourceGraphic, SourceAlpha, BackgroundImage, BackgroundAlpha, FillPaint or StrokePaint, as well as a named output of another filter effect in the stack. An empty input list of the first effect in the stack default to SourceGraphic, whereas on subsequent effects it defaults to the result of the previous filter effect.

◆ insertInput()

void KoFilterEffect::insertInput ( int index,
const QString & input )

Inserts an input at the given position in the input list.

Definition at line 87 of file KoFilterEffect.cpp.

88{
89 if (d->inputs.count() < d->maximalInputCount)
90 d->inputs.insert(index, input);
91}

References d.

◆ load()

virtual bool KoFilterEffect::load ( const QDomElement & element,
const KoFilterEffectLoadingContext & context )
pure virtual

Loads data from given xml element.

Parameters
elementthe xml element to load data from
contextthe loading context providing additional data
Returns
true if loading was successful, else false

◆ maximalInputCount()

int KoFilterEffect::maximalInputCount ( ) const

Returns the maximal number of input images. The default maximal number of input images is 1. Derived classes should call setMaximalInputCount to set a different number.

◆ name()

QString KoFilterEffect::name ( ) const

Returns the user visible name of the filter.

◆ output()

QString KoFilterEffect::output ( ) const

Returns the name of the output image.

◆ Private()

KoFilterEffect::Private ( )
inline

Definition at line 18 of file KoFilterEffect.cpp.

19 : filterRect(0, 0, 1, 1)
21 {
22 // add the default input
23 inputs.append(QString());
24 }
QList< QString > inputs

◆ processImage()

virtual QImage KoFilterEffect::processImage ( const QImage & image,
const KoFilterEffectRenderContext & context ) const
pure virtual

Apply the effect on an image.

Parameters
imagethe image the filter should be applied to
contextthe render context providing additional data

◆ processImages()

QImage KoFilterEffect::processImages ( const QList< QImage > & images,
const KoFilterEffectRenderContext & context ) const
virtual

Apply the effect on a list of images.

Parameters
imagesthe images the filter should be applied to
contextthe render context providing additional data

Definition at line 125 of file KoFilterEffect.cpp.

126{
127 Q_ASSERT(images.count());
128 return images.first();
129}

◆ removeInput()

void KoFilterEffect::removeInput ( int index)

Removes an input from the given position in the input list.

Definition at line 99 of file KoFilterEffect.cpp.

100{
101 if (d->inputs.count() > d->requiredInputCount)
102 d->inputs.removeAt(index);
103}

References d.

◆ requiredInputCount()

int KoFilterEffect::requiredInputCount ( ) const

Return the required number of input images. The default required number of input images is 1. Derived classes should call setRequiredInputCount to set a different number.

◆ save()

virtual void KoFilterEffect::save ( KoXmlWriter & writer)
pure virtual

Writes custom data to given xml element.

Parameters
writerthe xml writer to write data to

◆ saveCommonAttributes()

void KoFilterEffect::saveCommonAttributes ( KoXmlWriter & writer)
protected

Saves common filter attributes

Saves result, subregion and input attributes. The input attribute is only saved if required, maximal and actual input count equals 1. All other filters have to write inputs on their own.

Definition at line 148 of file KoFilterEffect.cpp.

149{
150 writer.addAttribute("result", output());
151 if (requiredInputCount() == 1 && maximalInputCount() == 1 && d->inputs.count() == 1) {
152 writer.addAttribute("in", d->inputs[0]);
153 }
154 writer.addAttribute("x", d->filterRect.x());
155 writer.addAttribute("y", d->filterRect.y());
156 writer.addAttribute("width", d->filterRect.width());
157 writer.addAttribute("height", d->filterRect.height());
158}
void addAttribute(const char *attrName, const QString &value)
Definition KoXmlWriter.h:61

References KoXmlWriter::addAttribute(), d, maximalInputCount, output, and requiredInputCount.

◆ setFilterRect()

void KoFilterEffect::setFilterRect ( const QRectF & filterRect)

Sets the region the filter is applied to in bounding box units.

Definition at line 57 of file KoFilterEffect.cpp.

58{
59 d->filterRect = filterRect;
60}

References d, and filterRect.

◆ setInput()

void KoFilterEffect::setInput ( int index,
const QString & input )

Sets an existing input to a new value.

Definition at line 93 of file KoFilterEffect.cpp.

94{
95 if (index < d->inputs.count())
96 d->inputs[index] = input;
97}

References d, and inputs.

◆ setMaximalInputCount()

void KoFilterEffect::setMaximalInputCount ( int count)
protected

Sets the maximal number of input images.

Definition at line 138 of file KoFilterEffect.cpp.

139{
140 d->maximalInputCount = qMax(0,count);
141 if (d->inputs.count() > maximalInputCount()) {
142 int removeCount = d->inputs.count()-maximalInputCount();
143 for (int i = 0; i < removeCount; ++i)
144 d->inputs.pop_back();
145 }
146}

References d, and maximalInputCount.

◆ setOutput()

void KoFilterEffect::setOutput ( const QString & output)

Sets the name of the output image

The name is used so that other effects can reference the output of this effect as one of their input images.

Parameters
outputthe output image name

Definition at line 105 of file KoFilterEffect.cpp.

106{
107 d->output = output;
108}

References d, and output.

◆ setRequiredInputCount()

void KoFilterEffect::setRequiredInputCount ( int count)
protected

Sets the required number of input images.

Definition at line 131 of file KoFilterEffect.cpp.

132{
133 d->requiredInputCount = qMax(0, count);
134 for (int i = d->inputs.count(); i < d->requiredInputCount; ++i)
135 d->inputs.append(QString());
136}

References d.

Member Data Documentation

◆ d

Private* const KoFilterEffect::d
private

Definition at line 155 of file KoFilterEffect.h.

◆ filterRect

QRectF KoFilterEffect::filterRect

Definition at line 28 of file KoFilterEffect.cpp.

◆ id

QString KoFilterEffect::id

Definition at line 26 of file KoFilterEffect.cpp.

◆ inputs

QList< QString > KoFilterEffect::inputs

Definition at line 29 of file KoFilterEffect.cpp.

◆ maximalInputCount

int KoFilterEffect::maximalInputCount

Definition at line 32 of file KoFilterEffect.cpp.

◆ name

QString KoFilterEffect::name

Definition at line 27 of file KoFilterEffect.cpp.

◆ output

QString KoFilterEffect::output

Definition at line 30 of file KoFilterEffect.cpp.

◆ requiredInputCount

int KoFilterEffect::requiredInputCount

Definition at line 31 of file KoFilterEffect.cpp.


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