C# Class Hjg.Pngcs.PngWriter

Writes a PNG image, line by line.
Show file Open project: devedse/DeveMazeGenerator Class Usage Examples

Public Properties

Property Type Description
ImgInfo Hjg.Pngcs.ImageInfo

Protected Properties

Property Type Description
filename String
rowb byte[]
rowbfilter byte[]
rowbprev byte[]

Public Methods

Method Description
ComputeCompressionRatio ( ) : double

Computes compressed size/raw size, approximate

Actually: compressed size = total size of IDAT data , raw size = uncompressed pixel bytes = rows * (bytesPerRow + 1)

CopyChunksFirst ( PngReader reader, int copy_mask ) : void
CopyChunksLast ( PngReader reader, int copy_mask ) : void
End ( ) : void

Finalizes the image creation and closes the file stream.

This MUST be called after writing the lines.

GetChunksList ( ) : ChunksListForWrite
GetFilename ( ) : String

Filename or description, from the optional constructor argument.

GetMetadata ( ) : PngMetadata
IsUnpackedMode ( ) : bool
PngWriter ( Stream outputStream, Hjg.Pngcs.ImageInfo imgInfo ) : System

Constructs a PngWriter from a outputStream, with no filename information

PngWriter ( Stream outputStream, Hjg.Pngcs.ImageInfo imgInfo, String filename ) : System

Constructs a PngWriter from a outputStream, with optional filename or description

After construction nothing is writen yet. You still can set some parameters (compression, filters) and queue chunks before start writing the pixels. See also FileHelper.createPngWriter()

SetFilterType ( FilterType filterType ) : void

Sets internal prediction filter type, or strategy to choose it.

This must be called just after constructor, before starting writing. Recommended values: DEFAULT (default) or AGGRESIVE

SetUseUnPackedMode ( bool useUnpackedMode ) : void
WriteRow ( Hjg.Pngcs.ImageLine imgline, int rownumber ) : void

this uses the row number from the imageline!

WriteRow ( int newrow ) : void
WriteRow ( int newrow, int rown ) : void
WriteRowByte ( byte newrow, int rown ) : void
WriteRowInt ( int newrow, int rown ) : void

Writes a full image row.

This must be called sequentially from n=0 to n=rows-1 One integer per sample , in the natural order: R G B R G B ... (or R G B A R G B A... if has alpha) The values should be between 0 and 255 for 8 bitspc images, and between 0- 65535 form 16 bitspc images (this applies also to the alpha channel if present) The array can be reused.

WriteRowsByte ( byte image ) : void
WriteRowsInt ( int image ) : void

Protected Methods

Method Description
encodeRowFromByte ( byte row ) : void
encodeRowFromInt ( int row ) : void

Private Methods

Method Description
CopyChunks ( PngReader reader, int copy_mask, bool onlyAfterIdat ) : void

copy chunks from reader - copy_mask : see ChunksToWrite.COPY_XXX If we are after idat, only considers those chunks after IDAT in PngReader TODO: this should be more customizable

FilterRow ( int rown ) : void
FilterRowAverage ( ) : void
FilterRowNone ( ) : void
FilterRowPaeth ( ) : void
FilterRowSub ( ) : void
FilterRowUp ( ) : void
SumRowbfilter ( ) : long
WriteEndChunk ( ) : void
WriteFirstChunks ( ) : void
WriteLastChunks ( ) : void
WriteSignatureAndIHDR ( ) : void

Write id signature and also "IHDR" chunk

filterAndSend ( int rown ) : void
init ( ) : void

init: is called automatically before writing the first row

prepareEncodeRow ( int rown ) : void
reportResultsForFilter ( int rown, FilterType type, bool tentative ) : void

Method Details

ComputeCompressionRatio() public method

Computes compressed size/raw size, approximate
Actually: compressed size = total size of IDAT data , raw size = uncompressed pixel bytes = rows * (bytesPerRow + 1)
public ComputeCompressionRatio ( ) : double
return double

CopyChunksFirst() public method

public CopyChunksFirst ( PngReader reader, int copy_mask ) : void
reader PngReader
copy_mask int
return void

CopyChunksLast() public method

public CopyChunksLast ( PngReader reader, int copy_mask ) : void
reader PngReader
copy_mask int
return void

End() public method

Finalizes the image creation and closes the file stream.
This MUST be called after writing the lines.
public End ( ) : void
return void

GetChunksList() public method

public GetChunksList ( ) : ChunksListForWrite
return ChunksListForWrite

GetFilename() public method

Filename or description, from the optional constructor argument.
public GetFilename ( ) : String
return String

GetMetadata() public method

public GetMetadata ( ) : PngMetadata
return PngMetadata

IsUnpackedMode() public method

public IsUnpackedMode ( ) : bool
return bool

PngWriter() public method

Constructs a PngWriter from a outputStream, with no filename information
public PngWriter ( Stream outputStream, Hjg.Pngcs.ImageInfo imgInfo ) : System
outputStream Stream
imgInfo Hjg.Pngcs.ImageInfo
return System

PngWriter() public method

Constructs a PngWriter from a outputStream, with optional filename or description
After construction nothing is writen yet. You still can set some parameters (compression, filters) and queue chunks before start writing the pixels. See also FileHelper.createPngWriter()
public PngWriter ( Stream outputStream, Hjg.Pngcs.ImageInfo imgInfo, String filename ) : System
outputStream Stream Opened stream for binary writing
imgInfo Hjg.Pngcs.ImageInfo Basic image parameters
filename String Optional, can be the filename or a description.
return System

SetFilterType() public method

Sets internal prediction filter type, or strategy to choose it.
This must be called just after constructor, before starting writing. Recommended values: DEFAULT (default) or AGGRESIVE
public SetFilterType ( FilterType filterType ) : void
filterType FilterType One of the five prediction types or strategy to choose it
return void

SetUseUnPackedMode() public method

public SetUseUnPackedMode ( bool useUnpackedMode ) : void
useUnpackedMode bool
return void

WriteRow() public method

this uses the row number from the imageline!
public WriteRow ( Hjg.Pngcs.ImageLine imgline, int rownumber ) : void
imgline Hjg.Pngcs.ImageLine
rownumber int
return void

WriteRow() public method

public WriteRow ( int newrow ) : void
newrow int
return void

WriteRow() public method

public WriteRow ( int newrow, int rown ) : void
newrow int
rown int
return void

WriteRowByte() public method

public WriteRowByte ( byte newrow, int rown ) : void
newrow byte
rown int
return void

WriteRowInt() public method

Writes a full image row.
This must be called sequentially from n=0 to n=rows-1 One integer per sample , in the natural order: R G B R G B ... (or R G B A R G B A... if has alpha) The values should be between 0 and 255 for 8 bitspc images, and between 0- 65535 form 16 bitspc images (this applies also to the alpha channel if present) The array can be reused.
public WriteRowInt ( int newrow, int rown ) : void
newrow int Array of pixel values
rown int Number of row, from 0 (top) to rows-1 (bottom)
return void

WriteRowsByte() public method

public WriteRowsByte ( byte image ) : void
image byte
return void

WriteRowsInt() public method

public WriteRowsInt ( int image ) : void
image int
return void

encodeRowFromByte() protected method

protected encodeRowFromByte ( byte row ) : void
row byte
return void

encodeRowFromInt() protected method

protected encodeRowFromInt ( int row ) : void
row int
return void

Property Details

ImgInfo public property

Basic image info, inmutable
public ImageInfo,Hjg.Pngcs ImgInfo
return Hjg.Pngcs.ImageInfo

filename protected property

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

rowb protected 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 property

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

rowbprev protected property

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