1 18 package org.apache.batik.ext.awt.image.rendered; 19 20 import java.awt.Rectangle ; 21 import java.awt.image.ColorModel ; 22 import java.awt.image.SampleModel ; 23 import java.awt.image.WritableRaster ; 24 25 32 public class TileCacheRed extends AbstractTiledRed { 33 34 38 public TileCacheRed(CachableRed cr) { 39 super(cr, null); 40 } 41 42 46 public TileCacheRed(CachableRed cr, int tileWidth, int tileHeight) { 47 super(); 48 ColorModel cm = cr.getColorModel(); 49 Rectangle bounds = cr.getBounds(); 50 if (tileWidth > bounds.width) tileWidth = bounds.width; 51 if (tileHeight > bounds.height) tileHeight = bounds.height; 52 SampleModel sm = cm.createCompatibleSampleModel(tileWidth, tileHeight); 53 init(cr, cr.getBounds(), cm, sm, 54 cr.getTileGridXOffset(), cr.getTileGridYOffset(), 55 null); 56 } 57 58 public void genRect(WritableRaster wr) { 59 CachableRed src = (CachableRed)getSources().get(0); 61 62 src.copyData(wr); 63 } 64 65 public void flushCache(Rectangle rect) { 66 int tx0 = getXTile(rect.x); 67 int ty0 = getYTile(rect.y); 68 int tx1 = getXTile(rect.x+rect.width -1); 69 int ty1 = getYTile(rect.y+rect.height-1); 70 71 if (tx0 < minTileX) tx0 = minTileX; 72 if (ty0 < minTileY) ty0 = minTileY; 73 74 if (tx1 >= minTileX+numXTiles) tx1 = minTileX+numXTiles-1; 75 if (ty1 >= minTileY+numYTiles) ty1 = minTileY+numYTiles-1; 76 77 if ((tx1 < tx0) || (ty1 < ty0)) 78 return; 79 80 TileStore store = getTileStore(); 81 for (int y=ty0; y<=ty1; y++) 82 for (int x=tx0; x<=tx1; x++) 83 store.setTile(x, y, null); 84 } 85 } 86 | Popular Tags |