public class DiskMemImage extends javax.media.jai.PlanarImage implements WritableRenderedImage
TiledImage that uses a
DiskMemTileCache to manage its data. Image tiles are cached in memory
and, if the volume of image data is greater than available memory, also on disk
as temporary files. When a tile is accessed it is swapped into memory if not
already resident. Thus, very large images can be handled, albeit at the cost of
disk I/O.
By default, each DiskMemImage uses its own tile cache but it is also
possible for images to share a common tile cache as shown here:
DiskMemImage image1 = new DiskMemImage(...);
image1.useCommonTileCache(true);
DiskMemImage image2 = new DiskMemImage(...);
image2.useCommonTileCache(true);
DiskMemImage image3 = new DiskMemImage(...);
In the example above, image1 and image2 will share a common tile cache while
image3 will use a separate, exclusive tile cache. You can test whether an
image is using the common cache like this:
boolean usingCommonCache = image.isUsingCommonTileCache();
The memory capacity of the common cache can be set like this:
long memCapacity = 128 * 1024 * 1024; // 128 Mb
DiskMemImage.getCommonCache().setMemoryCapacity(memCapacity);
DiskMemTileCache| Modifier and Type | Field and Description |
|---|---|
static long |
DEFAULT_COMMON_CACHE_SIZE
The default memory capacity of the common tile cache in bytes
(256 * 1024 * 1024 = 256 Mb)
|
protected int |
numTilesInUse
The number of tiles that are currently checked out
for writing
|
protected int[][] |
numWriters
A 2D array with dimensions corresponding to the tile grid width
and height that records, for each tile, the number of writers
that have the tile checked out currently
|
protected DiskMemTileCache |
tileCache
The tile cache in use by this image.
|
protected Rectangle |
tileGrid
Defines the valid range of tile x and y coordinates.
|
protected long |
tileMemorySize
The amount of memory (in bytes) required to hold
the data for an image tile
|
protected Set<TileObserver> |
tileObservers
The set of tile observers currently registered with
this image
|
| Constructor and Description |
|---|
DiskMemImage(int minX,
int minY,
int width,
int height,
int tileGridXOffset,
int tileGridYOffset,
SampleModel tileSampleModel)
Creates a new image.
|
DiskMemImage(int minX,
int minY,
int width,
int height,
int tileGridXOffset,
int tileGridYOffset,
SampleModel tileSampleModel,
ColorModel colorModel)
Creates a new image.
|
DiskMemImage(int minX,
int minY,
int width,
int height,
SampleModel tileSampleModel)
Creates a new image with default values for tile offsets (0)
and
ColorModel (null) |
DiskMemImage(int width,
int height,
SampleModel tileSampleModel)
Creates a new image with default values for origin (0, 0),
x and y tile offsets (0) and
ColorModel
(null). |
DiskMemImage(int width,
int height,
SampleModel tileSampleModel,
ColorModel colorModel)
Creates a new image with default values for origin (0, 0) and
tile offsets (0).
|
| Modifier and Type | Method and Description |
|---|---|
void |
addTileObserver(TileObserver to) |
Graphics2D |
createGraphics()
Creates a Graphics2D object for drawing operations with this image.
|
static DiskMemTileCache |
getCommonTileCache()
Get the common tile cache.
|
long |
getMemoryCapacity()
Gets the maximum amount of memory, in bytes, that this
image will use for in-memory storage of its data.
|
int |
getSample(int x,
int y,
int b)
Gets the image value for the given image position as an integer.
|
double |
getSampleDouble(int x,
int y,
int b)
Gets the image value for the given image position as a double.
|
float |
getSampleFloat(int x,
int y,
int b)
Gets the image value for the given image position as a float.
|
Raster |
getTile(int tileX,
int tileY)
Gets a tile for reading.
|
DiskMemTileCache |
getTileCache()
Gets a reference to the
DiskMemTileCache instance
used by this image. |
long |
getTileMemorySize()
Gets the amount of memory (bytes) required to store a single
tile's data.
|
WritableRaster |
getWritableTile(int tileX,
int tileY)
Checks out a tile for writing.
|
Point[] |
getWritableTileIndices()
Gets the indices (tile grid col,row) of tiles that are
currently checked out for writing.
|
boolean |
hasTileWriters()
Tests if any tiles are currently checked out for writing.
|
boolean |
isTileWritable(int tileX,
int tileY)
Tests if a tile is currently checked-out for writing (via
a call to getWritableTile(int, int).
|
boolean |
isUsingCommonCache()
Tests if this image is using the common tile cache.
|
void |
releaseWritableTile(int tileX,
int tileY)
Releases a tile that was checked out for writing.
|
void |
removeTileObserver(TileObserver to) |
static void |
setCommonTileCache(DiskMemTileCache newCache)
Sets a new common cache.
|
void |
setData(Raster data)
Copies data from the given
Raster object into this
image. |
void |
setSample(int x,
int y,
int b,
double value)
Sets the image value for the given image position as a double.
|
void |
setSample(int x,
int y,
int b,
float value)
Sets the image value for the given image position as a float.
|
void |
setSample(int x,
int y,
int b,
int value)
Sets the image value for the given image position as an integer.
|
void |
setUseCommonCache(boolean useCommon)
Sets whether this image will use the common tile cache.
|
addPropertyChangeListener, addPropertyChangeListener, addSink, addSink, addSource, addTileComputationListener, cancelTiles, copyData, copyData, copyExtendedData, createColorModel, createSnapshot, createWritableRaster, dispose, finalize, getAsBufferedImage, getAsBufferedImage, getBounds, getColorModel, getData, getData, getDefaultColorModel, getExtendedData, getGraphics, getHeight, getImageID, getMaxTileX, getMaxTileY, getMaxX, getMaxY, getMinTileX, getMinTileY, getMinX, getMinY, getNumBands, getNumSources, getNumXTiles, getNumYTiles, getProperties, getProperty, getPropertyClass, getPropertyNames, getPropertyNames, getSampleModel, getSinks, getSource, getSourceImage, getSourceObject, getSources, getSplits, getTileComputationListeners, getTileFactory, getTileGridXOffset, getTileGridYOffset, getTileHeight, getTileIndices, getTileRect, getTiles, getTiles, getTileWidth, getWidth, overlapsMultipleTiles, prefetchTiles, queueTiles, removeProperty, removePropertyChangeListener, removePropertyChangeListener, removeSink, removeSink, removeSinks, removeSource, removeSources, removeTileComputationListener, setImageLayout, setProperties, setProperty, setSource, setSources, tileXToX, tileXToX, tileYToY, tileYToY, toString, wrapRenderedImage, XToTileX, XToTileX, YToTileY, YToTileYclone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitcopyData, getColorModel, getData, getData, getHeight, getMinTileX, getMinTileY, getMinX, getMinY, getNumXTiles, getNumYTiles, getProperty, getPropertyNames, getSampleModel, getSources, getTileGridXOffset, getTileGridYOffset, getTileHeight, getTileWidth, getWidthpublic static final long DEFAULT_COMMON_CACHE_SIZE
protected DiskMemTileCache tileCache
protected field,
it is recommended that sub-classes use getTileCache()
for general purposes.protected Rectangle tileGrid
protected int[][] numWriters
protected int numTilesInUse
getWritableTileIndices()protected long tileMemorySize
protected Set<TileObserver> tileObservers
public DiskMemImage(int width,
int height,
SampleModel tileSampleModel)
ColorModel
(null).width - image widthheight - image heighttileSampleModel - a SampleModel specifying the dimensions
data type etc. for image tilespublic DiskMemImage(int width,
int height,
SampleModel tileSampleModel,
ColorModel colorModel)
width - image widthheight - image heighttileSampleModel - the SampleModelcolorModel - the ColorModelpublic DiskMemImage(int minX,
int minY,
int width,
int height,
SampleModel tileSampleModel)
ColorModel (null)minX - x coordinate of the upper-left image pixelminY - y coordinate of the upper-left image pixelwidth - image widthheight - image heighttileSampleModel - the SampleModelpublic DiskMemImage(int minX,
int minY,
int width,
int height,
int tileGridXOffset,
int tileGridYOffset,
SampleModel tileSampleModel)
ColorModel to nullminX - x coordinate of the upper-left image pixelminY - y coordinate of the upper-left image pixelwidth - image widthheight - image height
data type etc. for image tilestileGridXOffset - x coordinate of the upper-left pixel of the upper-left tiletileGridYOffset - y coordinate of the upper-left pixel of the upper-left tiletileSampleModel - the SampleModelpublic DiskMemImage(int minX,
int minY,
int width,
int height,
int tileGridXOffset,
int tileGridYOffset,
SampleModel tileSampleModel,
ColorModel colorModel)
minX - x coordinate of the upper-left image pixelminY - y coordinate of the upper-left image pixelwidth - image widthheight - image height
data type etc. for image tilestileGridXOffset - x coordinate of the upper-left pixel of the upper-left tiletileGridYOffset - y coordinate of the upper-left pixel of the upper-left tiletileSampleModel - the SampleModelcolorModel - the ColorModelpublic static DiskMemTileCache getCommonTileCache()
null).isUsingCommonCache(),
setUseCommonCache(boolean)public static void setCommonTileCache(DiskMemTileCache newCache)
newCache - the cache instance to use as the common tile
cache for DiskMemImage objects (null
arguments are ignored)public Raster getTile(int tileX, int tileY)
getTile in interface RenderedImagegetTile in class javax.media.jai.PlanarImagetileX - the tile's column in the tile gridtileY - the tile's row in the tile gridpublic void addTileObserver(TileObserver to)
addTileObserver in interface WritableRenderedImagepublic void removeTileObserver(TileObserver to)
removeTileObserver in interface WritableRenderedImagepublic WritableRaster getWritableTile(int tileX, int tileY)
null and a warning message is logged.getWritableTile in interface WritableRenderedImagetileX - tile X ordinatetileY - tile Y ordinatenull if the tile
is already checked-outpublic void releaseWritableTile(int tileX,
int tileY)
If the cache no longer has the tile in its memory storage, e.g. because of memory swapping for other tile accesses, the cache will be unable to refresh the tile's data on disk. In this case a warning message is logged.
If the tile was not previously checked-out via getWritableTile(int, int) a warning message is logged.
releaseWritableTile in interface WritableRenderedImagetileX - tile X ordinatetileY - tile Y ordinatepublic boolean isTileWritable(int tileX,
int tileY)
isTileWritable in interface WritableRenderedImagetileX - tile X ordinatetileY - tile Y ordinatetrue if the tile is currently checked-out for
writing; false otherwise.public Point[] getWritableTileIndices()
getWritableTileIndices in interface WritableRenderedImagepublic boolean hasTileWriters()
hasTileWriters in interface WritableRenderedImagetrue if any tiles are currently checked out;
false otherwisepublic int getSample(int x,
int y,
int b)
throws PixelOutsideImageException
x - X ordinatey - Y ordinateb - band indexPixelOutsideImageExceptionpublic float getSampleFloat(int x,
int y,
int b)
throws PixelOutsideImageException
x - X ordinatey - Y ordinateb - band indexPixelOutsideImageExceptionpublic double getSampleDouble(int x,
int y,
int b)
throws PixelOutsideImageException
x - X ordinatey - Y ordinateb - band indexPixelOutsideImageExceptionpublic void setSample(int x,
int y,
int b,
int value)
throws PixelOutsideImageException
x - X ordinatey - Y ordinateb - band indexvalue - the new valuePixelOutsideImageExceptionpublic void setSample(int x,
int y,
int b,
float value)
throws PixelOutsideImageException
x - X ordinatey - Y ordinateb - band indexvalue - the new valuePixelOutsideImageExceptionpublic void setSample(int x,
int y,
int b,
double value)
throws PixelOutsideImageException
x - X ordinatey - Y ordinateb - band indexvalue - the new valuePixelOutsideImageExceptionpublic void setData(Raster data)
Raster object into this
image. The bounds of data will be used to
place the data and only that portion of data
within this image's bounds will be copied.setData in interface WritableRenderedImagedata - the data to copyIllegalArgumentException - if data is nullpublic Graphics2D createGraphics()
DiskMemImageGraphics.
Note that only images of integral data type support graphics operations.
UnsupportedOperationException - if the image is not of integral data typeDiskMemImageGraphicspublic long getMemoryCapacity()
DiskMemTileCache this is not
the limit of image size.public long getTileMemorySize()
public void setUseCommonCache(boolean useCommon)
useCommon
is true) or to a new exclusive tile cache ((if useCommon
is false).
By default, the image will use an exclusive cache.
useCommon - true to set this image to use the common tile cache; false
for the image to use its own exclusive cache.getCommonTileCache(),
isUsingCommonCache()public DiskMemTileCache getTileCache()
DiskMemTileCache instance
used by this image. This method is intended for client
code that wishes to query cache state or receive cache diagnostic
messages (via the Observer interface). It is probably not
a good idea to manipulate the cache state directly.isUsingCommonCache(),
DiskMemTileCachepublic boolean isUsingCommonCache()
true if using the common tile cache; false otherwisesetUseCommonCache(boolean)Copyright © 2009–2020. All rights reserved.