Class ImageReaderBase
- java.lang.Object
-
- javax.imageio.ImageReader
-
- com.twelvemonkeys.imageio.ImageReaderBase
-
- Direct Known Subclasses:
BMPImageReader,DCXImageReader,DDSImageReader,DIBImageReader,EXIFUtilities.DisplayHelper,HDRImageReader,ICNSImageReader,IFFImageReader,JPEGImageReader,PCXImageReader,PICTImageReader,PNMImageReader,PNTGImageReader,PSDImageReader,SGIImageReader,SVGImageReader,TGAImageReader,ThumbsDBImageReader,TIFFImageReader,WebPImageReader,WMFImageReader,XWDImageReader
public abstract class ImageReaderBase extends javax.imageio.ImageReaderAbstract base class for image readers.- Version:
- $Id: ImageReaderBase.java,v 1.0 Sep 20, 2007 5:28:37 PM haraldk Exp$
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classImageReaderBase.ExitIfNoWindowPresentHandlerprivate static classImageReaderBase.ImageLabel
-
Field Summary
Fields Modifier and Type Field Description protected javax.imageio.stream.ImageInputStreamimageInputFor convenience.private static java.awt.PointORIGIN
-
Constructor Summary
Constructors Modifier Constructor Description protectedImageReaderBase(javax.imageio.spi.ImageReaderSpi provider)Constructs anImageReaderand sets itsoriginatingProviderfield to the supplied value.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidassertInput()Makes sure input is set.protected voidcheckBounds(int index)Convenience method to make sure image index is within bounds.voiddispose()protected static java.awt.image.BufferedImagefakeAOI(java.awt.image.BufferedImage pImage, javax.imageio.ImageReadParam pParam)Utility method for getting the area of interest (AOI) of an image.protected static java.awt.ImagefakeSubsampling(java.awt.Image pImage, javax.imageio.ImageReadParam pParam)Utility method for getting the subsampled image.static java.awt.image.BufferedImagegetDestination(javax.imageio.ImageReadParam param, java.util.Iterator<javax.imageio.ImageTypeSpecifier> types, int width, int height)Returns theBufferedImageto which decoded pixel data should be written.javax.imageio.metadata.IIOMetadatagetImageMetadata(int imageIndex)Default implementation that always returnsnull.intgetNumImages(boolean allowSearch)Default implementation that always returns1.javax.imageio.metadata.IIOMetadatagetStreamMetadata()Default implementation that always returnsnull.protected static booleanhasExplicitDestination(javax.imageio.ImageReadParam pParam)Tests if param has explicit destination.static voidmain(java.lang.String[] pArgs)voidreset()protected abstract voidresetMembers()Resets all member variables.voidsetInput(java.lang.Object input, boolean seekForwardOnly, boolean ignoreMetadata)OverridessetInput, to allow easy access to the input, in case it is anImageInputStream.protected static voidshowIt(java.awt.image.BufferedImage pImage, java.lang.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
-
-
-
-
Field Detail
-
ORIGIN
private static final java.awt.Point ORIGIN
-
imageInput
protected javax.imageio.stream.ImageInputStream imageInput
For convenience. Only set if the input is anImageInputStream.- See Also:
setInput(Object, boolean, boolean)
-
-
Constructor Detail
-
ImageReaderBase
protected ImageReaderBase(javax.imageio.spi.ImageReaderSpi provider)
Constructs anImageReaderand sets itsoriginatingProviderfield 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, anIllegalArgumentExceptionshould be thrown.- Parameters:
provider- theImageReaderSpithat is invoking this constructor, ornull.
-
-
Method Detail
-
setInput
public void setInput(java.lang.Object input, boolean seekForwardOnly, boolean ignoreMetadata)OverridessetInput, to allow easy access to the input, in case it is anImageInputStream.- Overrides:
setInputin classjavax.imageio.ImageReader- Parameters:
input- theImageInputStreamor otherObjectto use for future decoding.seekForwardOnly- iftrue, images and metadata may only be read in ascending order from this input source.ignoreMetadata- iftrue, metadata may be ignored during reads.- Throws:
java.lang.IllegalArgumentException- ifinputis not an instance of one of the classes returned by the originating service provider'sgetInputTypesmethod, or is not anImageInputStream.- See Also:
ImageInputStream
-
dispose
public void dispose()
- Overrides:
disposein classjavax.imageio.ImageReader
-
reset
public void reset()
- Overrides:
resetin classjavax.imageio.ImageReader
-
resetMembers
protected abstract void resetMembers()
Resets all member variables. This method is by default invoked from:
-
getImageMetadata
public javax.imageio.metadata.IIOMetadata getImageMetadata(int imageIndex) throws java.io.IOExceptionDefault implementation that always returnsnull.- Specified by:
getImageMetadatain classjavax.imageio.ImageReader- Parameters:
imageIndex- ignored, unless overridden- Returns:
null, unless overridden- Throws:
java.io.IOException- never, unless overridden.
-
getStreamMetadata
public javax.imageio.metadata.IIOMetadata getStreamMetadata() throws java.io.IOExceptionDefault implementation that always returnsnull.- Specified by:
getStreamMetadatain classjavax.imageio.ImageReader- Returns:
null, unless overridden- Throws:
java.io.IOException- never, unless overridden.
-
getNumImages
public int getNumImages(boolean allowSearch) throws java.io.IOExceptionDefault implementation that always returns1.- Specified by:
getNumImagesin classjavax.imageio.ImageReader- Parameters:
allowSearch- ignored, unless overridden- Returns:
1, unless overridden- Throws:
java.io.IOException- never, unless overridden
-
checkBounds
protected void checkBounds(int index) throws java.io.IOExceptionConvenience method to make sure image index is within bounds.- Parameters:
index- the image index- Throws:
java.io.IOException- if an error occurs during readingjava.lang.IndexOutOfBoundsException- if notminIndex <= index < numImages
-
assertInput
protected void assertInput()
Makes sure input is set.- Throws:
java.lang.IllegalStateException- ifgetInput() == null.
-
getDestination
public static java.awt.image.BufferedImage getDestination(javax.imageio.ImageReadParam param, java.util.Iterator<javax.imageio.ImageTypeSpecifier> types, int width, int height) throws javax.imageio.IIOExceptionReturns theBufferedImageto which decoded pixel data should be written.As
ImageReader.getDestination(javax.imageio.ImageReadParam, java.util.Iterator<javax.imageio.ImageTypeSpecifier>, int, int)but tests if the explicit destination image (if set) is valid according to theImageTypeSpecifiers given intypes.- Parameters:
param- anImageReadParamto be used to get the destination image or image type, ornull.types- anIteratorofImageTypeSpecifiers 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
BufferedImageto which decoded pixel data should be written. - Throws:
javax.imageio.IIOException- if theImageTypeSpecifierorBufferedImagespecified byparamdoes not match any of the legal ones fromtypes.java.lang.IllegalArgumentException- iftypesisnullor empty, or if an object not of typeImageTypeSpecifieris retrieved from it. Or, if the resulting image would have a width or height less than 1, or if the product ofwidthandheightof the resulting image is greater thanInteger.MAX_VALUE.
-
fakeAOI
protected static java.awt.image.BufferedImage fakeAOI(java.awt.image.BufferedImage pImage, javax.imageio.ImageReadParam pParam)Utility method for getting the area of interest (AOI) of an image. The AOI is defined by theIIOParam.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 frompParam- the param optionally specifying the AOI- Returns:
- a
BufferedImagecontaining the area of interest (source region), or the original image, if no source region was set, orpParamwasnull
-
fakeSubsampling
protected static java.awt.Image fakeSubsampling(java.awt.Image pImage, javax.imageio.ImageReadParam pParam)Utility method for getting the subsampled image. The subsampling is defined by theIIOParam.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 subsamplepParam- the param optionally specifying subsampling- Returns:
- an
Imagecontaining the subsampled image, or the original image, if no subsampling was specified, orpParamwasnull
-
hasExplicitDestination
protected static boolean hasExplicitDestination(javax.imageio.ImageReadParam pParam)
Tests if param has explicit destination.- Parameters:
pParam- the image read parameter, ornull- Returns:
- true if
pParamis non-nulland either itsgetDestination,getDestinationTypereturns a non-nullvalue, orgetDestinationOffsetreturns aPointthat is not the upper left corner(0, 0).
-
main
public static void main(java.lang.String[] pArgs) throws java.io.IOException- Throws:
java.io.IOException
-
showIt
protected static void showIt(java.awt.image.BufferedImage pImage, java.lang.String pTitle)
-
-