Remove BinaryReader from R8Reader.
This commit is contained in:
@@ -34,22 +34,22 @@ namespace OpenRA.Utility
|
|||||||
public int OffsetX;
|
public int OffsetX;
|
||||||
public int OffsetY;
|
public int OffsetY;
|
||||||
|
|
||||||
public R8Image(BinaryReader reader, int Frame)
|
public R8Image(Stream s, int Frame)
|
||||||
{
|
{
|
||||||
var offset = reader.BaseStream.Position;
|
var offset = s.Position;
|
||||||
var ID = reader.ReadByte(); // 0 = no data, 1 = picture with palette, 2 = picture with current palette
|
var ID = s.ReadUInt8(); // 0 = no data, 1 = picture with palette, 2 = picture with current palette
|
||||||
while (ID == 0)
|
while (ID == 0)
|
||||||
ID = reader.ReadByte();
|
ID = s.ReadUInt8();
|
||||||
Width = reader.ReadInt32(); //Width of picture
|
Width = s.ReadInt32(); //Width of picture
|
||||||
Height = reader.ReadInt32(); //Height of picture
|
Height = s.ReadInt32(); //Height of picture
|
||||||
OffsetX = reader.ReadInt32(); //Offset on X axis from left border edge of virtual frame
|
OffsetX = s.ReadInt32(); //Offset on X axis from left border edge of virtual frame
|
||||||
OffsetY = reader.ReadInt32(); //Offset on Y axis from top border edge of virtual frame
|
OffsetY = s.ReadInt32(); //Offset on Y axis from top border edge of virtual frame
|
||||||
ImageHandle = reader.ReadInt32(); // 0 = no picture
|
ImageHandle = s.ReadInt32(); // 0 = no picture
|
||||||
PaletteHandle = reader.ReadInt32(); // 0 = no palette
|
PaletteHandle = s.ReadInt32(); // 0 = no palette
|
||||||
var Bpp = reader.ReadByte(); // Bits per Pixel
|
var Bpp = s.ReadUInt8(); // Bits per Pixel
|
||||||
FrameHeight = reader.ReadByte(); // Height of virtual frame
|
FrameHeight = s.ReadUInt8(); // Height of virtual frame
|
||||||
FrameWidth = reader.ReadByte(); // Width of virtual frame
|
FrameWidth = s.ReadUInt8(); // Width of virtual frame
|
||||||
var Align = reader.ReadByte(); //Alignment on even border
|
var Align = s.ReadUInt8(); //Alignment on even border
|
||||||
|
|
||||||
Console.WriteLine("Offset: {0}",offset);
|
Console.WriteLine("Offset: {0}",offset);
|
||||||
Console.WriteLine("ID: {0}",ID);
|
Console.WriteLine("ID: {0}",ID);
|
||||||
@@ -74,23 +74,23 @@ namespace OpenRA.Utility
|
|||||||
if (ID == 1 && PaletteHandle != 0)
|
if (ID == 1 && PaletteHandle != 0)
|
||||||
{
|
{
|
||||||
// read and ignore custom palette
|
// read and ignore custom palette
|
||||||
reader.ReadInt32(); //Memory
|
s.ReadInt32(); //Memory
|
||||||
reader.ReadInt32(); //Handle
|
s.ReadInt32(); //Handle
|
||||||
|
|
||||||
for (int i = 0; i < Width*Height; i++)
|
for (int i = 0; i < Width*Height; i++)
|
||||||
Image[i] = reader.ReadByte();
|
Image[i] = s.ReadUInt8();
|
||||||
for (int i = 0; i < 256; i++)
|
for (int i = 0; i < 256; i++)
|
||||||
reader.ReadUInt16();
|
s.ReadUInt16();
|
||||||
}
|
}
|
||||||
else if (ID == 2 && PaletteHandle != 0) // image with custom palette
|
else if (ID == 2 && PaletteHandle != 0) // image with custom palette
|
||||||
{
|
{
|
||||||
for (int i = 0; i < Width*Height; i++)
|
for (int i = 0; i < Width*Height; i++)
|
||||||
Image[i] = reader.ReadByte();
|
Image[i] = s.ReadUInt8();
|
||||||
}
|
}
|
||||||
else //standard palette or 16 Bpp
|
else //standard palette or 16 Bpp
|
||||||
{
|
{
|
||||||
for (int i = 0; i < Width*Height; i++)
|
for (int i = 0; i < Width*Height; i++)
|
||||||
Image[i] = reader.ReadByte();
|
Image[i] = s.ReadUInt8();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -102,15 +102,13 @@ namespace OpenRA.Utility
|
|||||||
public readonly int Frames;
|
public readonly int Frames;
|
||||||
public R8Reader(Stream stream)
|
public R8Reader(Stream stream)
|
||||||
{
|
{
|
||||||
BinaryReader reader = new BinaryReader( stream );
|
|
||||||
|
|
||||||
Frames = 0;
|
Frames = 0;
|
||||||
while (reader.BaseStream.Position < stream.Length)
|
while (stream.Position < stream.Length)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Console.WriteLine("Frame {0}: {1}",Frames, reader.BaseStream.Position);
|
Console.WriteLine("Frame {0}: {1}",Frames, stream.Position);
|
||||||
headers.Add( new R8Image( reader, Frames ) );
|
headers.Add(new R8Image(stream, Frames));
|
||||||
Frames++;
|
Frames++;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|||||||
Reference in New Issue
Block a user