|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectImageReader
SpatialImageReader
ImageReaderAdapter
@Decorator(value=javax.imageio.ImageReader.class) public abstract class ImageReaderAdapter
Base class for readers which delegate most of their work to an other ImageReader.
This is used for reusing an existing image reader while adding some extra functionalities,
like adding geographic information in SpatialMetadata.
The wrapped image reader is called the main reader. The input given to that
reader is determined by the createInput(String) method - it may or may not be the
same input than the one given to this ImageReaderAdapter. Most methods like
getWidth(int), getHeight(int) and read(int) delegate directly
to the main reader.
The amount of methods declared in this class is large, but the only new methods are
createInput(String) and initialize(). All other methods override
existing methods declared in parent classes, mostly ImageReader and
SpatialImageReader.
Subclasses typically need to implement of override the following methods only:
initialize() as a hook available for custom initialization.createInput(String) for defining how, given a "main" file,
to find the additional files (TFW, PRJ, DIM, etc.).createMetadata(int) for creating the IIOMetadata objects.
Example
The World File format is composed of a classical image file (usually with the
".tiff", ".jpg" or ".png" extension) together with a small text file
containing geolocalization information (often with the ".tfw" extension) and an other
small text file containing projection information (".prj" extension). This
ImageReaderAdapter class can be used for wrapping a TIFF image reader, augmented with
the parsing of TFW and PRJ files. The information fetched from those files are stored in the
SpatialMetadata object returned by the getImageMetadata(int) method in this
class. The createMetadata(int) protected method provides a convenient hook where to
fill the metadata information.
ImageWriterAdapter
| coverage/geotk-coverageio (download) | View source code for this class |
| Nested Class Summary | |
|---|---|
static class |
ImageReaderAdapter.Spi
Service provider interface (SPI) for ImageReaderAdapters. |
| Field Summary | |
|---|---|
protected ImageReader |
main
The reader to use for reading the pixel values. |
| Fields inherited from class ImageReader |
|---|
availableLocales, ignoreMetadata, input, locale, minIndex, originatingProvider, progressListeners, seekForwardOnly, updateListeners, warningListeners, warningLocales |
| Fields inherited from interface WarningProducer |
|---|
LOGGER |
| Constructor Summary | |
|---|---|
protected |
ImageReaderAdapter(ImageReaderAdapter.Spi provider)
Constructs a new image reader. |
protected |
ImageReaderAdapter(ImageReaderAdapter.Spi provider,
ImageReader main)
Constructs a new image reader wrapping the given reader. |
| Method Summary | |
|---|---|
void |
abort()
Requests that any current read operation be aborted. |
void |
addIIOReadProgressListener(IIOReadProgressListener listener)
Adds the given listener to the list of registered progress listeners. |
void |
addIIOReadUpdateListener(IIOReadUpdateListener listener)
Adds the given listener to the list of registered update listeners. |
void |
addIIOReadWarningListener(IIOReadWarningListener listener)
Adds the given listener to the list of registered warning listeners. |
boolean |
canReadRaster()
Returns true if this plug-in supports reading just a Raster of pixel data. |
protected void |
close()
Closes the input stream created by createInput(String). |
protected Object |
createInput(String readerID)
Creates the input to give to the main reader, or to an other reader identified by the readerID argument. |
protected SpatialMetadata |
createMetadata(int imageIndex)
Creates a new stream or image metadata. |
void |
dispose()
Allows any resources held by this object to be released. |
protected void |
finalize()
Invokes the close() method when this reader is garbage-collected. |
float |
getAspectRatio(int imageIndex)
Returns the aspect ratio of the given image. |
Locale[] |
getAvailableLocales()
Returns the locales that may be used to localize warning listeners. |
SpatialImageReadParam |
getDefaultReadParam()
Returns a default parameter object appropriate for this format. |
int |
getDimension(int imageIndex)
Returns the number of dimension of the image at the given index. |
GridEnvelope |
getGridEnvelope(int imageIndex)
Returns the grid range of the image at the given index. |
int |
getHeight(int imageIndex)
Returns the height in pixels of the given image within the input source. |
SpatialMetadata |
getImageMetadata(int imageIndex)
Returns metadata associated with the given image. |
Iterator<ImageTypeSpecifier> |
getImageTypes(int imageIndex)
Returns a collection of ImageTypeSpecifier containing possible image types
to which the given image may be decoded. |
Locale |
getLocale()
Returns the locale used to localize warning listeners. |
int |
getNumBands(int imageIndex)
Returns the number of bands available for the specified image. |
int |
getNumImages(boolean allowSearch)
Returns the number of images available from the current input source. |
int |
getNumThumbnails(int imageIndex)
Returns the number of thumbnail preview images associated with the given image. |
ImageTypeSpecifier |
getRawImageType(int imageIndex)
Returns an image type specifier indicating the SampleModel and
ColorModel which most closely represents the "raw" internal format
of the image. |
SpatialMetadata |
getStreamMetadata()
Returns metadata associated with the input source as a whole. |
int |
getThumbnailHeight(int imageIndex,
int thumbnailIndex)
Returns the height of the thumbnail preview image associated to the given image. |
int |
getThumbnailWidth(int imageIndex,
int thumbnailIndex)
Returns the width of the thumbnail preview image associated to the given image. |
int |
getTileGridXOffset(int imageIndex)
Returns the X coordinate of the upper-left corner of tile (0, 0) in the given image. |
int |
getTileGridYOffset(int imageIndex)
Returns the Y coordinate of the upper-left corner of tile (0, 0) in the given image. |
int |
getTileHeight(int imageIndex)
Returns the height of a tile in the given image. |
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 |
hasColors(int imageIndex)
Returns true if the image at the given index has a color palette. |
boolean |
hasThumbnails(int imageIndex)
Returns true if the given image has thumbnail preview images associated with it. |
protected void |
initialize()
Invoked automatically when the main reader has been given a new input. |
boolean |
isImageTiled(int imageIndex)
Returns true if the image is organized into tiles, that is, equal-sized
non-overlapping rectangles. |
boolean |
isRandomAccessEasy(int imageIndex)
Returns true if the storage format of the given image places no inherent impediment
on random access to pixels. |
BufferedImage |
read(int imageIndex)
Reads the image indexed by imageIndex using a default ImageReadParam. |
BufferedImage |
read(int imageIndex,
ImageReadParam param)
Reads the image indexed by imageIndex using the given parameters. |
RenderedImage |
readAsRenderedImage(int imageIndex,
ImageReadParam param)
Reads the image indexed by imageIndex as a rendered image. |
boolean |
readerSupportsThumbnails()
Returns true if the image format supports thumbnail preview images associated
with it. |
Raster |
readRaster(int imageIndex,
ImageReadParam param)
Returns a new raster containing the raw pixel data from the image stream, without any color conversion applied. |
BufferedImage |
readThumbnail(int imageIndex,
int thumbnailIndex)
Returns the thumbnail preview image indexed by thumbnailIndex, associated with the
given image. |
BufferedImage |
readTile(int imageIndex,
int tileX,
int tileY)
Reads the tile indicated by the tileX and tileY arguments. |
Raster |
readTileRaster(int imageIndex,
int tileX,
int tileY)
Reads the raster indicated by the tileX and tileY arguments, without any
color conversion applied. |
void |
removeAllIIOReadProgressListeners()
Removes all currently registered progress listeners. |
void |
removeAllIIOReadUpdateListeners()
Removes all currently registered update listeners. |
void |
removeAllIIOReadWarningListeners()
Removes all currently registered warning listeners. |
void |
removeIIOReadProgressListener(IIOReadProgressListener listener)
Removes the given listener from the list of registered progress listeners. |
void |
removeIIOReadUpdateListener(IIOReadUpdateListener listener)
Removes the given listener from the list of registered update listeners. |
void |
removeIIOReadWarningListener(IIOReadWarningListener listener)
Removes the given listener from the list of registered warning listeners. |
void |
reset()
Restores the ImageReader to its initial state. |
void |
setLocale(Locale locale)
Sets the locale used to localize warning listeners. |
| Methods inherited from class SpatialImageReader |
|---|
checkBandIndex, checkImageIndex, collapseNoDataValues, flipVertically, getDestination, getImageType, getRawDataType, setInput, warningOccurred |
| Methods inherited from class Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final ImageReader main
| Constructor Detail |
|---|
protected ImageReaderAdapter(ImageReaderAdapter.Spi provider)
throws IOException
provider - The ImageReaderSpi that is constructing this object.
IOException - If an error occurred while creating the main reader.
protected ImageReaderAdapter(ImageReaderAdapter.Spi provider,
ImageReader main)
provider - The ImageReaderSpi that is constructing this object, or null.main - The reader to use for reading the pixel values.| Method Detail |
|---|
protected Object createInput(String readerID)
throws IllegalStateException,
IOException
readerID argument. The default ImageReaderAdapter implementation
invokes this method with a readerID argument value equals to "main" when
the main reader needs to be used for the first time. This may happen at any
time after the setInput method has been invoked.
The only readerID argument value accepted by the default implementation is
"main"; any other argument value causes a null value to be returned.
However subclasses can override this method for supporting more reader types. The
table below summarizes a few types supported by this reader and different subclasses:
| Reader type | Defined by | Usage |
|---|---|---|
"main" |
ImageReaderAdapter |
The input to be given to the main reader. |
"tfw" |
WorldFileImageReader |
The input for the World File. |
"prj" |
WorldFileImageReader |
The input for the Map Projection file. |
The default implementation first checks if the main reader accepts directly
the input of this reader. If so, then that input is returned with no
change. Otherwise the input is wrapped in an ImageInputStream, which is
returned. The input stream assigned to the main reader will be closed by
the close() method.
readerID - Identifier of the reader for which an input is needed.
null if this
method can not create such input.
IllegalStateException - if the input source has not been set.
IOException - If an error occurred while creating the input for the reader.ImageWriterAdapter.createOutput(String)
protected void initialize()
throws IOException
createInput("main").
The default implementation does nothing. Subclasses can override this method for performing additional initialization.
IOException - If an error occurred while initializing the main reader.
public int getNumImages(boolean allowSearch)
throws IllegalStateException,
IOException
getNumImages in class SpatialImageReaderallowSearch - If true, the number of images will be returned
even if a search is required.
allowSearch
is false and a search would be required.
IllegalStateException - if the input source has not been set.
IOException - if an error occurs reading the information from the input source.
public int getNumThumbnails(int imageIndex)
throws IllegalStateException,
IOException
getNumImages(boolean).
getNumThumbnails in class ImageReaderIllegalStateException
IOExceptionhasThumbnails(int)
public int getNumBands(int imageIndex)
throws IOException
SpatialImageReader,
or returns the number of bands of the raw image
type otherwise.
Note that the main reader is indirectly initialized by an implicit call to
getNumImages(boolean).
getNumBands in class SpatialImageReaderimageIndex - The image index.
IOException - if an error occurs reading the information from the input source.
public int getDimension(int imageIndex)
throws IOException
SpatialImageReader,
or returns 2 otherwise.
Note that the main reader is indirectly initialized by an implicit call to
getNumImages(boolean).
getDimension in class SpatialImageReaderimageIndex - The image index.
IOException - if an error occurs reading the information from the input source.MultidimensionalImageStore
public GridEnvelope getGridEnvelope(int imageIndex)
throws IOException
SpatialImageReader,
or to the super-class otherwise.
Note that the main reader is indirectly initialized by an implicit call to
getNumImages(boolean).
getGridEnvelope in class SpatialImageReaderimageIndex - The image index.
IOException - if an error occurs reading the information from the input source.MultidimensionalImageStore
public float getAspectRatio(int imageIndex)
throws IOException
getNumImages(boolean).
getAspectRatio in class ImageReaderIOExceptiongetWidth(int),
getHeight(int)
public int getWidth(int imageIndex)
throws IOException
getNumImages(boolean).
getWidth in class ImageReaderIOExceptiongetTileWidth(int),
getThumbnailWidth(int, int)
public int getHeight(int imageIndex)
throws IOException
getNumImages(boolean).
getHeight in class ImageReaderIOExceptiongetTileHeight(int),
getThumbnailHeight(int, int)
public int getTileWidth(int imageIndex)
throws IOException
getNumImages(boolean).
getTileWidth in class ImageReaderIOExceptionisImageTiled(int),
getTileGridXOffset(int)
public int getTileHeight(int imageIndex)
throws IOException
getNumImages(boolean).
getTileHeight in class ImageReaderIOExceptionisImageTiled(int),
getTileGridYOffset(int)
public int getTileGridXOffset(int imageIndex)
throws IOException
getNumImages(boolean).
getTileGridXOffset in class ImageReaderIOExceptionisImageTiled(int)
public int getTileGridYOffset(int imageIndex)
throws IOException
getNumImages(boolean).
getTileGridYOffset in class ImageReaderIOExceptionisImageTiled(int)
public int getThumbnailWidth(int imageIndex,
int thumbnailIndex)
throws IOException
getNumImages(boolean).
getThumbnailWidth in class ImageReaderIOExceptionhasThumbnails(int),
getNumThumbnails(int)
public int getThumbnailHeight(int imageIndex,
int thumbnailIndex)
throws IOException
getNumImages(boolean).
getThumbnailHeight in class ImageReaderIOExceptionhasThumbnails(int),
getNumThumbnails(int)
public boolean hasThumbnails(int imageIndex)
throws IOException
true if the given image has thumbnail preview images associated with it.
The default implementation delegates to the main reader. Note that the main
reader is indirectly initialized by an implicit call to getNumImages(boolean).
hasThumbnails in class ImageReaderIOExceptiongetNumThumbnails(int),
readerSupportsThumbnails(),
getThumbnailWidth(int, int),
getThumbnailHeight(int, int)
public boolean isImageTiled(int imageIndex)
throws IOException
true if the image is organized into tiles, that is, equal-sized
non-overlapping rectangles. The default implementation delegates to the main
reader. Note that the main reader is indirectly initialized by an implicit call to
getNumImages(boolean).
isImageTiled in class ImageReaderIOExceptiongetTileWidth(int),
getTileHeight(int),
getTileGridXOffset(int),
getTileGridYOffset(int)
public boolean isRandomAccessEasy(int imageIndex)
throws IOException
true if the storage format of the given image places no inherent impediment
on random access to pixels. The default implementation delegates to the main
reader. Note that the main reader is indirectly initialized by an implicit call to
getNumImages(boolean).
isRandomAccessEasy in class ImageReaderIOException
public SpatialMetadata getStreamMetadata()
throws IOException
Subclasses should consider overriding the createMetadata(int) method instead
than this one.
getStreamMetadata in class SpatialImageReadernull if none.
IOException - if an error occurs during reading.
public SpatialMetadata getImageMetadata(int imageIndex)
throws IOException
getNumImages(boolean)) that the main
reader is initialized, then delegates to the createMetadata(int) method as
documented in the super-class method.
Subclasses should consider overriding the createMetadata(int) method instead
than this one.
getImageMetadata in class SpatialImageReaderimageIndex - The image index.
null if none.
IOException - if an error occurs during reading.
protected SpatialMetadata createMetadata(int imageIndex)
throws IOException
getStreamMetadata() and getImageMetadata(int) methods. The
default implementation delegates to the corresponding method of the
main reader. Then there is a choice:
SpatialMetadata,
returns it unchanged.SpatialMetadata, which will
delegate the request for any metadata format other than
"geotk-coverageio_3.07"
to the wrapped format.
createMetadata in class SpatialImageReaderimageIndex - -1 for stream metadata, or the image index for image metadata.
null if none.
IOException - If an error occurred while reading metadata.
public boolean hasColors(int imageIndex)
throws IOException
true if the image at the given index has a color palette. The default
implementation delegates to the main reader if it is an instance of
SpatialImageReader, or returns true otherwise (on the assumption that
the wrapped reader is for some standard format like PNG).
hasColors in class SpatialImageReaderimageIndex - The index of the image to be queried.
true if the image at the given index has a color palette.
IOException - If an error occurs reading the information from the input source.SpatialImageReadParam.setPaletteName(String)
public Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex)
throws IOException
ImageTypeSpecifier containing possible image types
to which the given image may be decoded. The default implementation delegates to the
main image reader. Note that the main reader is indirectly
initialized by an implicit call to getNumImages(boolean).
getImageTypes in class SpatialImageReaderimageIndex - The index of the image to be queried.
IOException - If an error occurs reading the format information from the input source.
public ImageTypeSpecifier getRawImageType(int imageIndex)
throws IOException
SampleModel and
ColorModel which most closely represents the "raw" internal format
of the image. The default implementation delegates to the main image reader.
Note that the main reader is indirectly initialized by an implicit call to
getNumImages(boolean).
getRawImageType in class SpatialImageReaderimageIndex - The index of the image to be queried.
null).
IOException - If an error occurs reading the format information from the input source.SpatialImageReader.getImageType(int, ImageReadParam, SampleConverter[]),
SpatialImageReader.getDefaultReadParam()public SpatialImageReadParam getDefaultReadParam()
getDefaultReadParam in class SpatialImageReaderImageReadParam object which may be used.
public BufferedImage read(int imageIndex)
throws IOException
imageIndex using a default ImageReadParam.
The default implementation delegates to the main image reader. Note that
the main reader is indirectly initialized by an implicit call to
getNumImages(boolean).
read in class ImageReaderIOException
public BufferedImage read(int imageIndex,
ImageReadParam param)
throws IOException
imageIndex using the given parameters.
The default implementation delegates to the main image reader.
Note that the main reader is indirectly initialized by an implicit call to
getNumImages(boolean).
read in class ImageReaderIOException
public RenderedImage readAsRenderedImage(int imageIndex,
ImageReadParam param)
throws IOException
imageIndex as a rendered image.
The default implementation delegates to the main image reader.
Note that the main reader is indirectly initialized by an implicit call to
getNumImages(boolean).
readAsRenderedImage in class ImageReaderIOException
public BufferedImage readTile(int imageIndex,
int tileX,
int tileY)
throws IOException
tileX and tileY arguments.
The default implementation delegates to the main image reader.
Note that the main reader is indirectly initialized by an implicit call to
getNumImages(boolean).
readTile in class ImageReaderIOExceptionisImageTiled(int)
public Raster readRaster(int imageIndex,
ImageReadParam param)
throws IOException
getNumImages(boolean).
readRaster in class ImageReaderIOExceptioncanReadRaster()
public Raster readTileRaster(int imageIndex,
int tileX,
int tileY)
throws IOException
tileX and tileY arguments, without any
color conversion applied. The default implementation delegates to the main
image reader. Note that the main reader is indirectly initialized by an
implicit call to getNumImages(boolean).
readTileRaster in class ImageReaderIOExceptionisImageTiled(int),
canReadRaster()
public BufferedImage readThumbnail(int imageIndex,
int thumbnailIndex)
throws IOException
thumbnailIndex, associated with the
given image. The default implementation delegates to the main image reader.
Note that the main reader is indirectly initialized by an implicit call to
getNumImages(boolean).
readThumbnail in class ImageReaderIOExceptionhasThumbnails(int)public boolean readerSupportsThumbnails()
true if the image format supports thumbnail preview images associated
with it. The default implementation delegates to the main reader.
No input needs to be set for this method.
readerSupportsThumbnails in class ImageReaderhasThumbnails(int)public boolean canReadRaster()
true if this plug-in supports reading just a Raster of pixel data.
The default implementation delegates to the main reader.
No input needs to be set for this method.
canReadRaster in class ImageReaderpublic Locale[] getAvailableLocales()
getAvailableLocales in class ImageReaderpublic Locale getLocale()
getLocale in interface LocalizedgetLocale in class ImageReadernull if not explicitly defined.public void setLocale(Locale locale)
setLocale in class ImageReaderpublic void addIIOReadWarningListener(IIOReadWarningListener listener)
addIIOReadWarningListener in class ImageReaderpublic void removeIIOReadWarningListener(IIOReadWarningListener listener)
removeIIOReadWarningListener in class ImageReaderpublic void removeAllIIOReadWarningListeners()
removeAllIIOReadWarningListeners in class ImageReaderpublic void addIIOReadProgressListener(IIOReadProgressListener listener)
addIIOReadProgressListener in class ImageReaderpublic void removeIIOReadProgressListener(IIOReadProgressListener listener)
removeIIOReadProgressListener in class ImageReaderpublic void removeAllIIOReadProgressListeners()
removeAllIIOReadProgressListeners in class ImageReaderpublic void addIIOReadUpdateListener(IIOReadUpdateListener listener)
addIIOReadUpdateListener in class ImageReaderpublic void removeIIOReadUpdateListener(IIOReadUpdateListener listener)
removeIIOReadUpdateListener in class ImageReaderpublic void removeAllIIOReadUpdateListeners()
removeAllIIOReadUpdateListeners in class ImageReaderpublic void abort()
abort in class ImageReaderpublic void reset()
ImageReader to its initial state. The default implementation
delegates to both the main reader and to the super-class method.
reset in class ImageReaderpublic void dispose()
dispose in interface Disposabledispose in class SpatialImageReader
protected void close()
throws IOException
createInput(String). This method does nothing
if the input used by the main reader is the one given by the user to the
setInput method. Otherwise, if the input of
the main reader is an instance of ImageInputStream or Closeable, then it
is closed.
This method is invoked automatically by setInput(...), reset(), dispose() or
finalize() methods and doesn't need to be invoked explicitly.
It has protected access only in order to allow overriding by subclasses.
Overriding methods shall make sure that super.close() is invoked
even in case of failure.
close in class SpatialImageReaderIOException - if an error occurred while closing the stream.
protected void finalize()
throws Throwable
close() method when this reader is garbage-collected.
Note that this will actually close the stream only if it has been created
by this reader, rather than supplied by the user.
finalize in class ObjectThrowable
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||