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

#include <Filter.h>

+ Inheritance diagram for Filter:

Classes

struct  Private
 

Public Slots

bool apply (Node *node, int x, int y, int w, int h)
 Apply the filter to the given node.
 
InfoObjectconfiguration () const
 
QString name () const
 name the internal name of this filter.
 
void setConfiguration (InfoObject *value)
 setConfiguration set the configuration object for the filter
 
void setName (const QString &name)
 setName set the filter's name to the given name.
 
bool startFilter (Node *node, int x, int y, int w, int h)
 startFilter starts the given filter on the given node.
 

Public Member Functions

 Filter ()
 Filter: create an empty filter object. Until a name is set, the filter cannot be applied.
 
bool operator!= (const Filter &other) const
 
bool operator== (const Filter &other) const
 
 ~Filter () override
 

Private Member Functions

KisFilterConfigurationSP filterConfig ()
 

Private Attributes

Private *const d
 

Friends

class FilterLayer
 
class FilterMask
 

Detailed Description

Filter: represents a filter and its configuration. A filter is identified by an internal name. The configuration for each filter is defined as an InfoObject: a map of name and value pairs.

Currently available filters are:

'autocontrast', 'blur', 'bottom edge detections', 'brightnesscontrast', 'burn', 'colorbalance', 'colortoalpha', 'colortransfer', 'desaturate', 'dodge', 'emboss', 'emboss all directions', 'emboss horizontal and vertical', 'emboss horizontal only', 'emboss laplascian', 'emboss vertical only', 'gaussian blur', 'gaussiannoisereducer', 'gradientmap', 'halftone', 'hsvadjustment', 'indexcolors', 'invert', 'left edge detections', 'lens blur', 'levels', 'maximize', 'mean removal', 'minimize', 'motion blur', 'noise', 'normalize', 'oilpaint', 'perchannel', 'phongbumpmap', 'pixelize', 'posterize', 'raindrops', 'randompick', 'right edge detections', 'roundcorners', 'sharpen', 'smalltiles', 'sobel', 'threshold', 'top edge detections', 'unsharp', 'wave', 'waveletnoisereducer']

Definition at line 30 of file Filter.h.

Constructor & Destructor Documentation

◆ Filter()

Filter::Filter ( )
explicit

Filter: create an empty filter object. Until a name is set, the filter cannot be applied.

Definition at line 37 of file Filter.cpp.

38 : QObject(0)
39 , d(new Private)
40{
41}
Private *const d
Definition Filter.h:102

◆ ~Filter()

Filter::~Filter ( )
override

Definition at line 43 of file Filter.cpp.

44{
45 delete d->configuration;
46 delete d;
47}
InfoObject * configuration
Definition Filter.cpp:34

References Filter::Private::configuration, and d.

Member Function Documentation

◆ apply

bool Filter::apply ( Node * node,
int x,
int y,
int w,
int h )
slot

Apply the filter to the given node.

Parameters
nodethe node to apply the filter to
x
y
w
hdescribe the rectangle the filter should be apply. This is always in image pixel coordinates and not relative to the x, y of the node.
Returns
true if the filter was applied successfully, or false if the filter could not be applied because the node is locked or does not have an editable paint device.

Definition at line 85 of file Filter.cpp.

86{
87 if (node->locked()) return false;
88
90 if (!filter) return false;
91
92 KisPaintDeviceSP dev = node->paintDevice();
93 if (!dev) return false;
94
95 QRect applyRect = QRect(x, y, w, h);
97 filter->process(dev, applyRect, config->cloneWithResourcesSnapshot());
98 return true;
99}
KisPropertiesConfigurationSP configuration() const
configuration gives access to the internal configuration object. Must be used internally in libkis
static KisFilterRegistry * instance()
void process(const KisPaintDeviceSP src, KisPaintDeviceSP dst, KisSelectionSP selection, const QRect &applyRect, const KisFilterConfigurationSP config, KoUpdater *progressUpdater=0) const
Definition kis_filter.cc:41
const T value(const QString &id) const
bool locked() const
locked checks whether the Node is locked. A locked node cannot be changed.
Definition Node.cpp:411
KisPaintDeviceSP paintDevice() const
paintDevice gives access to the internal paint device of this Node
Definition Node.cpp:817
QString name
Definition Filter.cpp:33

References Filter::Private::configuration, InfoObject::configuration(), d, KisSharedPtr< T >::data(), KisFilterRegistry::instance(), Node::locked(), Filter::Private::name, Node::paintDevice(), KisFilter::process(), and KoGenericRegistry< T >::value().

◆ configuration

InfoObject * Filter::configuration ( ) const
slot
Returns
the configuration object for the filter

Definition at line 75 of file Filter.cpp.

76{
77 return d->configuration;
78}

References Filter::Private::configuration, and d.

◆ filterConfig()

KisFilterConfigurationSP Filter::filterConfig ( )
private

Definition at line 152 of file Filter.cpp.

153{
155 Q_FOREACH(const QString property, d->configuration->properties().keys()) {
156 config->setProperty(property, d->configuration->property(property));
157 }
158 return config;
159}
QVariant property(const QString &key)
QMap< QString, QVariant > properties() const
static KisResourcesInterfaceSP instance()
T get(const QString &id) const
virtual KisFilterConfigurationSP factoryConfiguration(KisResourcesInterfaceSP resourcesInterface) const

References Filter::Private::configuration, d, KisBaseProcessor::factoryConfiguration(), KoGenericRegistry< T >::get(), KisFilterRegistry::instance(), KisGlobalResourcesInterface::instance(), Filter::Private::name, InfoObject::properties(), and InfoObject::property().

◆ name

QString Filter::name ( ) const
slot

name the internal name of this filter.

Returns
the name.

Definition at line 61 of file Filter.cpp.

62{
63 return d->name;
64}

References d, and Filter::Private::name.

◆ operator!=()

bool Filter::operator!= ( const Filter & other) const

Definition at line 55 of file Filter.cpp.

56{
57 return !(operator==(other));
58}
bool operator==(const Filter &other) const
Definition Filter.cpp:49

References operator==().

◆ operator==()

bool Filter::operator== ( const Filter & other) const

Definition at line 49 of file Filter.cpp.

50{
51 return (d->name == other.d->name
52 && d->configuration == other.d->configuration);
53}

References Filter::Private::configuration, d, and Filter::Private::name.

◆ setConfiguration

void Filter::setConfiguration ( InfoObject * value)
slot

setConfiguration set the configuration object for the filter

Definition at line 80 of file Filter.cpp.

81{
83}
float value(const T *src, size_t ch)

References Filter::Private::configuration, d, and value().

◆ setName

void Filter::setName ( const QString & name)
slot

setName set the filter's name to the given name.

Definition at line 66 of file Filter.cpp.

67{
68 d->name = name;
69 delete d->configuration;
70
73}
QString name() const
name the internal name of this filter.
Definition Filter.cpp:61
virtual KisFilterConfigurationSP defaultConfiguration(KisResourcesInterfaceSP resourcesInterface) const

References Filter::Private::configuration, d, KisBaseProcessor::defaultConfiguration(), KisFilterRegistry::instance(), KisGlobalResourcesInterface::instance(), Filter::Private::name, name(), and KoGenericRegistry< T >::value().

◆ startFilter

bool Filter::startFilter ( Node * node,
int x,
int y,
int w,
int h )
slot

startFilter starts the given filter on the given node.

Parameters
nodethe node to apply the filter to
x
y
w
hdescribe the rectangle the filter should be apply. This is always in image pixel coordinates and not relative to the x, y of the node.

Definition at line 101 of file Filter.cpp.

102{
103 if (node->locked()) return false;
104
106 if (!filter) return false;
107
108 KisImageWSP image = node->image();
109 if (!image) return false;
110
112
113 image->waitForDone();
114 QRect initialApplyRect = QRect(x, y, w, h);
115
116 QRect applyRect = initialApplyRect;
117
118 KisPaintDeviceSP paintDevice = node->paintDevice();
119 if (paintDevice && filter->needsTransparentPixels(filterConfig.data(), paintDevice->colorSpace())) {
120 applyRect |= image->bounds();
121 }
122
123 KisResourcesSnapshotSP resources = new KisResourcesSnapshot(image, node->node());
124
125 Document *document = Krita::instance()->activeDocument();
126 if (document && KisPart::instance()->viewCount(document->document()) > 0) {
127 Q_FOREACH (QPointer<KisView> view, KisPart::instance()->views()) {
128 if (view && view->document() == document->document()) {
129 resources = new KisResourcesSnapshot(image, node->node(), view->resourceProvider()->resourceManager());
130 break;
131 }
132 }
133 }
134 delete document;
135
136 KisStrokeId currentStrokeId = image->startStroke(new KisFilterStrokeStrategy(filter,
138 resources));
139
140 QRect processRect = filter->changedRect(applyRect, filterConfig.data(), 0);
141 processRect &= image->bounds();
142
143 image->addJob(currentStrokeId, new KisFilterStrokeStrategy::FilterJobData());
144
145
146 image->endStroke(currentStrokeId);
147 image->waitForDone();
148
149 return true;
150}
KisFilterConfigurationSP filterConfig()
Definition Filter.cpp:152
virtual bool needsTransparentPixels(const KisFilterConfigurationSP config, const KoColorSpace *cs) const
virtual QRect changedRect(const QRect &rect, const KisFilterConfigurationSP config, int lod) const
Definition kis_filter.cc:98
void waitForDone()
void addJob(KisStrokeId id, KisStrokeJobData *data) override
KisStrokeId startStroke(KisStrokeStrategy *strokeStrategy) override
QRect bounds() const override
void endStroke(KisStrokeId id) override
const KoColorSpace * colorSpace() const
static KisPart * instance()
Definition KisPart.cpp:131
The KisResourcesSnapshot class takes a snapshot of the various resources like colors and settings use...
Document * activeDocument() const
Definition Krita.cpp:104
static Krita * instance()
instance retrieve the singleton instance of the Application object.
Definition Krita.cpp:390
KisNodeSP node() const
Definition Node.cpp:827
KisImageSP image() const
Definition Node.cpp:822
KisPinnedSharedPtr< KisFilterConfiguration > KisFilterConfigurationSP
Definition kis_types.h:275

References Krita::activeDocument(), KisImage::addJob(), KisImage::bounds(), KisFilter::changedRect(), KisPaintDevice::colorSpace(), Filter::Private::configuration, InfoObject::configuration(), d, KisSharedPtr< T >::data(), KisImage::endStroke(), filterConfig(), Node::image(), KisFilterRegistry::instance(), Krita::instance(), KisPart::instance(), Node::locked(), Filter::Private::name, KisFilter::needsTransparentPixels(), Node::node(), Node::paintDevice(), KisImage::startStroke(), KoGenericRegistry< T >::value(), and KisImage::waitForDone().

Friends And Related Symbol Documentation

◆ FilterLayer

friend class FilterLayer
friend

Definition at line 98 of file Filter.h.

◆ FilterMask

friend class FilterMask
friend

Definition at line 99 of file Filter.h.

Member Data Documentation

◆ d

Private* const Filter::d
private

Definition at line 102 of file Filter.h.


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