com.twelvemonkeys.imageio
Class ImageReaderBase

java.lang.Object
  extended by javax.imageio.ImageReader
      extended by com.twelvemonkeys.imageio.ImageReaderBase

public abstract class ImageReaderBase
extends ImageReader

Abstract base class for image readers.

Version:
$Id: ImageReaderBase.java,v 1.0 Sep 20, 2007 5:28:37 PM haraldk Exp$
Author:
Harald Kuhr, last modified by $Author: haraldk$

Field Summary
protected  ImageInputStream imageInput
          For convenience.
 
Fields inherited from class javax.imageio.ImageReader
availableLocales, ignoreMetadata, input, locale, minIndex, originatingProvider, progressListeners, seekForwardOnly, updateListeners, warningListeners, warningLocales
 
Constructor Summary
protected ImageReaderBase(ImageReaderSpi provider)
          Constructs an ImageReader and sets its originatingProvider field to the supplied value.
 
Method Summary
protected  void assertInput()
          Makes sure input is set.
protected  void checkBounds(int index)
          Convenience method to make sure image index is within bounds.
 void dispose()
           
protected static BufferedImage fakeAOI(BufferedImage pImage, ImageReadParam pParam)
          Utility method for getting the area of interest (AOI) of an image.
protected static Image fakeSubsampling(Image pImage, ImageReadParam pParam)
          Utility method for getting the subsampled image.
static BufferedImage getDestination(ImageReadParam param, Iterator<ImageTypeSpecifier> types, int width, int height)
          Returns the BufferedImage to which decoded pixel data should be written.
 IIOMetadata getImageMetadata(int imageIndex)
          Default implementation that always returns null.
 int getNumImages(boolean allowSearch)
          Default implementation that always returns 1.
 IIOMetadata getStreamMetadata()
          Default implementation that always returns null.
protected static boolean hasExplicitDestination(ImageReadParam pParam)
          Tests if param has explicit destination.
static void main(String[] pArgs)
           
 void reset()
           
protected abstract  void resetMembers()
          Resets all member variables.
 void setInput(Object input, boolean seekForwardOnly, boolean ignoreMetadata)
          Overrides setInput, to allow easy access to the input, in case it is an ImageInputStream.
protected static void showIt(BufferedImage pImage, String pTitle)
           
 
Methods inherited from class javax.imageio.ImageReader
abort, abortRequested, addIIOReadProgressListener, addIIOReadUpdateListener, addIIOReadWarningListener, canReadRaster, checkReadParamBandSettings, clearAbortRequest, computeRegions, getAspectRatio, getAvailableLocales, getDefaultReadParam, getFormatName, getHeight, getImageMetadata, getImageTypes, getInput, getLocale, getMinIndex, getNumThumbnails, getOriginatingProvider, getRawImageType, getSourceRegion, getStreamMetadata, getThumbnailHeight, getThumbnailWidth, getTileGridXOffset, getTileGridYOffset, getTileHeight, getTileWidth, getWidth, hasThumbnails, isIgnoringMetadata, isImageTiled, isRandomAccessEasy, isSeekForwardOnly, processImageComplete, processImageProgress, processImageStarted, processImageUpdate, processPassComplete, processPassStarted, processReadAborted, processSequenceComplete, processSequenceStarted, processThumbnailComplete, processThumbnailPassComplete, processThumbnailPassStarted, processThumbnailProgress, processThumbnailStarted, processThumbnailUpdate, processWarningOccurred, processWarningOccurred, read, read, readAll, readAll, readAsRenderedImage, readerSupportsThumbnails, readRaster, readThumbnail, readTile, readTileRaster, removeAllIIOReadProgressListeners, removeAllIIOReadUpdateListeners, removeAllIIOReadWarningListeners, removeIIOReadProgressListener, removeIIOReadUpdateListener, removeIIOReadWarningListener, setInput, setInput, setLocale
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

imageInput

protected ImageInputStream imageInput
For convenience. Only set if the input is an ImageInputStream.

See Also:
setInput(Object, boolean, boolean)
Constructor Detail

ImageReaderBase

protected ImageReaderBase(ImageReaderSpi provider)
Constructs an ImageReader and sets its originatingProvider field to the supplied value.

Subclasses that make use of extensions should provide a constructor with signature (ImageReaderSpi, Object) in order to retrieve the extension object. If the extension object is unsuitable, an IllegalArgumentException should be thrown.

Parameters:
provider - the ImageReaderSpi that is invoking this constructor, or null.
Method Detail

setInput

public void setInput(Object input,
                     boolean seekForwardOnly,
                     boolean ignoreMetadata)
Overrides setInput, to allow easy access to the input, in case it is an ImageInputStream.

Overrides:
setInput in class ImageReader
Parameters:
input - the ImageInputStream or other 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.
Throws:
IllegalArgumentException - if input is not an instance of one of the classes returned by the originating service provider's getInputTypes method, or is not an ImageInputStream.
See Also:
ImageInputStream

dispose

public void dispose()
Overrides:
dispose in class ImageReader

reset

public void reset()
Overrides:
reset in class ImageReader

resetMembers

protected abstract void resetMembers()
Resets all member variables. This method is by default invoked from:


getImageMetadata

public IIOMetadata getImageMetadata(int imageIndex)
                             throws IOException
Default implementation that always returns null.

Specified by:
getImageMetadata in class ImageReader
Parameters:
imageIndex - ignored, unless overridden
Returns:
null, unless overridden
Throws:
IOException - never, unless overridden.

getStreamMetadata

public IIOMetadata getStreamMetadata()
                              throws IOException
Default implementation that always returns null.

Specified by:
getStreamMetadata in class ImageReader
Returns:
null, unless overridden
Throws:
IOException - never, unless overridden.

getNumImages

public int getNumImages(boolean allowSearch)
                 throws IOException
Default implementation that always returns 1.

Specified by:
getNumImages in class ImageReader
Parameters:
allowSearch - ignored, unless overridden
Returns:
1, unless overridden
Throws:
IOException - never, unless overridden

checkBounds

protected void checkBounds(int index)
                    throws IOException
Convenience method to make sure image index is within bounds.

Parameters:
index - the image index
Throws:
IOException - if an error occurs during reading
IndexOutOfBoundsException - if not minIndex <= index < numImages

assertInput

protected void assertInput()
Makes sure input is set.

Throws:
IllegalStateException - if getInput() == null.

getDestination

public static BufferedImage getDestination(ImageReadParam param,
                                           Iterator<ImageTypeSpecifier> types,
                                           int width,
                                           int height)
                                    throws IIOException
Returns the BufferedImage to which decoded pixel data should be written.

As ImageReader.getDestination(javax.imageio.ImageReadParam, java.util.Iterator, int, int) but tests if the explicit destination image (if set) is valid according to the ImageTypeSpecifiers given in types.

Parameters:
param - an ImageReadParam to be used to get the destination image or image type, or null.
types - an Iterator of ImageTypeSpecifiers indicating the legal image types, with the default first.
width - the true width of the image or tile begin decoded.
height - the true width of the image or tile being decoded.
Returns:
the BufferedImage to which decoded pixel data should be written.
Throws:
IIOException - if the ImageTypeSpecifier or BufferedImage specified by param does not match any of the legal ones from types.
IllegalArgumentException - if types is null or empty, or if an object not of type ImageTypeSpecifier is retrieved from it. Or, if the resulting image would have a width or height less than 1, or if the product of width and height of the resulting image is greater than Integer.MAX_VALUE.

fakeAOI

protected static BufferedImage fakeAOI(BufferedImage pImage,
                                       ImageReadParam pParam)
Utility method for getting the area of interest (AOI) of an image. The AOI is defined by the IIOParam.setSourceRegion(java.awt.Rectangle) method.

Note: If it is possible for the reader to read the AOI directly, such a method should be used instead, for efficiency.

Parameters:
pImage - the image to get AOI from
pParam - the param optionally specifying the AOI
Returns:
a BufferedImage containing the area of interest (source region), or the original image, if no source region was set, or pParam was null

fakeSubsampling

protected static Image fakeSubsampling(Image pImage,
                                       ImageReadParam pParam)
Utility method for getting the subsampled image. The subsampling is defined by the IIOParam.setSourceSubsampling(int, int, int, int) method.

NOTE: This method does not take the subsampling offsets into consideration.

Note: If it is possible for the reader to subsample directly, such a method should be used instead, for efficiency.

Parameters:
pImage - the image to subsample
pParam - the param optionally specifying subsampling
Returns:
an Image containing the subsampled image, or the original image, if no subsampling was specified, or pParam was null

hasExplicitDestination

protected static boolean hasExplicitDestination(ImageReadParam pParam)
Tests if param has explicit destination.

Parameters:
pParam - the image read parameter, or null
Returns:
true if pParam is non-null and either its getDestination, getDestinationType returns a non-null value, or getDestinationOffset returns a Point that is not the upper left corner (0, 0).

main

public static void main(String[] pArgs)
                 throws IOException
Throws:
IOException

showIt

protected static void showIt(BufferedImage pImage,
                             String pTitle)


Copyright © 2015. All Rights Reserved.