File indexing completed on 2024-05-12 15:56:40
0001 /* This file is part of the KDE project 0002 * SPDX-FileCopyrightText: 2009 Cyrille Berger <cberger@cberger.net> 0003 * SPDX-FileCopyrightText: 2009 Jan Hambrecht <jaham@gmx.net> 0004 * 0005 * SPDX-License-Identifier: LGPL-2.1-or-later 0006 */ 0007 0008 #ifndef _KO_FILTER_EFFECT_H_ 0009 #define _KO_FILTER_EFFECT_H_ 0010 0011 class QImage; 0012 class QString; 0013 class QRectF; 0014 class KoXmlWriter; 0015 class KoFilterEffectRenderContext; 0016 class KoFilterEffectLoadingContext; 0017 0018 #include <QDomDocument> 0019 0020 #include "kritaflake_export.h" 0021 #include <QList> 0022 0023 /** 0024 * This is the base for filter effect (blur, invert...) that can be applied on a shape. 0025 * All sizes and coordinates of the filter effect are stored in object bounding box 0026 * coordinates, where (0,0) refers to the top-left corner of a shapes bounding rect 0027 * and (1,1) refers to the bottom-right corner. 0028 * When loading, a transformation matrix is given to convert from user space coordinates. 0029 * Another transformation matrix is given via the render context to convert back to 0030 * user space coordinates when applying the effect. 0031 * Using object bounding box coordinates internally makes it easy to share effects 0032 * between shapes or even between users via the filter effect resources. 0033 */ 0034 class KRITAFLAKE_EXPORT KoFilterEffect 0035 { 0036 public: 0037 KoFilterEffect(const QString &id, const QString &name); 0038 virtual ~KoFilterEffect(); 0039 0040 /// Returns the user visible name of the filter 0041 QString name() const; 0042 0043 /// Returns the unique id of the filter 0044 QString id() const; 0045 0046 /// Sets the region the filter is applied to in bounding box units 0047 void setFilterRect(const QRectF &filterRect); 0048 0049 /// Returns the region this filter is applied to in bounding box units 0050 QRectF filterRect() const; 0051 0052 /// Returns the region this filter is applied to for the given bounding rect 0053 QRectF filterRectForBoundingRect(const QRectF &boundingRect) const; 0054 0055 /** 0056 * Sets the name of the output image 0057 * 0058 * The name is used so that other effects can reference 0059 * the output of this effect as one of their input images. 0060 * 0061 * @param output the output image name 0062 */ 0063 void setOutput(const QString &output); 0064 0065 /// Returns the name of the output image 0066 QString output() const; 0067 0068 /** 0069 * Returns list of named input images of this filter effect. 0070 * 0071 * These names identify the input images for this filter effect. 0072 * These can be one of the keywords SourceGraphic, SourceAlpha, 0073 * BackgroundImage, BackgroundAlpha, FillPaint or StrokePaint, 0074 * as well as a named output of another filter effect in the stack. 0075 * An empty input list of the first effect in the stack default to 0076 * SourceGraphic, whereas on subsequent effects it defaults to the 0077 * result of the previous filter effect. 0078 */ 0079 QList<QString> inputs() const; 0080 0081 /// Adds a new input at the end of the input list 0082 void addInput(const QString &input); 0083 0084 /// Inserts an input at the giben position in the input list 0085 void insertInput(int index, const QString &input); 0086 0087 /// Sets an existing input to a new value 0088 void setInput(int index, const QString &input); 0089 0090 /// Removes an input from the given position in the input list 0091 void removeInput(int index); 0092 0093 /** 0094 * Return the required number of input images. 0095 * The default required number of input images is 1. 0096 * Derived classes should call setRequiredInputCount to set 0097 * a different number. 0098 */ 0099 int requiredInputCount() const; 0100 0101 /** 0102 * Returns the maximal number of input images. 0103 * The default maximal number of input images is 1. 0104 * Derived classes should call setMaximalInputCount to set 0105 * a different number. 0106 */ 0107 int maximalInputCount() const; 0108 0109 /** 0110 * Apply the effect on an image. 0111 * @param image the image the filter should be applied to 0112 * @param context the render context providing additional data 0113 */ 0114 virtual QImage processImage(const QImage &image, const KoFilterEffectRenderContext &context) const = 0; 0115 0116 /** 0117 * Apply the effect on a list of images. 0118 * @param images the images the filter should be applied to 0119 * @param context the render context providing additional data 0120 */ 0121 virtual QImage processImages(const QList<QImage> &images, const KoFilterEffectRenderContext &context) const; 0122 0123 /** 0124 * Loads data from given xml element. 0125 * @param element the xml element to load data from 0126 * @param context the loading context providing additional data 0127 * @return true if loading was successful, else false 0128 */ 0129 virtual bool load(const QDomElement &element, const KoFilterEffectLoadingContext &context) = 0; 0130 0131 /** 0132 * Writes custom data to given xml element. 0133 * @param writer the xml writer to write data to 0134 */ 0135 virtual void save(KoXmlWriter &writer) = 0; 0136 0137 protected: 0138 /// Sets the required number of input images 0139 void setRequiredInputCount(int count); 0140 0141 /// Sets the maximal number of input images 0142 void setMaximalInputCount(int count); 0143 0144 /** 0145 * Saves common filter attributes 0146 * 0147 * Saves result, subregion and input attributes. The input attribute 0148 * is only saved if required, maximal and actual input count equals 1. 0149 * All other filters have to write inputs on their own. 0150 */ 0151 void saveCommonAttributes(KoXmlWriter &writer); 0152 0153 private: 0154 class Private; 0155 Private* const d; 0156 }; 0157 0158 #endif // _KO_FILTER_EFFECT_H_