ImageReadParam (Java Platform SE 6) (original) (raw)



javax.imageio

Class ImageReadParam

java.lang.Object extended by javax.imageio.IIOParam extended by javax.imageio.ImageReadParam

Direct Known Subclasses:

JPEGImageReadParam


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 of ImageReader.

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 ColorModel andSampleModel of the destination image, either by providing a BufferedImage or by using anImageTypeSpecifier.

An ImageReadParam object 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 ofImageReadParam from thegetDefaultReadParam method of itsImageReader implementation.

The state maintained by an instance ofImageReadParam is 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 destinationBufferedImage that will receive the decoded pixel data. For example, the source region set usingsetSourceRegion will first be intersected with the actual valid source area. The result will be translated by the value returned by getDestinationOffset, 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 ImageReadParam are applied to an image as follows. First, if a rendering size has been set by setSourceRenderSize, the entire decoded image is rendered at the size given bygetSourceRenderSize. Otherwise, the image has its natural size given by ImageReader.getWidth andImageReader.getHeight.

Next, the image is clipped against the source region specified by getSourceXOffset, getSourceYOffset,getSourceWidth, and getSourceHeight.

The resulting region is then subsampled according to the factors given in [IIOParam.setSourceSubsampling](../../javax/imageio/IIOParam.html#setSourceSubsampling%28int, int, int, int%29). 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 width w and its height h.

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 of getDestinationOffset().y + h so 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 getSourceMinProgressivePass andgetSourceNumProgressivePasses are 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 ofImageReadParam by 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 anImageReadParam subclass of which they are not aware. Also, they may ignore any optional features that they normally disable when creating their own ImageReadParam instances via getDefaultReadParam.

Note that unless a query method exists for a capability, it must be supported by all ImageReader implementations (e.g. source render size is optional, but subsampling must be supported).

See Also:

ImageReader, ImageWriter, ImageWriteParam


Field Summary
protected boolean canSetSourceRenderSize true if this ImageReadParam allows the source rendering dimensions to be set.
protected BufferedImage destination The current destination BufferedImage, ornull if none has been set.
protected int[] destinationBands The set of destination bands to be used, as an array ofints.
protected int minProgressivePass The minimum index of a progressive pass to read from the source.
protected int numProgressivePasses The maximum number of progressive passes to read from the source.
protected Dimension sourceRenderSize The desired rendering width and height of the source, ifcanSetSourceRenderSize is true, ornull.
Fields inherited from class javax.imageio.IIOParam
controller, defaultController, destinationOffset, destinationType, sourceBands, sourceRegion, sourceXSubsampling, sourceYSubsampling, subsamplingXOffset, subsamplingYOffset
Constructor Summary
ImageReadParam() Constructs an ImageReadParam.
Method Summary
boolean canSetSourceRenderSize() Returns true if this reader allows the source image to be rendered at an arbitrary size as part of the decoding process, by means of thesetSourceRenderSize method.
BufferedImage getDestination() Returns the BufferedImage currently set by thesetDestination method, or null if none is set.
int[] getDestinationBands() Returns the set of band indices where data will be placed.
int getSourceMaxProgressivePass() If getSourceNumProgressivePasses is equal toInteger.MAX_VALUE, returnsInteger.MAX_VALUE.
int getSourceMinProgressivePass() Returns the index of the first progressive pass that will be decoded.
int getSourceNumProgressivePasses() Returns the number of the progressive passes that will be decoded.
Dimension getSourceRenderSize() Returns the width and height of the source image as it will be rendered during decoding, if they have been set via thesetSourceRenderSize method.
void setDestination(BufferedImage destination) Supplies a BufferedImage to be used as the destination for decoded pixel data.
void setDestinationBands(int[] destinationBands) Sets the indices of the destination bands where data will be placed.
void setDestinationType(ImageTypeSpecifier destinationType) Sets the desired image type for the destination image, using anImageTypeSpecifier.
void [setSourceProgressivePasses](../../javax/imageio/ImageReadParam.html#setSourceProgressivePasses%28int, int%29)(int minPass, int numPasses) Sets the range of progressive passes that will be decoded.
void setSourceRenderSize(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 inherited from class javax.imageio.IIOParam
activateController, getController, getDefaultController, getDestinationOffset, getDestinationType, getSourceBands, getSourceRegion, getSourceXSubsampling, getSourceYSubsampling, getSubsamplingXOffset, getSubsamplingYOffset, hasController, setController, setDestinationOffset, setSourceBands, setSourceRegion, [setSourceSubsampling](../../javax/imageio/IIOParam.html#setSourceSubsampling%28int, int, int, int%29)
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, [wait](../../java/lang/Object.html#wait%28long, int%29)
Field Detail

canSetSourceRenderSize

protected boolean canSetSourceRenderSize

true if this ImageReadParam allows the source rendering dimensions to be set. By default, the value is false. Subclasses must set this value manually.

ImageReaders that do not support setting of the source render size should set this value tofalse.


sourceRenderSize

protected Dimension sourceRenderSize

The desired rendering width and height of the source, ifcanSetSourceRenderSize is true, ornull.

ImageReaders that do not support setting of the source render size may ignore this value.


destination

protected BufferedImage destination

The current destination BufferedImage, ornull if none has been set. By default, the value is null.


destinationBands

protected int[] destinationBands

The set of destination bands to be used, as an array ofints. By default, the value is null, indicating all destination bands should be written in order.


minProgressivePass

protected 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.


numProgressivePasses

protected 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 notInteger.MAX_VALUE, then minProgressivePass + numProgressivePasses - 1 should not exceedInteger.MAX_VALUE.

Constructor Detail

ImageReadParam

public ImageReadParam()

Constructs an ImageReadParam.

Method Detail

setDestinationType

public void setDestinationType(ImageTypeSpecifier destinationType)

Description copied from class: [IIOParam](../../javax/imageio/IIOParam.html#setDestinationType%28javax.imageio.ImageTypeSpecifier%29)

Sets the desired image type for the destination image, using anImageTypeSpecifier.

When reading, if the layout of the destination has been set using this method, each call to an ImageReader read method will return a newBufferedImage using the format specified by the supplied type specifier. As a side effect, any destinationBufferedImage set byImageReadParam.setDestination(BufferedImage) will no longer be set as the destination. In other words, this method may be thought of as callingsetDestination((BufferedImage)null).

When writing, the destination type maybe used to determine the color type of the image. The SampleModel information will be ignored, and may be null. For example, a 4-banded image could represent either CMYK or RGBA data. If a destination type is set, itsColorModel will override anyColorModel on the image itself. This is crucial when setSourceBands is used since the image'sColorModel will refer to the entire image rather than to the subset of bands being written.

Overrides:

[setDestinationType](../../javax/imageio/IIOParam.html#setDestinationType%28javax.imageio.ImageTypeSpecifier%29) in class [IIOParam](../../javax/imageio/IIOParam.html "class in javax.imageio")

Parameters:

destinationType - the ImageTypeSpecifier to be used to determine the destination layout and color type.

See Also:

IIOParam.getDestinationType()


setDestination

public void setDestination(BufferedImage destination)

Supplies a BufferedImage to be used as the destination for decoded pixel data. The currently set image will be written to by the read,readAll, and readRaster methods, 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 bygetDestinationOffset.

If destination is null, a newly-created BufferedImage will be returned by those methods.

At the time of reading, the image is checked to verify that its ColorModel and SampleModel correspond to one of the ImageTypeSpecifiers returned from the ImageReader'sgetImageTypes method. If it does not, the reader will throw an IIOException.

Parameters:

destination - the BufferedImage to be written to, ornull.

See Also:

getDestination()


getDestination

public BufferedImage getDestination()

Returns the BufferedImage currently set by thesetDestination method, or null if none is set.

Returns:

the BufferedImage to be written to.

See Also:

setDestination(java.awt.image.BufferedImage)


setDestinationBands

public void setDestinationBands(int[] destinationBands)

Sets the indices of the destination bands where data will be placed. Duplicate indices are not allowed.

A null value 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 theImageReadParam.setDestination method.

At the time of reading or writing, anIllegalArgumentException will 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.checkReadParamBandSettings method may be used to automate this test.

Parameters:

destinationBands - an array of integer band indices to be used.

Throws:

[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang") - if destinationBands contains a negative or duplicate value.

See Also:

getDestinationBands(), IIOParam.getSourceBands(), [ImageReader.checkReadParamBandSettings(javax.imageio.ImageReadParam, int, int)](../../javax/imageio/ImageReader.html#checkReadParamBandSettings%28javax.imageio.ImageReadParam, int, int%29)


getDestinationBands

public int[] getDestinationBands()

Returns the set of band indices where data will be placed. If no value has been set, null is 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[])


canSetSourceRenderSize

public boolean canSetSourceRenderSize()

Returns true if this reader allows the source image to be rendered at an arbitrary size as part of the decoding process, by means of thesetSourceRenderSize method. If this method returns false, calls tosetSourceRenderSize will throw anUnsupportedOperationException.

Returns:

true if setting source rendering size is supported.

See Also:

setSourceRenderSize(java.awt.Dimension)


setSourceRenderSize

public 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 the getWidth andgetHeight methods on ImageReader are 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 fromImageReader.getAspectRatio.

If this plug-in does not allow the rendering size to be set, an UnsupportedOperationException will be thrown.

To remove the render size setting, pass in a value ofnull for size.

Parameters:

size - a Dimension indicating the desired width and height.

Throws:

[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang") - if either the width or the height is negative or 0.

[UnsupportedOperationException](../../java/lang/UnsupportedOperationException.html "class in java.lang") - if image resizing is not supported by this plug-in.

See Also:

getSourceRenderSize(), ImageReader.getWidth(int), ImageReader.getHeight(int), ImageReader.getAspectRatio(int)


getSourceRenderSize

public Dimension getSourceRenderSize()

Returns the width and height of the source image as it will be rendered during decoding, if they have been set via thesetSourceRenderSize method. 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)


setSourceProgressivePasses

public 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 - 1 is larger than the index of the last available passes, decoding will end with that pass.

A value of numPasses ofInteger.MAX_VALUE indicates that all passes fromminPass forward should be read. Otherwise, the index of the last pass (i.e., minPass + numPasses - 1) must not exceed Integer.MAX_VALUE.

There is no unsetSourceProgressivePasses method; 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](../../java/lang/IllegalArgumentException.html "class in java.lang") - if minPass is negative, numPasses is negative or 0, ornumPasses is smaller thanInteger.MAX_VALUE but minPass + numPasses - 1 is greater thanINTEGER.MAX_VALUE.

See Also:

getSourceMinProgressivePass(), getSourceMaxProgressivePass()


getSourceMinProgressivePass

public 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)](../../javax/imageio/ImageReadParam.html#setSourceProgressivePasses%28int, int%29), getSourceNumProgressivePasses()


getSourceMaxProgressivePass

public int getSourceMaxProgressivePass()

If getSourceNumProgressivePasses is equal toInteger.MAX_VALUE, returnsInteger.MAX_VALUE. Otherwise, returnsgetSourceMinProgressivePass() + getSourceNumProgressivePasses() - 1.

Returns:

the index of the last pass to be read, orInteger.MAX_VALUE.


getSourceNumProgressivePasses

public int getSourceNumProgressivePasses()

Returns the number of the progressive passes that will be decoded. If no value has been set,Integer.MAX_VALUE will be returned (which is the correct value).

Returns:

the number of the passes that will be decoded.

See Also:

[setSourceProgressivePasses(int, int)](../../javax/imageio/ImageReadParam.html#setSourceProgressivePasses%28int, int%29), getSourceMinProgressivePass()



Submit a bug or feature
For further API reference and developer documentation, see Java SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Copyright © 1993, 2015, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.

Scripting on this page tracks web page traffic, but does not change the content in any way.