1 18 package org.apache.batik.ext.awt.image.rendered; 19 20 import java.awt.Color ; 21 import java.awt.Graphics2D ; 22 import java.awt.Paint ; 23 import java.awt.Point ; 24 import java.awt.Rectangle ; 25 import java.awt.image.BufferedImage ; 26 import java.awt.image.ColorModel ; 27 import java.awt.image.Raster ; 28 import java.awt.image.SampleModel ; 29 import java.awt.image.WritableRaster ; 30 31 import org.apache.batik.ext.awt.image.GraphicsUtil; 32 33 41 public class FloodRed extends AbstractRed { 42 43 46 private WritableRaster raster; 47 48 53 public FloodRed(Rectangle bounds) { 54 this(bounds, new Color (0, 0, 0, 0)); 55 } 56 57 64 public FloodRed(Rectangle bounds, 65 Paint paint) { 66 super(); 68 ColorModel cm = GraphicsUtil.sRGB_Unpre; 69 70 int defSz = AbstractTiledRed.getDefaultTileSize(); 71 72 int tw = bounds.width; 73 if (tw > defSz) tw = defSz; 74 int th = bounds.height; 75 if (th > defSz) th = defSz; 76 77 SampleModel sm = cm.createCompatibleSampleModel(tw, th); 79 80 init((CachableRed)null, bounds, cm, sm, 0, 0, null); 82 83 raster = Raster.createWritableRaster(sm, new Point (0, 0)); 84 BufferedImage offScreen = new BufferedImage (cm, raster, 85 cm.isAlphaPremultiplied(), 86 null); 87 88 Graphics2D g = GraphicsUtil.createGraphics(offScreen); 89 g.setPaint(paint); 90 g.fillRect(0, 0, bounds.width, bounds.height); 91 g.dispose(); 92 } 93 94 public Raster getTile(int x, int y) { 95 int tx = tileGridXOff+x*tileWidth; 98 int ty = tileGridYOff+y*tileHeight; 99 return raster.createTranslatedChild(tx, ty); 100 } 101 102 public WritableRaster copyData(WritableRaster wr) { 103 int tx0 = getXTile(wr.getMinX()); 104 int ty0 = getYTile(wr.getMinY()); 105 int tx1 = getXTile(wr.getMinX()+wr.getWidth() -1); 106 int ty1 = getYTile(wr.getMinY()+wr.getHeight()-1); 107 108 final boolean is_INT_PACK = 109 GraphicsUtil.is_INT_PACK_Data(getSampleModel(), false); 110 111 for (int y=ty0; y<=ty1; y++) 112 for (int x=tx0; x<=tx1; x++) { 113 Raster r = getTile(x, y); 114 if (is_INT_PACK) 115 GraphicsUtil.copyData_INT_PACK(r, wr); 116 else 117 GraphicsUtil.copyData_FALLBACK(r, wr); 118 } 119 120 return wr; 121 } 122 } 123 124 125 126 127 | Popular Tags |