ar.com.hjg.pngj
Class PngReader

java.lang.Object
  extended by ar.com.hjg.pngj.PngReader

public class PngReader
extends Object

Reads a PNG image, line by line

The reading sequence is as follows:
1. At construction time, the header and IHDR chunk are read (basic image info)
2. Optional: If you call GetMetadata() before reading the rows, the chunks before IDAT are automatically loaded
3. The rows are read in strict sequence, from 0 to nrows-1
4. The reading of the last row triggers the loading of trailing chunks, and ends the reader.


Field Summary
 ImageInfo imgInfo
          Basic image info - final and inmutable.
 
Constructor Summary
PngReader(InputStream inputStream, String filenameOrDescription)
          Constructs a PngReader from an InputStream.
 
Method Summary
 void end()
          Normally this does nothing, but it can be used to force a premature closing
 ChunkLoadBehaviour getChunkLoadBehaviour()
           
 ChunksList getChunksList()
          All loaded chunks.
 int getCurrentChunkGroup()
           
 PngMetadata getMetadata()
          High level wrapper over chunksList
 ImageLine getRow(int nrow)
          Like readRow(int nrow) but this accepts non consecutive rows.
 ImageLine readRow(int nrow)
          Calls readRow(int[] buffer, int nrow) using internal ImageLine as buffer.
 int[] readRow(int[] buffer, int nrow)
          Reads a line and returns it as a int[] array.
 void setChunkLoadBehaviour(ChunkLoadBehaviour chunkLoadBehaviour)
           
 void setMaxBytesChunksToLoad(int maxBytesChunksToLoad)
          Total maximum bytes to load from ancillary ckunks (default: 1Mb) If exceeded, chunks will be ignored
 void setShouldCloseStream(boolean shouldCloseStream)
          if true, input stream will be closed after ending read default=true
 String toString()
          Basic info, for debugging.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

imgInfo

public final ImageInfo imgInfo
Basic image info - final and inmutable.

Constructor Detail

PngReader

public PngReader(InputStream inputStream,
                 String filenameOrDescription)
Constructs a PngReader from an InputStream.

See also FileHelper.createPngReader(File f) if available. Reads only the signature and first chunk (IDHR)

Parameters:
filenameOrDescription - : Optional, can be a filename or a description. Just for error/debug messages
Method Detail

end

public void end()
Normally this does nothing, but it can be used to force a premature closing


getChunkLoadBehaviour

public ChunkLoadBehaviour getChunkLoadBehaviour()

getChunksList

public ChunksList getChunksList()
All loaded chunks.

Critical chunks are included, except that all IDAT chunks appearance are replaced by a single dummy-marker IDAT chunk. These might be copied to the PngWriter


getCurrentChunkGroup

public int getCurrentChunkGroup()

getMetadata

public PngMetadata getMetadata()
High level wrapper over chunksList


getRow

public ImageLine getRow(int nrow)
Like readRow(int nrow) but this accepts non consecutive rows.

If it's the current row, it will just return it. Elsewhere, it will try to read it. This implementation only accepts nrow greater or equal than current row, but an extended class could implement some partial or full cache of lines.

This should not not be mixed with calls to readRow(int[] buffer, final int nrow)

Parameters:
nrow -
Returns:

readRow

public ImageLine readRow(int nrow)
Calls readRow(int[] buffer, int nrow) using internal ImageLine as buffer. This doesn't allocate or copy anything.

Returns:
The ImageLine that also is available inside this object.

readRow

public int[] readRow(int[] buffer,
                     int nrow)
Reads a line and returns it as a int[] array.

You can pass (optionally) a prealocatted buffer.

Parameters:
buffer - Prealocated buffer, or null.
nrow - Row number (0 is top). This is mostly for checking, because this library reads rows in sequence.
Returns:
The scanline in the same passwd buffer if it was allocated, a newly allocated one otherwise

setChunkLoadBehaviour

public void setChunkLoadBehaviour(ChunkLoadBehaviour chunkLoadBehaviour)

setMaxBytesChunksToLoad

public void setMaxBytesChunksToLoad(int maxBytesChunksToLoad)
Total maximum bytes to load from ancillary ckunks (default: 1Mb)

If exceeded, chunks will be ignored


setShouldCloseStream

public void setShouldCloseStream(boolean shouldCloseStream)
if true, input stream will be closed after ending read

default=true


toString

public String toString()
Basic info, for debugging.

Overrides:
toString in class Object