Class RecyclingTileFactory
- Object
-
- Observable
-
- RecyclingTileFactory
-
- All Implemented Interfaces:
Observer
,TileFactory
,TileRecycler
public class RecyclingTileFactory extends Observable implements TileFactory, TileRecycler, Observer
A simple implementation ofTileFactory
wherein the tiles returned fromcreateTile()
attempt to re-use primitive arrays provided by theTileRecycler
methodrecycleTile()
.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 theSampleModel
of all source images is identical, then data arrays should only be created in the first iteration.- Since:
- JAI 1.1.2
-
-
Constructor Summary
Constructors Constructor Description RecyclingTileFactory(Observable tileCache)
Constructs aRecyclingTileFactory
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canReclaimMemory()
Returnstrue
.WritableRaster
createTile(SampleModel sampleModel, Point location)
void
flush()
long
getMemoryUsed()
boolean
isMemoryCache()
Returnstrue
.void
recycleTile(Raster tile)
Recycle the given tile.void
update(Observable o, Object arg)
-
Methods inherited from class Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
-
-
-
-
Constructor Detail
-
RecyclingTileFactory
public RecyclingTileFactory(Observable tileCache)
Constructs aRecyclingTileFactory
.
-
-
Method Detail
-
canReclaimMemory
public boolean canReclaimMemory()
Returnstrue
.- Specified by:
canReclaimMemory
in interfaceTileFactory
-
isMemoryCache
public boolean isMemoryCache()
Returnstrue
.- Specified by:
isMemoryCache
in interfaceTileFactory
-
getMemoryUsed
public long getMemoryUsed()
- Specified by:
getMemoryUsed
in interfaceTileFactory
-
flush
public void flush()
- Specified by:
flush
in interfaceTileFactory
-
createTile
public WritableRaster createTile(SampleModel sampleModel, Point location)
- Specified by:
createTile
in interfaceTileFactory
-
recycleTile
public void recycleTile(Raster tile)
Recycle the given tile.- Specified by:
recycleTile
in interfaceTileRecycler
-
update
public void update(Observable o, Object arg)
-
-