1 18 package org.apache.batik.ext.awt.image.renderable; 19 20 import java.awt.Composite ; 21 import java.awt.Graphics2D ; 22 import java.awt.geom.Rectangle2D ; 23 import java.awt.image.RenderedImage ; 24 import java.awt.image.renderable.RenderContext ; 25 26 import org.apache.batik.ext.awt.image.GraphicsUtil; 27 import org.apache.batik.ext.awt.image.PadMode; 28 import org.apache.batik.ext.awt.image.SVGComposite; 29 30 46 public class FilterChainRable8Bit extends AbstractRable 47 implements FilterChainRable, PaintRable { 48 51 private int filterResolutionX; 52 53 56 private int filterResolutionY; 57 58 61 private Filter chainSource; 62 63 66 private FilterResRable filterRes; 67 68 71 private PadRable crop; 72 73 76 private Rectangle2D filterRegion; 77 78 81 public FilterChainRable8Bit(Filter source, Rectangle2D filterRegion){ 82 if(source == null){ 83 throw new IllegalArgumentException (); 84 } 85 if(filterRegion == null){ 86 throw new IllegalArgumentException (); 87 } 88 89 Rectangle2D padRect = (Rectangle2D )filterRegion.clone(); 92 crop = new PadRable8Bit(source, padRect, 93 PadMode.ZERO_PAD); 94 95 this.chainSource = source; 98 this.filterRegion = filterRegion; 99 100 init(crop); 104 105 } 106 107 110 public int getFilterResolutionX(){ 111 return filterResolutionX; 112 } 113 114 122 public void setFilterResolutionX(int filterResolutionX){ 123 touch(); 124 this.filterResolutionX = filterResolutionX; 125 126 setupFilterRes(); 127 } 128 129 132 public int getFilterResolutionY(){ 133 return filterResolutionY; 134 } 135 136 142 public void setFilterResolutionY(int filterResolutionY){ 143 touch(); 144 this.filterResolutionY = filterResolutionY; 145 setupFilterRes(); 146 } 147 148 153 private void setupFilterRes(){ 154 if(filterResolutionX >=0){ 155 if(filterRes == null){ 156 filterRes = new FilterResRable8Bit(); 157 filterRes.setSource(chainSource); 158 } 159 160 filterRes.setFilterResolutionX(filterResolutionX); 161 filterRes.setFilterResolutionY(filterResolutionY); 162 } 163 else{ 164 filterRes = null; 166 } 167 168 if(filterRes != null){ 171 crop.setSource(filterRes); 172 } 173 else{ 174 crop.setSource(chainSource); 175 } 176 } 177 178 182 public void setFilterRegion(Rectangle2D filterRegion){ 183 if(filterRegion == null){ 184 throw new IllegalArgumentException (); 185 } 186 touch(); 187 this.filterRegion = filterRegion; 188 } 189 190 193 public Rectangle2D getFilterRegion(){ 194 return filterRegion; 195 } 196 197 203 public Filter getSource() { 204 return (Filter)crop; 205 } 206 207 211 public void setSource(Filter chainSource) { 212 if(chainSource == null){ 213 throw new IllegalArgumentException ("Null Source for Filter Chain"); 214 } 215 touch(); 216 this.chainSource = chainSource; 217 218 if(filterRes == null){ 219 crop.setSource(chainSource); 220 } 221 else{ 222 filterRes.setSource(chainSource); 223 } 224 } 225 226 229 public Rectangle2D getBounds2D(){ 230 return (Rectangle2D )filterRegion.clone(); 231 } 232 233 243 public boolean paintRable(Graphics2D g2d) { 244 Composite c = g2d.getComposite(); 247 if (!SVGComposite.OVER.equals(c)) 248 return false; 249 250 GraphicsUtil.drawImage(g2d, getSource()); 251 252 return true; 253 } 254 255 public RenderedImage createRendering(RenderContext context){ 256 return crop.createRendering(context); 257 } 258 } 259 | Popular Tags |