C# Class FlatRedBall.IO.PngLoader

Notes: Interlaced pngs are now fully supported Only the chunks of data that are outlined in the Png specification as Critical Chunks are supported. TODO: Allow use of the CRC values to check the validity of the Chunk data Consider implementing the Ancillary Chunks since chunks like gAMA can drastically change visible colors.
显示文件 Open project: vchelaru/FlatRedBall

Public Properties

Property Type Description
ByteBufferSize int
ColorBufferSize int

Public Methods

Method Description
GetPixelData ( string fileName ) : ImageData

Loads a .png image from the fileName given and returns an array of pixel colors.

Initialize ( ) : void

Private Methods

Method Description
BuildPixels ( byte image, HeaderInfo &header, PaletteInfo &palette ) : Color[]

Does the remaining work to convert the byte[] containing the image into a Color[] containing colors for each pixel. This operation is different for most individual combinations of ColorType and bitDepth and currently only ColorType 2 is supported.

CheckSignature ( Stream &file ) : bool

Checks the first 8 bytes of the file in the given Stream against the standard signature for .png images.

ConvertToType ( uint type ) : ChunkTypes

Converts a 4-byte uint into an enumerated ChunkType

ExtractBits ( byte sourceByte, int pointer, byte bitDepth ) : byte
FormUint ( Stream &bytes ) : uint

Arranges and combines the byte values stored in byte[] bytes in order to form a uint.

GetBytesPerPixel ( HeaderInfo header ) : float

Uses the ColorType and Bitdepth of this image to calculate the number of bytes per pixel.

GetChunkData ( Stream &file, uint length ) : byte[]

Reads the bytes of a chunk's ChunkData segment from the Stream and returns it in a byte[].

GetNextChunk ( Stream &file, List &chunks ) : bool

Reads the length, type, data and CRC of the next chunk in the file, and then forms a Chunk struct using this data.

LoadFile ( string fileName ) : int

Loads a file (hopefully a .png image) into a byte[].

OldMethod ( byte image, HeaderInfo &header, PaletteInfo &palette ) : Color[]
PaethPredictor ( int left, int up, int upLeft ) : byte

A helper for the ReverseFilterPaeth method

ProcessChunks ( List chunks, HeaderInfo header, PaletteInfo &palette ) : byte[]

Takes a List of all of the Chunks in the .png image being loaded (after IHDR is loaded and removed) and processes each Chunk appropriately before returning the compressed image. NOTE: Currently only processes the required Chunks PLTE, IDAT and IEND. Ancillary chunks are currently unsupported.

ReadFile ( Stream stream ) : int

Reads the data in the given Stream and stores it in a byte[] that is then trimmed and returned.

ReadHeader ( List &chunks ) : HeaderInfo

Processes the IHDR chunk by reading and storing all of its information in a HeaderInfo struct.

ReadImageData ( Chunk idat, byte &imageData, int &numberOfBytesRead ) : void

Reads data from the given IDAT chunk and appends it to the List imageData.

ReadPalette ( Chunk plte, PaletteInfo &palette ) : void

Processes the PLTE chunk by reading in all of the indexed color values and storing them in a PaletteInfo struct.

ReadStream ( InflaterInputStream &stream ) : void

Reads the decompressed(inflated) image data from an InflaterInputStream that was fed the compressed image.

ReverseFilterAverage ( byte &image, uint pointer, uint bps, float bpp, byte bitDepth ) : void

Reverses the filtering done on a scanline of pixels that have been filtered using Method 2 (Average)

ReverseFilterPaeth ( byte &image, uint pointer, uint bps, float bpp, byte bitDepth ) : void

Reverses the filtering done on a scanline of pixels that have been filtered using Method 3 (Paeth)

ReverseFilterSub ( byte &image, uint pointer, uint bps, float bpp, byte bitDepth ) : void

Reverses the filtering done on a scanline of pixels that have been filtered using Method 0 (Subtract)

ReverseFilterUp ( byte &image, uint pointer, uint bps, float bpp, byte bitDepth ) : void

Reverses the filtering done on a scanline of pixels that have been filtered using Method 1 (Up)

ReverseFiltering ( byte image, HeaderInfo header ) : byte[]

Calls the appropriate Reverse Filtering methods to return the image to its original state.

Method Details

GetPixelData() public static method

Loads a .png image from the fileName given and returns an array of pixel colors.
public static GetPixelData ( string fileName ) : ImageData
fileName string The name of the .png image to be loaded.
return FlatRedBall.Graphics.Texture.ImageData

Initialize() public static method

public static Initialize ( ) : void
return void

Property Details

ByteBufferSize public_oe static_oe property

public static int ByteBufferSize
return int

ColorBufferSize public_oe static_oe property

public static int ColorBufferSize
return int