001package com.hfg.svg.filtereffect;
002
003import com.hfg.svg.AbstractSvgNode;
004import com.hfg.svg.SVG;
005import com.hfg.svg.SvgAttr;
006import com.hfg.xml.XMLTag;
007
008//------------------------------------------------------------------------------
009/**
010 Object representation of an SVG (Scalable Vector Graphics) 'feConvolveMatrix' filter effect tag.
011 <div>
012 From <a href='http://www.w3.org/TR/2003/REC-SVG11-20030114/filters.html#feConvolveMatrix'>
013 http://www.w3.org/TR/2003/REC-SVG11-20030114/filters.html#feConvolveMatrix</a>:
014 </div>
015 <div style='font-style:italic'>
016 <p>
017 "feConvolveMatrix applies a matrix convolution filter effect. A convolution combines pixels
018 in the input image with neighboring pixels to produce a resulting image. A wide variety of
019 imaging operations can be achieved through convolutions, including blurring, edge detection,
020 sharpening, embossing and beveling.
021 </p>
022 <p>
023 A matrix convolution is based on an n-by-m matrix (the convolution kernel) which describes how a
024 given pixel value in the input image is combined with its neighboring pixel values to produce a
025 resulting pixel value. Each result pixel is determined by applying the kernel matrix to the
026 corresponding source pixel and its neighboring pixels. The basic convolution formula which is
027 applied to each color value for a given pixel is:
028 </p>
029 <code>
030 RESULT<sub>X,Y</sub> = (
031              SUM <sub>I=0 to [orderY-1]</sub> {
032                SUM <sub>J=0 to [orderX-1]</sub> {
033                  SOURCE <sub>X-targetX+J, Y-targetY+I</sub> *  kernelMatrix<sub>orderX-J-1,  orderY-I-1</sub>
034                }
035              }
036            ) /  divisor +  bias
037 </code>
038 <p>
039 where "orderX" and "orderY" represent the X and Y values for the order attribute, "targetX" represents
040 the value of the targetX attribute, "targetY" represents the value of the targetY attribute,
041 "kernelMatrix" represents the value of the kernelMatrix attribute, "divisor" represents the value
042 of the divisor attribute, and "bias" represents the value of the bias attribute.
043 </p>
044 <p>
045 Note in the above formulas that the values in the kernel matrix are applied such that the kernel matrix
046 is rotated 180 degrees relative to the source and destination images in order to match convolution theory
047 as described in many computer graphics textbooks."
048 </p>
049 </div>
050 @author J. Alex Taylor, hairyfatguy.com
051 */
052//------------------------------------------------------------------------------
053// com.hfg XML/HTML Coding Library
054//
055// This library is free software; you can redistribute it and/or
056// modify it under the terms of the GNU Lesser General Public
057// License as published by the Free Software Foundation; either
058// version 2.1 of the License, or (at your option) any later version.
059//
060// This library is distributed in the hope that it will be useful,
061// but WITHOUT ANY WARRANTY; without even the implied warranty of
062// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
063// Lesser General Public License for more details.
064//
065// You should have received a copy of the GNU Lesser General Public
066// License along with this library; if not, write to the Free Software
067// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
068//
069// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
070// jataylor@hairyfatguy.com
071//------------------------------------------------------------------------------
072
073public class SvgFeConvolveMatrix extends AbstractSvgNode
074{
075   //###########################################################################
076   // CONSTRUCTORS
077   //###########################################################################
078
079   //---------------------------------------------------------------------------
080   public SvgFeConvolveMatrix()
081   {
082      super(SVG.feConvolveMatrix);
083   }
084
085   //---------------------------------------------------------------------------
086   public SvgFeConvolveMatrix(XMLTag inXMLTag)
087   {
088      this();
089      initFromXMLTag(inXMLTag);
090   }
091
092   //###########################################################################
093   // PUBLIC METHODS
094   //###########################################################################
095
096
097   //---------------------------------------------------------------------------
098   public SvgFeConvolveMatrix setColorInterpolationFilters(ColorInterpolationFilters inValue)
099   {
100      setAttribute(SvgAttr.colorInterpolationFilters, inValue);
101      return this;
102   }
103
104   //---------------------------------------------------------------------------
105   public SvgFeConvolveMatrix setIn(FeInput inValue)
106   {
107      setAttribute(SvgAttr.in, inValue);
108      return this;
109   }
110
111   //---------------------------------------------------------------------------
112   public SvgFeConvolveMatrix setOrder(int inValue)
113   {
114      return setOrder(inValue + "");
115   }
116
117   //---------------------------------------------------------------------------
118   public SvgFeConvolveMatrix setOrder(String inValue)
119   {
120      setAttribute(SvgAttr.order, inValue);
121      return this;
122   }
123
124   //---------------------------------------------------------------------------
125   public SvgFeConvolveMatrix setKernelMatrix(String inValue)
126   {
127      setAttribute(SvgAttr.kernelMatrix, inValue);
128      return this;
129   }
130
131   //---------------------------------------------------------------------------
132   public SvgFeConvolveMatrix setDivisor(float inValue)
133   {
134      setAttribute(SvgAttr.divisor, inValue);
135      return this;
136   }
137
138   //---------------------------------------------------------------------------
139   public SvgFeConvolveMatrix setBias(float inValue)
140   {
141      setAttribute(SvgAttr.bias, inValue);
142      return this;
143   }
144
145   //---------------------------------------------------------------------------
146   public SvgFeConvolveMatrix setTargetX(float inValue)
147   {
148      setAttribute(SvgAttr.targetX, inValue);
149      return this;
150   }
151
152   //---------------------------------------------------------------------------
153   public SvgFeConvolveMatrix setTargetY(float inValue)
154   {
155      setAttribute(SvgAttr.targetY, inValue);
156      return this;
157   }
158
159   //---------------------------------------------------------------------------
160   public SvgFeConvolveMatrix setEdgeMode(MatrixEdgeMode inValue)
161   {
162      setAttribute(SvgAttr.edgeMode, inValue);
163      return this;
164   }
165
166   //---------------------------------------------------------------------------
167   public SvgFeConvolveMatrix setKernelUnitLength(String inValue)
168   {
169      setAttribute(SvgAttr.kernelUnitLength, inValue);
170      return this;
171   }
172
173   //---------------------------------------------------------------------------
174   public SvgFeConvolveMatrix setPreserveAlpha(boolean inValue)
175   {
176      setAttribute(SvgAttr.preserveAlpha, inValue);
177      return this;
178   }
179
180
181   //---------------------------------------------------------------------------
182   public SvgFeConvolveMatrix setHeight(int inValue)
183   {
184      setAttribute(SvgAttr.height, inValue);
185      return this;
186   }
187
188   //---------------------------------------------------------------------------
189   public SvgFeConvolveMatrix setHeight(String inValue)
190   {
191      setAttribute(SvgAttr.height, inValue);
192      return this;
193   }
194
195   //---------------------------------------------------------------------------
196   public SvgFeConvolveMatrix setResult(String inValue)
197   {
198      setAttribute(SvgAttr.result, inValue);
199      return this;
200   }
201
202   //---------------------------------------------------------------------------
203   public SvgFeConvolveMatrix setWidth(int inValue)
204   {
205      setAttribute(SvgAttr.width, inValue);
206      return this;
207   }
208
209   //---------------------------------------------------------------------------
210   public SvgFeConvolveMatrix setWidth(String inValue)
211   {
212      setAttribute(SvgAttr.width, inValue);
213      return this;
214   }
215
216   //---------------------------------------------------------------------------
217   public SvgFeConvolveMatrix setX(int inValue)
218   {
219      setAttribute(SvgAttr.x, inValue);
220      return this;
221   }
222
223   //---------------------------------------------------------------------------
224   public SvgFeConvolveMatrix setX(String inValue)
225   {
226      setAttribute(SvgAttr.x, inValue);
227      return this;
228   }
229
230
231   //---------------------------------------------------------------------------
232   public SvgFeConvolveMatrix setY(int inValue)
233   {
234      setAttribute(SvgAttr.y, inValue);
235      return this;
236   }
237
238   //---------------------------------------------------------------------------
239   public SvgFeConvolveMatrix setY(String inValue)
240   {
241      setAttribute(SvgAttr.y, inValue);
242      return this;
243   }
244}