1 18 package org.apache.batik.ext.awt.image.renderable; 19 20 import java.awt.Graphics2D ; 21 import java.awt.RenderingHints ; 22 import java.awt.Shape ; 23 import java.awt.geom.AffineTransform ; 24 import java.awt.geom.NoninvertibleTransformException ; 25 import java.awt.geom.Rectangle2D ; 26 import java.awt.image.RenderedImage ; 27 import java.awt.image.renderable.RenderContext ; 28 29 import org.apache.batik.ext.awt.image.GraphicsUtil; 30 31 38 public class AffineRable8Bit 39 extends AbstractRable 40 implements AffineRable, PaintRable { 41 42 AffineTransform affine; 43 AffineTransform invAffine; 44 45 public AffineRable8Bit(Filter src, AffineTransform affine) { 46 init(src); 47 setAffine(affine); 48 } 49 50 public Rectangle2D getBounds2D() { 51 Filter src = getSource(); 52 Rectangle2D r = src.getBounds2D(); 53 return affine.createTransformedShape(r).getBounds2D(); 54 } 55 58 public Filter getSource() { 59 return (Filter)srcs.get(0); 60 } 61 62 66 public void setSource(Filter src) { 67 init(src); 68 } 69 70 74 public void setAffine(AffineTransform affine) { 75 touch(); 76 this.affine = affine; 77 try { 78 invAffine = affine.createInverse(); 79 } catch (NoninvertibleTransformException e) { 80 invAffine = null; 81 } 82 } 83 84 88 public AffineTransform getAffine() { 89 return (AffineTransform )affine.clone(); 90 } 91 92 101 public boolean paintRable(Graphics2D g2d) { 102 AffineTransform at = g2d.getTransform(); 103 104 g2d.transform(getAffine()); 105 GraphicsUtil.drawImage(g2d, getSource()); 106 107 g2d.setTransform(at); 108 109 return true; 110 } 111 112 113 public RenderedImage createRendering(RenderContext rc) { 114 if (invAffine == null) return null; 116 117 RenderingHints rh = rc.getRenderingHints(); 119 if (rh == null) rh = new RenderingHints (null); 120 121 Shape aoi = rc.getAreaOfInterest(); 123 if (aoi != null) 124 aoi = invAffine.createTransformedShape(aoi); 125 126 AffineTransform at = rc.getTransform(); 128 at.concatenate(affine); 129 130 return getSource().createRendering(new RenderContext (at, aoi, rh)); 132 } 133 134 public Shape getDependencyRegion(int srcIndex, Rectangle2D outputRgn) { 135 if (srcIndex != 0) 136 throw new IndexOutOfBoundsException ("Affine only has one input"); 137 if (invAffine == null) 138 return null; 139 return invAffine.createTransformedShape(outputRgn); 140 } 141 142 public Shape getDirtyRegion(int srcIndex, Rectangle2D inputRgn) { 143 if (srcIndex != 0) 144 throw new IndexOutOfBoundsException ("Affine only has one input"); 145 return affine.createTransformedShape(inputRgn); 146 } 147 148 } 149 | Popular Tags |