001package com.hfg.svg.filtereffect;
002
003import com.hfg.graphics.ColorChannel;
004import com.hfg.svg.AbstractSvgNode;
005import com.hfg.svg.SVG;
006import com.hfg.svg.SvgAttr;
007import com.hfg.util.collection.CollectionUtil;
008import com.hfg.xml.XMLAttribute;
009import com.hfg.xml.XMLTag;
010
011//------------------------------------------------------------------------------
012/**
013 Object representation of an SVG (Scalable Vector Graphics) 'feDisplacementMap' filter effect tag.
014 <div>
015 From <a href='http://www.w3.org/TR/2003/REC-SVG11-20030114/filters.html#feDisplacementMap'>
016 http://www.w3.org/TR/2003/REC-SVG11-20030114/filters.html#feDisplacementMap</a>:
017 </div>
018 <div style='font-style:italic'>
019 "This filter primitive uses the pixels values from the image from in2 to spatially displace
020 the image from in. This is the transformation to be performed:
021 <pre>
022 P'(x,y) &lt;- P( x + scale * (XC(x,y) - .5), y + scale * (YC(x,y) - .5))
023 </pre>
024 <p>
025 where P(x,y) is the input image, in, and P'(x,y) is the destination. XC(x,y) and YC(x,y)
026 are the component values of the designated by the xChannelSelector and yChannelSelector.
027 For example, to use the R component of in2 to control displacement in x and the G component of
028 Image2 to control displacement in y, set xChannelSelector to "R" and yChannelSelector to "G".
029 </p>
030 <p>
031 The displacement map defines the inverse of the mapping performed.
032 </p>
033 <p>
034 The calculations using the pixel values from in2 are performed using non-premultiplied color values.
035 If the image from in2 consists of premultiplied color values, those values are automatically converted
036 into non-premultiplied color values before performing this operation.
037 </p>
038 <p>
039 This filter can have arbitrary non-localized effect on the input which might require substantial
040 buffering in the processing pipeline. However with this formulation, any intermediate buffering
041 needs can be determined by scale which represents the maximum range of displacement in either x or y.
042 </p>
043 <p>
044 When applying this filter, the source pixel location will often lie between several source pixels.
045 In this case it is recommended that high quality viewers apply an interpolent on the surrounding pixels,
046 for example bilinear or bicubic, rather than simply selecting the nearest source pixel. Depending
047 on the speed of the available interpolents, this choice may be affected by the 'image-rendering' property setting."
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 SvgFeDisplacementMap extends AbstractSvgNode
074{
075
076   //###########################################################################
077   // CONSTRUCTORS
078   //###########################################################################
079
080   //---------------------------------------------------------------------------
081   public SvgFeDisplacementMap()
082   {
083      super(SVG.feDisplacementMap);
084   }
085
086   //---------------------------------------------------------------------------
087   public SvgFeDisplacementMap(XMLTag inXMLTag)
088   {
089      this();
090      initFromXMLTag(inXMLTag);
091   }
092
093   //###########################################################################
094   // PUBLIC METHODS
095   //###########################################################################
096
097
098   //---------------------------------------------------------------------------
099   public SvgFeDisplacementMap setColorInterpolationFilters(ColorInterpolationFilters inValue)
100   {
101      setAttribute(SvgAttr.colorInterpolationFilters, inValue);
102      return this;
103   }
104
105
106   //---------------------------------------------------------------------------
107   /**
108    Displacement scale factor. The amount is expressed in the coordinate system
109    established by attribute primitiveUnits on the 'filter' element.
110    When the value of this attribute is 0, this operation has no effect on the source image.
111    If the attribute is not specified, then the effect is as if a value of 0 were specified.
112    */
113   public SvgFeDisplacementMap setScale(int inValue)
114   {
115      setAttribute(SvgAttr.scale, inValue);
116      return this;
117   }
118
119
120   //---------------------------------------------------------------------------
121   /**
122    Indicates which channel from <code>in2</code> to use to displace the pixels in <code>in</code> along the x-axis.
123    */
124   public SvgFeDisplacementMap setXChannelSelector(ColorChannel inValue)
125   {
126      setAttribute(SvgAttr.xChannelSelector, inValue.name());
127      return this;
128   }
129
130
131   //---------------------------------------------------------------------------
132   /**
133    Indicates which channel from <code>in2</code> to use to displace the pixels in <code>in</code> along the y-axis.
134    */
135   public SvgFeDisplacementMap setYChannelSelector(ColorChannel inValue)
136   {
137      setAttribute(SvgAttr.yChannelSelector, inValue.name());
138      return this;
139   }
140
141
142   //---------------------------------------------------------------------------
143   public SvgFeDisplacementMap setIn(FeInput inValue)
144   {
145      setAttribute(SvgAttr.in, inValue.toString());
146      return this;
147   }
148
149
150   //---------------------------------------------------------------------------
151   /**
152    The second input image, which is used to displace the pixels in the image from attribute <code>in</code>.
153    This attribute can take on the same values as the <code>in</code> attribute.
154    */
155   public SvgFeDisplacementMap setIn2(FeInput inValue)
156   {
157      setAttribute(SvgAttr.in2, inValue.toString());
158      return this;
159   }
160
161   //---------------------------------------------------------------------------
162   public SvgFeDisplacementMap setHeight(int inValue)
163   {
164      setAttribute(SvgAttr.height, inValue);
165      return this;
166   }
167
168   //---------------------------------------------------------------------------
169   public SvgFeDisplacementMap setHeight(String inValue)
170   {
171      setAttribute(SvgAttr.height, inValue);
172      return this;
173   }
174
175   //---------------------------------------------------------------------------
176   public SvgFeDisplacementMap setResult(String inValue)
177   {
178      setAttribute(SvgAttr.result, inValue);
179      return this;
180   }
181
182   //---------------------------------------------------------------------------
183   public SvgFeDisplacementMap setWidth(int inValue)
184   {
185      setAttribute(SvgAttr.width, inValue);
186      return this;
187   }
188
189   //---------------------------------------------------------------------------
190   public SvgFeDisplacementMap setWidth(String inValue)
191   {
192      setAttribute(SvgAttr.width, inValue);
193      return this;
194   }
195
196   //---------------------------------------------------------------------------
197   public SvgFeDisplacementMap setX(int inValue)
198   {
199      setAttribute(SvgAttr.x, inValue);
200      return this;
201   }
202
203   //---------------------------------------------------------------------------
204   public SvgFeDisplacementMap setX(String inValue)
205   {
206      setAttribute(SvgAttr.x, inValue);
207      return this;
208   }
209
210
211   //---------------------------------------------------------------------------
212   public SvgFeDisplacementMap setY(int inValue)
213   {
214      setAttribute(SvgAttr.y, inValue);
215      return this;
216   }
217
218   //---------------------------------------------------------------------------
219   public SvgFeDisplacementMap setY(String inValue)
220   {
221      setAttribute(SvgAttr.y, inValue);
222      return this;
223   }
224
225}