1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QSVGFILTER_P_H
5#define QSVGFILTER_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qsvgnode_p.h"
19#include "qtsvgglobal_p.h"
20#include "qsvgstructure_p.h"
21#include "qgenericmatrix.h"
22
23#include "QtCore/qlist.h"
24#include "QtCore/qhash.h"
25#include "QtGui/qvector4d.h"
26
27QT_BEGIN_NAMESPACE
28
29class Q_SVG_EXPORT QSvgFeFilterPrimitive : public QSvgStructureNode
30{
31public:
32 QSvgFeFilterPrimitive(QSvgNode *parent, QString input, QString result, const QSvgRectF &rect);
33 void drawCommand(QPainter *, QSvgExtraStates &) override {};
34 bool shouldDrawNode(QPainter *, QSvgExtraStates &) const override;
35 QRectF internalFastBounds(QPainter *, QSvgExtraStates &) const override { return QRectF(); }
36 QRectF internalBounds(QPainter *, QSvgExtraStates &) const override { return QRectF(); }
37 QRectF localSubRegion(const QRectF &itemBounds, const QRectF &filterBounds,
38 QtSvg::UnitTypes primitiveUnits, QtSvg::UnitTypes filterUnits) const;
39 QRectF globalSubRegion(QPainter *p,
40 const QRectF &itemBounds, const QRectF &filterBounds,
41 QtSvg::UnitTypes primitiveUnits, QtSvg::UnitTypes filterUnits) const;
42 void clipToTransformedBounds(QImage *buffer, QPainter *p, const QRectF &localRect) const;
43 virtual QImage apply(const QMap<QString, QImage> &sources,
44 QPainter *p, const QRectF &itemBounds, const QRectF &filterBounds,
45 QtSvg::UnitTypes primitiveUnits, QtSvg::UnitTypes filterUnits) const = 0;
46 virtual bool requiresSourceAlpha() const;
47 QString input() const {
48 return m_input;
49 }
50 QString result() const {
51 return m_result;
52 }
53
54 static const QSvgFeFilterPrimitive *castToFilterPrimitive(const QSvgNode *node);
55
56protected:
57 QString m_input;
58 QString m_result;
59 QSvgRectF m_rect;
60
61
62};
63
64class Q_SVG_EXPORT QSvgFeColorMatrix : public QSvgFeFilterPrimitive
65{
66public:
67 enum class ColorShiftType : quint8 {
68 Matrix,
69 Saturate,
70 HueRotate,
71 LuminanceToAlpha
72 };
73
74 typedef QGenericMatrix<5, 5, qreal> Matrix;
75 typedef QGenericMatrix<5, 1, qreal> Vector;
76
77 QSvgFeColorMatrix(QSvgNode *parent, QString input, QString result, const QSvgRectF &rect,
78 ColorShiftType type, Matrix matrix);
79 Type type() const override;
80 QImage apply(const QMap<QString, QImage> &sources,
81 QPainter *p, const QRectF &itemBounds, const QRectF &filterBounds,
82 QtSvg::UnitTypes primitiveUnits, QtSvg::UnitTypes filterUnits) const override;
83private:
84 ColorShiftType m_type;
85 Matrix m_matrix;
86};
87
88class Q_SVG_EXPORT QSvgFeGaussianBlur : public QSvgFeFilterPrimitive
89{
90public:
91 enum class EdgeMode : quint8 {
92 Duplicate,
93 Wrap,
94 None
95 };
96
97 QSvgFeGaussianBlur(QSvgNode *parent, QString input, QString result, const QSvgRectF &rect,
98 qreal stdDeviationX, qreal stdDeviationY, EdgeMode edgemode);
99 Type type() const override;
100 QImage apply(const QMap<QString, QImage> &sources,
101 QPainter *p, const QRectF &itemBounds, const QRectF &filterBounds,
102 QtSvg::UnitTypes primitiveUnits, QtSvg::UnitTypes filterUnits) const override;
103private:
104 qreal m_stdDeviationX;
105 qreal m_stdDeviationY;
106 EdgeMode m_edgemode;
107};
108
109class Q_SVG_EXPORT QSvgFeOffset : public QSvgFeFilterPrimitive
110{
111public:
112 QSvgFeOffset(QSvgNode *parent, QString input, QString result, const QSvgRectF &rect,
113 qreal dx, qreal dy);
114 Type type() const override;
115 QImage apply(const QMap<QString, QImage> &sources,
116 QPainter *p, const QRectF &itemBounds, const QRectF &filterBounds,
117 QtSvg::UnitTypes primitiveUnits, QtSvg::UnitTypes filterUnits) const override;
118private:
119 qreal m_dx;
120 qreal m_dy;
121};
122
123class Q_SVG_EXPORT QSvgFeMerge : public QSvgFeFilterPrimitive
124{
125public:
126 QSvgFeMerge(QSvgNode *parent, QString input, QString result, const QSvgRectF &rect);
127 Type type() const override;
128 QImage apply(const QMap<QString, QImage> &sources,
129 QPainter *p, const QRectF &itemBounds, const QRectF &filterBounds,
130 QtSvg::UnitTypes primitiveUnits, QtSvg::UnitTypes filterUnits) const override;
131 bool requiresSourceAlpha() const override;
132};
133
134class Q_SVG_EXPORT QSvgFeMergeNode : public QSvgFeFilterPrimitive
135{
136public:
137 QSvgFeMergeNode(QSvgNode *parent, QString input, QString result, const QSvgRectF &rect);
138 Type type() const override;
139 QImage apply(const QMap<QString, QImage> &sources,
140 QPainter *p, const QRectF &itemBounds, const QRectF &filterBounds,
141 QtSvg::UnitTypes primitiveUnits, QtSvg::UnitTypes filterUnits) const override;
142};
143
144class Q_SVG_EXPORT QSvgFeComposite : public QSvgFeFilterPrimitive
145{
146public:
147 enum class Operator : quint8 {
148 Over,
149 In,
150 Out,
151 Atop,
152 Xor,
153 Lighter,
154 Arithmetic
155 };
156 QSvgFeComposite(QSvgNode *parent, QString input, QString result, const QSvgRectF &rect,
157 QString input2, Operator op, QVector4D k);
158 Type type() const override;
159 QImage apply(const QMap<QString, QImage> &sources,
160 QPainter *p, const QRectF &itemBounds, const QRectF &filterBounds,
161 QtSvg::UnitTypes primitiveUnits, QtSvg::UnitTypes filterUnits) const override;
162 bool requiresSourceAlpha() const override;
163private:
164 QString m_input2;
165 Operator m_operator;
166 QVector4D m_k;
167};
168
169class Q_SVG_EXPORT QSvgFeFlood : public QSvgFeFilterPrimitive
170{
171public:
172 QSvgFeFlood(QSvgNode *parent, QString input, QString result, const QSvgRectF &rect, const QColor &color);
173 Type type() const override;
174 QImage apply(const QMap<QString, QImage> &sources,
175 QPainter *p, const QRectF &itemBounds, const QRectF &filterBounds,
176 QtSvg::UnitTypes primitiveUnits, QtSvg::UnitTypes filterUnits) const override;
177private:
178 QColor m_color;
179};
180
181class Q_SVG_EXPORT QSvgFeUnsupported : public QSvgFeFilterPrimitive
182{
183public:
184 QSvgFeUnsupported(QSvgNode *parent, QString input, QString result, const QSvgRectF &rect);
185 Type type() const override;
186 QImage apply(const QMap<QString, QImage> &sources,
187 QPainter *p, const QRectF &itemBounds, const QRectF &filterBounds,
188 QtSvg::UnitTypes primitiveUnits, QtSvg::UnitTypes filterUnits) const override;
189};
190
191QT_END_NAMESPACE
192
193#endif // QSVGFILTER_P_H
194

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of qtsvg/src/svg/qsvgfilter_p.h