C# Class Hjg.Pngcs.Chunks.ChunkHelper

Static utility methods for CHunks
Client code should rarely need this, see PngMetada and ChunksList
Mostrar archivo Open project: devedse/DeveMazeGenerator Class Usage Examples

Public Methods

Method Description
Equivalent ( PngChunk c1, PngChunk c2 ) : bool

Ad-hoc criteria for 'equivalent' chunks.

Two chunks are equivalent if they have the same Id AND either: 1. they are Single 2. both are textual and have the same key 3. both are SPLT and have the same palette name Bear in mind that this is an ad-hoc, non-standard, nor required (nor wrong) criterion. Use it only if you find it useful. Notice that PNG allows to have repeated textual keys with same keys.

FilterList ( List list, ChunkPredicate predicateKeep ) : List

Filters a list of Chunks, keeping those which match the predicate

The original list is not altered

IsCritical ( String id ) : bool

Critical chunks: first letter is uppercase

IsPublic ( String id ) : bool

Public chunks: second letter is uppercase

IsSafeToCopy ( String id ) : bool

Safe to copy chunk: fourth letter is lower case

IsText ( PngChunk c ) : bool
IsUnknown ( PngChunk chunk ) : bool

We consider a chunk as "unknown" if our chunk factory (even when it has been augmented by client code) doesn't recognize it

PosNullByte ( byte bytes ) : int

Finds position of null byte in array

ShouldLoad ( String id, ChunkLoadBehaviour behav ) : bool

Decides if a chunk should be loaded, according to a ChunkLoadBehaviour

ToBytes ( String x ) : byte[]

Converts to bytes using Latin1 (ISO-8859-1)

ToBytesUTF8 ( String x ) : byte[]

Converts to bytes using UTF-8

ToString ( byte x ) : String

Converts to String using Latin1 (ISO-8859-1)

ToString ( byte x, int offset, int len ) : String

Converts to String using Latin1 (ISO-8859-1)

ToStringUTF8 ( byte x ) : String

Converts to string using UTF-8

ToStringUTF8 ( byte x, int offset, int len ) : String

Converts to string using UTF-8

TrimList ( List list, ChunkPredicate predicateRemove ) : int

Filters a list of Chunks, removing those which match the predicate

The original list is not altered

WriteBytesToStream ( Stream stream, byte bytes ) : void

Writes full array of bytes to stream

Private Methods

Method Description
compressBytes ( byte ori, bool compress ) : byte[]
compressBytes ( byte ori, int offset, int len, bool compress ) : byte[]
maskMatch ( int v, int mask ) : bool
shovelInToOut ( Stream inx, Stream outx ) : void

Method Details

Equivalent() public static method

Ad-hoc criteria for 'equivalent' chunks.
Two chunks are equivalent if they have the same Id AND either: 1. they are Single 2. both are textual and have the same key 3. both are SPLT and have the same palette name Bear in mind that this is an ad-hoc, non-standard, nor required (nor wrong) criterion. Use it only if you find it useful. Notice that PNG allows to have repeated textual keys with same keys.
public static Equivalent ( PngChunk c1, PngChunk c2 ) : bool
c1 PngChunk Chunk1
c2 PngChunk Chunk1
return bool

FilterList() public static method

Filters a list of Chunks, keeping those which match the predicate
The original list is not altered
public static FilterList ( List list, ChunkPredicate predicateKeep ) : List
list List
predicateKeep ChunkPredicate
return List

IsCritical() public static method

Critical chunks: first letter is uppercase
public static IsCritical ( String id ) : bool
id String
return bool

IsPublic() public static method

Public chunks: second letter is uppercase
public static IsPublic ( String id ) : bool
id String
return bool

IsSafeToCopy() public static method

Safe to copy chunk: fourth letter is lower case
public static IsSafeToCopy ( String id ) : bool
id String
return bool

IsText() public static method

public static IsText ( PngChunk c ) : bool
c PngChunk
return bool

IsUnknown() public static method

We consider a chunk as "unknown" if our chunk factory (even when it has been augmented by client code) doesn't recognize it
public static IsUnknown ( PngChunk chunk ) : bool
chunk PngChunk
return bool

PosNullByte() public static method

Finds position of null byte in array
public static PosNullByte ( byte bytes ) : int
bytes byte
return int

ShouldLoad() public static method

Decides if a chunk should be loaded, according to a ChunkLoadBehaviour
public static ShouldLoad ( String id, ChunkLoadBehaviour behav ) : bool
id String
behav ChunkLoadBehaviour
return bool

ToBytes() public static method

Converts to bytes using Latin1 (ISO-8859-1)
public static ToBytes ( String x ) : byte[]
x String
return byte[]

ToBytesUTF8() public static method

Converts to bytes using UTF-8
public static ToBytesUTF8 ( String x ) : byte[]
x String
return byte[]

ToString() public static method

Converts to String using Latin1 (ISO-8859-1)
public static ToString ( byte x ) : String
x byte
return String

ToString() public static method

Converts to String using Latin1 (ISO-8859-1)
public static ToString ( byte x, int offset, int len ) : String
x byte
offset int
len int
return String

ToStringUTF8() public static method

Converts to string using UTF-8
public static ToStringUTF8 ( byte x ) : String
x byte
return String

ToStringUTF8() public static method

Converts to string using UTF-8
public static ToStringUTF8 ( byte x, int offset, int len ) : String
x byte
offset int
len int
return String

TrimList() public static method

Filters a list of Chunks, removing those which match the predicate
The original list is not altered
public static TrimList ( List list, ChunkPredicate predicateRemove ) : int
list List
predicateRemove ChunkPredicate
return int

WriteBytesToStream() public static method

Writes full array of bytes to stream
public static WriteBytesToStream ( Stream stream, byte bytes ) : void
stream Stream
bytes byte
return void