PngCs  1.1.4
A C# library for read/write PNG images
Public Member Functions | Public Attributes | Protected Attributes | Properties | List of all members
Hjg.Pngcs.PngReader Class Reference

Reads a PNG image, line by line More...

Public Member Functions

 PngReader (Stream inputStream)
 Constructs a PngReader from a Stream, with no filename information
 
 PngReader (Stream inputStream, String filename)
 Constructs a PNGReader objet from a opened Stream
 
ChunksList GetChunksList ()
 Returns the ancillary chunks available
 
PngMetadata GetMetadata ()
 Returns the ancillary chunks available
 
ImageLine ReadRow (int nrow)
 reads the row using ImageLine as buffer
 
ImageLine ReadRowInt (int nrow)
 
ImageLine ReadRowByte (int nrow)
 
int[] ReadRow (int[] buffer, int nrow)
 
int[] ReadRowInt (int[] buffer, int nrow)
 
byte[] ReadRowByte (byte[] buffer, int nrow)
 
ImageLine GetRow (int nrow)
 
 
ImageLines ReadRowsInt (int rowOffset, int nRows, int rowStep)
 
ImageLines ReadRowsInt ()
 
ImageLines ReadRowsByte (int rowOffset, int nRows, int rowStep)
 
ImageLines ReadRowsByte ()
 
void ReadSkippingAllRows ()
 
override String ToString ()
 
void End ()
 Normally this does nothing, but it can be used to force a premature closing
 
bool IsInterlaced ()
 
void SetUnpackedMode (bool unPackedMode)
 
bool IsUnpackedMode ()
 
void SetCrcCheckDisabled ()
 

Public Attributes

readonly bool interlaced
 

Protected Attributes

readonly String filename
 filename, or description - merely informative, can be empty
 
ImageLine imgLine
 buffer: last read line
 
byte[] rowb
 raw current row, as array of bytes,counting from 1 (index 0 is reserved for filter type)
 
byte[] rowbprev
 previuos raw row
 
byte[] rowbfilter
 raw current row, after unfiltered
 
int rowNum = -1
 last read row number
 
Adler32 crctest
 

Properties

ImageInfo ImgInfo [get, set]
 Basic image info, inmutable
 
ChunkLoadBehaviour ChunkLoadBehaviour [get, set]
 Strategy for chunk loading. Default: LOAD_CHUNK_ALWAYS
 
bool ShouldCloseStream [get, set]
 Should close the underlying Input Stream when ends?
 
long MaxBytesMetadata [get, set]
 Maximum amount of bytes from ancillary chunks to load in memory
 
long MaxTotalBytesRead [get, set]
 Maximum total bytes to read from stream
 
int SkipChunkMaxSize [get, set]
 Maximum ancillary chunk size
 
String[] SkipChunkIds [get, set]
 Ancillary chunks to skip
 
int CurrentChunkGroup [get, set]
 number of chunk group (0-6) last read, or currently reading
 

Detailed Description

Reads a PNG image, line by line

The typical reading sequence is as follows:

1. At construction time, the header and IHDR chunk are read (basic image info)

2 (Optional) you can set some global options: UnpackedMode CrcCheckDisabled

3. (Optional) If you call GetMetadata() or or GetChunksLisk() before reading the pixels, the chunks before IDAT are automatically loaded and available

4a. The rows are read, one by one, with the ReadRowXXX methods: (ReadRowInt() , ReadRowByte(), 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: see ReadRowsInt(), ReadRowsByte() 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 automatically loads the trailing chunks, and ends the reader.

6. End() forcibly finishes/aborts the reading and closes the stream

Constructor & Destructor Documentation

Hjg.Pngcs.PngReader.PngReader ( Stream  inputStream)

Constructs a PngReader from a Stream, with no filename information

Parameters
inputStream
Hjg.Pngcs.PngReader.PngReader ( Stream  inputStream,
String  filename 
)

Constructs a PNGReader objet from a opened Stream

The constructor reads the signature and first chunk (IDHR)

See Also
FileHelper.CreatePngReader(string)
Parameters
inputStream
filenameOptional, can be the filename or a description.

Member Function Documentation

ChunksList Hjg.Pngcs.PngReader.GetChunksList ( )

Returns the ancillary chunks available

If the rows have not yet still been read, this includes only the chunks placed before the pixels (IDAT)

Returns
ChunksList
PngMetadata Hjg.Pngcs.PngReader.GetMetadata ( )

Returns the ancillary chunks available

see GetChunksList

Returns
PngMetadata
ImageLine Hjg.Pngcs.PngReader.ReadRow ( int  nrow)

reads the row using ImageLine as buffer

param name="nrow">row number - just as a check

Returns
the ImageLine that also is available inside this object
ImageLine Hjg.Pngcs.PngReader.ReadRowInt ( int  nrow)
ImageLine Hjg.Pngcs.PngReader.ReadRowByte ( int  nrow)
int [] Hjg.Pngcs.PngReader.ReadRow ( int[]  buffer,
int  nrow 
)
int [] Hjg.Pngcs.PngReader.ReadRowInt ( int[]  buffer,
int  nrow 
)
byte [] Hjg.Pngcs.PngReader.ReadRowByte ( byte[]  buffer,
int  nrow 
)
ImageLine Hjg.Pngcs.PngReader.GetRow ( int  nrow)

Parameters
nrow
Returns
ImageLines Hjg.Pngcs.PngReader.ReadRowsInt ( int  rowOffset,
int  nRows,
int  rowStep 
)
ImageLines Hjg.Pngcs.PngReader.ReadRowsInt ( )
ImageLines Hjg.Pngcs.PngReader.ReadRowsByte ( int  rowOffset,
int  nRows,
int  rowStep 
)
ImageLines Hjg.Pngcs.PngReader.ReadRowsByte ( )
void Hjg.Pngcs.PngReader.ReadSkippingAllRows ( )
override String Hjg.Pngcs.PngReader.ToString ( )
void Hjg.Pngcs.PngReader.End ( )

Normally this does nothing, but it can be used to force a premature closing

bool Hjg.Pngcs.PngReader.IsInterlaced ( )
void Hjg.Pngcs.PngReader.SetUnpackedMode ( bool  unPackedMode)
bool Hjg.Pngcs.PngReader.IsUnpackedMode ( )
See Also
PngReader::setUnpackedMode(boolean)
void Hjg.Pngcs.PngReader.SetCrcCheckDisabled ( )

Member Data Documentation

readonly String Hjg.Pngcs.PngReader.filename
protected

filename, or description - merely informative, can be empty

ImageLine Hjg.Pngcs.PngReader.imgLine
protected

buffer: last read line

byte [] Hjg.Pngcs.PngReader.rowb
protected

raw current row, as array of bytes,counting from 1 (index 0 is reserved for filter type)

byte [] Hjg.Pngcs.PngReader.rowbprev
protected

previuos raw row

byte [] Hjg.Pngcs.PngReader.rowbfilter
protected

raw current row, after unfiltered

readonly bool Hjg.Pngcs.PngReader.interlaced
int Hjg.Pngcs.PngReader.rowNum = -1
protected

last read row number

Adler32 Hjg.Pngcs.PngReader.crctest
protected

Property Documentation

ImageInfo Hjg.Pngcs.PngReader.ImgInfo
getset

Basic image info, inmutable

ChunkLoadBehaviour Hjg.Pngcs.PngReader.ChunkLoadBehaviour
getset

Strategy for chunk loading. Default: LOAD_CHUNK_ALWAYS

bool Hjg.Pngcs.PngReader.ShouldCloseStream
getset

Should close the underlying Input Stream when ends?

long Hjg.Pngcs.PngReader.MaxBytesMetadata
getset

Maximum amount of bytes from ancillary chunks to load in memory

Default: 5MB. 0: unlimited. If exceeded, chunks will be skipped

long Hjg.Pngcs.PngReader.MaxTotalBytesRead
getset

Maximum total bytes to read from stream

Default: 200MB. 0: Unlimited. If exceeded, an exception will be thrown

int Hjg.Pngcs.PngReader.SkipChunkMaxSize
getset

Maximum ancillary chunk size

Default: 2MB, 0: unlimited. Chunks exceeding this size will be skipped (nor even CRC checked)

String [] Hjg.Pngcs.PngReader.SkipChunkIds
getset

Ancillary chunks to skip

Default: { "fdAT" }. chunks with these ids will be skipped (nor even CRC checked)

int Hjg.Pngcs.PngReader.CurrentChunkGroup
getset

number of chunk group (0-6) last read, or currently reading

see ChunksList.CHUNK_GROUP_NNN