1 /*
2 Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005 Rob Buis <buis@kde.org>
4 2005 Eric Seidel <eric@webkit.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 aint with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20 */
21
22 #include "config.h"
23
24 #if ENABLE(SVG) && ENABLE(FILTERS)
25 #include "SVGFEConvolveMatrix.h"
26 #include "Filter.h"
27 #include "SVGRenderTreeAsText.h"
28
29 namespace WebCore {
30
FEConvolveMatrix(FilterEffect * in,FilterEffect * in2,const FloatSize & kernelSize,const float & divisor,const float & bias,const FloatSize & targetOffset,EdgeModeType edgeMode,const FloatPoint & kernelUnitLength,bool preserveAlpha,const Vector<float> & kernelMatrix)31 FEConvolveMatrix::FEConvolveMatrix(FilterEffect* in, FilterEffect* in2, const FloatSize& kernelSize,
32 const float& divisor, const float& bias, const FloatSize& targetOffset, EdgeModeType edgeMode,
33 const FloatPoint& kernelUnitLength, bool preserveAlpha, const Vector<float>& kernelMatrix)
34 : FilterEffect()
35 , m_in(in)
36 , m_in2(in2)
37 , m_kernelSize(kernelSize)
38 , m_divisor(divisor)
39 , m_bias(bias)
40 , m_targetOffset(targetOffset)
41 , m_edgeMode(edgeMode)
42 , m_kernelUnitLength(kernelUnitLength)
43 , m_preserveAlpha(preserveAlpha)
44 , m_kernelMatrix(kernelMatrix)
45 {
46 }
47
create(FilterEffect * in,FilterEffect * in2,const FloatSize & kernelSize,const float & divisor,const float & bias,const FloatSize & targetOffset,EdgeModeType edgeMode,const FloatPoint & kernelUnitLength,bool preserveAlpha,const Vector<float> & kernelMatrix)48 PassRefPtr<FEConvolveMatrix> FEConvolveMatrix::create(FilterEffect* in, FilterEffect* in2, const FloatSize& kernelSize,
49 const float& divisor, const float& bias, const FloatSize& targetOffset, EdgeModeType edgeMode,
50 const FloatPoint& kernelUnitLength, bool preserveAlpha, const Vector<float>& kernelMatrix)
51 {
52 return adoptRef(new FEConvolveMatrix(in, in2, kernelSize, divisor, bias, targetOffset, edgeMode, kernelUnitLength,
53 preserveAlpha, kernelMatrix));
54 }
55
56
kernelSize() const57 FloatSize FEConvolveMatrix::kernelSize() const
58 {
59 return m_kernelSize;
60 }
61
setKernelSize(FloatSize kernelSize)62 void FEConvolveMatrix::setKernelSize(FloatSize kernelSize)
63 {
64 m_kernelSize = kernelSize;
65 }
66
kernel() const67 const Vector<float>& FEConvolveMatrix::kernel() const
68 {
69 return m_kernelMatrix;
70 }
71
setKernel(const Vector<float> & kernel)72 void FEConvolveMatrix::setKernel(const Vector<float>& kernel)
73 {
74 m_kernelMatrix = kernel;
75 }
76
divisor() const77 float FEConvolveMatrix::divisor() const
78 {
79 return m_divisor;
80 }
81
setDivisor(float divisor)82 void FEConvolveMatrix::setDivisor(float divisor)
83 {
84 m_divisor = divisor;
85 }
86
bias() const87 float FEConvolveMatrix::bias() const
88 {
89 return m_bias;
90 }
91
setBias(float bias)92 void FEConvolveMatrix::setBias(float bias)
93 {
94 m_bias = bias;
95 }
96
targetOffset() const97 FloatSize FEConvolveMatrix::targetOffset() const
98 {
99 return m_targetOffset;
100 }
101
setTargetOffset(FloatSize targetOffset)102 void FEConvolveMatrix::setTargetOffset(FloatSize targetOffset)
103 {
104 m_targetOffset = targetOffset;
105 }
106
edgeMode() const107 EdgeModeType FEConvolveMatrix::edgeMode() const
108 {
109 return m_edgeMode;
110 }
111
setEdgeMode(EdgeModeType edgeMode)112 void FEConvolveMatrix::setEdgeMode(EdgeModeType edgeMode)
113 {
114 m_edgeMode = edgeMode;
115 }
116
kernelUnitLength() const117 FloatPoint FEConvolveMatrix::kernelUnitLength() const
118 {
119 return m_kernelUnitLength;
120 }
121
setKernelUnitLength(FloatPoint kernelUnitLength)122 void FEConvolveMatrix::setKernelUnitLength(FloatPoint kernelUnitLength)
123 {
124 m_kernelUnitLength = kernelUnitLength;
125 }
126
preserveAlpha() const127 bool FEConvolveMatrix::preserveAlpha() const
128 {
129 return m_preserveAlpha;
130 }
131
setPreserveAlpha(bool preserveAlpha)132 void FEConvolveMatrix::setPreserveAlpha(bool preserveAlpha)
133 {
134 m_preserveAlpha = preserveAlpha;
135 }
136
apply(Filter *)137 void FEConvolveMatrix::apply(Filter*)
138 {
139 }
140
dump()141 void FEConvolveMatrix::dump()
142 {
143 }
144
operator <<(TextStream & ts,EdgeModeType t)145 static TextStream& operator<<(TextStream& ts, EdgeModeType t)
146 {
147 switch (t)
148 {
149 case EDGEMODE_UNKNOWN:
150 ts << "UNKNOWN";break;
151 case EDGEMODE_DUPLICATE:
152 ts << "DUPLICATE";break;
153 case EDGEMODE_WRAP:
154 ts << "WRAP"; break;
155 case EDGEMODE_NONE:
156 ts << "NONE"; break;
157 }
158 return ts;
159 }
160
externalRepresentation(TextStream & ts) const161 TextStream& FEConvolveMatrix::externalRepresentation(TextStream& ts) const
162 {
163 ts << "[type=CONVOLVE-MATRIX] ";
164 FilterEffect::externalRepresentation(ts);
165 ts << " [order " << m_kernelSize << "]"
166 << " [kernel matrix=" << m_kernelMatrix << "]"
167 << " [divisor=" << m_divisor << "]"
168 << " [bias=" << m_bias << "]"
169 << " [target " << m_targetOffset << "]"
170 << " [edge mode=" << m_edgeMode << "]"
171 << " [kernel unit length " << m_kernelUnitLength << "]"
172 << " [preserve alpha=" << m_preserveAlpha << "]";
173 return ts;
174 }
175
176 }; // namespace WebCore
177
178 #endif // ENABLE(SVG) && ENABLE(FILTERS)
179