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

@@ -92,7 +92,7 @@ namespace GameRes.Formats.Ffa
using (var reader = new LzssReader (input, packed, unpacked))
{
reader.Unpack();
return new MemoryStream (reader.Data);
return new BinMemoryStream (reader.Data, entry.Name);
}
}
}

View File

@@ -39,18 +39,9 @@ namespace GameRes.Formats.Ffa
public override string Description { get { return "FFA System wave audio format"; } }
public override uint Signature { get { return 0; } }
private static int ReadInt32 (Stream file)
public override SoundInput TryOpen (IBinaryStream file)
{
int dword = file.ReadByte();
dword |= file.ReadByte() << 8;
dword |= file.ReadByte() << 16;
dword |= file.ReadByte() << 24;
return dword;
}
public override SoundInput TryOpen (Stream file)
{
int packed = ReadInt32 (file);
int packed = file.ReadInt32();
if (packed < 0)
return null;
byte[] input;
@@ -58,10 +49,10 @@ namespace GameRes.Formats.Ffa
{
if ((packed + 8) != file.Length)
return null;
int unpacked = ReadInt32 (file);
int unpacked = file.ReadInt32();
if (unpacked <= 0)
return null;
using (var reader = new LzssReader (file, packed, unpacked))
using (var reader = new LzssReader (file.AsStream, packed, unpacked))
{
reader.Unpack();
if (Binary.AsciiEqual (reader.Data, 0, "RIFF"))
@@ -75,7 +66,7 @@ namespace GameRes.Formats.Ffa
}
else
{
if (0x46464952 != ReadInt32 (file)) // 'RIFF'
if (0x46464952 != file.ReadInt32()) // 'RIFF'
return null;
file.Position = 0;
input = new byte[file.Length];

View File

@@ -36,7 +36,7 @@ namespace GameRes.Formats.Ffa
public override string Description { get { return "FFA System PCM audio format"; } }
public override uint Signature { get { return 0x4D435041; } } // 'APCM'
public override SoundInput TryOpen (Stream file)
public override SoundInput TryOpen (IBinaryStream file)
{
return new Wa2Input (file);
}
@@ -51,27 +51,25 @@ namespace GameRes.Formats.Ffa
get { return (int)Format.AverageBytesPerSecond * 8; }
}
public Wa2Input (Stream file) : base (null)
public Wa2Input (IBinaryStream file) : base (null)
{
var header = new byte[0x2C];
if (header.Length != file.Read (header, 0, header.Length))
throw new EndOfStreamException();
if (!Binary.AsciiEqual (header, 8, "WAVEfmt "))
var header = file.ReadHeader (0x2C);
if (!header.AsciiEqual (8, "WAVEfmt "))
throw new InvalidFormatException();
var format = new WaveFormat();
format.FormatTag = LittleEndian.ToUInt16 (header, 0x14);
format.Channels = LittleEndian.ToUInt16 (header, 0x16);
format.SamplesPerSecond = LittleEndian.ToUInt32 (header, 0x18);
format.AverageBytesPerSecond = LittleEndian.ToUInt32 (header, 0x1C);
format.BlockAlign = LittleEndian.ToUInt16 (header, 0x20);
format.BitsPerSample = LittleEndian.ToUInt16 (header, 0x22);
format.FormatTag = header.ToUInt16 (0x14);
format.Channels = header.ToUInt16 (0x16);
format.SamplesPerSecond = header.ToUInt32 (0x18);
format.AverageBytesPerSecond = header.ToUInt32 (0x1C);
format.BlockAlign = header.ToUInt16 (0x20);
format.BitsPerSample = header.ToUInt16 (0x22);
format.ExtraSize = 0;
this.Format = format;
uint pcm_size = LittleEndian.ToUInt32 (header, 0x28);
uint pcm_size = header.ToUInt32 (0x28);
var pcm = new byte[pcm_size];
Decode (file, pcm);
Decode (file.AsStream, pcm);
Source = new MemoryStream (pcm);
this.PcmSize = pcm_size;
file.Dispose();

View File

@@ -59,40 +59,37 @@ namespace GameRes.Formats.Ffa
throw new NotImplementedException ("Pt1Format.Write not implemented");
}
public override ImageMetaData ReadMetaData (Stream stream)
public override ImageMetaData ReadMetaData (IBinaryStream file)
{
using (var input = new ArcView.Reader (stream))
{
int type = input.ReadInt32();
if (type < 0 || type > 3)
return null;
if (-1 != input.ReadInt32())
return null;
int x = input.ReadInt32();
int y = input.ReadInt32();
uint width = input.ReadUInt32();
uint height = input.ReadUInt32();
uint comp_size = input.ReadUInt32();
uint uncomp_size = input.ReadUInt32();
if (uncomp_size != width*height*3u)
return null;
return new Pt1MetaData {
Width = width,
Height = height,
OffsetX = x,
OffsetY = y,
BPP = 3 == type ? 32 : 24,
Type = type,
PackedSize = comp_size,
UnpackedSize = uncomp_size
};
}
int type = file.ReadInt32();
if (type < 0 || type > 3)
return null;
if (-1 != file.ReadInt32())
return null;
int x = file.ReadInt32();
int y = file.ReadInt32();
uint width = file.ReadUInt32();
uint height = file.ReadUInt32();
uint comp_size = file.ReadUInt32();
uint uncomp_size = file.ReadUInt32();
if (uncomp_size != width*height*3u)
return null;
return new Pt1MetaData {
Width = width,
Height = height,
OffsetX = x,
OffsetY = y,
BPP = 3 == type ? 32 : 24,
Type = type,
PackedSize = comp_size,
UnpackedSize = uncomp_size
};
}
public override ImageData Read (Stream stream, ImageMetaData info)
public override ImageData Read (IBinaryStream stream, ImageMetaData info)
{
var meta = (Pt1MetaData)info;
var reader = new Reader (stream, meta);
var reader = new Reader (stream.AsStream, meta);
reader.Unpack();
return ImageData.Create (meta, reader.Format, null, reader.Data);
}