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