mirror of
https://github.com/crskycode/GARbro.git
synced 2026-07-08 01:30:18 +08:00
IBinaryStream migration.
This commit is contained in:
@@ -55,33 +55,29 @@ namespace GameRes.Formats.ISM
|
||||
throw new NotImplementedException ("IsgFormat.Write not implemented");
|
||||
}
|
||||
|
||||
public override ImageMetaData ReadMetaData (Stream stream)
|
||||
public override ImageMetaData ReadMetaData (IBinaryStream stream)
|
||||
{
|
||||
var header = new byte[0x24];
|
||||
if (header.Length != stream.Read (header, 0, header.Length))
|
||||
return null;
|
||||
if (!Binary.AsciiEqual (header, "ISM IMAGEFILE\x00"))
|
||||
var header = stream.ReadHeader (0x24);
|
||||
if (!header.AsciiEqual ("ISM IMAGEFILE\x00"))
|
||||
return null;
|
||||
int colors = header[0x23];
|
||||
if (0 == colors)
|
||||
colors = 256;
|
||||
return new IsgMetaData
|
||||
{
|
||||
Width = LittleEndian.ToUInt16 (header, 0x1d),
|
||||
Height = LittleEndian.ToUInt16 (header, 0x1f),
|
||||
Width = header.ToUInt16 (0x1d),
|
||||
Height = header.ToUInt16 (0x1f),
|
||||
BPP = 8,
|
||||
Type = header[0x10],
|
||||
Colors = colors,
|
||||
Packed = LittleEndian.ToUInt32 (header, 0x11),
|
||||
Unpacked = LittleEndian.ToUInt32 (header, 0x15),
|
||||
Packed = header.ToUInt32 (0x11),
|
||||
Unpacked = header.ToUInt32 (0x15),
|
||||
};
|
||||
}
|
||||
|
||||
public override ImageData Read (Stream stream, ImageMetaData info)
|
||||
public override ImageData Read (IBinaryStream stream, ImageMetaData info)
|
||||
{
|
||||
var meta = info as IsgMetaData;
|
||||
if (null == meta)
|
||||
throw new ArgumentException ("IsgFormat.Read should be supplied with IsgMetaData", "info");
|
||||
var meta = (IsgMetaData)info;
|
||||
if (0x21 != meta.Type && 0x10 != meta.Type)
|
||||
throw new InvalidFormatException ("Unsupported ISM image type");
|
||||
|
||||
@@ -99,7 +95,7 @@ namespace GameRes.Formats.ISM
|
||||
|
||||
internal class Reader : IDisposable
|
||||
{
|
||||
BinaryReader m_input;
|
||||
IBinaryStream m_input;
|
||||
byte[] m_data;
|
||||
Color[] m_palette;
|
||||
int m_input_size;
|
||||
@@ -107,7 +103,7 @@ namespace GameRes.Formats.ISM
|
||||
public Color[] Palette { get { return m_palette; } }
|
||||
public byte[] Data { get { return m_data; } }
|
||||
|
||||
public Reader (Stream file, IsgMetaData info)
|
||||
public Reader (IBinaryStream file, IsgMetaData info)
|
||||
{
|
||||
int palette_size = (int)info.Colors*4;
|
||||
var palette_data = new byte[Math.Max (0x400, palette_size)];
|
||||
@@ -118,7 +114,7 @@ namespace GameRes.Formats.ISM
|
||||
{
|
||||
m_palette[i] = Color.FromRgb (palette_data[i*4+2], palette_data[i*4+1], palette_data[i*4]);
|
||||
}
|
||||
m_input = new BinaryReader (file, Encoding.ASCII, true);
|
||||
m_input = file;
|
||||
m_input_size = (int)info.Packed;
|
||||
m_data = new byte[info.Width * info.Height];
|
||||
}
|
||||
@@ -129,15 +125,15 @@ namespace GameRes.Formats.ISM
|
||||
var frame = new byte[2048];
|
||||
int frame_pos = 2039;
|
||||
int remaining = m_input_size;
|
||||
byte ctl = m_input.ReadByte();
|
||||
byte ctl = m_input.ReadUInt8();
|
||||
--remaining;
|
||||
int bit = 0x80;
|
||||
while (remaining > 0)
|
||||
{
|
||||
if (0 != (ctl & bit))
|
||||
{
|
||||
byte hi = m_input.ReadByte();
|
||||
byte lo = m_input.ReadByte();
|
||||
byte hi = m_input.ReadUInt8();
|
||||
byte lo = m_input.ReadUInt8();
|
||||
remaining -= 2;
|
||||
int offset = (hi & 7) << 8 | lo;
|
||||
for (int count = (hi >> 3) + 3; count > 0; --count)
|
||||
@@ -151,7 +147,7 @@ namespace GameRes.Formats.ISM
|
||||
}
|
||||
else
|
||||
{
|
||||
byte p = m_input.ReadByte();
|
||||
byte p = m_input.ReadUInt8();
|
||||
--remaining;
|
||||
m_data[dst++] = p;
|
||||
frame[frame_pos] = p;
|
||||
@@ -159,7 +155,7 @@ namespace GameRes.Formats.ISM
|
||||
}
|
||||
if (0 == (bit >>= 1))
|
||||
{
|
||||
ctl = m_input.ReadByte();
|
||||
ctl = m_input.ReadUInt8();
|
||||
--remaining;
|
||||
bit = 0x80;
|
||||
}
|
||||
@@ -170,16 +166,16 @@ namespace GameRes.Formats.ISM
|
||||
{
|
||||
int dst = 0;
|
||||
int remaining = m_input_size;
|
||||
byte ctl = m_input.ReadByte();
|
||||
byte ctl = m_input.ReadUInt8();
|
||||
--remaining;
|
||||
int bit = 1;
|
||||
while (remaining > 0)
|
||||
{
|
||||
byte p = m_input.ReadByte();
|
||||
byte p = m_input.ReadUInt8();
|
||||
--remaining;
|
||||
if (0 != (ctl & bit))
|
||||
{
|
||||
for (int count = 2 + m_input.ReadByte(); count > 0; --count)
|
||||
for (int count = 2 + m_input.ReadUInt8(); count > 0; --count)
|
||||
m_data[dst++] = p;
|
||||
--remaining;
|
||||
}
|
||||
@@ -189,7 +185,7 @@ namespace GameRes.Formats.ISM
|
||||
}
|
||||
if (0x100 == (bit <<= 1))
|
||||
{
|
||||
ctl = m_input.ReadByte();
|
||||
ctl = m_input.ReadUInt8();
|
||||
--remaining;
|
||||
bit = 1;
|
||||
}
|
||||
@@ -199,11 +195,6 @@ namespace GameRes.Formats.ISM
|
||||
#region IDisposable Members
|
||||
public void Dispose ()
|
||||
{
|
||||
if (null != m_input)
|
||||
{
|
||||
m_input.Dispose();
|
||||
m_input = null;
|
||||
}
|
||||
GC.SuppressFinalize (this);
|
||||
}
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user