IBinaryStream migration.

This commit is contained in:
morkt
2016-10-16 09:22:53 +04:00
parent d0c1d5da01
commit bb18303eb4
251 changed files with 3277 additions and 3630 deletions

View File

@@ -117,7 +117,7 @@ namespace GameRes.Formats.Circus
{
data = UnpackCps (data);
}
return new MemoryStream (data);
return new BinMemoryStream (data, entry.Name);
}
byte[] UnpackCps (byte[] input)

View File

@@ -38,46 +38,43 @@ namespace GameRes.Formats.Circus
public override string Description { get { return "Circus PCM audio"; } }
public override uint Signature { get { return 0x4d435058; } } // 'XPCM'
public override SoundInput TryOpen (Stream file)
public override SoundInput TryOpen (IBinaryStream file)
{
file.Position = 4;
using (var input = new ArcView.Reader (file))
int src_size = file.ReadInt32();
if (src_size <= 0)
throw new InvalidFormatException();
int mode = file.ReadInt32();
int extra = (mode >> 8) & 0xff;
mode &= 0xff;
if (5 == mode)
{
int src_size = input.ReadInt32();
if (src_size <= 0)
throw new InvalidFormatException();
int mode = input.ReadInt32();
int extra = (mode >> 8) & 0xff;
mode &= 0xff;
if (5 == mode)
{
uint ogg_size = input.ReadUInt32();
var ogg = new StreamRegion (file, 0x10, ogg_size);
return new OggInput (ogg);
}
var format = new WaveFormat();
format.FormatTag = input.ReadUInt16();
format.Channels = input.ReadUInt16();
format.SamplesPerSecond = input.ReadUInt32();
format.AverageBytesPerSecond = input.ReadUInt32();
format.BlockAlign = input.ReadUInt16();
format.BitsPerSample = input.ReadUInt16();
Stream pcm;
if (0 == mode)
{
pcm = new StreamRegion (file, file.Position, src_size);
}
else if (1 == mode || 3 == mode)
{
var decoder = new PcmDecoder (input, src_size, extra, (XpcmCompression)mode);
pcm = new MemoryStream (decoder.Unpack(), 0, src_size);
file.Dispose();
}
else
throw new NotSupportedException ("Not supported Circus PCM audio compression");
return new RawPcmInput (pcm, format);
uint ogg_size = file.ReadUInt32();
var ogg = new StreamRegion (file.AsStream, 0x10, ogg_size);
return new OggInput (ogg);
}
var format = new WaveFormat();
format.FormatTag = file.ReadUInt16();
format.Channels = file.ReadUInt16();
format.SamplesPerSecond = file.ReadUInt32();
format.AverageBytesPerSecond = file.ReadUInt32();
format.BlockAlign = file.ReadUInt16();
format.BitsPerSample = file.ReadUInt16();
Stream pcm;
if (0 == mode)
{
pcm = new StreamRegion (file.AsStream, file.Position, src_size);
}
else if (1 == mode || 3 == mode)
{
var decoder = new PcmDecoder (file, src_size, extra, (XpcmCompression)mode);
pcm = new MemoryStream (decoder.Unpack(), 0, src_size);
file.Dispose();
}
else
throw new NotSupportedException ("Not supported Circus PCM audio compression");
return new RawPcmInput (pcm, format);
}
}
@@ -97,7 +94,7 @@ namespace GameRes.Formats.Circus
public byte[] Data { get { return m_pcm_data; } }
public PcmDecoder (BinaryReader input, int pcm_size, int extra, XpcmCompression mode)
public PcmDecoder (IBinaryStream input, int pcm_size, int extra, XpcmCompression mode)
{
if (extra < 0 || extra > 3)
throw new InvalidFormatException();
@@ -114,7 +111,7 @@ namespace GameRes.Formats.Circus
}
else if (XpcmCompression.Zlib == mode)
{
using (var z = new ZLibStream (input.BaseStream, CompressionMode.Decompress, true))
using (var z = new ZLibStream (input.AsStream, CompressionMode.Decompress, true))
z.Read (m_encoded, 0, m_encoded.Length);
}
else

View File

@@ -266,23 +266,23 @@ namespace GameRes.Formats.Circus
{
flag >>= 1;
if (0 == (flag & 0x100))
flag = m_input.ReadByte() | 0xff00;
flag = m_input.ReadUInt8() | 0xff00;
if (0 != (flag & 1))
{
byte dat = m_input.ReadByte();
byte dat = m_input.ReadUInt8();
window[win_pos++] = dat;
win_pos &= 0xffff;
m_output[dst++] = dat;
}
else
{
byte control = m_input.ReadByte();
byte control = m_input.ReadUInt8();
int count, offset;
if (control >= 0xc0)
{
offset = ((control & 3) << 8) | m_input.ReadByte();
offset = ((control & 3) << 8) | m_input.ReadUInt8();
count = 4 + ((control >> 2) & 0xf);
}
else if (0 != (control & 0x80))
@@ -290,7 +290,7 @@ namespace GameRes.Formats.Circus
offset = control & 0x1f;
count = 2 + ((control >> 5) & 3);
if (0 == offset)
offset = m_input.ReadByte();
offset = m_input.ReadUInt8();
}
else if (0x7f == control)
{

View File

@@ -70,7 +70,7 @@ namespace GameRes.Formats.Circus
else if (header.AsciiEqual (0x20, "CRXG"))
{
using (var crx_input = new StreamRegion (stream.AsStream, 0x20, true))
using (var crx = new BinaryStream (crx_input))
using (var crx = new BinaryStream (crx_input, stream.Name))
{
var diff_info = base.ReadMetaData (crx) as CrxMetaData;
if (null == diff_info)
@@ -90,12 +90,12 @@ namespace GameRes.Formats.Circus
if (info != null)
{
info.BaseOffset = header.ToUInt32 (8);
info.BaseFileName = Binary.GetCString (header, 0xC, 0x14);
info.BaseFileName = header.GetCString (0xC, 0x14);
}
return info;
}
Stream OpenByOffset (uint offset)
IBinaryStream OpenByOffset (uint offset)
{
var vfs = VFS.Top as ArchiveFileSystem;
if (null == vfs)
@@ -118,9 +118,9 @@ namespace GameRes.Formats.Circus
diff = OpenByOffset (info.DiffOffset);
if (null == diff)
throw new FileNotFoundException ("Referenced diff image not found");
input = new StreamRegion (diff, 0x20);
input = new StreamRegion (diff.AsStream, 0x20);
}
return new BinaryStream (input);
return new BinaryStream (input, diff.Name);
}
public override ImageData Read (IBinaryStream stream, ImageMetaData info)