C# Class Hjg.Pngcs.PngReader

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
ファイルを表示 Open project: devedse/DeveMazeGenerator Class Usage Examples

Public Properties

Property Type Description
interlaced bool

Protected Properties

Property Type Description
crctest Hjg.Pngcs.Zlib.Adler32
filename String
imgLine Hjg.Pngcs.ImageLine
rowNum int
rowb byte[]
rowbfilter byte[]
rowbprev byte[]

Public Methods

Method Description
End ( ) : void

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

GetChunksList ( ) : Hjg.Pngcs.Chunks.ChunksList

Returns the ancillary chunks available

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

GetMetadata ( ) : Hjg.Pngcs.Chunks.PngMetadata

Returns the ancillary chunks available

see GetChunksList

IsInterlaced ( ) : bool
IsUnpackedMode ( ) : bool
PngReader ( Stream inputStream ) : System

Constructs a PngReader from a Stream, with no filename information

PngReader ( Stream inputStream, String filename ) : System

Constructs a PNGReader objet from a opened Stream

The constructor reads the signature and first chunk (IDHR)FileHelper.CreatePngReader(string)

ReadRow ( int nrow ) : Hjg.Pngcs.ImageLine

reads the row using ImageLine as buffer

ReadRow ( int buffer, int nrow ) : int[]
ReadRowByte ( int nrow ) : Hjg.Pngcs.ImageLine
ReadRowByte ( byte buffer, int nrow ) : byte[]
ReadRowInt ( int nrow ) : Hjg.Pngcs.ImageLine
ReadRowInt ( int buffer, int nrow ) : int[]
ReadRowsByte ( ) : Hjg.Pngcs.ImageLines
ReadRowsByte ( int rowOffset, int nRows, int rowStep ) : Hjg.Pngcs.ImageLines
ReadRowsInt ( ) : Hjg.Pngcs.ImageLines
ReadRowsInt ( int rowOffset, int nRows, int rowStep ) : Hjg.Pngcs.ImageLines
ReadSkippingAllRows ( ) : void
SetCrcCheckDisabled ( ) : void
SetUnpackedMode ( bool unPackedMode ) : void
ToString ( ) : String

Private Methods

Method Description
Close ( ) : void
FirstChunksNotYetRead ( ) : bool
GetCrctestVal ( ) : long
GetRow ( int nrow ) : Hjg.Pngcs.ImageLine
InitCrctest ( ) : void
ReadChunk ( byte chunkid, int clen, bool skipforced ) : PngChunk

Reads chunkd from input stream, adds to ChunksList, and returns it. If it's skipped, a PngChunkSkipped object is created

ReadFirstChunks ( ) : void

Reads chunks before first IDAT. Position before: after IDHR (crc included) Position after: just after the first IDAT chunk id Returns length of first IDAT chunk , -1 if not found

ReadLastAndClose ( ) : void

Internally called after having read the last line. It reads extra chunks after IDAT, if present.

ReadLastChunks ( ) : void

Reads (and processes ... up to a point) chunks after last IDAT.

ReadRowRaw ( int nrow ) : int
UnfilterRow ( int nbytes ) : void
UnfilterRowAverage ( int nbytes ) : void
UnfilterRowNone ( int nbytes ) : void
UnfilterRowPaeth ( int nbytes ) : void
UnfilterRowSub ( int nbytes ) : void
UnfilterRowUp ( int nbytes ) : void
decodeLastReadRowToByte ( byte buffer, int bytesRead ) : void
decodeLastReadRowToInt ( int buffer, int bytesRead ) : void
logWarn ( String warn ) : void

Logs/prints a warning.

The default behaviour is print to stderr, but it can be overriden. This happens rarely - most errors are fatal.

Method Details

End() public method

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

GetChunksList() public method

Returns the ancillary chunks available
If the rows have not yet still been read, this includes only the chunks placed before the pixels (IDAT)
public GetChunksList ( ) : Hjg.Pngcs.Chunks.ChunksList
return Hjg.Pngcs.Chunks.ChunksList

GetMetadata() public method

Returns the ancillary chunks available
see GetChunksList
public GetMetadata ( ) : Hjg.Pngcs.Chunks.PngMetadata
return Hjg.Pngcs.Chunks.PngMetadata

IsInterlaced() public method

public IsInterlaced ( ) : bool
return bool

IsUnpackedMode() public method

public IsUnpackedMode ( ) : bool
return bool

PngReader() public method

Constructs a PngReader from a Stream, with no filename information
public PngReader ( Stream inputStream ) : System
inputStream Stream
return System

PngReader() public method

Constructs a PNGReader objet from a opened Stream
The constructor reads the signature and first chunk (IDHR)FileHelper.CreatePngReader(string)
public PngReader ( Stream inputStream, String filename ) : System
inputStream Stream
filename String Optional, can be the filename or a description.
return System

ReadRow() public method

reads the row using ImageLine as buffer
public ReadRow ( int nrow ) : Hjg.Pngcs.ImageLine
nrow int row number - just as a check
return Hjg.Pngcs.ImageLine

ReadRow() public method

public ReadRow ( int buffer, int nrow ) : int[]
buffer int
nrow int
return int[]

ReadRowByte() public method

public ReadRowByte ( int nrow ) : Hjg.Pngcs.ImageLine
nrow int
return Hjg.Pngcs.ImageLine

ReadRowByte() public method

public ReadRowByte ( byte buffer, int nrow ) : byte[]
buffer byte
nrow int
return byte[]

ReadRowInt() public method

public ReadRowInt ( int nrow ) : Hjg.Pngcs.ImageLine
nrow int
return Hjg.Pngcs.ImageLine

ReadRowInt() public method

public ReadRowInt ( int buffer, int nrow ) : int[]
buffer int
nrow int
return int[]

ReadRowsByte() public method

public ReadRowsByte ( ) : Hjg.Pngcs.ImageLines
return Hjg.Pngcs.ImageLines

ReadRowsByte() public method

public ReadRowsByte ( int rowOffset, int nRows, int rowStep ) : Hjg.Pngcs.ImageLines
rowOffset int
nRows int
rowStep int
return Hjg.Pngcs.ImageLines

ReadRowsInt() public method

public ReadRowsInt ( ) : Hjg.Pngcs.ImageLines
return Hjg.Pngcs.ImageLines

ReadRowsInt() public method

public ReadRowsInt ( int rowOffset, int nRows, int rowStep ) : Hjg.Pngcs.ImageLines
rowOffset int
nRows int
rowStep int
return Hjg.Pngcs.ImageLines

ReadSkippingAllRows() public method

public ReadSkippingAllRows ( ) : void
return void

SetCrcCheckDisabled() public method

public SetCrcCheckDisabled ( ) : void
return void

SetUnpackedMode() public method

public SetUnpackedMode ( bool unPackedMode ) : void
unPackedMode bool
return void

ToString() public method

public ToString ( ) : String
return String

Property Details

crctest protected_oe property

protected Adler32,Hjg.Pngcs.Zlib crctest
return Hjg.Pngcs.Zlib.Adler32

filename protected_oe property

filename, or description - merely informative, can be empty
protected String filename
return String

imgLine protected_oe property

buffer: last read line
protected ImageLine,Hjg.Pngcs imgLine
return Hjg.Pngcs.ImageLine

interlaced public_oe property

public bool interlaced
return bool

rowNum protected_oe property

last read row number
protected int rowNum
return int

rowb protected_oe property

raw current row, as array of bytes,counting from 1 (index 0 is reserved for filter type)
protected byte[] rowb
return byte[]

rowbfilter protected_oe property

raw current row, after unfiltered
protected byte[] rowbfilter
return byte[]

rowbprev protected_oe property

previuos raw row
protected byte[] rowbprev
return byte[]