org.geotools.image.io.mosaic
Class MosaicImageReader

java.lang.Object
  extended by javax.imageio.ImageReader
      extended by org.geotools.image.io.mosaic.MosaicImageReader

public class MosaicImageReader
extends javax.imageio.ImageReader

An image reader built from a mosaic of other image readers. The mosaic is specified as a collection of Tile objects, organized in a TileManager.

Since:
2.5
Version:
$Id: MosaicImageReader.java 31445 2008-09-07 18:14:23Z desruisseaux $
Author:
Martin Desruisseaux

Nested Class Summary
static class MosaicImageReader.Spi
          Service provider for MosaicImageReader.
 
Field Summary
 
Fields inherited from class javax.imageio.ImageReader
availableLocales, ignoreMetadata, input, locale, minIndex, originatingProvider, progressListeners, seekForwardOnly, updateListeners, warningListeners, warningLocales
 
Constructor Summary
MosaicImageReader()
          Constructs an image reader with the default provider.
MosaicImageReader(javax.imageio.spi.ImageReaderSpi spi)
          Constructs an image reader with the specified provider.
 
Method Summary
 void abort()
          Requests that any current read operation be aborted.
 void close()
          Closes any image input streams thay may be held by tiles.
 void dispose()
          Allows any resources held by this reader to be released.
 float getAspectRatio(int imageIndex)
          Returns the aspect ratio.
 java.util.Locale[] getAvailableLocales()
          Returns an array of locales that may be used to localize warning listeners.
 ImageTypePolicy getDefaultImageTypePolicy()
          Returns the policy for computing image types.
 MosaicImageReadParam getDefaultReadParam()
          Returns default parameters appropriate for this format.
 int getHeight(int imageIndex)
          Returns the height in pixels of the given image within the input source.
 javax.imageio.metadata.IIOMetadata getImageMetadata(int imageIndex)
          Returns the metadata associated with the given image, or null.
 javax.imageio.metadata.IIOMetadata getImageMetadata(int imageIndex, java.lang.String formatName, java.util.Set<java.lang.String> nodeNames)
          Returns the image metadata for the given format and nodes, or null.
 java.util.Iterator<javax.imageio.ImageTypeSpecifier> getImageTypes(int imageIndex)
          Returns possible image types to which the given image may be decoded.
 TileManager[] getInput()
          Returns the input, which is a an array of tile managers.
 java.util.logging.Level getLogLevel()
          Returns the logging level for tile information during reads.
 int getNumImages(boolean allowSearch)
          Returns the number of images, not including thumbnails.
 javax.imageio.ImageTypeSpecifier getRawImageType(int imageIndex)
          Returns an image type which most closely represents the "raw" internal format of the image.
 javax.imageio.metadata.IIOMetadata getStreamMetadata()
          Returns the metadata associated with the input source as a whole, or null.
 javax.imageio.metadata.IIOMetadata getStreamMetadata(java.lang.String formatName, java.util.Set<java.lang.String> nodeNames)
          Returns the stream metadata for the given format and nodes, or null.
 int getTileHeight(int imageIndex)
          Returns the height of a tile in the given image.
 java.util.Set<javax.imageio.spi.ImageReaderSpi> getTileReaderSpis()
          Returns the Service Provider Interfaces (SPI) of every image readers to be used for reading tiles.
 int getTileWidth(int imageIndex)
          Returns the width of a tile in the given image.
 int getWidth(int imageIndex)
          Returns the width in pixels of the given image within the input source.
 boolean isImageTiled(int imageIndex)
          Returns true if there is more than one tile for the given image index.
 boolean isRandomAccessEasy(int imageIndex)
          Returns true if the storage format of the given image places no inherent impediment on random access to pixels.
 java.awt.image.BufferedImage read(int imageIndex, javax.imageio.ImageReadParam param)
          Reads the image indexed by imageIndex using a supplied parameters.
 java.awt.image.BufferedImage readTile(int imageIndex, int tileX, int tileY)
          Reads the tile indicated by the tileX and tileY arguments.
 void setInput(java.lang.Object input, boolean seekForwardOnly, boolean ignoreMetadata)
          Sets the input source, which is expected to be an array of tile managers.
 void setLocale(java.util.Locale locale)
          Sets the current locale of this image reader and every tile readers.
 void setLogLevel(java.util.logging.Level level)
          Sets the logging level for tile information during reads.
 
Methods inherited from class javax.imageio.ImageReader
abortRequested, addIIOReadProgressListener, addIIOReadUpdateListener, addIIOReadWarningListener, canReadRaster, checkReadParamBandSettings, clearAbortRequest, computeRegions, getDestination, getFormatName, getLocale, getMinIndex, getNumThumbnails, getOriginatingProvider, getSourceRegion, getThumbnailHeight, getThumbnailWidth, getTileGridXOffset, getTileGridYOffset, hasThumbnails, isIgnoringMetadata, isSeekForwardOnly, processImageComplete, processImageProgress, processImageStarted, processImageUpdate, processPassComplete, processPassStarted, processReadAborted, processSequenceComplete, processSequenceStarted, processThumbnailComplete, processThumbnailPassComplete, processThumbnailPassStarted, processThumbnailProgress, processThumbnailStarted, processThumbnailUpdate, processWarningOccurred, processWarningOccurred, read, readAll, readAll, readAsRenderedImage, readerSupportsThumbnails, readRaster, readThumbnail, readTileRaster, removeAllIIOReadProgressListeners, removeAllIIOReadUpdateListeners, removeAllIIOReadWarningListeners, removeIIOReadProgressListener, removeIIOReadUpdateListener, removeIIOReadWarningListener, reset, setInput, setInput
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MosaicImageReader

public MosaicImageReader()
Constructs an image reader with the default provider.


MosaicImageReader

public MosaicImageReader(javax.imageio.spi.ImageReaderSpi spi)
Constructs an image reader with the specified provider.

Parameters:
spi - The image reader provider, or null for the default one.
Method Detail

getLogLevel

public java.util.logging.Level getLogLevel()
Returns the logging level for tile information during reads.

Returns:
The current logging level.

setLogLevel

public void setLogLevel(java.util.logging.Level level)
Sets the logging level for tile information during reads. The default value is Level.FINE. A null value restore the default.

Parameters:
level - The new logging level, or null for the default.

getInput

public TileManager[] getInput()
Returns the input, which is a an array of tile managers. The array length is the number of images. The element at index i is the tile manager to use when reading at image index i.

Overrides:
getInput in class javax.imageio.ImageReader

setInput

public void setInput(java.lang.Object input,
                     boolean seekForwardOnly,
                     boolean ignoreMetadata)
              throws java.lang.IllegalArgumentException
Sets the input source, which is expected to be an array of tile managers. If the given input is a singleton, an array or a collection of Tile objects, then it will be wrapped in an array of TileManagers.

Overrides:
setInput in class javax.imageio.ImageReader
Parameters:
input - The input.
seekForwardOnly - if true, images and metadata may only be read in ascending order from this input source.
ignoreMetadata - if true, metadata may be ignored during reads.
Throws:
java.lang.IllegalArgumentException - if input is not an instance of one of the expected classes, or if the input can not be used because of an I/O error (in which case the exception has a IOException as its cause).

getTileReaderSpis

public java.util.Set<javax.imageio.spi.ImageReaderSpi> getTileReaderSpis()
Returns the Service Provider Interfaces (SPI) of every image readers to be used for reading tiles. This method returns an empty set if no input has been set.

Returns:
The service providers for tile readers.
See Also:
TileManager.getImageReaderSpis()

getAvailableLocales

public java.util.Locale[] getAvailableLocales()
Returns an array of locales that may be used to localize warning listeners. The default implementations returns the union of the locales supported by this reader and every tile readers.

Overrides:
getAvailableLocales in class javax.imageio.ImageReader
Returns:
An array of supported locales, or null.

setLocale

public void setLocale(java.util.Locale locale)
               throws java.lang.IllegalArgumentException
Sets the current locale of this image reader and every tile readers.

Overrides:
setLocale in class javax.imageio.ImageReader
Parameters:
locale - the desired locale, or null.
Throws:
java.lang.IllegalArgumentException - if locale is non-null but is not one of the available locales.

getNumImages

public int getNumImages(boolean allowSearch)
                 throws java.io.IOException
Returns the number of images, not including thumbnails.

Specified by:
getNumImages in class javax.imageio.ImageReader
Throws:
java.io.IOException - If an error occurs reading the information from the input source.

isImageTiled

public boolean isImageTiled(int imageIndex)
                     throws java.io.IOException
Returns true if there is more than one tile for the given image index.

Overrides:
isImageTiled in class javax.imageio.ImageReader
Parameters:
imageIndex - The index of the image to be queried.
Returns:
true If there is at least two tiles.
Throws:
java.io.IOException - If an error occurs reading the information from the input source.

getWidth

public int getWidth(int imageIndex)
             throws java.io.IOException
Returns the width in pixels of the given image within the input source.

Specified by:
getWidth in class javax.imageio.ImageReader
Parameters:
imageIndex - The index of the image to be queried.
Returns:
The width of the image.
Throws:
java.io.IOException - If an error occurs reading the information from the input source.

getHeight

public int getHeight(int imageIndex)
              throws java.io.IOException
Returns the height in pixels of the given image within the input source.

Specified by:
getHeight in class javax.imageio.ImageReader
Parameters:
imageIndex - The index of the image to be queried.
Returns:
The height of the image.
Throws:
java.io.IOException - If an error occurs reading the information from the input source.

getTileWidth

public int getTileWidth(int imageIndex)
                 throws java.io.IOException
Returns the width of a tile in the given image.

Overrides:
getTileWidth in class javax.imageio.ImageReader
Parameters:
imageIndex - The index of the image to be queried.
Returns:
The width of a tile.
Throws:
java.io.IOException - If an error occurs reading the information from the input source.

getTileHeight

public int getTileHeight(int imageIndex)
                  throws java.io.IOException
Returns the height of a tile in the given image.

Overrides:
getTileHeight in class javax.imageio.ImageReader
Parameters:
imageIndex - The index of the image to be queried.
Returns:
The height of a tile.
Throws:
java.io.IOException - If an error occurs reading the information from the input source.

isRandomAccessEasy

public boolean isRandomAccessEasy(int imageIndex)
                           throws java.io.IOException
Returns true if the storage format of the given image places no inherent impediment on random access to pixels. The default implementation returns true if the input of every tiles is a File and isRandomAccessEasy returned true for all tile readers.

Overrides:
isRandomAccessEasy in class javax.imageio.ImageReader
Throws:
java.io.IOException - If an error occurs reading the information from the input source.

getAspectRatio

public float getAspectRatio(int imageIndex)
                     throws java.io.IOException
Returns the aspect ratio. If all tiles have the same aspect ratio, then that ratio is returned. Otherwise the default value is returned.

Overrides:
getAspectRatio in class javax.imageio.ImageReader
Parameters:
imageIndex - The index of the image to be queried.
Throws:
java.io.IOException - If an error occurs reading the information from the input source.

getDefaultImageTypePolicy

public ImageTypePolicy getDefaultImageTypePolicy()
Returns the policy for computing image types. This is also the policy used by read method when none has been explicitly set in read parameters.

The default implementation makes the following choice based on the number of reader providers:

Note that SUPPORTED_BY_ONE is not a really safe choice even if there is only one provider, because the image type can also depends on tile input. However the safest choice in all cases (SUPPORTED_BY_ALL) is costly and often not necessary. The current implementation is a compromize between safety and performance.

If Java assertions are enabled, this reader will verify that SUPPORTED_BY_ONE produces the same result than SUPPORTED_BY_ALL.

Subclasses can override this method if they want a different policy.

Returns:
The default image type policy.

getRawImageType

public javax.imageio.ImageTypeSpecifier getRawImageType(int imageIndex)
                                                 throws java.io.IOException
Returns an image type which most closely represents the "raw" internal format of the image. The default implementation depends on the default image type policy:

Overrides:
getRawImageType in class javax.imageio.ImageReader
Parameters:
imageIndex - The image index, from 0 inclusive to getNumImages(boolean) exclusive.
Returns:
A raw image type specifier.
Throws:
java.io.IOException - If an error occurs reading the information from the input source.

getImageTypes

public java.util.Iterator<javax.imageio.ImageTypeSpecifier> getImageTypes(int imageIndex)
                                                                   throws java.io.IOException
Returns possible image types to which the given image may be decoded. The default implementation depends on the default image type policy:

Specified by:
getImageTypes in class javax.imageio.ImageReader
Parameters:
imageIndex - The image index, from 0 inclusive to getNumImages(boolean) exclusive.
Returns:
The image type specifiers that are common to all tiles.
Throws:
java.io.IOException - If an error occurs reading the information from the input source.

getDefaultReadParam

public MosaicImageReadParam getDefaultReadParam()
Returns default parameters appropriate for this format.

Overrides:
getDefaultReadParam in class javax.imageio.ImageReader

getStreamMetadata

public javax.imageio.metadata.IIOMetadata getStreamMetadata()
                                                     throws java.io.IOException
Returns the metadata associated with the input source as a whole, or null. The default implementation tries to merge the metadata from every tiles.

Specified by:
getStreamMetadata in class javax.imageio.ImageReader
Throws:
java.io.IOException - if an error occurs during reading.

getStreamMetadata

public javax.imageio.metadata.IIOMetadata getStreamMetadata(java.lang.String formatName,
                                                            java.util.Set<java.lang.String> nodeNames)
                                                     throws java.io.IOException
Returns the stream metadata for the given format and nodes, or null. The default implementation tries to merge the metadata from every tiles.

Overrides:
getStreamMetadata in class javax.imageio.ImageReader
Throws:
java.io.IOException - if an error occurs during reading.

getImageMetadata

public javax.imageio.metadata.IIOMetadata getImageMetadata(int imageIndex)
                                                    throws java.io.IOException
Returns the metadata associated with the given image, or null. The default implementation tries to merge the metadata from every tiles.

Specified by:
getImageMetadata in class javax.imageio.ImageReader
Parameters:
imageIndex - the index of the image whose metadata is to be retrieved.
Returns:
The metadata, or null.
Throws:
java.lang.IllegalStateException - if the input source has not been set.
java.lang.IndexOutOfBoundsException - if the supplied index is out of bounds.
java.io.IOException - if an error occurs during reading.

getImageMetadata

public javax.imageio.metadata.IIOMetadata getImageMetadata(int imageIndex,
                                                           java.lang.String formatName,
                                                           java.util.Set<java.lang.String> nodeNames)
                                                    throws java.io.IOException
Returns the image metadata for the given format and nodes, or null. The default implementation tries to merge the metadata from every tiles.

Overrides:
getImageMetadata in class javax.imageio.ImageReader
Throws:
java.io.IOException - if an error occurs during reading.

read

public java.awt.image.BufferedImage read(int imageIndex,
                                         javax.imageio.ImageReadParam param)
                                  throws java.io.IOException
Reads the image indexed by imageIndex using a supplied parameters. See MosaicImageReadParam for a performance recommandation. If the parameters allow subsampling changes, then the subsampling effectively used will be written back in the given parameters.

Specified by:
read in class javax.imageio.ImageReader
Parameters:
imageIndex - The index of the image to be retrieved.
param - The parameters used to control the reading process, or null. An instance of MosaicImageReadParam is expected but not required.
Returns:
The desired portion of the image.
Throws:
java.io.IOException - if an error occurs during reading.

readTile

public java.awt.image.BufferedImage readTile(int imageIndex,
                                             int tileX,
                                             int tileY)
                                      throws java.io.IOException
Reads the tile indicated by the tileX and tileY arguments.

Overrides:
readTile in class javax.imageio.ImageReader
Parameters:
imageIndex - The index of the image to be retrieved.
tileX - The column index (starting with 0) of the tile to be retrieved.
tileY - The row index (starting with 0) of the tile to be retrieved.
Returns:
The desired tile.
Throws:
java.io.IOException - if an error occurs during reading.

abort

public void abort()
Requests that any current read operation be aborted.

Overrides:
abort in class javax.imageio.ImageReader

close

public void close()
           throws java.io.IOException
Closes any image input streams thay may be held by tiles. The streams will be opened again when they will be first needed.

Throws:
java.io.IOException - if error occured while closing a stream.

dispose

public void dispose()
Allows any resources held by this reader to be released. The default implementation closes any image input streams thay may be held by tiles, then disposes every tile image readers.

Overrides:
dispose in class javax.imageio.ImageReader


Copyright © 1996-2010 Geotools. All Rights Reserved.