Class RecyclingTileFactory
Object
Observable
RecyclingTileFactory
- All Implemented Interfaces:
Observer,TileFactory,TileRecycler
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
KernelImageN kernel; // filtering kernel
// Create a RenderingHints object and set hints.
RenderingHints rh = new RenderingHints(null);
RecyclingTileFactory rtf = new RecyclingTileFactory();
rh.put(ImageN.KEY_TILE_RECYCLER, rtf);
rh.put(ImageN.KEY_TILE_FACTORY, rtf);
rh.put(ImageN.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 = ImageN.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 = ImageN.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:
- ImageN 0.4.0
-
Constructor Summary
ConstructorsConstructorDescriptionRecyclingTileFactory(Observable tileCache) Constructs aRecyclingTileFactory. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturnstrue.createTile(SampleModel sampleModel, Point location) voidflush()longbooleanReturnstrue.voidrecycleTile(Raster tile) Recycle the given tile.voidupdate(Observable o, Object arg) Methods inherited from class Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
-
Constructor Details
-
RecyclingTileFactory
Constructs aRecyclingTileFactory.
-
-
Method Details
-
canReclaimMemory
public boolean canReclaimMemory()Returnstrue.- Specified by:
canReclaimMemoryin interfaceTileFactory
-
isMemoryCache
public boolean isMemoryCache()Returnstrue.- Specified by:
isMemoryCachein interfaceTileFactory
-
getMemoryUsed
public long getMemoryUsed()- Specified by:
getMemoryUsedin interfaceTileFactory
-
flush
public void flush()- Specified by:
flushin interfaceTileFactory
-
createTile
- Specified by:
createTilein interfaceTileFactory
-
recycleTile
Recycle the given tile.- Specified by:
recycleTilein interfaceTileRecycler
-
update
-