public PaletteFile(string filename)
{
EndianBinaryReader reader = new EndianBinaryReader(EndianBitConverter.Big, File.Open(filename, FileMode.Open));
while (true)
{
int blockLength = 0;
PaletteBlockType blockType = (PaletteBlockType)reader.ReadInt32();
blockLength = reader.ReadInt32();
switch (blockType)
{
case PaletteBlockType.Attributes:
//contains name of palette and some attributes
//we dont care about this
reader.Seek(blockLength, SeekOrigin.Current);
break;
case PaletteBlockType.PixelData:
int entryCount = reader.ReadInt32();
int bytesPerEntry = reader.ReadInt32();
_paletteData = reader.ReadBytes(entryCount * bytesPerEntry);
break;
case PaletteBlockType.Null:
break;
default:
reader.Seek(blockLength, SeekOrigin.Current);
break;
}
if (reader.BaseStream.Position == reader.BaseStream.Length)
break;
}
reader.Close();
}