1 18 package org.apache.batik.extension.svg; 19 20 import java.awt.geom.Rectangle2D ; 21 import java.util.Map ; 22 23 import org.apache.batik.bridge.AbstractSVGFilterPrimitiveElementBridge; 24 import org.apache.batik.bridge.Bridge; 25 import org.apache.batik.bridge.BridgeContext; 26 import org.apache.batik.bridge.BridgeException; 27 import org.apache.batik.bridge.SVGUtilities; 28 import org.apache.batik.ext.awt.image.PadMode; 29 import org.apache.batik.ext.awt.image.renderable.Filter; 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 39 public class BatikHistogramNormalizationElementBridge 40 extends AbstractSVGFilterPrimitiveElementBridge 41 implements BatikExtConstants { 42 43 46 public BatikHistogramNormalizationElementBridge() { } 47 48 51 public String getNamespaceURI() { 52 return BATIK_EXT_NAMESPACE_URI; 53 } 54 55 58 public String getLocalName() { 59 return BATIK_EXT_HISTOGRAM_NORMALIZATION_TAG; 60 } 61 62 65 public Bridge getInstance() { 66 return new BatikHistogramNormalizationElementBridge(); 67 } 68 69 87 public Filter createFilter(BridgeContext ctx, 88 Element filterElement, 89 Element filteredElement, 90 GraphicsNode filteredNode, 91 Filter inputFilter, 92 Rectangle2D filterRegion, 93 Map filterMap) { 94 95 Filter in = getIn(filterElement, 97 filteredElement, 98 filteredNode, 99 inputFilter, 100 filterMap, 101 ctx); 102 if (in == null) { 103 return null; } 105 106 Filter sourceGraphics = (Filter)filterMap.get(SVG_SOURCE_GRAPHIC_VALUE); 110 Rectangle2D defaultRegion; 111 if (in == sourceGraphics) { 112 defaultRegion = filterRegion; 113 } else { 114 defaultRegion = in.getBounds2D(); 115 } 116 117 Rectangle2D primitiveRegion 118 = SVGUtilities.convertFilterPrimitiveRegion(filterElement, 119 filteredElement, 120 filteredNode, 121 defaultRegion, 122 filterRegion, 123 ctx); 124 125 float trim = 1; 126 String s = filterElement.getAttributeNS 127 (null, BATIK_EXT_TRIM_ATTRIBUTE); 128 129 if (s.length() != 0) { 130 try { 131 trim = SVGUtilities.convertSVGNumber(s); 132 } catch (NumberFormatException ex) { 133 throw new BridgeException 134 (filterElement, ERR_ATTRIBUTE_VALUE_MALFORMED, 135 new Object [] {BATIK_EXT_TRIM_ATTRIBUTE, s}); 136 } 137 } 138 139 if (trim < 0) trim =0; 140 else if (trim > 100) trim=100; 141 142 Filter filter = in; 143 filter = new BatikHistogramNormalizationFilter8Bit(filter, trim/100); 144 145 filter = new PadRable8Bit(filter, primitiveRegion, PadMode.ZERO_PAD); 146 147 updateFilterMap(filterElement, filter, filterMap); 149 150 handleColorInterpolationFilters(filter, filterElement); 152 153 return filter; 154 } 155 156 166 protected static int convertSides(Element filterElement, 167 String attrName, 168 int defaultValue) { 169 String s = filterElement.getAttributeNS(null, attrName); 170 if (s.length() == 0) { 171 return defaultValue; 172 } else { 173 int ret = 0; 174 try { 175 ret = SVGUtilities.convertSVGInteger(s); 176 } catch (NumberFormatException ex) { 177 throw new BridgeException 178 (filterElement, ERR_ATTRIBUTE_VALUE_MALFORMED, 179 new Object [] {attrName, s}); 180 } 181 182 if (ret <3) 183 throw new BridgeException 184 (filterElement, ERR_ATTRIBUTE_VALUE_MALFORMED, 185 new Object [] {attrName, s}); 186 return ret; 187 } 188 } 189 } 190 | Popular Tags |