The reading sequence is as follows:
1. At construction time, the header and IHDR chunk are read (basic image
info)
2. Afterwards you can set some additional global options. Eg.
setUnpackedMode(boolean), setCrcCheckDisabled().
3. Optional: If you call getMetadata() or getChunksLisk() before start
reading the rows, all the chunks before IDAT are automatically loaded and
available
4a. The rows are read onen by one of the readRowXXX methods:
readRowInt(int), PngReader#readRowByte(int), etc, in order,
from 0 to nrows-1 (you can skip or repeat rows, but not go backwards)
4b. Alternatively, you can read all rows, or a subset, in a single call:
readRowsInt(), readRowsByte() ,etc. In general this
consumes more memory, but for interlaced images this is equally efficient,
and more so if reading a small subset of rows.
5. Read of the last row auyomatically loads the trailing chunks, and ends the
reader.
6. end() forcibly finishes/aborts the reading and closes the stream
| Modifier and Type | Field and Description |
|---|---|
| protected final int | |
| private int | |
| private ChunkLoadBehaviour | |
| protected final ChunksList | |
| private boolean | |
| protected CRC32 | |
| protected int | |
| private final PngDeinterlacer | |
| protected final String | filename
not necesarily a filename, can be a description - merely informative |
| protected InflaterInputStream | |
| protected PngIDatChunkInputStream | |
| public final ImageInfo | imgInfo
Basic image info - final and inmutable. |
| protected ImageLine | |
| private Inflater | |
| protected final InputStream | |
| private final boolean | |
| private int | |
| private long | |
| protected final PngMetadata | |
| private long | |
| protected byte[] | |
| protected byte[] | |
| protected byte[] | |
| protected int | |
| private boolean | |
| private String[] | |
| private HashSet | |
| private int | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public | PngReader(final InputStream inputStream, final String
: Optional, can be a filename or a description. Just for
error/debug messages filenameOrDescription)Constructs a PngReader from an InputStream. |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| private void | |
| private void | |
| private void | |
| public void | |
| private boolean | |
| public ChunkLoadBehaviour | |
| public ChunksList | |
| pack-priv long | |
| pack-priv int | |
| public int | |
| public long | |
| public PngMetadata | |
| public ImageLine | getRow(final int nrow)
Deprecated
Now
readRow(int) implements the same funcion. This
method will be removed in future releases
|
| public String[] | |
| public int | |
| pack-priv void | |
| public boolean | |
| public boolean | |
| protected void | |
| private PngChunk | readChunk(final byte[] chunkid, final int clen, final boolean skipforced)
Reads chunkd from input stream, adds to ChunksList, and returns it. |
| private final void | |
| private void | |
| pack-priv void | |
| public ImageLine | |
| public final int[] | |
| public ImageLine | Returns: ImageLine object, also available as field. Data is inImageLine#scanlineb (byte) field.Row number, from 0 to rows-1. Increasing order. nrow)Reads the row as BYTES, storing it in the |
| public final byte[] | Returns: The scanline in the same passwd buffer if it was allocated, a newly allocated one otherwisePrealocated buffer, or null. buffer, final int Row number (0 is top). Most be strictly greater than the last
read row. nrow)Reads a line and returns it as a byte[] array. |
| public ImageLine | Returns: ImageLine object, also available as field. Data is inImageLine#scanline (int) field.Row number, from 0 to rows-1. Increasing order. nrow)Reads the row as INT, storing it in the |
| public final int[] | Returns: The scanline in the same passwd buffer if it was allocated, a newly allocated one otherwisePrealocated buffer, or null. buffer, final int Row number (0 is top). Most be strictly greater than the last
read row. nrow)Reads a line and returns it as a int[] array. |
| private int | |
| public ImageLines | Returns: Set of lines as a matrixNumber of rows to be skipped rowOffset, int Total number of rows to be read. -1: read all available nRows, final int Row increment. If 1, we read consecutive lines; if 2, we read
even/odd lines, etc rowStep)Reads a set of lines and returns it as a ImageLines object, which wrapas a byte[][] matrix. |
| public ImageLines | |
| public ImageLines | Returns: Set of lines as a ImageLines, which wraps a matrixNumber of rows to be skipped rowOffset, int Total number of rows to be read. -1: read all available nRows, final int Row increment. If 1, we read consecutive lines; if 2, we read
even/odd lines, etc rowStep)Reads a set of lines and returns it as a ImageLines object, which wraps matrix. |
| public ImageLines | |
| public void | |
| public void | reuseBuffersFrom(final PngReader
A PngReader that has already finished reading pixels. Can be null. other)Tries to reuse the allocated buffers from other already used PngReader object. |
| public void | setChunkLoadBehaviour(final ChunkLoadBehaviour chunkLoadBehaviour)
Determines which ancillary chunks (metada) are to be loaded |
| public void | setCrcCheckDisabled()
Disables the CRC integrity check in IDAT chunks and ancillary chunks, this gives a slight increase in reading speed for big files |
| public void | setMaxBytesMetadata(final int maxBytesChunksToLoad)
Set total maximum bytes to load from ancillary chunks (0: unlimited; default: 5Mb). |
| public void | setMaxTotalBytesRead(final long maxTotalBytesToRead)
Set total maximum bytes to read (0: unlimited; default: 200MB). |
| public void | setShouldCloseStream(final boolean shouldCloseStream)
if true, input stream will be closed after ending read default=true |
| public void | |
| public void | setSkipChunkMaxSize(final int skipChunksBySize)
Set maximum size in bytes for individual ancillary chunks (0: unlimited; default: 2MB). |
| public void | setUnpackedMode(final boolean unPackedMode)
set/unset "unpackedMode" If false (default) packed types (bitdepth=1,2 or 4) will keep several samples packed in one element (byte or int) If true, samples will be unpacked on reading, and each element in the scanline will be sample. |
| public String | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void |
| buffersLen | back to summary |
|---|---|
| protected final int buffersLen | |
| bytesChunksLoaded | back to summary |
|---|---|
| private int bytesChunksLoaded | |
| chunkLoadBehaviour | back to summary |
|---|---|
| private ChunkLoadBehaviour chunkLoadBehaviour | |
| chunksList | back to summary |
|---|---|
| protected final ChunksList chunksList | |
| crcEnabled | back to summary |
|---|---|
| private boolean crcEnabled | |
| crctest | back to summary |
|---|---|
| protected CRC32 crctest | |
| currentChunkGroup | back to summary |
|---|---|
| protected int currentChunkGroup Current chunk group, (0-6) already read or reading
see | |
| deinterlacer | back to summary |
|---|---|
| private final PngDeinterlacer deinterlacer | |
| filename | back to summary |
|---|---|
| protected final String filename not necesarily a filename, can be a description - merely informative | |
| idatIstream | back to summary |
|---|---|
| protected InflaterInputStream idatIstream | |
| iIdatCstream | back to summary |
|---|---|
| protected PngIDatChunkInputStream iIdatCstream | |
| imgInfo | back to summary |
|---|---|
| public final ImageInfo imgInfo Basic image info - final and inmutable. | |
| imgLine | back to summary |
|---|---|
| protected ImageLine imgLine | |
| inflater | back to summary |
|---|---|
| private Inflater inflater | |
| inputStream | back to summary |
|---|---|
| protected final InputStream inputStream | |
| interlaced | back to summary |
|---|---|
| private final boolean interlaced | |
| maxBytesMetadata | back to summary |
|---|---|
| private int maxBytesMetadata | |
| maxTotalBytesRead | back to summary |
|---|---|
| private long maxTotalBytesRead | |
| metadata | back to summary |
|---|---|
| protected final PngMetadata metadata | |
| offset | back to summary |
|---|---|
| private long offset | |
| rowb | back to summary |
|---|---|
| protected byte[] rowb | |
| rowbfilter | back to summary |
|---|---|
| protected byte[] rowbfilter | |
| rowbprev | back to summary |
|---|---|
| protected byte[] rowbprev | |
| rowNum | back to summary |
|---|---|
| protected int rowNum | |
| shouldCloseStream | back to summary |
|---|---|
| private boolean shouldCloseStream | |
| skipChunkIds | back to summary |
|---|---|
| private String[] skipChunkIds | |
| skipChunkIdsSet | back to summary |
|---|---|
| private HashSet<String> skipChunkIdsSet | |
| skipChunkMaxSize | back to summary |
|---|---|
| private int skipChunkMaxSize | |
| unpackedMode | back to summary |
|---|---|
| private boolean unpackedMode | |
| PngReader | back to summary |
|---|---|
| public PngReader(final InputStream inputStream, final String filenameOrDescription) Constructs a PngReader from an InputStream.
See also
| |
| allocateBuffers | back to summary |
|---|---|
| private void allocateBuffers() | |
| close | back to summary |
|---|---|
| private void close() | |
| decodeLastReadRowToByte | back to summary |
|---|---|
| private void decodeLastReadRowToByte(final byte[] buffer, final int bytesRead) | |
| decodeLastReadRowToInt | back to summary |
|---|---|
| private void decodeLastReadRowToInt(final int[] buffer, final int bytesRead) | |
| end | back to summary |
|---|---|
| public void end() Normally this does nothing, but it can be used to force a premature closing. Its recommended practice to call it after reading the image pixels. | |
| firstChunksNotYetRead | back to summary |
|---|---|
| private boolean firstChunksNotYetRead() | |
| getChunkLoadBehaviour | back to summary |
|---|---|
| public ChunkLoadBehaviour getChunkLoadBehaviour() | |
| getChunksList | back to summary |
|---|---|
| public ChunksList getChunksList() All loaded chunks (metada). If we have not yet end reading the image, this will include only the chunks before the pixels data (IDAT) 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
| |
| getCrctestVal | back to summary |
|---|---|
| pack-priv long getCrctestVal() Just for testing. TO be called after ending reading, only if initCrctest() was called before start
| |
| getCurrentChunkGroup | back to summary |
|---|---|
| pack-priv int getCurrentChunkGroup() | |
| getMaxBytesMetadata | back to summary |
|---|---|
public int getMaxBytesMetadata()
| |
| getMaxTotalBytesRead | back to summary |
|---|---|
public long getMaxTotalBytesRead()
| |
| getMetadata | back to summary |
|---|---|
| public PngMetadata getMetadata() High level wrapper over chunksList
| |
| getRow | back to summary |
|---|---|
| public ImageLine getRow(final int nrow)
Deprecated Now | |
| getSkipChunkIds | back to summary |
|---|---|
public String[] getSkipChunkIds()
| |
| getSkipChunkMaxSize | back to summary |
|---|---|
public int getSkipChunkMaxSize()
| |
| initCrctest | back to summary |
|---|---|
| pack-priv void initCrctest() Inits CRC object and enables CRC calculation | |
| isInterlaced | back to summary |
|---|---|
| public boolean isInterlaced() Interlaced PNG is accepted -though not welcomed- now... | |
| isUnpackedMode | back to summary |
|---|---|
public boolean isUnpackedMode()
| |
| logWarn | back to summary |
|---|---|
| protected void logWarn(final String warn) Logs/prints a warning. The default behaviour is print to stderr, but it can be overriden. This happens rarely - most errors are fatal. | |
| readChunk | back to summary |
|---|---|
| private PngChunk readChunk(final byte[] chunkid, final int clen, final boolean skipforced) Reads chunkd from input stream, adds to ChunksList, and returns it. If it's skipped, a PngChunkSkipped object is created | |
| readFirstChunks | back to summary |
|---|---|
| private final void readFirstChunks() Reads chunks before first IDAT. Normally this is called automatically Position before: after IDHR (crc included) Position after: just after the first IDAT chunk id This can be called several times (tentatively), it does nothing if already run (Note: when should this be called? in the constructor? hardly, because we loose the opportunity to call setChunkLoadBehaviour() and perhaps other settings before reading the first row? but sometimes we want to access some metadata (plte, phys) before. Because of this, this method can be called explicitly but is also called implicititly in some methods (getMetatada(), getChunksList()) | |
| readLastAndClose | back to summary |
|---|---|
| private void readLastAndClose() Reads last Internally called after having read the last line. It reads extra chunks after IDAT, if present. | |
| readLastChunks | back to summary |
|---|---|
| pack-priv void readLastChunks() Reads (and processes) chunks after last IDAT. | |
| readRow | back to summary |
|---|---|
| public ImageLine readRow(final int nrow) If called for first time, calls readRowInt. Elsewhere, it calls the appropiate readRowInt/readRowByte In general, specifying the concrete readRowInt/readRowByte is preferrable | |
| readRow | back to summary |
|---|---|
public final int[] readRow(final int[] buffer, final int nrow)
| |
| readRowByte | back to summary |
|---|---|
| public ImageLine readRowByte(final int nrow) Reads the row as BYTES, storing it in the
| |
| readRowByte | back to summary |
|---|---|
| public final byte[] readRowByte(byte[] buffer, final int nrow) Reads a line and returns it as a byte[] array. You can pass (optionally) a prealocatted buffer.
If the bitdepth is less than 8, the bytes are packed - unless
| |
| readRowInt | back to summary |
|---|---|
| public ImageLine readRowInt(final int nrow) Reads the row as INT, storing it in the
| |
| readRowInt | back to summary |
|---|---|
| public final int[] readRowInt(int[] buffer, final int nrow) Reads a line and returns it as a int[] array. You can pass (optionally) a prealocatted buffer.
If the bitdepth is less than 8, the bytes are packed - unless
| |
| readRowRaw | back to summary |
|---|---|
| private int readRowRaw(final int nrow) | |
| readRowsByte | back to summary |
|---|---|
| public ImageLines readRowsByte(final int rowOffset, int nRows, final int rowStep) Reads a set of lines and returns it as a ImageLines object, which wrapas a byte[][] matrix. Internally it reads all lines, but decodes and stores only the wanted ones. This starts and ends the reading, and cannot be combined with other reading methods. This it's more efficient (speed an memory) that doing calling readRowByte() for each desired line only if the image is interlaced. Notice that the columns in the matrix is not the pixel width of the image, but rather pixels x channels
| |
| readRowsByte | back to summary |
|---|---|
| public ImageLines readRowsByte() Same as readRowsByte(0, imgInfo.rows, 1)
| |
| readRowsInt | back to summary |
|---|---|
| public ImageLines readRowsInt(final int rowOffset, int nRows, final int rowStep) Reads a set of lines and returns it as a ImageLines object, which wraps matrix. Internally it reads all lines, but decodes and stores only the wanted ones. This starts and ends the reading, and cannot be combined with other reading methods. This it's more efficient (speed an memory) that doing calling readRowInt() for each desired line only if the image is interlaced. Notice that the columns in the matrix is not the pixel width of the image, but rather pixels x channels
| |
| readRowsInt | back to summary |
|---|---|
| public ImageLines readRowsInt() Same as readRowsInt(0, imgInfo.rows, 1)
| |
| readSkippingAllRows | back to summary |
|---|---|
| public void readSkippingAllRows() Reads all the (remaining) file, skipping the pixels data. This is much more efficient that calling readRow(), specially for big files (about 10 times faster!), because it doesn't even decompress the IDAT stream and disables CRC check Use this if you are not interested in reading pixels,only metadata. | |
| reuseBuffersFrom | back to summary |
|---|---|
| public void reuseBuffersFrom(final PngReader other) Tries to reuse the allocated buffers from other already used PngReader object. This will have no effect if the buffers are smaller than necessary. It also reuses the inflater.
| |
| setChunkLoadBehaviour | back to summary |
|---|---|
| public void setChunkLoadBehaviour(final ChunkLoadBehaviour chunkLoadBehaviour) Determines which ancillary chunks (metada) are to be loaded
| |
| setCrcCheckDisabled | back to summary |
|---|---|
| public void setCrcCheckDisabled() Disables the CRC integrity check in IDAT chunks and ancillary chunks, this gives a slight increase in reading speed for big files | |
| setMaxBytesMetadata | back to summary |
|---|---|
| public void setMaxBytesMetadata(final int maxBytesChunksToLoad) Set total maximum bytes to load from ancillary chunks (0: unlimited;
default: 5Mb). | |
| setMaxTotalBytesRead | back to summary |
|---|---|
| public void setMaxTotalBytesRead(final long maxTotalBytesToRead) Set total maximum bytes to read (0: unlimited; default: 200MB). | |
| setShouldCloseStream | back to summary |
|---|---|
| public void setShouldCloseStream(final boolean shouldCloseStream) if true, input stream will be closed after ending read default=true | |
| setSkipChunkIds | back to summary |
|---|---|
| public void setSkipChunkIds(final String[] skipChunksById) Chunks ids to be skipped. | |
| setSkipChunkMaxSize | back to summary |
|---|---|
| public void setSkipChunkMaxSize(final int skipChunksBySize) Set maximum size in bytes for individual ancillary chunks (0: unlimited;
default: 2MB). | |
| setUnpackedMode | back to summary |
|---|---|
| public void setUnpackedMode(final boolean unPackedMode) set/unset "unpackedMode" | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Basic info, for debugging.
| |
| unfilterRow | back to summary |
|---|---|
| private void unfilterRow(final int nbytes) | |
| unfilterRowAverage | back to summary |
|---|---|
| private void unfilterRowAverage(final int nbytes) | |
| unfilterRowNone | back to summary |
|---|---|
| private void unfilterRowNone(final int nbytes) | |
| unfilterRowPaeth | back to summary |
|---|---|
| private void unfilterRowPaeth(final int nbytes) | |
| unfilterRowSub | back to summary |
|---|---|
| private void unfilterRowSub(final int nbytes) | |
| unfilterRowUp | back to summary |
|---|---|
| private void unfilterRowUp(final int nbytes) | |