org.geotoolkit.coverage.io
Class ImageReaderAdapter

Object
  extended by ImageReader
      extended by SpatialImageReader
          extended by ImageReaderAdapter
All Implemented Interfaces:
WarningProducer, Disposable, Localized

public class ImageReaderAdapter
extends SpatialImageReader

An ImageReader implementation which use a GridCoverageReader for reading sample values. This class is the converse of ImageCoverageReader: it takes a high level construct (GridCoverageReader) and wraps it as a lower level construct (ImageReader). This is an unusual thing to do - consequently, the only purpose of this class is to allow usage of an existing GridCoverageReader instance with API working only with ImageReader instances.


Example
ImageReaderAdapter can be used in order to show the content of a GridCoverageReader in an ImageFileProperties widget.

Note: An other approach would be to unwrap the ImageReader which is wrapped by ImageCoverageReader. However the result would not be always the same, because some modules (for example geotk-coverage-sql) define subclasses of ImageCoverageReader which alter the way the image is read. The purpose of ImageReaderAdapter is to get exactly the same image than the one produced by the wrapped GridCoverageReader.

Since:
3.14
Version:
3.19
Author:
Martin Desruisseaux (Geomatys)
Module:
coverage/geotk-coverageio (download)    View source code for this class

Nested Class Summary
 
Nested classes/interfaces inherited from class SpatialImageReader
SpatialImageReader.Spi
 
Field Summary
protected  GridCoverageReader reader
          The coverage reader on which to delegate all ImageReader method invocations.
 
Fields inherited from class ImageReader
availableLocales, ignoreMetadata, input, locale, minIndex, originatingProvider, progressListeners, seekForwardOnly, updateListeners, warningListeners, warningLocales
 
Fields inherited from interface WarningProducer
LOGGER
 
Constructor Summary
ImageReaderAdapter(GridCoverageReader reader)
          Creates a new adapter for the given coverage reader.
 
Method Summary
 void abort()
          Aborts the current reading process.
protected  SpatialMetadata createMetadata(int imageIndex)
          Fetches the stream metadata or image metadata.
 void dispose()
          Disposes this image reader and the wrapped GridCoverageReader.
 int getDimension(int imageIndex)
          Returns the number of dimension of the image at the given index.
 GridEnvelope getGridEnvelope(int imageIndex)
          Returns the grid envelope of the image at the given index.
 int getHeight(int imageIndex)
          Returns the height of the image at the given index.
 Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex)
          Returns the possible image types to which the given image can be decoded.
 int getNumBands(int imageIndex)
          Returns the number of bands available for the specified image.
 int getNumImages(boolean allowSearch)
          Returns the number of images in the current input.
 ImageReaderSpi getOriginatingProvider()
          Returns the ImageReader provider, or null if none.
protected  int getRawDataType(int imageIndex)
          Returns the data type which most closely represents the "raw" internal data of the image.
 ImageTypeSpecifier getRawImageType(int imageIndex)
          Returns the raw type of the image at the given index.
protected  Dimension getSize(int imageIndex)
          Returns the image width and height at the given index.
 int getWidth(int imageIndex)
          Returns the width of the image at the given index.
protected  GridCoverage read(int index, GridCoverageReadParam param)
          Reads the coverage at the given index.
 BufferedImage read(int imageIndex, ImageReadParam param)
          Reads the image at the given index.
 RenderedImage readAsRenderedImage(int imageIndex, ImageReadParam param)
          Reads the image at the given index.
 void setInput(Object input, boolean seekForwardOnly, boolean ignoreMetadata)
          Sets the input to be read.
 
Methods inherited from class SpatialImageReader
checkBandIndex, checkImageIndex, close, collapseNoDataValues, flipVertically, getDefaultReadParam, getDestination, getImageMetadata, getImageType, getStreamMetadata, hasColors, warningOccurred
 
Methods inherited from class ImageReader
abortRequested, addIIOReadProgressListener, addIIOReadUpdateListener, addIIOReadWarningListener, canReadRaster, checkReadParamBandSettings, clearAbortRequest, computeRegions, getAspectRatio, getAvailableLocales, getDestination, getFormatName, getImageMetadata, getInput, getLocale, getMinIndex, getNumThumbnails, getSourceRegion, getStreamMetadata, getThumbnailHeight, getThumbnailWidth, getTileGridXOffset, getTileGridYOffset, getTileHeight, getTileWidth, hasThumbnails, isIgnoringMetadata, isImageTiled, isRandomAccessEasy, isSeekForwardOnly, processImageComplete, processImageProgress, processImageStarted, processImageUpdate, processPassComplete, processPassStarted, processReadAborted, processSequenceComplete, processSequenceStarted, processThumbnailComplete, processThumbnailPassComplete, processThumbnailPassStarted, processThumbnailProgress, processThumbnailStarted, processThumbnailUpdate, processWarningOccurred, processWarningOccurred, read, readAll, readAll, readerSupportsThumbnails, readRaster, readThumbnail, readTile, readTileRaster, removeAllIIOReadProgressListeners, removeAllIIOReadUpdateListeners, removeAllIIOReadWarningListeners, removeIIOReadProgressListener, removeIIOReadUpdateListener, removeIIOReadWarningListener, reset, setInput, setInput, setLocale
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface Localized
getLocale
 

Field Detail

reader

protected final GridCoverageReader reader
The coverage reader on which to delegate all ImageReader method invocations.

Constructor Detail

ImageReaderAdapter

public ImageReaderAdapter(GridCoverageReader reader)
Creates a new adapter for the given coverage reader.

Parameters:
reader - The coverage reader on which to delegate all ImageReader method invocations.
Method Detail

getOriginatingProvider

public ImageReaderSpi getOriginatingProvider()
Returns the ImageReader provider, or null if none.

Overrides:
getOriginatingProvider in class ImageReader

setInput

public void setInput(Object input,
                     boolean seekForwardOnly,
                     boolean ignoreMetadata)
Sets the input to be read. In the input can be successfully assigned to the wrapped GridCoverageReader, then it is also saved in the inherited ImageReader.input field for retrieval by ImageReader.getInput().

Overrides:
setInput in class SpatialImageReader
Parameters:
input - The input object to use for future decoding.
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.

getNumImages

public int getNumImages(boolean allowSearch)
                 throws IOException
Returns the number of images in the current input. The default implementation returns the length of the list returned by GridCoverageReader.getCoverageNames().

Overrides:
getNumImages in class SpatialImageReader
Parameters:
allowSearch - If true, the number of images will be returned even if a search is required.
Returns:
The number of images, or -1 if allowSearch is false and a search would be required.
Throws:
IOException - if an error occurs reading the information from the input source.

getNumBands

public int getNumBands(int imageIndex)
                throws IOException
Returns the number of bands available for the specified image. The default implementation returns the length of the list returned by GridCoverageReader.getSampleDimensions(int).

Overrides:
getNumBands in class SpatialImageReader
Parameters:
imageIndex - The image index.
Returns:
The number of bands available for the specified image.
Throws:
IOException - if an error occurs reading the information from the input source.

getDimension

public int getDimension(int imageIndex)
                 throws IOException
Returns the number of dimension of the image at the given index. The default implementation returns the dimension of the geometry returned by GridCoverageReader.getGridGeometry(int).

Overrides:
getDimension in class SpatialImageReader
Parameters:
imageIndex - The image index.
Returns:
The number of dimension for the image at the given index.
Throws:
IOException - if an error occurs reading the information from the input source.
See Also:
MultidimensionalImageStore

getGridEnvelope

public GridEnvelope getGridEnvelope(int imageIndex)
                             throws IOException
Returns the grid envelope of the image at the given index. The default implementation returns the grid range of the geometry returned by GridCoverageReader.getGridGeometry(int).

Overrides:
getGridEnvelope in class SpatialImageReader
Parameters:
imageIndex - The image index.
Returns:
The grid envelope for the image at the given index.
Throws:
IOException - if an error occurs reading the information from the input source.
Since:
3.19
See Also:
MultidimensionalImageStore

getSize

protected Dimension getSize(int imageIndex)
                     throws IOException
Returns the image width and height at the given index. The default implementation computes the size from the geometry returned by GridCoverageReader.getGridGeometry(int). Subclasses can override this method if they want to compute the size in a different way.

Parameters:
imageIndex - The image index.
Returns:
The width and height of the image at the given index.
Throws:
IOException - if an error occurs reading the information from the input source.

getWidth

public final int getWidth(int imageIndex)
                   throws IOException
Returns the width of the image at the given index. This method delegates to getSize(int), which computes the size from the grid geometry.

Specified by:
getWidth in class ImageReader
Throws:
IOException - if an error occurs reading the information from the input source.

getHeight

public final int getHeight(int imageIndex)
                    throws IOException
Returns the height of the image at the given index. This method delegates to getSize(int), which computes the size from the grid geometry.

Specified by:
getHeight in class ImageReader
Throws:
IOException - if an error occurs reading the information from the input source.

getRawDataType

protected int getRawDataType(int imageIndex)
                      throws IOException
Returns the data type which most closely represents the "raw" internal data of the image. The default implementation returns the data type of the sample model of the type returned by getRawImageType(int).

Overrides:
getRawDataType in class SpatialImageReader
Parameters:
imageIndex - The index of the image to be queried.
Returns:
The data type (DataBuffer.TYPE_FLOAT by default).
Throws:
IOException - if an error occurs reading the information from the input source.
See Also:
SpatialImageReader.getImageType(int, ImageReadParam, SampleConverter[]), SampleConversionType.SHIFT_SIGNED_INTEGERS

getRawImageType

public ImageTypeSpecifier getRawImageType(int imageIndex)
                                   throws IOException
Returns the raw type of the image at the given index. The default implementation computes the type from the value returned by GridCoverageReader.getSampleDimensions(int).

Overrides:
getRawImageType in class SpatialImageReader
Parameters:
imageIndex - The index of the image to be queried.
Returns:
The image type (never null).
Throws:
IOException - if an error occurs reading the information from the input source.
See Also:
SpatialImageReader.getImageType(int, ImageReadParam, SampleConverter[]), SpatialImageReader.getDefaultReadParam()

getImageTypes

public Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex)
                                           throws IOException
Returns the possible image types to which the given image can be decoded. The default implementation puts the value returned by getRawDataType(int) in a singleton set.

Overrides:
getImageTypes in class SpatialImageReader
Parameters:
imageIndex - The index of the image to be queried.
Returns:
A set of suggested image types for decoding the current given image.
Throws:
IOException - if an error occurs reading the information from the input source.

createMetadata

protected SpatialMetadata createMetadata(int imageIndex)
                                  throws IOException
Fetches the stream metadata or image metadata. This method is invoked automatically when the metadata are requested for the first time. The default implementation delegates directly to the coverage reader.

Overrides:
createMetadata in class SpatialImageReader
Parameters:
imageIndex - -1 for stream metadata, or the image index for image metadata.
Returns:
The requested metadata, or null if none.
Throws:
IOException - if an error occurs reading the information from the input source.

readAsRenderedImage

public RenderedImage readAsRenderedImage(int imageIndex,
                                         ImageReadParam param)
                                  throws IOException
Reads the image at the given index. The default implementation reads the coverage using the wrapped GridCoverageReader, then extracts the RenderedImage from the coverage. Note that the image returned by this method will typically be an instance of PlanarImage rather than BufferedImage.

Overrides:
readAsRenderedImage in class ImageReader
Throws:
IOException - if an error occurs reading the information from the input source.

read

public BufferedImage read(int imageIndex,
                          ImageReadParam param)
                   throws IOException
Reads the image at the given index. The default implementation delegates to readAsRenderedImage(int, ImageReadParam), then converts the image to an instance of BufferedImage.

The readAsRenderedImage method should be preferred when the image is not required to be an instance of BufferedImage.

Specified by:
read in class ImageReader
Throws:
IOException - if an error occurs reading the information from the input source.

read

protected GridCoverage read(int index,
                            GridCoverageReadParam param)
                     throws IOException
Reads the coverage at the given index. This method is invoked by readAsRenderedImage after the image parameters have been converted to coverage parameters.

The default implementation delegates to GridCoverageReader.read(int, GridCoverageReadParam). Subclasses can override this method if they want to perform additional processing before or after the coverage is read. For example a subclass may invoke GridCoverage2D.view(ViewType.RENDERED) for a better image rendering.

Parameters:
index - The index of the coverage to be queried.
param - Optional parameters used to control the reading process, or null.
Returns:
The GridCoverage at the specified index, or null if abort() has been invoked in an other thread during the execution of this method.
Throws:
IOException - If the coverage can not be read.

abort

public void abort()
Aborts the current reading process. This method forward the call to the wrapped GridCoverageReader, but does not set the ImageReader.abortRequested() flag in this class (because it is not used).

Overrides:
abort in class ImageReader

dispose

public void dispose()
Disposes this image reader and the wrapped GridCoverageReader.

Specified by:
dispose in interface Disposable
Overrides:
dispose in class SpatialImageReader


Copyright © 2009-2012 Geotoolkit.org. All Rights Reserved.