net.sourceforge.jiu.codecs
Class PngIdatInputStream
InputStream
net.sourceforge.jiu.codecs.PngIdatInputStream
(package private) class PngIdatInputStream
extends InputStream
An input stream that reads from an underlying stream of PNG
IDAT chunks and skips all header information.
PNG uses one or more IDAT chunks to store image data.
The resulting stream looks like that:
IDAT [chunk size] [compressed data] [checksum]
IDAT [chunk size] [compressed data] [checksum] ...
This stream class expects an input stream where the first IDAT chunk name and chunk
size have been read already, the stream is thus pointing to the
first byte of the first [compressed data] section.
The size of that section is given to the constructor.
This class then returns calls to read(), counts the bytes it has given
away and, whenever a compressed data section has been consumed, it reads
the IDAT chunk and stores its size, using it to determine when the
next compressed data section will end.
That way, for the caller the stream appears to be one large compressed
section.
According to the PNG specs the reason for multiple IDAT chunks is as
follows:
(Multiple IDAT chunks are allowed so that encoders can work in a fixed
amount of memory; typically the chunk size will correspond to the encoder's
buffer size.)
4.1.3. IDAT Image data
If there is a more elegant approach to read multiple IDAT chunks, please
let me know.
However, reading everything into memory is not an option.
IDAT
private static final int IDAT
bytesLeft
private long bytesLeft
in
private DataInputStream in
PngIdatInputStream
public PngIdatInputStream(DataInputStream input,
long bytes)
read
public int read()
throws IOException
skipHeaders
private void skipHeaders()
throws IOException