- java.lang.Object
- 
- javax.imageio.IIOParam
- 
- javax.imageio.ImageReadParam
 
 
- 
- Direct Known Subclasses:
- JPEGImageReadParam,- TIFFImageReadParam
 
 public class ImageReadParam extends IIOParam A class describing how a stream is to be decoded. Instances of this class or its subclasses are used to supply prescriptive "how-to" information to instances ofImageReader.An image encoded as part of a file or stream may be thought of extending out in multiple dimensions: the spatial dimensions of width and height, a number of bands, and a number of progressive decoding passes. This class allows a contiguous (hyper)rectangular subarea of the image in all of these dimensions to be selected for decoding. Additionally, the spatial dimensions may be subsampled discontinuously. Finally, color and format conversions may be specified by controlling the ColorModelandSampleModelof the destination image, either by providing aBufferedImageor by using anImageTypeSpecifier.An ImageReadParamobject is used to specify how an image, or a set of images, will be converted on input from a stream in the context of the Java Image I/O framework. A plug-in for a specific image format will return instances ofImageReadParamfrom thegetDefaultReadParammethod of itsImageReaderimplementation.The state maintained by an instance of ImageReadParamis independent of any particular image being decoded. When actual decoding takes place, the values set in the read param are combined with the actual properties of the image being decoded from the stream and the destinationBufferedImagethat will receive the decoded pixel data. For example, the source region set usingsetSourceRegionwill first be intersected with the actual valid source area. The result will be translated by the value returned bygetDestinationOffset, and the resulting rectangle intersected with the actual valid destination area to yield the destination area that will be written.The parameters specified by an ImageReadParamare applied to an image as follows. First, if a rendering size has been set bysetSourceRenderSize, the entire decoded image is rendered at the size given bygetSourceRenderSize. Otherwise, the image has its natural size given byImageReader.getWidthandImageReader.getHeight.Next, the image is clipped against the source region specified by getSourceXOffset,getSourceYOffset,getSourceWidth, andgetSourceHeight.The resulting region is then subsampled according to the factors given in IIOParam.setSourceSubsampling. The first pixel, the number of pixels per row, and the number of rows all depend on the subsampling settings. Call the minimum X and Y coordinates of the resulting rectangle (minX,minY), its widthwand its heighth.This rectangle is offset by ( getDestinationOffset().x,getDestinationOffset().y) and clipped against the destination bounds. If no destination image has been set, the destination is defined to have a width ofgetDestinationOffset().x+w, and a height ofgetDestinationOffset().y+hso that all pixels of the source region may be written to the destination.Pixels that land, after subsampling, within the destination image, and that are written in one of the progressive passes specified by getSourceMinProgressivePassandgetSourceNumProgressivePassesare passed along to the next step.Finally, the source samples of each pixel are mapped into destination bands according to the algorithm described in the comment for setDestinationBands.Plug-in writers may extend the functionality of ImageReadParamby providing a subclass that implements additional, plug-in specific interfaces. It is up to the plug-in to document what interfaces are available and how they are to be used. Readers will silently ignore any extended features of anImageReadParamsubclass of which they are not aware. Also, they may ignore any optional features that they normally disable when creating their ownImageReadParaminstances viagetDefaultReadParam.Note that unless a query method exists for a capability, it must be supported by all ImageReaderimplementations (e.g. source render size is optional, but subsampling must be supported).- See Also:
- ImageReader,- ImageWriter,- ImageWriteParam
 
- 
- 
Field SummaryFields Modifier and Type Field Description protected booleancanSetSourceRenderSizetrueif thisImageReadParamallows the source rendering dimensions to be set.protected BufferedImagedestinationThe current destinationBufferedImage, ornullif none has been set.protected int[]destinationBandsThe set of destination bands to be used, as an array ofints.protected intminProgressivePassThe minimum index of a progressive pass to read from the source.protected intnumProgressivePassesThe maximum number of progressive passes to read from the source.protected DimensionsourceRenderSizeThe desired rendering width and height of the source, ifcanSetSourceRenderSizeistrue, ornull.- 
Fields declared in class javax.imageio.IIOParamcontroller, defaultController, destinationOffset, destinationType, sourceBands, sourceRegion, sourceXSubsampling, sourceYSubsampling, subsamplingXOffset, subsamplingYOffset
 
- 
 - 
Constructor SummaryConstructors Constructor Description ImageReadParam()Constructs anImageReadParam.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanSetSourceRenderSize()Returnstrueif this reader allows the source image to be rendered at an arbitrary size as part of the decoding process, by means of thesetSourceRenderSizemethod.BufferedImagegetDestination()Returns theBufferedImagecurrently set by thesetDestinationmethod, ornullif none is set.int[]getDestinationBands()Returns the set of band indices where data will be placed.intgetSourceMaxProgressivePass()IfgetSourceNumProgressivePassesis equal toInteger.MAX_VALUE, returnsInteger.MAX_VALUE.intgetSourceMinProgressivePass()Returns the index of the first progressive pass that will be decoded.intgetSourceNumProgressivePasses()Returns the number of the progressive passes that will be decoded.DimensiongetSourceRenderSize()Returns the width and height of the source image as it will be rendered during decoding, if they have been set via thesetSourceRenderSizemethod.voidsetDestination(BufferedImage destination)Supplies aBufferedImageto be used as the destination for decoded pixel data.voidsetDestinationBands(int[] destinationBands)Sets the indices of the destination bands where data will be placed.voidsetSourceProgressivePasses(int minPass, int numPasses)Sets the range of progressive passes that will be decoded.voidsetSourceRenderSize(Dimension size)If the image is able to be rendered at an arbitrary size, sets the source width and height to the supplied values.- 
Methods declared in class javax.imageio.IIOParamactivateController, getController, getDefaultController, getDestinationOffset, getDestinationType, getSourceBands, getSourceRegion, getSourceXSubsampling, getSourceYSubsampling, getSubsamplingXOffset, getSubsamplingYOffset, hasController, setController, setDestinationOffset, setDestinationType, setSourceBands, setSourceRegion, setSourceSubsampling
 
- 
 
- 
- 
- 
Field Detail- 
canSetSourceRenderSizeprotected boolean canSetSourceRenderSize trueif thisImageReadParamallows the source rendering dimensions to be set. By default, the value isfalse. Subclasses must set this value manually.ImageReaders that do not support setting of the source render size should set this value tofalse.
 - 
sourceRenderSizeprotected Dimension sourceRenderSize The desired rendering width and height of the source, ifcanSetSourceRenderSizeistrue, ornull.ImageReaders that do not support setting of the source render size may ignore this value.
 - 
destinationprotected BufferedImage destination The current destinationBufferedImage, ornullif none has been set. By default, the value isnull.
 - 
destinationBandsprotected int[] destinationBands The set of destination bands to be used, as an array ofints. By default, the value isnull, indicating all destination bands should be written in order.
 - 
minProgressivePassprotected int minProgressivePass The minimum index of a progressive pass to read from the source. By default, the value is set to 0, which indicates that passes starting with the first available pass should be decoded.Subclasses should ensure that this value is non-negative. 
 - 
numProgressivePassesprotected int numProgressivePasses The maximum number of progressive passes to read from the source. By default, the value is set toInteger.MAX_VALUE, which indicates that passes up to and including the last available pass should be decoded.Subclasses should ensure that this value is positive. Additionally, if the value is not Integer.MAX_VALUE, thenminProgressivePass + numProgressivePasses - 1should not exceedInteger.MAX_VALUE.
 
- 
 - 
Method Detail- 
setDestinationpublic void setDestination(BufferedImage destination) Supplies aBufferedImageto be used as the destination for decoded pixel data. The currently set image will be written to by theread,readAll, andreadRastermethods, and a reference to it will be returned by those methods.Pixel data from the aforementioned methods will be written starting at the offset specified by getDestinationOffset.If destinationisnull, a newly-createdBufferedImagewill be returned by those methods.At the time of reading, the image is checked to verify that its ColorModelandSampleModelcorrespond to one of theImageTypeSpecifiers returned from theImageReader'sgetImageTypesmethod. If it does not, the reader will throw anIIOException.- Parameters:
- destination- the BufferedImage to be written to, or- null.
- See Also:
- getDestination()
 
 - 
getDestinationpublic BufferedImage getDestination() Returns theBufferedImagecurrently set by thesetDestinationmethod, ornullif none is set.- Returns:
- the BufferedImage to be written to.
- See Also:
- setDestination(java.awt.image.BufferedImage)
 
 - 
setDestinationBandspublic void setDestinationBands(int[] destinationBands) Sets the indices of the destination bands where data will be placed. Duplicate indices are not allowed.A nullvalue indicates that all destination bands will be used.Choosing a destination band subset will not affect the number of bands in the output image of a read if no destination image is specified; the created destination image will still have the same number of bands as if this method had never been called. If a different number of bands in the destination image is desired, an image must be supplied using the ImageReadParam.setDestinationmethod.At the time of reading or writing, an IllegalArgumentExceptionwill be thrown by the reader or writer if a value larger than the largest destination band index has been specified, or if the number of source bands and destination bands to be used differ. TheImageReader.checkReadParamBandSettingsmethod may be used to automate this test.- Parameters:
- destinationBands- an array of integer band indices to be used.
- Throws:
- IllegalArgumentException- if- destinationBandscontains a negative or duplicate value.
- See Also:
- getDestinationBands(),- IIOParam.getSourceBands(),- ImageReader.checkReadParamBandSettings(javax.imageio.ImageReadParam, int, int)
 
 - 
getDestinationBandspublic int[] getDestinationBands() Returns the set of band indices where data will be placed. If no value has been set,nullis returned to indicate that all destination bands will be used.- Returns:
- the indices of the destination bands to be used,
 or null.
- See Also:
- setDestinationBands(int[])
 
 - 
canSetSourceRenderSizepublic boolean canSetSourceRenderSize() Returnstrueif this reader allows the source image to be rendered at an arbitrary size as part of the decoding process, by means of thesetSourceRenderSizemethod. If this method returnsfalse, calls tosetSourceRenderSizewill throw anUnsupportedOperationException.- Returns:
- trueif setting source rendering size is supported.
- See Also:
- setSourceRenderSize(java.awt.Dimension)
 
 - 
setSourceRenderSizepublic void setSourceRenderSize(Dimension size) throws UnsupportedOperationException If the image is able to be rendered at an arbitrary size, sets the source width and height to the supplied values. Note that the values returned from thegetWidthandgetHeightmethods onImageReaderare not affected by this method; they will continue to return the default size for the image. Similarly, if the image is also tiled the tile width and height are given in terms of the default size.Typically, the width and height should be chosen such that the ratio of width to height closely approximates the aspect ratio of the image, as returned from ImageReader.getAspectRatio.If this plug-in does not allow the rendering size to be set, an UnsupportedOperationExceptionwill be thrown.To remove the render size setting, pass in a value of nullforsize.- Parameters:
- size- a- Dimensionindicating the desired width and height.
- Throws:
- IllegalArgumentException- if either the width or the height is negative or 0.
- UnsupportedOperationException- if image resizing is not supported by this plug-in.
- See Also:
- getSourceRenderSize(),- ImageReader.getWidth(int),- ImageReader.getHeight(int),- ImageReader.getAspectRatio(int)
 
 - 
getSourceRenderSizepublic Dimension getSourceRenderSize() Returns the width and height of the source image as it will be rendered during decoding, if they have been set via thesetSourceRenderSizemethod. Anullvalue indicates that no setting has been made.- Returns:
- the rendered width and height of the source image
 as a Dimension.
- See Also:
- setSourceRenderSize(java.awt.Dimension)
 
 - 
setSourceProgressivePassespublic void setSourceProgressivePasses(int minPass, int numPasses)Sets the range of progressive passes that will be decoded. Passes outside of this range will be ignored.A progressive pass is a re-encoding of the entire image, generally at progressively higher effective resolutions, but requiring greater transmission bandwidth. The most common use of progressive encoding is found in the JPEG format, where successive passes include more detailed representations of the high-frequency image content. The actual number of passes to be decoded is determined during decoding, based on the number of actual passes available in the stream. Thus if minPass + numPasses - 1is larger than the index of the last available passes, decoding will end with that pass.A value of numPassesofInteger.MAX_VALUEindicates that all passes fromminPassforward should be read. Otherwise, the index of the last pass (i.e.,minPass + numPasses - 1) must not exceedInteger.MAX_VALUE.There is no unsetSourceProgressivePassesmethod; the same effect may be obtained by callingsetSourceProgressivePasses(0, Integer.MAX_VALUE).- Parameters:
- minPass- the index of the first pass to be decoded.
- numPasses- the maximum number of passes to be decoded.
- Throws:
- IllegalArgumentException- if- minPassis negative,- numPassesis negative or 0, or- numPassesis smaller than- Integer.MAX_VALUEbut- minPass + numPasses - 1is greater than- INTEGER.MAX_VALUE.
- See Also:
- getSourceMinProgressivePass(),- getSourceMaxProgressivePass()
 
 - 
getSourceMinProgressivePasspublic int getSourceMinProgressivePass() Returns the index of the first progressive pass that will be decoded. If no value has been set, 0 will be returned (which is the correct value).- Returns:
- the index of the first pass that will be decoded.
- See Also:
- setSourceProgressivePasses(int, int),- getSourceNumProgressivePasses()
 
 - 
getSourceMaxProgressivePasspublic int getSourceMaxProgressivePass() IfgetSourceNumProgressivePassesis equal toInteger.MAX_VALUE, returnsInteger.MAX_VALUE. Otherwise, returnsgetSourceMinProgressivePass() + getSourceNumProgressivePasses() - 1.- Returns:
- the index of the last pass to be read, or
 Integer.MAX_VALUE.
 
 - 
getSourceNumProgressivePassespublic int getSourceNumProgressivePasses() Returns the number of the progressive passes that will be decoded. If no value has been set,Integer.MAX_VALUEwill be returned (which is the correct value).- Returns:
- the number of the passes that will be decoded.
- See Also:
- setSourceProgressivePasses(int, int),- getSourceMinProgressivePass()
 
 
- 
 
-