APIdia Launch Partner
Top Fields Constructors Methods
com.sun.imageio.plugins.png

public Class PNGImageReader

Additional top-level class in compilation unit: PNGImageDataEnumeration.

extends ImageReader
Class Inheritance
Imports
java.awt.Point, .Rectangle, java.awt.color.ColorSpace, java.awt.image.BufferedImage, .DataBuffer, .DataBufferByte, .DataBufferUShort, .Raster, .WritableRaster, java.io.BufferedInputStream, .ByteArrayInputStream, .ByteArrayOutputStream, .DataInputStream, .EOFException, .IOException, .InputStream, .SequenceInputStream, java.nio.charset.Charset, java.util.ArrayList, .Arrays, .Enumeration, .Iterator, java.util.zip.Inflater, .InflaterInputStream, javax.imageio.IIOException, .ImageReadParam, .ImageReader, .ImageTypeSpecifier, javax.imageio.metadata.IIOMetadata, javax.imageio.spi.ImageReaderSpi, javax.imageio.stream.ImageInputStream, com.sun.imageio.plugins.common.InputStreamAdapter, .ReaderUtil, .SubImageInputStream, sun.awt.image.ByteInterleavedRaster

Field Summary

Modifier and TypeField and Description
pack-priv static final int[]
pack-priv static final int[]
pack-priv static final int[]
pack-priv static final int[]
private static final int[][]
pack-priv static final int
pack-priv static final int
private static final boolean
pack-priv int[]
pack-priv Point
pack-priv static final int
pack-priv boolean
pack-priv boolean
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv long
pack-priv static final int[]
pack-priv static final int
pack-priv ImageReadParam
pack-priv static final int
pack-priv PNGMetadata
pack-priv static final int
pack-priv int
pack-priv DataInputStream
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv int[]
pack-priv int
pack-priv int
pack-priv Rectangle
pack-priv int
pack-priv int
pack-priv static final int
pack-priv static final int
pack-priv ImageInputStream
pack-priv static final int
pack-priv BufferedImage
pack-priv static final int
pack-priv int
pack-priv static final int
pack-priv static final int
Inherited from javax.imageio.ImageReader:
availableLocalesignoreMetadatainputlocaleminIndexoriginatingProviderprogressListenersseekForwardOnlyupdateListenerswarningListenerswarningLocales

Constructor Summary

AccessConstructor and Description
public
PNGImageReader(ImageReaderSpi originatingProvider)

Method Summary

Modifier and TypeMethod and Description
private WritableRaster
createRaster(int width, int height, int bands, int scanlineStride, int bitDepth)

private static void
decodeAverageFilter(byte[] curr, int coff, byte[] prev, int poff, int count, int bpp)

private void
private static void
decodePaethFilter(byte[] curr, int coff, byte[] prev, int poff, int count, int bpp)

private void
decodePass(int passNum, int xStart, int yStart, int xStep, int yStep, int passWidth, int passHeight)

private static void
decodeSubFilter(byte[] curr, int coff, int count, int bpp)

private static void
decodeUpFilter(byte[] curr, int coff, byte[] prev, int poff, int count)

public ImageReadParam
getDefaultReadParam()

Overrides javax.imageio.ImageReader.getDefaultReadParam.

Returns a default ImageReadParam object appropriate for this format.

public int
getHeight(int imageIndex)

Implements abstract javax.imageio.ImageReader.getHeight.

Returns the height in pixels of the given image within the input source.

public IIOMetadata
getImageMetadata(int imageIndex)

Implements abstract javax.imageio.ImageReader.getImageMetadata.

Returns an IIOMetadata object containing metadata associated with the given image, or null if the reader does not support reading metadata, is set to ignore metadata, or if no metadata is available.

public Iterator<ImageTypeSpecifier>
getImageTypes(int imageIndex)

Implements abstract javax.imageio.ImageReader.getImageTypes.

Returns an Iterator containing possible image types to which the given image may be decoded, in the form of ImageTypeSpecifierss.

public int
getNumImages(boolean allowSearch)

Implements abstract javax.imageio.ImageReader.getNumImages.

Returns the number of images, not including thumbnails, available from the current input source.

public ImageTypeSpecifier
getRawImageType(int imageIndex)

Overrides javax.imageio.ImageReader.getRawImageType.

Returns an ImageTypeSpecifier indicating the SampleModel and ColorModel which most closely represents the "raw" internal format of the image.

public IIOMetadata
getStreamMetadata()

Implements abstract javax.imageio.ImageReader.getStreamMetadata.

Returns an IIOMetadata object representing the metadata associated with the input source as a whole (i.e., not associated with any particular image), or null if the reader does not support reading metadata, is set to ignore metadata, or if no metadata is available.

public int
getWidth(int imageIndex)

Implements abstract javax.imageio.ImageReader.getWidth.

Returns the width in pixels of the given image within the input source.

private static byte[]
inflate(byte[] b)

private static int
paethPredictor(int a, int b, int c)

private void
private void
private void
private void
parse_hIST_chunk(int chunkLength)

private void
parse_iCCP_chunk(int chunkLength)

private void
parse_iTXt_chunk(int chunkLength)

private void
private void
parse_PLTE_chunk(int chunkLength)

private void
private void
parse_sPLT_chunk(int chunkLength)

private void
private void
parse_tEXt_chunk(int chunkLength)

private void
private void
parse_tRNS_chunk(int chunkLength)

private void
parse_zTXt_chunk(int chunkLength)

public BufferedImage
read(int imageIndex, ImageReadParam param)

Implements abstract javax.imageio.ImageReader.read.

Reads the image indexed by imageIndex and returns it as a complete BufferedImage, using a supplied ImageReadParam.

private void
private void
private void
private String
readNullTerminatedString(Charset charset, int maxLen)

public void
reset()

Overrides javax.imageio.ImageReader.reset.

Restores the ImageReader to its initial state.

private void
public void
setInput(Object input, boolean seekForwardOnly, boolean ignoreMetadata)

Overrides javax.imageio.ImageReader.setInput.

Sets the input source to use to the given ImageInputStream or other Object.

private void
skipPass(int passWidth, int passHeight)

private void
updateImageProgress(int newPixels)

Inherited from javax.imageio.ImageReader:
abortabortRequestedaddIIOReadProgressListeneraddIIOReadUpdateListeneraddIIOReadWarningListenercanReadRastercheckReadParamBandSettingsclearAbortRequestcomputeRegionsdisposegetAspectRatiogetAvailableLocalesgetDestinationgetFormatNamegetImageMetadatagetInputgetLocalegetMinIndexgetNumThumbnailsgetOriginatingProvidergetSourceRegiongetStreamMetadatagetThumbnailHeightgetThumbnailWidthgetTileGridXOffsetgetTileGridYOffsetgetTileHeightgetTileWidthhasThumbnailsisIgnoringMetadataisImageTiledisRandomAccessEasyisSeekForwardOnlyprocessImageCompleteprocessImageProgressprocessImageStartedprocessImageUpdateprocessPassCompleteprocessPassStartedprocessReadAbortedprocessSequenceCompleteprocessSequenceStartedprocessThumbnailCompleteprocessThumbnailPassCompleteprocessThumbnailPassStartedprocessThumbnailProgressprocessThumbnailStartedprocessThumbnailUpdateprocessWarningOccurredprocessWarningOccurredreadreadAllreadAllreadAsRenderedImagereaderSupportsThumbnailsreadRasterreadThumbnailreadTilereadTileRasterremoveAllIIOReadProgressListenersremoveAllIIOReadUpdateListenersremoveAllIIOReadWarningListenersremoveIIOReadProgressListenerremoveIIOReadUpdateListenerremoveIIOReadWarningListenersetInputsetInputsetLocale

Field Detail

adam7XOffsetback to summary
pack-priv static final int[] adam7XOffset
adam7XSubsamplingback to summary
pack-priv static final int[] adam7XSubsampling
adam7YOffsetback to summary
pack-priv static final int[] adam7YOffset
adam7YSubsamplingback to summary
pack-priv static final int[] adam7YSubsampling
bandOffsetsback to summary
private static final int[][] bandOffsets
bKGD_TYPEback to summary
pack-priv static final int bKGD_TYPE
cHRM_TYPEback to summary
pack-priv static final int cHRM_TYPE
debugback to summary
private static final boolean debug
destinationBandsback to summary
pack-priv int[] destinationBands
destinationOffsetback to summary
pack-priv Point destinationOffset
gAMA_TYPEback to summary
pack-priv static final int gAMA_TYPE
gotHeaderback to summary
pack-priv boolean gotHeader
gotMetadataback to summary
pack-priv boolean gotMetadata
hIST_TYPEback to summary
pack-priv static final int hIST_TYPE
iCCP_TYPEback to summary
pack-priv static final int iCCP_TYPE
IDAT_TYPEback to summary
pack-priv static final int IDAT_TYPE
IEND_TYPEback to summary
pack-priv static final int IEND_TYPE
IHDR_TYPEback to summary
pack-priv static final int IHDR_TYPE
imageStartPositionback to summary
pack-priv long imageStartPosition
inputBandsForColorTypeback to summary
pack-priv static final int[] inputBandsForColorType
iTXt_TYPEback to summary
pack-priv static final int iTXt_TYPE
lastParamback to summary
pack-priv ImageReadParam lastParam
MAX_INFLATED_TEXT_LENGTHback to summary
pack-priv static final int MAX_INFLATED_TEXT_LENGTH
metadataback to summary
pack-priv PNGMetadata metadata
pHYs_TYPEback to summary
pack-priv static final int pHYs_TYPE
pixelsDoneback to summary
pack-priv int pixelsDone
pixelStreamback to summary
pack-priv DataInputStream pixelStream
PLTE_TYPEback to summary
pack-priv static final int PLTE_TYPE
PNG_COLOR_GRAYback to summary
pack-priv static final int PNG_COLOR_GRAY
PNG_COLOR_GRAY_ALPHAback to summary
pack-priv static final int PNG_COLOR_GRAY_ALPHA
PNG_COLOR_PALETTEback to summary
pack-priv static final int PNG_COLOR_PALETTE
PNG_COLOR_RGBback to summary
pack-priv static final int PNG_COLOR_RGB
PNG_COLOR_RGB_ALPHAback to summary
pack-priv static final int PNG_COLOR_RGB_ALPHA
PNG_FILTER_AVERAGEback to summary
pack-priv static final int PNG_FILTER_AVERAGE
PNG_FILTER_NONEback to summary
pack-priv static final int PNG_FILTER_NONE
PNG_FILTER_PAETHback to summary
pack-priv static final int PNG_FILTER_PAETH
PNG_FILTER_SUBback to summary
pack-priv static final int PNG_FILTER_SUB
PNG_FILTER_UPback to summary
pack-priv static final int PNG_FILTER_UP
sBIT_TYPEback to summary
pack-priv static final int sBIT_TYPE
sourceBandsback to summary
pack-priv int[] sourceBands
sourceMaxProgressivePassback to summary
pack-priv int sourceMaxProgressivePass
sourceMinProgressivePassback to summary
pack-priv int sourceMinProgressivePass
sourceRegionback to summary
pack-priv Rectangle sourceRegion
sourceXSubsamplingback to summary
pack-priv int sourceXSubsampling
sourceYSubsamplingback to summary
pack-priv int sourceYSubsampling
sPLT_TYPEback to summary
pack-priv static final int sPLT_TYPE
sRGB_TYPEback to summary
pack-priv static final int sRGB_TYPE
streamback to summary
pack-priv ImageInputStream stream
tEXt_TYPEback to summary
pack-priv static final int tEXt_TYPE
theImageback to summary
pack-priv BufferedImage theImage
tIME_TYPEback to summary
pack-priv static final int tIME_TYPE
totalPixelsback to summary
pack-priv int totalPixels
tRNS_TYPEback to summary
pack-priv static final int tRNS_TYPE
zTXt_TYPEback to summary
pack-priv static final int zTXt_TYPE

Constructor Detail

PNGImageReaderback to summary
public PNGImageReader(ImageReaderSpi originatingProvider)

Method Detail

createRasterback to summary
private WritableRaster createRaster(int width, int height, int bands, int scanlineStride, int bitDepth)
decodeAverageFilterback to summary
private static void decodeAverageFilter(byte[] curr, int coff, byte[] prev, int poff, int count, int bpp)
decodeImageback to summary
private void decodeImage() throws IOException, IIOException
decodePaethFilterback to summary
private static void decodePaethFilter(byte[] curr, int coff, byte[] prev, int poff, int count, int bpp)
decodePassback to summary
private void decodePass(int passNum, int xStart, int yStart, int xStep, int yStep, int passWidth, int passHeight) throws IOException
decodeSubFilterback to summary
private static void decodeSubFilter(byte[] curr, int coff, int count, int bpp)
decodeUpFilterback to summary
private static void decodeUpFilter(byte[] curr, int coff, byte[] prev, int poff, int count)
getDefaultReadParamback to summary
public ImageReadParam getDefaultReadParam()

Overrides javax.imageio.ImageReader.getDefaultReadParam.

Doc from javax.imageio.ImageReader.getDefaultReadParam.

Returns a default ImageReadParam object appropriate for this format. All subclasses should define a set of default values for all parameters and return them with this call. This method may be called before the input source is set.

The default implementation constructs and returns a new ImageReadParam object that does not allow source scaling (i.e., it returns new ImageReadParam().

Annotations
@Override
getHeightback to summary
public int getHeight(int imageIndex) throws IIOException

Implements abstract javax.imageio.ImageReader.getHeight.

Doc from javax.imageio.ImageReader.getHeight.

Returns the height in pixels of the given image within the input source.

If the image can be rendered to a user-specified size, then this method returns the default height.

Annotations
@Override
getImageMetadataback to summary
public IIOMetadata getImageMetadata(int imageIndex) throws IIOException

Implements abstract javax.imageio.ImageReader.getImageMetadata.

Doc from javax.imageio.ImageReader.getImageMetadata.

Returns an IIOMetadata object containing metadata associated with the given image, or null if the reader does not support reading metadata, is set to ignore metadata, or if no metadata is available.

Annotations
@Override
getImageTypesback to summary
public Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex) throws IIOException

Implements abstract javax.imageio.ImageReader.getImageTypes.

Doc from javax.imageio.ImageReader.getImageTypes.

Returns an Iterator containing possible image types to which the given image may be decoded, in the form of ImageTypeSpecifierss. At least one legal image type will be returned.

The first element of the iterator should be the most "natural" type for decoding the image with as little loss as possible. For example, for a JPEG image the first entry should be an RGB image, even though the image data is stored internally in a YCbCr color space.

Annotations
@Override
getNumImagesback to summary
public int getNumImages(boolean allowSearch) throws IIOException

Implements abstract javax.imageio.ImageReader.getNumImages.

Doc from javax.imageio.ImageReader.getNumImages.

Returns the number of images, not including thumbnails, available from the current input source.

Note that some image formats (such as animated GIF) do not specify how many images are present in the stream. Thus determining the number of images will require the entire stream to be scanned and may require memory for buffering. If images are to be processed in order, it may be more efficient to simply call read with increasing indices until an IndexOutOfBoundsException is thrown to indicate that no more images are available. The allowSearch parameter may be set to false to indicate that an exhaustive search is not desired; the return value will be -1 to indicate that a search is necessary. If the input has been specified with seekForwardOnly set to true, this method throws an IllegalStateException if allowSearch is set to true.

Annotations
@Override
getRawImageTypeback to summary
public ImageTypeSpecifier getRawImageType(int imageIndex) throws IOException

Overrides javax.imageio.ImageReader.getRawImageType.

Doc from javax.imageio.ImageReader.getRawImageType.

Returns an ImageTypeSpecifier indicating the SampleModel and ColorModel which most closely represents the "raw" internal format of the image. If there is no close match then a type which preserves the most information from the image should be returned. The returned value should also be included in the list of values returned by getImageTypes.

The default implementation simply returns the first entry from the list provided by getImageType.

Annotations
@Override
Exceptions
IOException:
if an error occurs reading the format information from the input source.
getStreamMetadataback to summary
public IIOMetadata getStreamMetadata() throws IIOException

Implements abstract javax.imageio.ImageReader.getStreamMetadata.

Doc from javax.imageio.ImageReader.getStreamMetadata.

Returns an IIOMetadata object representing the metadata associated with the input source as a whole (i.e., not associated with any particular image), or null if the reader does not support reading metadata, is set to ignore metadata, or if no metadata is available.

Annotations
@Override
getWidthback to summary
public int getWidth(int imageIndex) throws IIOException

Implements abstract javax.imageio.ImageReader.getWidth.

Doc from javax.imageio.ImageReader.getWidth.

Returns the width in pixels of the given image within the input source.

If the image can be rendered to a user-specified size, then this method returns the default width.

Annotations
@Override
inflateback to summary
private static byte[] inflate(byte[] b) throws IOException
paethPredictorback to summary
private static int paethPredictor(int a, int b, int c)
parse_bKGD_chunkback to summary
private void parse_bKGD_chunk() throws IOException
parse_cHRM_chunkback to summary
private void parse_cHRM_chunk() throws IOException
parse_gAMA_chunkback to summary
private void parse_gAMA_chunk() throws IOException
parse_hIST_chunkback to summary
private void parse_hIST_chunk(int chunkLength) throws IOException, IIOException
parse_iCCP_chunkback to summary
private void parse_iCCP_chunk(int chunkLength) throws IOException
parse_iTXt_chunkback to summary
private void parse_iTXt_chunk(int chunkLength) throws IOException
parse_pHYs_chunkback to summary
private void parse_pHYs_chunk() throws IOException
parse_PLTE_chunkback to summary
private void parse_PLTE_chunk(int chunkLength) throws IOException
parse_sBIT_chunkback to summary
private void parse_sBIT_chunk() throws IOException
parse_sPLT_chunkback to summary
private void parse_sPLT_chunk(int chunkLength) throws IOException, IIOException
parse_sRGB_chunkback to summary
private void parse_sRGB_chunk() throws IOException
parse_tEXt_chunkback to summary
private void parse_tEXt_chunk(int chunkLength) throws IOException
parse_tIME_chunkback to summary
private void parse_tIME_chunk() throws IOException
parse_tRNS_chunkback to summary
private void parse_tRNS_chunk(int chunkLength) throws IOException
parse_zTXt_chunkback to summary
private void parse_zTXt_chunk(int chunkLength) throws IOException
readback to summary
public BufferedImage read(int imageIndex, ImageReadParam param) throws IIOException

Implements abstract javax.imageio.ImageReader.read.

Doc from javax.imageio.ImageReader.read.

Reads the image indexed by imageIndex and returns it as a complete BufferedImage, using a supplied ImageReadParam.

The actual BufferedImage returned will be chosen using the algorithm defined by the getDestination method.

Any registered IIOReadProgressListener objects will be notified by calling their imageStarted method, followed by calls to their imageProgress method as the read progresses. Finally their imageComplete method will be called. IIOReadUpdateListener objects may be updated at other times during the read as pixels are decoded. Finally, IIOReadWarningListener objects will receive notification of any non-fatal warnings that occur during decoding.

The set of source bands to be read and destination bands to be written is determined by calling getSourceBands and getDestinationBands on the supplied ImageReadParam. If the lengths of the arrays returned by these methods differ, the set of source bands contains an index larger that the largest available source index, or the set of destination bands contains an index larger than the largest legal destination index, an IllegalArgumentException is thrown.

If the supplied ImageReadParam contains optional setting values not supported by this reader (e.g. source render size or any format-specific settings), they will be ignored.

Annotations
@Override
readHeaderback to summary
private void readHeader() throws IIOException
readImageback to summary
private void readImage(ImageReadParam param) throws IIOException
readMetadataback to summary
private void readMetadata() throws IIOException
readNullTerminatedStringback to summary
private String readNullTerminatedString(Charset charset, int maxLen) throws IOException
resetback to summary
public void reset()

Overrides javax.imageio.ImageReader.reset.

Doc from javax.imageio.ImageReader.reset.

Restores the ImageReader to its initial state.

The default implementation calls setInput(null, false), setLocale(null), removeAllIIOReadUpdateListeners(), removeAllIIOReadWarningListeners(), removeAllIIOReadProgressListeners(), and clearAbortRequest.

Annotations
@Override
resetStreamSettingsback to summary
private void resetStreamSettings()
setInputback to summary
public void setInput(Object input, boolean seekForwardOnly, boolean ignoreMetadata)

Overrides javax.imageio.ImageReader.setInput.

Doc from javax.imageio.ImageReader.setInput.

Sets the input source to use to the given ImageInputStream or other Object. The input source must be set before any of the query or read methods are used. If input is null, any currently set input source will be removed. In any case, the value of minIndex will be initialized to 0.

The seekForwardOnly parameter controls whether the value returned by getMinIndex will be increased as each image (or thumbnail, or image metadata) is read. If seekForwardOnly is true, then a call to read(index) will throw an IndexOutOfBoundsException if index < this.minIndex; otherwise, the value of minIndex will be set to index. If seekForwardOnly is false, the value of minIndex will remain 0 regardless of any read operations.

The ignoreMetadata parameter, if set to true, allows the reader to disregard any metadata encountered during the read. Subsequent calls to the getStreamMetadata and getImageMetadata methods may return null, and an IIOImage returned from readAll may return null from their getMetadata method. Setting this parameter may allow the reader to work more efficiently. The reader may choose to disregard this setting and return metadata normally.

Subclasses should take care to remove any cached information based on the previous stream, such as header information or partially decoded image data.

Use of a general Object other than an ImageInputStream is intended for readers that interact directly with a capture device or imaging protocol. The set of legal classes is advertised by the reader's service provider's getInputTypes method; most readers will return a single-element array containing only ImageInputStream.class to indicate that they accept only an ImageInputStream.

The default implementation checks the input argument against the list returned by originatingProvider.getInputTypes() and fails if the argument is not an instance of one of the classes in the list. If the originating provider is set to null, the input is accepted only if it is an ImageInputStream.

Annotations
@Override
skipPassback to summary
private void skipPass(int passWidth, int passHeight) throws IOException, IIOException
updateImageProgressback to summary
private void updateImageProgress(int newPixels)