Top Description Constructors Methods
com.sun.imageio.plugins.common

public Class ReaderUtil

extends Object
Class Inheritance
Imports
java.awt.Point, .Rectangle, java.io.IOException, java.util.List, .ArrayList, javax.imageio.stream.ImageInputStream

This class contains utility methods that may be useful to ImageReader plugins. Ideally these methods would be in the ImageReader base class so that all subclasses could benefit from them, but that would be an addition to the existing API, and it is not yet clear whether these methods are universally useful, so for now we will leave them here.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static void
computeUpdatedPixels(int sourceOffset, int sourceExtent, int destinationOffset, int dstMin, int dstMax, int sourceSubsampling, int passStart, int passExtent, int passPeriod, int[] vals, int offset)

public static int[]

Returns:

an array of 6 ints containing the destination min X, min Y, width, height, X period and Y period of the region that will be updated.
computeUpdatedPixels
(Rectangle
a Rectangle containing the source region being read, offset by the source subsampling offsets, and clipped against the source bounds, as returned by the getSourceRegion method.
sourceRegion
,
Point
a Point containing the coordinates of the upper-left pixel to be written in the destination.
destinationOffset
,
int
the smallest X coordinate (inclusive) of the destination Raster.
dstMinX
,
int
the smallest Y coordinate (inclusive) of the destination Raster.
dstMinY
,
int
the largest X coordinate (inclusive) of the destination Raster.
dstMaxX
,
int
the largest Y coordinate (inclusive) of the destination Raster.
dstMaxY
,
int
the X subsampling factor.
sourceXSubsampling
,
int
the Y subsampling factor.
sourceYSubsampling
,
int
the smallest source X coordinate (inclusive) of the current progressive pass.
passXStart
,
int
the smallest source Y coordinate (inclusive) of the current progressive pass.
passYStart
,
int
the width in pixels of the current progressive pass.
passWidth
,
int
the height in pixels of the current progressive pass.
passHeight
,
int
the X period (horizontal spacing between pixels) of the current progressive pass.
passPeriodX
,
int
the Y period (vertical spacing between pixels) of the current progressive pass.
passPeriodY
)

A utility method that computes the exact set of destination pixels that will be written during a particular decoding pass.

public static int
public static byte[]

Returns:

array of size length when decode succeeds
staggeredReadByteStream
(ImageInputStream
a ImageInputStream to decode data and store it in byte array.
iis
,
int
the size of data to decode
length
)

An utility method to allocate and initialize a byte array step by step with pre-defined limit, instead of allocating a large array up-front based on the length derived from an image header.

public static boolean

Returns:

true on success, or false on EOF.
tryReadFully
(ImageInputStream
the stream to read.
iis
,
byte[]
an array where to store the bytes.
b
)

Tries to read b.length bytes from the stream, and stores them into b starting at index 0.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ReaderUtilback to summary
public ReaderUtil()

Method Detail

computeUpdatedPixelsback to summary
private static void computeUpdatedPixels(int sourceOffset, int sourceExtent, int destinationOffset, int dstMin, int dstMax, int sourceSubsampling, int passStart, int passExtent, int passPeriod, int[] vals, int offset)
computeUpdatedPixelsback to summary
public static int[] computeUpdatedPixels(Rectangle sourceRegion, Point destinationOffset, int dstMinX, int dstMinY, int dstMaxX, int dstMaxY, int sourceXSubsampling, int sourceYSubsampling, int passXStart, int passYStart, int passWidth, int passHeight, int passPeriodX, int passPeriodY)

A utility method that computes the exact set of destination pixels that will be written during a particular decoding pass. The intent is to simplify the work done by readers in combining the source region, source subsampling, and destination offset information obtained from the ImageReadParam with the offsets and periods of a progressive or interlaced decoding pass.

Parameters
sourceRegion:Rectangle

a Rectangle containing the source region being read, offset by the source subsampling offsets, and clipped against the source bounds, as returned by the getSourceRegion method.

destinationOffset:Point

a Point containing the coordinates of the upper-left pixel to be written in the destination.

dstMinX:int

the smallest X coordinate (inclusive) of the destination Raster.

dstMinY:int

the smallest Y coordinate (inclusive) of the destination Raster.

dstMaxX:int

the largest X coordinate (inclusive) of the destination Raster.

dstMaxY:int

the largest Y coordinate (inclusive) of the destination Raster.

sourceXSubsampling:int

the X subsampling factor.

sourceYSubsampling:int

the Y subsampling factor.

passXStart:int

the smallest source X coordinate (inclusive) of the current progressive pass.

passYStart:int

the smallest source Y coordinate (inclusive) of the current progressive pass.

passWidth:int

the width in pixels of the current progressive pass.

passHeight:int

the height in pixels of the current progressive pass.

passPeriodX:int

the X period (horizontal spacing between pixels) of the current progressive pass.

passPeriodY:int

the Y period (vertical spacing between pixels) of the current progressive pass.

Returns:int[]

an array of 6 ints containing the destination min X, min Y, width, height, X period and Y period of the region that will be updated.

readMultiByteIntegerback to summary
public static int readMultiByteInteger(ImageInputStream iis) throws IOException
staggeredReadByteStreamback to summary
public static byte[] staggeredReadByteStream(ImageInputStream iis, int length) throws IOException

An utility method to allocate and initialize a byte array step by step with pre-defined limit, instead of allocating a large array up-front based on the length derived from an image header.

Parameters
iis:ImageInputStream

a ImageInputStream to decode data and store it in byte array.

length:int

the size of data to decode

Returns:byte[]

array of size length when decode succeeds

Exceptions
IOException:
if decoding of stream fails
tryReadFullyback to summary
public static boolean tryReadFully(ImageInputStream iis, byte[] b) throws IOException

Tries to read b.length bytes from the stream, and stores them into b starting at index 0. If the end of the stream is reached, a false will be returned.

Parameters
iis:ImageInputStream

the stream to read.

b:byte[]

an array where to store the bytes.

Returns:boolean

true on success, or false on EOF.