1 18 package org.apache.batik.gvt.filter; 19 20 import java.awt.geom.Rectangle2D ; 21 import java.awt.image.RenderedImage ; 22 import java.awt.image.renderable.RenderContext ; 23 24 import org.apache.batik.ext.awt.image.GraphicsUtil; 25 import org.apache.batik.ext.awt.image.PadMode; 26 import org.apache.batik.ext.awt.image.renderable.AbstractRable; 27 import org.apache.batik.ext.awt.image.renderable.Filter; 28 import org.apache.batik.ext.awt.image.renderable.FilterAsAlphaRable; 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.ext.awt.image.rendered.CachableRed; 32 import org.apache.batik.ext.awt.image.rendered.MultiplyAlphaRed; 33 import org.apache.batik.ext.awt.image.rendered.RenderedImageCachableRed; 34 import org.apache.batik.gvt.GraphicsNode; 35 36 42 public class MaskRable8Bit 43 extends AbstractRable 44 implements Mask { 45 46 49 protected GraphicsNode mask; 50 51 54 protected Rectangle2D filterRegion; 55 56 public MaskRable8Bit(Filter src, GraphicsNode mask, 57 Rectangle2D filterRegion) { 58 super(src, null); 59 setMaskNode(mask); 60 setFilterRegion(filterRegion); 61 } 62 63 67 public void setSource(Filter src) { 68 init(src, null); 69 } 70 71 75 public Filter getSource() { 76 return (Filter)getSources().get(0); 77 } 78 79 82 public Rectangle2D getFilterRegion(){ 83 return (Rectangle2D )filterRegion.clone(); 84 } 85 86 89 public void setFilterRegion(Rectangle2D filterRegion){ 90 if(filterRegion == null){ 91 throw new IllegalArgumentException (); 92 } 93 94 this.filterRegion = filterRegion; 95 } 96 97 106 public void setMaskNode(GraphicsNode mask) { 107 touch(); 108 this.mask = mask; 109 } 110 111 116 public GraphicsNode getMaskNode() { 117 return mask; 118 } 119 120 123 public Rectangle2D getBounds2D(){ 124 return (Rectangle2D )filterRegion.clone(); 125 } 126 127 public RenderedImage createRendering(RenderContext rc) { 128 Filter maskSrc = getMaskNode().getGraphicsNodeRable(true); 132 PadRable maskPad = new PadRable8Bit(maskSrc, getBounds2D(), 133 PadMode.ZERO_PAD); 134 maskSrc = new FilterAsAlphaRable(maskPad); 135 RenderedImage ri = maskSrc.createRendering(rc); 136 if (ri == null) 137 return null; 138 139 CachableRed maskCr = RenderedImageCachableRed.wrap(ri); 140 141 PadRable maskedPad = new PadRable8Bit(getSource(), 145 getBounds2D(), 146 PadMode.ZERO_PAD); 147 148 ri = maskedPad.createRendering(rc); 149 if (ri == null) 150 return null; 151 152 CachableRed cr; 153 cr = GraphicsUtil.wrap(ri); 154 cr = GraphicsUtil.convertToLsRGB(cr); 155 156 159 CachableRed ret = new MultiplyAlphaRed(cr, maskCr); 160 161 163 164 166 return ret; 167 } 168 } 169 | Popular Tags |