Package net.sourceforge.jiu.codecs
Class PngIdatInputStream
java.lang.Object
java.io.InputStream
net.sourceforge.jiu.codecs.PngIdatInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
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.
- Since:
- 0.12.0
- Author:
- Marco Schmidt
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Methods inherited from class java.io.InputStream
available, close, mark, markSupported, nullInputStream, read, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Field Details
-
IDAT
private static final int IDAT- See Also:
-
in
-
bytesLeft
private long bytesLeft
-
-
Constructor Details
-
PngIdatInputStream
-
-
Method Details
-
read
- Specified by:
read
in classInputStream
- Throws:
IOException
-
skipHeaders
- Throws:
IOException
-