| java.lang.Object javax.imageio.ImageReader org.geotools.image.io.GeographicImageReader
All known Subclasses: org.geotools.image.io.NullImageReader, org.geotools.image.io.StreamImageReader,
GeographicImageReader | abstract public class GeographicImageReader extends ImageReader (Code) | | Base class for readers of geographic images. The default implementation assumes that only one
is supported (as opposed to the arbitrary number
allowed by the standard
ImageReader ). It also provides a default image type built
automatically from a color palette and a range of valid values.
More specifically, this class provides the following conveniences to implementors:
Images may be flat binary or ASCII files with no meta-data and no color information.
Their pixel values may be floating point values instead of integers. The default
implementation assumes floating point values and uses a grayscale color space scaled
to fit the range of values. Displaying such an image may be very slow. Consequently,
users who want to display image are encouraged to change data type and color space with
Java Advanced Imaging
operators after reading.
since: 2.4 version: $Id: GeographicImageReader.java 27862 2007-11-12 19:51:19Z desruisseaux $ author: Martin Desruisseaux |
Field Summary | |
final static Logger | LOGGER The logger to use for events related to this image reader. |
Method Summary | |
protected void | checkBandIndex(int imageIndex, int bandIndex) Ensures that the specified band index is inside the expected range. | protected void | checkImageIndex(int imageIndex) Ensures that the specified image index is inside the expected range. | void | close() To be overriden and made
protected by
StreamImageReader only. | protected boolean | collapseNoDataValues(boolean isZeroValid, double[] nodataValues, int unusedSpace) Returns
true if the no-data values should be collapsed to 0 in order to save memory.
This method is invoked automatically by the
GeographicImageReader.getRawImageType(int,ImageReadParam,SampleConverter[]) getRawImageType method when it detected some unused space between the
and at least one
.
The default implementation returns
false in all cases, thus avoiding arbitrary
choice. | protected static void | flipVertically(ImageReadParam param, int srcHeight, Rectangle srcRegion) Flips the source region vertically. | public ImageReadParam | getDefaultReadParam() Returns a default parameter object appropriate for this format. | protected BufferedImage | getDestination(int imageIndex, ImageReadParam parameters, int width, int height, SampleConverter[] converters) Returns the buffered image to which decoded pixel data should be written. | final IndexedResourceBundle | getErrorResources() Returns the resources for formatting error messages. | public GeographicMetadata | getGeographicMetadata(int imageIndex) Returns a helper parser for metadata associated with the given image. | public IIOMetadata | getImageMetadata(int imageIndex) Returns metadata associated with the given image. | public Iterator | getImageTypes(int imageIndex) Returns a collection of
ImageTypeSpecifier containing possible image types to which
the given image may be decoded. | public int | getNumBands(int imageIndex) Returns the number of bands available for the specified image. | public int | getNumImages(boolean allowSearch) Returns the number of images available from the current input source.
The default implementation returns 1.
Parameters: allowSearch - If true, the number of images will be returnedeven if a search is required. | protected int | getRawDataType(int imageIndex) Returns the data type which most closely represents the "raw" internal data of the image.
It should be one of
DataBuffer constants. | public 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. | protected ImageTypeSpecifier | getRawImageType(int imageIndex, ImageReadParam parameters, SampleConverter[] converters) Returns an image type specifier indicating the
SampleModel and
ColorModel which most closely represents the "raw" internal format of the image. | public IIOMetadata | getStreamMetadata() Returns metadata associated with the input source as a whole. | public BufferedImage | read(int imageIndex) Reads the image indexed by
imageIndex using a default
ImageReadParam .
This is a convenience method that calls
(imageIndex,
) .
The default Java implementation passed a
null parameter. | public void | setInput(Object input, boolean seekForwardOnly, boolean ignoreMetadata) Sets the input source to use. | public void | warningOccurred(LogRecord record) Invoked when a warning occured. |
LOGGER | final static Logger LOGGER(Code) | | The logger to use for events related to this image reader.
|
GeographicImageReader | protected GeographicImageReader(ImageReaderSpi provider)(Code) | | Constructs a new image reader.
Parameters: provider - The ImageReaderSpi that is invoking this constructor,or null if none. |
collapseNoDataValues | protected boolean collapseNoDataValues(boolean isZeroValid, double[] nodataValues, int unusedSpace)(Code) | | Returns
true if the no-data values should be collapsed to 0 in order to save memory.
This method is invoked automatically by the
GeographicImageReader.getRawImageType(int,ImageReadParam,SampleConverter[]) getRawImageType method when it detected some unused space between the
and at least one
.
The default implementation returns
false in all cases, thus avoiding arbitrary
choice. Subclasses can override this method with some arbitrary threashold, as in the
example below:
return unusedSpace >= 1024;
Parameters: isZeroValid - true if 0 is a valid value. If this method returns true while isZeroValid is true , then the to be returned by GeographicImageReader.getRawImageType(int,ImageReadParam,SampleConverter[]) getRawImageType will offset all valid values by 1. Parameters: nodataValues - The (never null and never empty). Parameters: unusedSpace - The largest amount of unused space outside the range of valid values. |
flipVertically | protected static void flipVertically(ImageReadParam param, int srcHeight, Rectangle srcRegion)(Code) | | Flips the source region vertically. This method should be invoked straight after
GeographicImageReader.computeRegions computeRegions when the image to be read will be flipped
vertically, for example when the
sample
values are filled in a "
for (y=ymax-1; y>=ymin; y--) " loop instead of
"
for (y=ymin; y
This method should be invoked as in the example below:
computeRegions(param, srcWidth, srcHeight, image, srcRegion, destRegion);
flipVertically(param, srcHeight, srcRegion);
Parameters: param - The param argument given to computeRegions . Parameters: srcHeight - The srcHeight argument given to computeRegions . Parameters: srcRegion - The srcRegion argument given to computeRegions . |
getDestination | protected BufferedImage getDestination(int imageIndex, ImageReadParam parameters, int width, int height, SampleConverter[] converters) throws IOException(Code) | | Returns the buffered image to which decoded pixel data should be written. The image
is determined by inspecting the supplied parameters if it is non-null, as described
in the
.
In the default implementation, the
set is a singleton containing only the
.
Implementations of the
GeographicImageReader.read(int,ImageReadParam) method should invoke this
method instead of
GeographicImageReader.getDestination(ImageReadParam,Iterator,int,int) .
Parameters: imageIndex - The index of the image to be retrieved. Parameters: parameters - The parameter given to the read method. Parameters: width - The true width of the image or tile begin decoded. Parameters: height - The true width of the image or tile being decoded. Parameters: converters - If non-null, an array where to store the converters requiredfor converting decoded pixel data into stored pixel data. The buffered image to which decoded pixel data should be written. throws: IOException - If an error occurs reading the format information from the input source. See Also: GeographicImageReader.getRawImageType(int,ImageReadParam,SampleConverter[]) |
getGeographicMetadata | public GeographicMetadata getGeographicMetadata(int imageIndex) throws IOException(Code) | | Returns a helper parser for metadata associated with the given image. This implementation
invokes
(imageIndex) , wraps
the result in a
GeographicMetadata object if non-null and caches the result.
Note that this method forces
GeographicImageReader.ignoreMetadata to
false for the time of
(imageIndex) execution,
because some image reader implementations need geographic metadata in order to infer
a valid
.
Parameters: imageIndex - The image index. The geographic metadata, or null if none. throws: IOException - if an error occurs during reading. |
getImageMetadata | public IIOMetadata getImageMetadata(int imageIndex) throws IOException(Code) | | Returns metadata associated with the given image. Since many raw images
can't store metadata, the default implementation returns
null .
Parameters: imageIndex - The image index. The metadata, or null if none. throws: IOException - if an error occurs during reading. |
getImageTypes | public Iterator getImageTypes(int imageIndex) throws IOException(Code) | | Returns a collection of
ImageTypeSpecifier containing possible image types to which
the given image may be decoded. The default implementation returns a singleton containing
GeographicImageReader.getRawImageType(int) getRawImageType (imageIndex) .
Parameters: imageIndex - The index of the image to be retrieved. A set of suggested image types for decoding the current given image. throws: IOException - If an error occurs reading the format information from the input source. |
getNumBands | public int getNumBands(int imageIndex) throws IOException(Code) | | Returns the number of bands available for the specified image.
The default implementation returns 1.
Parameters: imageIndex - The image index. throws: IOException - if an error occurs reading the information from the input source. |
getNumImages | public int getNumImages(boolean allowSearch) throws IllegalStateException, IOException(Code) | | Returns the number of images available from the current input source.
The default implementation returns 1.
Parameters: allowSearch - If true, the number of images will be returnedeven if a search is required. The number of images, or -1 if allowSearch is false and a search would be required. throws: IllegalStateException - if the input source has not been set. throws: IOException - if an error occurs reading the information from the input source. |
getRawDataType | protected int getRawDataType(int imageIndex) throws IOException(Code) | | Returns the data type which most closely represents the "raw" internal data of the image.
It should be one of
DataBuffer constants. The default
GeographicImageReader implementation works better with the following types:
DataBuffer.TYPE_BYTE TYPE_BYTE ,
DataBuffer.TYPE_SHORT TYPE_SHORT ,
DataBuffer.TYPE_USHORT TYPE_USHORT and
DataBuffer.TYPE_FLOAT TYPE_FLOAT .
The default implementation returns
DataBuffer.TYPE_FLOAT TYPE_FLOAT in every cases.
Handling of negative integer values
If the raw internal data contains negative values but this method still declares a unsigned
integer type (
DataBuffer.TYPE_BYTE TYPE_BYTE or
DataBuffer.TYPE_USHORT TYPE_USHORT ),
then the values will be translated in order to fit in the range of strictly positive values.
For example if the raw internal data range from -23000 to +23000, then there is a choice:
If this method returns
DataBuffer.TYPE_SHORT , then the data will be
stored "as is" without transformation. However the
will have the maximal length allowed by 16 bits integers, with
positive values in the [0 ..
] range and negative
values wrapped in the [32768 .. 65535] range in two's complement binary form. The
results is a color model consuming 256 kilobytes in every cases. The space not used
by the [-23000 .. +23000] range (in the above example) is lost.
If this method returns
DataBuffer.TYPE_USHORT , then the data will be
translated to the smallest strictly positive range that can holds the data
([1..46000] for the above example). Value 0 is reserved for missing data. The
result is a smaller
than the
one used by untranslated data.
Parameters: imageIndex - The index of the image to be queried. The data type (DataBuffer.TYPE_FLOAT by default). throws: IOException - If an error occurs reading the format information from the input source. See Also: GeographicImageReader.getRawImageType(int,ImageReadParam,SampleConverter[]) |
getRawImageType | public ImageTypeSpecifier getRawImageType(int imageIndex) throws IOException(Code) | | Returns an image type specifier indicating the
SampleModel and
ColorModel which most closely represents the "raw" internal format of the image. The default
implementation delegates to the following:
(imageIndex,
, null);
If this method needs to be overriden, consider overriding the later instead.
Parameters: imageIndex - The index of the image to be queried. The image type (never null ). throws: IOException - If an error occurs reading the format information from the input source. |
getRawImageType | protected ImageTypeSpecifier getRawImageType(int imageIndex, ImageReadParam parameters, SampleConverter[] converters) throws IOException(Code) | | Returns an image type specifier indicating the
SampleModel and
ColorModel which most closely represents the "raw" internal format of the image. The default
implementation applies the following rules:
The
and the
are extracted from the
, if any.
If the given
parameters argument is an instance of
GeographicImageReadParam ,
then the user-supplied
is fetched. Otherwise or if no palette name was explicitly set, then this method default
to
. The
palette name will be used in order to
(as RGB values) to be given to the
.
If the
is
DataBuffer.TYPE_FLOATTYPE_FLOAT or
DataBuffer.TYPE_DOUBLE TYPE_DOUBLE , then this method builds
a
suitable for
the range fetched at step 1. The data are assumed geophysics values
rather than some packed values. Consequently, the
will replace no-data values by
with no other
changes.
Otherwise, if the
is a unsigned integer type
like
DataBuffer.TYPE_BYTE TYPE_BYTE or
DataBuffer.TYPE_USHORT TYPE_USHORT ,
then this method builds an
(i.e. a
palette backed by an
) with just the minimal
needed for containing fully the range and the
no-data values fetched at step 1. The data are assumed packed values rather
than geophysics values. Consequently, the
will be the
except in the
following cases:
- The
is outside the range
allowed by the
(e.g. the range of
valid values contains negative integers). In this case, the sample converter
will shift the values to a strictly positive range and replace no-data values
by 0.
- At least one
is outside the range
of values allowed by the
. In this case,
this method will try to only replace the no-data values by 0, without shifting
the valid values if this shift can be avoided.
- At least one
is far away from the
(for example 9999 while
the range of valid values is [0..255]). The meaning of "far away" is determined
by the
GeographicImageReader.collapseNoDataValues collapseNoDataValues method.
Otherwise, if the
is a signed integer
type like
DataBuffer.TYPE_SHORT TYPE_SHORT , then this method builds an
with the maximal
supported by the raw data type (note that this is
memory expensive - typically 256 kilobytes). Negative values will be stored in their
two's complement binary form in order to fit in the range of positive integers
supported by the
.
Overriding this method
Subclasses may override this method when a constant color
is
wanted for all images in a series, for example for all Sea Surface Temperature
(SST) from the same provider. A constant color palette facilitates the visual comparaison
of different images at different time. The example below creates hard-coded objects:
int minimum = -2000; // minimal expected value
int maximum = +2300; // maximal expected value
int fillValue = -9999; // Value for missing data
String palette = "SST-Nasa";// Named set of RGB colors
converters[0] =
(1 - minimum, fillValue);
return
.
(paletteName, maximum - minimum).
();
Parameters: imageIndex - The index of the image to be queried. Parameters: parameters - The user-supplied parameters, or null . Note: we recommand to supplyGeographicImageReader.getDefaultReadParam instead of null since subclasses mayoverride the later with default values suitable to a particular format. Parameters: converters - If non-null, an array where to store the converters created by this method.Those converters should be used by (imageIndex, parameters) implementations for converting the valuesread in the datafile to values acceptable for the underling .The image type (never null ). throws: IOException - If an error occurs while reading the format information from the input source. See Also: GeographicImageReader.getRawDataType See Also: GeographicImageReader.collapseNoDataValues See Also: GeographicImageReader.getDestination(int,ImageReadParam,int,int,SampleConverter[]) |
getStreamMetadata | public IIOMetadata getStreamMetadata() throws IOException(Code) | | Returns metadata associated with the input source as a whole. Since many raw images
can't store metadata, the default implementation returns
null .
throws: IOException - if an error occurs during reading. |
read | public BufferedImage read(int imageIndex) throws IOException(Code) | | Reads the image indexed by
imageIndex using a default
ImageReadParam .
This is a convenience method that calls
(imageIndex,
) .
The default Java implementation passed a
null parameter. This implementation
passes the default parameter instead in order to improve consistency when a subclass
overrides
GeographicImageReader.getDefaultReadParam .
Parameters: imageIndex - the index of the image to be retrieved. the desired portion of the image. throws: IllegalStateException - if the input source has not been set. throws: IndexOutOfBoundsException - if the supplied index is out of bounds. throws: IOException - if an error occurs during reading. |
setInput | public void setInput(Object input, boolean seekForwardOnly, boolean ignoreMetadata)(Code) | | Sets the input source to use.
Parameters: input - The input object to use for future decoding. Parameters: seekForwardOnly - If true , images and metadata may only be readin ascending order from this input source. Parameters: ignoreMetadata - If true , metadata may be ignored during reads. |
warningOccurred | public void warningOccurred(LogRecord record)(Code) | | Invoked when a warning occured. The default implementation make the following choice:
- If at least one
has been
, then the
IIOReadWarningListener.warningOccurred warningOccurred method is
invoked for each of them and the log record is not logged.
- Otherwise, the log record is sent to the
"org.geotools.image.io" logger.
Subclasses may override this method if more processing is wanted, or for
throwing exception if some warnings should be considered as fatal errors.
|
Methods inherited from javax.imageio.ImageReader | public synchronized void abort()(Code)(Java Doc) protected synchronized boolean abortRequested()(Code)(Java Doc) public void addIIOReadProgressListener(IIOReadProgressListener listener)(Code)(Java Doc) public void addIIOReadUpdateListener(IIOReadUpdateListener listener)(Code)(Java Doc) public void addIIOReadWarningListener(IIOReadWarningListener listener)(Code)(Java Doc) public boolean canReadRaster()(Code)(Java Doc) protected static void checkReadParamBandSettings(ImageReadParam param, int numSrcBands, int numDstBands)(Code)(Java Doc) protected synchronized void clearAbortRequest()(Code)(Java Doc) protected static void computeRegions(ImageReadParam param, int srcWidth, int srcHeight, BufferedImage image, Rectangle srcRegion, Rectangle destRegion)(Code)(Java Doc) public void dispose()(Code)(Java Doc) public float getAspectRatio(int imageIndex) throws IOException(Code)(Java Doc) public Locale[] getAvailableLocales()(Code)(Java Doc) public ImageReadParam getDefaultReadParam()(Code)(Java Doc) protected static BufferedImage getDestination(ImageReadParam param, Iterator<ImageTypeSpecifier> imageTypes, int width, int height) throws IIOException(Code)(Java Doc) public String getFormatName() throws IOException(Code)(Java Doc) abstract public int getHeight(int imageIndex) throws IOException(Code)(Java Doc) abstract public IIOMetadata getImageMetadata(int imageIndex) throws IOException(Code)(Java Doc) public IIOMetadata getImageMetadata(int imageIndex, String formatName, Set<String> nodeNames) throws IOException(Code)(Java Doc) abstract public Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex) throws IOException(Code)(Java Doc) public Object getInput()(Code)(Java Doc) public Locale getLocale()(Code)(Java Doc) public int getMinIndex()(Code)(Java Doc) abstract public int getNumImages(boolean allowSearch) throws IOException(Code)(Java Doc) public int getNumThumbnails(int imageIndex) throws IOException(Code)(Java Doc) public ImageReaderSpi getOriginatingProvider()(Code)(Java Doc) public ImageTypeSpecifier getRawImageType(int imageIndex) throws IOException(Code)(Java Doc) protected static Rectangle getSourceRegion(ImageReadParam param, int srcWidth, int srcHeight)(Code)(Java Doc) abstract public IIOMetadata getStreamMetadata() throws IOException(Code)(Java Doc) public IIOMetadata getStreamMetadata(String formatName, Set<String> nodeNames) throws IOException(Code)(Java Doc) public int getThumbnailHeight(int imageIndex, int thumbnailIndex) throws IOException(Code)(Java Doc) public int getThumbnailWidth(int imageIndex, int thumbnailIndex) throws IOException(Code)(Java Doc) public int getTileGridXOffset(int imageIndex) throws IOException(Code)(Java Doc) public int getTileGridYOffset(int imageIndex) throws IOException(Code)(Java Doc) public int getTileHeight(int imageIndex) throws IOException(Code)(Java Doc) public int getTileWidth(int imageIndex) throws IOException(Code)(Java Doc) abstract public int getWidth(int imageIndex) throws IOException(Code)(Java Doc) public boolean hasThumbnails(int imageIndex) throws IOException(Code)(Java Doc) public boolean isIgnoringMetadata()(Code)(Java Doc) public boolean isImageTiled(int imageIndex) throws IOException(Code)(Java Doc) public boolean isRandomAccessEasy(int imageIndex) throws IOException(Code)(Java Doc) public boolean isSeekForwardOnly()(Code)(Java Doc) protected void processImageComplete()(Code)(Java Doc) protected void processImageProgress(float percentageDone)(Code)(Java Doc) protected void processImageStarted(int imageIndex)(Code)(Java Doc) protected void processImageUpdate(BufferedImage theImage, int minX, int minY, int width, int height, int periodX, int periodY, int[] bands)(Code)(Java Doc) protected void processPassComplete(BufferedImage theImage)(Code)(Java Doc) protected void processPassStarted(BufferedImage theImage, int pass, int minPass, int maxPass, int minX, int minY, int periodX, int periodY, int[] bands)(Code)(Java Doc) protected void processReadAborted()(Code)(Java Doc) protected void processSequenceComplete()(Code)(Java Doc) protected void processSequenceStarted(int minIndex)(Code)(Java Doc) protected void processThumbnailComplete()(Code)(Java Doc) protected void processThumbnailPassComplete(BufferedImage theThumbnail)(Code)(Java Doc) protected void processThumbnailPassStarted(BufferedImage theThumbnail, int pass, int minPass, int maxPass, int minX, int minY, int periodX, int periodY, int[] bands)(Code)(Java Doc) protected void processThumbnailProgress(float percentageDone)(Code)(Java Doc) protected void processThumbnailStarted(int imageIndex, int thumbnailIndex)(Code)(Java Doc) protected void processThumbnailUpdate(BufferedImage theThumbnail, int minX, int minY, int width, int height, int periodX, int periodY, int[] bands)(Code)(Java Doc) protected void processWarningOccurred(String warning)(Code)(Java Doc) protected void processWarningOccurred(String baseName, String keyword)(Code)(Java Doc) public BufferedImage read(int imageIndex) throws IOException(Code)(Java Doc) abstract public BufferedImage read(int imageIndex, ImageReadParam param) throws IOException(Code)(Java Doc) public IIOImage readAll(int imageIndex, ImageReadParam param) throws IOException(Code)(Java Doc) public Iterator<IIOImage> readAll(Iterator<? extends ImageReadParam> params) throws IOException(Code)(Java Doc) public RenderedImage readAsRenderedImage(int imageIndex, ImageReadParam param) throws IOException(Code)(Java Doc) public Raster readRaster(int imageIndex, ImageReadParam param) throws IOException(Code)(Java Doc) public BufferedImage readThumbnail(int imageIndex, int thumbnailIndex) throws IOException(Code)(Java Doc) public BufferedImage readTile(int imageIndex, int tileX, int tileY) throws IOException(Code)(Java Doc) public Raster readTileRaster(int imageIndex, int tileX, int tileY) throws IOException(Code)(Java Doc) public boolean readerSupportsThumbnails()(Code)(Java Doc) public void removeAllIIOReadProgressListeners()(Code)(Java Doc) public void removeAllIIOReadUpdateListeners()(Code)(Java Doc) public void removeAllIIOReadWarningListeners()(Code)(Java Doc) public void removeIIOReadProgressListener(IIOReadProgressListener listener)(Code)(Java Doc) public void removeIIOReadUpdateListener(IIOReadUpdateListener listener)(Code)(Java Doc) public void removeIIOReadWarningListener(IIOReadWarningListener listener)(Code)(Java Doc) public void reset()(Code)(Java Doc) public void setInput(Object input, boolean seekForwardOnly, boolean ignoreMetadata)(Code)(Java Doc) public void setInput(Object input, boolean seekForwardOnly)(Code)(Java Doc) public void setInput(Object input)(Code)(Java Doc) public void setLocale(Locale locale)(Code)(Java Doc)
|
|
|