removed redundant ArcView.Reader instances.

This commit is contained in:
morkt 2016-10-17 16:57:13 +04:00
parent 375e162959
commit 84985d18f5
5 changed files with 47 additions and 55 deletions

View File

@ -82,18 +82,18 @@ namespace GameRes.Formats.Ffa
if (!entry.Name.EndsWith (".so4", StringComparison.InvariantCultureIgnoreCase) &&
!entry.Name.EndsWith (".so5", StringComparison.InvariantCultureIgnoreCase))
return input;
using (var header = new ArcView.Reader (input))
int packed = input.ReadInt32();
int unpacked = input.ReadInt32();
if (packed+8 != entry.Size || packed <= 0 || unpacked <= 0)
{
int packed = header.ReadInt32();
int unpacked = header.ReadInt32();
if (packed+8 != entry.Size || packed <= 0 || unpacked <= 0)
return input;
using (input)
using (var reader = new LzssReader (input, packed, unpacked))
{
reader.Unpack();
return new BinMemoryStream (reader.Data, entry.Name);
}
input.Position = 0;
return input;
}
using (input)
using (var reader = new LzssReader (input, packed, unpacked))
{
reader.Unpack();
return new BinMemoryStream (reader.Data, entry.Name);
}
}
}

View File

@ -77,13 +77,13 @@ namespace GameRes.Formats.Glib2
stream.Position = 0x20;
if (0 != (meta.Flags & 0x1000))
{
ReadGms (stream.AsStream);
ReadGms (stream);
}
PixelFormat format = 32 == meta.BPP ? PixelFormats.Bgra32 : PixelFormats.Bgr32;
int stride = (int)meta.Width * 4;
var pixels = new byte[stride * (int)meta.Height];
// stream.Seek (-meta.PackedSize, SeekOrigin.End);
LzssUnpack (stream.AsStream, pixels);
LzssUnpack (stream, pixels);
var layer = InfoCache.GetInfo (info.FileName);
if (null != layer && null != layer.Rect)
{
@ -93,7 +93,7 @@ namespace GameRes.Formats.Glib2
return ImageData.Create (info, format, null, pixels);
}
void ReadGms (Stream input)
void ReadGms (IBinaryStream input)
{
var header = new byte[0x10];
if (0x10 != input.Read (header, 0, 0x10))
@ -123,42 +123,39 @@ namespace GameRes.Formats.Glib2
throw new System.NotImplementedException ("PgxFormat.Write not implemented");
}
static void LzssUnpack (Stream input, byte[] output)
static void LzssUnpack (IBinaryStream input, byte[] output)
{
var frame = new byte[0x1000];
int frame_pos = 0xFEE;
using (var lz = new ArcView.Reader (input))
int dst = 0;
int bits = 1;
while (dst < output.Length)
{
int dst = 0;
int bits = 1;
while (dst < output.Length)
{
if (1 == bits)
bits = lz.ReadByte() | 0x100;
if (1 == bits)
bits = input.ReadUInt8() | 0x100;
if (0 != (bits & 1))
if (0 != (bits & 1))
{
byte b = input.ReadUInt8();
output[dst++] = b;
frame[frame_pos++] = b;
frame_pos &= 0xFFF;
}
else
{
byte lo = input.ReadUInt8();
byte hi = input.ReadUInt8();
int offset = (hi & 0xF0) << 4 | lo;
int count = Math.Min ((~hi & 0xF) + 3, output.Length-dst);
for (int i = 0; i < count; ++i)
{
byte b = lz.ReadByte();
byte b = frame[offset++ & 0xFFF];
output[dst++] = b;
frame[frame_pos++] = b;
frame_pos &= 0xFFF;
}
else
{
byte lo = lz.ReadByte();
byte hi = lz.ReadByte();
int offset = (hi & 0xF0) << 4 | lo;
int count = Math.Min ((~hi & 0xF) + 3, output.Length-dst);
for (int i = 0; i < count; ++i)
{
byte b = frame[offset++ & 0xFFF];
output[dst++] = b;
frame[frame_pos++] = b;
frame_pos &= 0xFFF;
}
}
bits >>= 1;
}
bits >>= 1;
}
}
}

View File

@ -97,18 +97,15 @@ namespace GameRes.Formats.Kaguya
public byte[] Data { get { return m_output; } }
public BmrDecoder (Stream input)
public BmrDecoder (IBinaryStream input)
{
input.Position = 3;
using (var header = new ArcView.Reader (input))
{
m_step = header.ReadByte();
m_final_size = header.ReadInt32();
m_key = header.ReadInt32();
int unpacked_size = header.ReadInt32();
m_output = new byte[unpacked_size];
m_input = new MsbBitStream (input, true);
}
m_step = input.ReadUInt8();
m_final_size = input.ReadInt32();
m_key = input.ReadInt32();
int unpacked_size = input.ReadInt32();
m_output = new byte[unpacked_size];
m_input = new MsbBitStream (input.AsStream, true);
}
public void Unpack ()

View File

@ -54,7 +54,6 @@ namespace GameRes.Formats.Kiss
var dir = new List<Entry> (count);
using (var input = file.CreateStream())
using (var reader = new ArcView.Reader (input))
{
long prev_offset = 4;
input.Position = 4;
@ -64,7 +63,7 @@ namespace GameRes.Formats.Kiss
if (string.IsNullOrWhiteSpace (name))
return null;
var entry = FormatCatalog.Instance.Create<Entry> (name);
entry.Offset = reader.ReadInt64();
entry.Offset = input.ReadInt64();
if (entry.Offset < prev_offset || entry.Offset > file.MaxOffset)
return null;
dir.Add (entry);

View File

@ -108,14 +108,13 @@ namespace GameRes.Formats.SuperNekoX
void DetectFileTypes (ArcView file, List<Entry> dir)
{
using (var input = file.CreateStream())
using (var reader = new ArcView.Reader (input))
{
var buffer = new byte[0x10];
foreach (PackedEntry entry in dir)
{
input.Position = entry.Offset;
uint packed_size = reader.ReadUInt32();
entry.UnpackedSize = reader.ReadUInt32();
uint packed_size = input.ReadUInt32();
entry.UnpackedSize = input.ReadUInt32();
entry.Offset += 8;
if (0 == packed_size)
{
@ -135,7 +134,7 @@ namespace GameRes.Formats.SuperNekoX
signature = LittleEndian.ToUInt32 (buffer, 0);
}
else
signature = reader.ReadUInt32();
signature = input.ReadUInt32();
IResource res;
if (0x020000 == signature || 0x0A0000 == signature)
res = ImageFormat.Tga;