org.geotools.coverage.grid.io.imageio
Class RecyclingTileFactory

java.lang.Object
  extended by java.util.Observable
      extended by org.geotools.coverage.grid.io.imageio.RecyclingTileFactory
All Implemented Interfaces:
java.util.Observer, javax.media.jai.TileFactory, javax.media.jai.TileRecycler

public class RecyclingTileFactory
extends java.util.Observable
implements javax.media.jai.TileFactory, javax.media.jai.TileRecycler, java.util.Observer

A simple implementation of TileFactory wherein the tiles returned from createTile() attempt to re-use primitive arrays provided by the TileRecycler method recycleTile().

A simple example of the use of this class is as follows wherein image files are read, each image is filtered, and each output written to a file:

 String[] sourceFiles; // source file paths
 KernelJAI kernel; // filtering kernel
 
 // Create a RenderingHints object and set hints.
 RenderingHints rh = new RenderingHints(null);
 RecyclingTileFactory rtf = new RecyclingTileFactory();
 rh.put(JAI.KEY_TILE_RECYCLER, rtf);
 rh.put(JAI.KEY_TILE_FACTORY, rtf);
 rh.put(JAI.KEY_IMAGE_LAYOUT, new ImageLayout().setTileWidth(32).setTileHeight(
                32));
 
 int counter = 0;
 
 // Read each image, filter it, and save the output to a file.
 for (int i = 0; i < sourceFiles.length; i++) {
        PlanarImage source = JAI.create("fileload", sourceFiles[i]);
        ParameterBlock pb = (new ParameterBlock()).addSource(source).add(kernel);
 
        // The TileFactory hint will cause tiles to be created by 'rtf'.
        RenderedOp dest = JAI.create("convolve", pb, rh);
        String fileName = "image_" + (++counter) + ".tif";
        JAI.create("filestore", dest, fileName);
 
        // The TileRecycler hint will cause arrays to be reused by 'rtf'.
        dest.dispose();
 }
 
In the above code, if the SampleModel of all source images is identical, then data arrays should only be created in the first iteration.

Since:
JAI 1.1.2

Constructor Summary
RecyclingTileFactory(java.util.Observable tileCache)
          Constructs a RecyclingTileFactory.
 
Method Summary
 boolean canReclaimMemory()
          Returns true.
 java.awt.image.WritableRaster createTile(java.awt.image.SampleModel sampleModel, java.awt.Point location)
           
 void flush()
           
 long getMemoryUsed()
           
 boolean isMemoryCache()
          Returns true.
 void recycleTile(java.awt.image.Raster tile)
          Recycle the given tile.
 void update(java.util.Observable o, java.lang.Object arg)
           
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RecyclingTileFactory

public RecyclingTileFactory(java.util.Observable tileCache)
Constructs a RecyclingTileFactory.

Method Detail

canReclaimMemory

public boolean canReclaimMemory()
Returns true.

Specified by:
canReclaimMemory in interface javax.media.jai.TileFactory

isMemoryCache

public boolean isMemoryCache()
Returns true.

Specified by:
isMemoryCache in interface javax.media.jai.TileFactory

getMemoryUsed

public long getMemoryUsed()
Specified by:
getMemoryUsed in interface javax.media.jai.TileFactory

flush

public void flush()
Specified by:
flush in interface javax.media.jai.TileFactory

createTile

public java.awt.image.WritableRaster createTile(java.awt.image.SampleModel sampleModel,
                                                java.awt.Point location)
Specified by:
createTile in interface javax.media.jai.TileFactory

recycleTile

public void recycleTile(java.awt.image.Raster tile)
Recycle the given tile.

Specified by:
recycleTile in interface javax.media.jai.TileRecycler

update

public void update(java.util.Observable o,
                   java.lang.Object arg)
Specified by:
update in interface java.util.Observer


Copyright © 1996-2010 Geotools. All Rights Reserved.