1 18 package org.apache.batik.bridge; 19 20 import java.awt.geom.Rectangle2D ; 21 import java.util.ArrayList ; 22 import java.util.List ; 23 import java.util.Map ; 24 25 import org.apache.batik.ext.awt.image.ARGBChannel; 26 import org.apache.batik.ext.awt.image.PadMode; 27 import org.apache.batik.ext.awt.image.renderable.DisplacementMapRable8Bit; 28 import org.apache.batik.ext.awt.image.renderable.Filter; 29 import org.apache.batik.ext.awt.image.renderable.PadRable; 30 import org.apache.batik.ext.awt.image.renderable.PadRable8Bit; 31 import org.apache.batik.gvt.GraphicsNode; 32 import org.w3c.dom.Element ; 33 34 40 public class SVGFeDisplacementMapElementBridge 41 extends AbstractSVGFilterPrimitiveElementBridge { 42 43 44 47 public SVGFeDisplacementMapElementBridge() {} 48 49 52 public String getLocalName() { 53 return SVG_FE_DISPLACEMENT_MAP_TAG; 54 } 55 56 74 public Filter createFilter(BridgeContext ctx, 75 Element filterElement, 76 Element filteredElement, 77 GraphicsNode filteredNode, 78 Filter inputFilter, 79 Rectangle2D filterRegion, 80 Map filterMap) { 81 82 float scale = convertNumber(filterElement, SVG_SCALE_ATTRIBUTE, 0); 84 85 ARGBChannel xChannelSelector = convertChannelSelector 87 (filterElement, SVG_X_CHANNEL_SELECTOR_ATTRIBUTE, ARGBChannel.A); 88 89 ARGBChannel yChannelSelector = convertChannelSelector 91 (filterElement, SVG_Y_CHANNEL_SELECTOR_ATTRIBUTE, ARGBChannel.A); 92 93 Filter in = getIn(filterElement, 95 filteredElement, 96 filteredNode, 97 inputFilter, 98 filterMap, 99 ctx); 100 if (in == null) { 101 return null; } 103 104 Filter in2 = getIn2(filterElement, 106 filteredElement, 107 filteredNode, 108 inputFilter, 109 filterMap, 110 ctx); 111 if (in2 == null) { 112 return null; } 114 115 Rectangle2D defaultRegion; 116 defaultRegion = (Rectangle2D )in.getBounds2D().clone(); 117 defaultRegion.add(in2.getBounds2D()); 118 Rectangle2D primitiveRegion 120 = SVGUtilities.convertFilterPrimitiveRegion(filterElement, 121 filteredElement, 122 filteredNode, 123 defaultRegion, 124 filterRegion, 125 ctx); 126 127 PadRable pad 128 = new PadRable8Bit(in, primitiveRegion, PadMode.ZERO_PAD); 129 130 List srcs = new ArrayList (2); 132 srcs.add(pad); 133 srcs.add(in2); 134 Filter displacementMap = new DisplacementMapRable8Bit 135 (srcs, scale, xChannelSelector, yChannelSelector); 136 137 handleColorInterpolationFilters(displacementMap, filterElement); 139 140 PadRable filter = new PadRable8Bit 141 (displacementMap, primitiveRegion, PadMode.ZERO_PAD); 142 143 updateFilterMap(filterElement, filter, filterMap); 145 146 return filter; 147 } 148 149 156 protected static 157 ARGBChannel convertChannelSelector(Element filterElement, 158 String attrName, 159 ARGBChannel defaultChannel) { 160 161 String s = filterElement.getAttributeNS(null, attrName); 162 if (s.length() == 0) { 163 return defaultChannel; 164 } 165 if (SVG_A_VALUE.equals(s)) { 166 return ARGBChannel.A; 167 } 168 if (SVG_R_VALUE.equals(s)) { 169 return ARGBChannel.R; 170 } 171 if (SVG_G_VALUE.equals(s)) { 172 return ARGBChannel.G; 173 } 174 if (SVG_B_VALUE.equals(s)) { 175 return ARGBChannel.B; 176 } 177 throw new BridgeException(filterElement, ERR_ATTRIBUTE_VALUE_MALFORMED, 178 new Object [] {attrName, s}); 179 } 180 } 181 | Popular Tags |