8#include <KoCanvasResourceProvider.h>
10#include <kis_canvas_resource_provider.h>
11#include <kis_filter.h>
12#include <kis_properties_configuration.h>
13#include <kis_filter_configuration.h>
14#include <kis_filter_manager.h>
15#include <kis_filter_registry.h>
16#include <KisDocument.h>
17#include <kis_paint_device.h>
18#include <kis_paint_device_frames_interface.h>
22#include <strokes/kis_filter_stroke_strategy.h>
23#include <krita_utils.h>
24#include <KisGlobalResourcesInterface.h>
28#include "InfoObject.h"
31struct Filter::Private {
45 delete d->configuration;
49bool Filter::operator==(
const Filter &other)
const
51 return (d->name == other.d->name
52 && d->configuration == other.d->configuration);
55bool Filter::operator!=(
const Filter &other)
const
57 return !(operator==(other));
66void Filter::setName(
const QString &name)
69 delete d->configuration;
71 KisFilterSP
filter = KisFilterRegistry::instance()->value(d->name);
72 d->configuration =
new InfoObject(
filter->defaultConfiguration(KisGlobalResourcesInterface::instance()));
77 return d->configuration;
80void Filter::setConfiguration(
InfoObject* value)
82 d->configuration = value;
85bool Filter::apply(
Node *node,
int x,
int y,
int w,
int h)
87 if (node->
locked())
return false;
89 KisFilterSP
filter = KisFilterRegistry::instance()->value(d->name);
90 if (!filter)
return false;
92 KisPaintDeviceSP dev = node->paintDevice();
93 if (!dev)
return false;
96 KisFilterConfigurationSP config =
static_cast<KisFilterConfiguration*
>(d->configuration->configuration().data());
97 filter->process(dev, applyRect, config->cloneWithResourcesSnapshot());
101bool Filter::startFilter(
Node *node,
int x,
int y,
int w,
int h)
103 if (node->
locked())
return false;
105 KisFilterSP
filter = KisFilterRegistry::instance()->value(d->name);
106 if (!filter)
return false;
108 KisImageWSP image = node->image();
109 if (!image)
return false;
111 KisFilterConfigurationSP filterConfig =
static_cast<KisFilterConfiguration*
>(d->configuration->configuration().data());
113 image->waitForDone();
116 QRect applyRect = initialApplyRect;
118 KisPaintDeviceSP paintDevice = node->paintDevice();
119 if (paintDevice &&
filter->needsTransparentPixels(filterConfig.data(), paintDevice->colorSpace())) {
120 applyRect |= image->bounds();
123 KisResourcesSnapshotSP resources =
new KisResourcesSnapshot(image, node->node());
126 if (document && KisPart::instance()->viewCount(document->document()) > 0) {
128 if (view && view->document() == document->document()) {
129 resources =
new KisResourcesSnapshot(image, node->node(), view->resourceProvider()->resourceManager());
136 KisStrokeId currentStrokeId = image->startStroke(
new KisFilterStrokeStrategy(filter,
137 KisFilterConfigurationSP(filterConfig),
140 QRect processRect =
filter->changedRect(applyRect, filterConfig.data(), 0);
141 processRect &= image->bounds();
143 image->addJob(currentStrokeId,
new KisFilterStrokeStrategy::FilterJobData());
146 image->endStroke(currentStrokeId);
147 image->waitForDone();
152KisFilterConfigurationSP Filter::filterConfig()
154 KisFilterConfigurationSP config = KisFilterRegistry::instance()->get(d->name)->factoryConfiguration(KisGlobalResourcesInterface::instance());
The Document class encapsulates a Krita Document/Image.
InfoObject wrap a properties map.
QVariant property(const QString &key)
return the value for the property identified by key, or None if there is no such key.
QMap< QString, QVariant > properties() const
Return all properties this InfoObject manages.
Document * activeDocument() const
static Krita * instance()
instance retrieve the singleton instance of the Application object.
Node represents a layer or mask in a Krita image's Node hierarchy.
bool locked() const
locked checks whether the Node is locked.
QString name(StandardAction id)
QVariant property(const char *name) const const
QFuture< void > filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)