mirror of
https://github.com/lifegpc/GARbro.git
synced 2026-07-08 01:31:41 +08:00
IBinaryStream migration.
This commit is contained in:
@@ -78,7 +78,7 @@ namespace GameRes.Formats.Silky
|
||||
{
|
||||
lzss.FrameFill = 0x20;
|
||||
lzss.Unpack();
|
||||
return new MemoryStream (lzss.Data);
|
||||
return new BinMemoryStream (lzss.Data, entry.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,30 +46,27 @@ namespace GameRes.Formats.Silky
|
||||
public override string Description { get { return "AI6WIN engine image format"; } }
|
||||
public override uint Signature { get { return 0x20424B41; } } // 'AKB '
|
||||
|
||||
public override ImageMetaData ReadMetaData (Stream stream)
|
||||
public override ImageMetaData ReadMetaData (IBinaryStream file)
|
||||
{
|
||||
using (var reader = new ArcView.Reader (stream))
|
||||
{
|
||||
reader.ReadInt32();
|
||||
var info = new AkbMetaData();
|
||||
info.Width = reader.ReadUInt16();
|
||||
info.Height = reader.ReadUInt16();
|
||||
int flags = reader.ReadInt32() & 0xFFFF;
|
||||
info.BPP = 0 == flags ? 32 : 24;
|
||||
info.Background = reader.ReadBytes (4);
|
||||
info.OffsetX = reader.ReadInt32();
|
||||
info.OffsetY = reader.ReadInt32();
|
||||
info.InnerWidth = reader.ReadInt32() - info.OffsetX;
|
||||
info.InnerHeight = reader.ReadInt32() - info.OffsetY;
|
||||
if (info.InnerWidth > info.Width || info.InnerHeight > info.Height)
|
||||
return null;
|
||||
return info;
|
||||
}
|
||||
file.ReadInt32();
|
||||
var info = new AkbMetaData();
|
||||
info.Width = file.ReadUInt16();
|
||||
info.Height = file.ReadUInt16();
|
||||
int flags = file.ReadInt32() & 0xFFFF;
|
||||
info.BPP = 0 == flags ? 32 : 24;
|
||||
info.Background = file.ReadBytes (4);
|
||||
info.OffsetX = file.ReadInt32();
|
||||
info.OffsetY = file.ReadInt32();
|
||||
info.InnerWidth = file.ReadInt32() - info.OffsetX;
|
||||
info.InnerHeight = file.ReadInt32() - info.OffsetY;
|
||||
if (info.InnerWidth > info.Width || info.InnerHeight > info.Height)
|
||||
return null;
|
||||
return info;
|
||||
}
|
||||
|
||||
public override ImageData Read (Stream stream, ImageMetaData info)
|
||||
public override ImageData Read (IBinaryStream file, ImageMetaData info)
|
||||
{
|
||||
var reader = new AkbReader (stream, (AkbMetaData)info);
|
||||
var reader = new AkbReader (file.AsStream, (AkbMetaData)info);
|
||||
var image = reader.Unpack();
|
||||
return ImageData.Create (info, reader.Format, null, image, reader.Stride);
|
||||
}
|
||||
|
||||
@@ -52,12 +52,12 @@ namespace GameRes.Formats.Silky
|
||||
throw new NotImplementedException ("GrdFormat.Write not implemented");
|
||||
}
|
||||
|
||||
public override ImageMetaData ReadMetaData (Stream stream)
|
||||
public override ImageMetaData ReadMetaData (IBinaryStream stream)
|
||||
{
|
||||
stream.Seek (4, SeekOrigin.Current);
|
||||
int data_size = stream.ReadByte() | stream.ReadByte() << 8 | stream.ReadByte() << 16 | stream.ReadByte() << 24;
|
||||
int data_size = stream.ReadInt32();
|
||||
stream.Seek (4, SeekOrigin.Current);
|
||||
using (var reader = new Reader (stream, 0x22)) // BMP header
|
||||
using (var reader = new Reader (stream.AsStream, 0x22)) // BMP header
|
||||
{
|
||||
reader.Unpack();
|
||||
var bmp = reader.Data;
|
||||
@@ -76,18 +76,15 @@ namespace GameRes.Formats.Silky
|
||||
}
|
||||
}
|
||||
|
||||
public override ImageData Read (Stream stream, ImageMetaData info)
|
||||
public override ImageData Read (IBinaryStream stream, ImageMetaData info)
|
||||
{
|
||||
var meta = info as GrdMetaData;
|
||||
if (null == meta)
|
||||
throw new ArgumentException ("GrdFormat.Read should be supplied with GrdMetaData", "info");
|
||||
|
||||
var meta = (GrdMetaData)info;
|
||||
stream.Position = 12;
|
||||
using (var reader = new Reader (stream, meta.DataSize))
|
||||
using (var reader = new Reader (stream.AsStream, meta.DataSize))
|
||||
{
|
||||
reader.Unpack();
|
||||
byte[] pixels = reader.Data;
|
||||
using (var bmp = new MemoryStream (reader.Data, false))
|
||||
using (var bmp = new MemoryStream (reader.Data))
|
||||
{
|
||||
var decoder = new BmpBitmapDecoder (bmp,
|
||||
BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
|
||||
|
||||
@@ -46,15 +46,13 @@ namespace GameRes.Formats.Silky
|
||||
public override string Description { get { return "Silky's image format"; } }
|
||||
public override uint Signature { get { return 0x5355455Au; } } // 'ZEUS'
|
||||
|
||||
public override ImageMetaData ReadMetaData (Stream stream)
|
||||
public override ImageMetaData ReadMetaData (IBinaryStream stream)
|
||||
{
|
||||
var header = new byte[0x14];
|
||||
if (header.Length != stream.Read (header, 0, header.Length))
|
||||
return null;
|
||||
uint width = LittleEndian.ToUInt32 (header, 4);
|
||||
uint height = LittleEndian.ToUInt32 (header, 8);
|
||||
int unpacked_size = LittleEndian.ToInt32 (header, 0xC);
|
||||
int flags = LittleEndian.ToInt32 (header, 0x10);
|
||||
var header = stream.ReadHeader (0x14);
|
||||
uint width = header.ToUInt32 (4);
|
||||
uint height = header.ToUInt32 (8);
|
||||
int unpacked_size = header.ToInt32 (0xC);
|
||||
int flags = header.ToInt32 (0x10);
|
||||
int bpp = flags & 0xff;
|
||||
if (0 == bpp)
|
||||
bpp = 32;
|
||||
@@ -68,11 +66,9 @@ namespace GameRes.Formats.Silky
|
||||
};
|
||||
}
|
||||
|
||||
public override ImageData Read (Stream stream, ImageMetaData info)
|
||||
public override ImageData Read (IBinaryStream stream, ImageMetaData info)
|
||||
{
|
||||
var meta = info as IgfMetaData;
|
||||
if (null == meta)
|
||||
throw new ArgumentException ("IgfFormat.Read should be supplied with IgfMetaData", "info");
|
||||
var meta = (IgfMetaData)info as IgfMetaData;
|
||||
|
||||
int stride = (int)info.Width*info.BPP/8;
|
||||
stream.Position = 0x14;
|
||||
@@ -80,7 +76,7 @@ namespace GameRes.Formats.Silky
|
||||
if (meta.IsPacked)
|
||||
{
|
||||
int in_size = (int)(stream.Length - 0x14);
|
||||
using (var lzss = new LzssReader (stream, in_size, meta.UnpackedSize))
|
||||
using (var lzss = new LzssReader (stream.AsStream, in_size, meta.UnpackedSize))
|
||||
{
|
||||
lzss.FrameFill = 0x20;
|
||||
lzss.Unpack();
|
||||
|
||||
@@ -58,49 +58,40 @@ namespace GameRes.Formats.Silky
|
||||
throw new NotImplementedException ("MfgFormat.Write not implemented");
|
||||
}
|
||||
|
||||
public override ImageMetaData ReadMetaData (Stream stream)
|
||||
public override ImageMetaData ReadMetaData (IBinaryStream file)
|
||||
{
|
||||
using (var file = new ArcView.Reader (stream))
|
||||
file.Position = 3;
|
||||
byte id = file.ReadUInt8();
|
||||
uint data_size = file.ReadUInt32();
|
||||
uint width = file.ReadUInt32();
|
||||
uint height = file.ReadUInt32();
|
||||
uint stride = file.ReadUInt32();
|
||||
if (stride < width)
|
||||
throw new NotSupportedException();
|
||||
if (stride*height != data_size)
|
||||
return null;
|
||||
return new MfgMetaData
|
||||
{
|
||||
stream.Seek (3, SeekOrigin.Current);
|
||||
byte id = file.ReadByte();
|
||||
uint data_size = file.ReadUInt32();
|
||||
uint width = file.ReadUInt32();
|
||||
uint height = file.ReadUInt32();
|
||||
uint stride = file.ReadUInt32();
|
||||
if (stride < width)
|
||||
throw new NotSupportedException();
|
||||
if (stride*height != data_size)
|
||||
return null;
|
||||
return new MfgMetaData
|
||||
{
|
||||
Width = width,
|
||||
Height = height,
|
||||
BPP = (int)(stride*8/width),
|
||||
Type = id,
|
||||
Stride = (int)stride,
|
||||
};
|
||||
}
|
||||
Width = width,
|
||||
Height = height,
|
||||
BPP = (int)(stride*8/width),
|
||||
Type = id,
|
||||
Stride = (int)stride,
|
||||
};
|
||||
}
|
||||
|
||||
public override ImageData Read (Stream stream, ImageMetaData info)
|
||||
public override ImageData Read (IBinaryStream file, ImageMetaData info)
|
||||
{
|
||||
var meta = info as MfgMetaData;
|
||||
if (null == meta)
|
||||
throw new ArgumentException ("MfgFormat.Read should be supplied with MfgMetaData", "info");
|
||||
|
||||
stream.Position = 0x14;
|
||||
var meta = (MfgMetaData)info;
|
||||
file.Position = 0x14;
|
||||
if ('_' != meta.Type)
|
||||
using (var file = new ArcView.Reader (stream))
|
||||
for (uint i = 0; i < meta.Height; ++i)
|
||||
{
|
||||
for (uint i = 0; i < meta.Height; ++i)
|
||||
{
|
||||
uint n = file.ReadUInt32();
|
||||
file.BaseStream.Seek (n*8, SeekOrigin.Current);
|
||||
}
|
||||
uint n = file.ReadUInt32();
|
||||
file.Seek (n*8, SeekOrigin.Current);
|
||||
}
|
||||
byte[] pixels = new byte[meta.Stride*info.Height];
|
||||
if (pixels.Length != stream.Read (pixels, 0, pixels.Length))
|
||||
if (pixels.Length != file.Read (pixels, 0, pixels.Length))
|
||||
throw new InvalidFormatException ("Unexpected end of file");
|
||||
PixelFormat format;
|
||||
if (24 == meta.BPP)
|
||||
|
||||
@@ -43,24 +43,22 @@ namespace GameRes.Formats.Silky
|
||||
Extensions = new string[] { "msk" };
|
||||
}
|
||||
|
||||
public override ImageMetaData ReadMetaData (Stream stream)
|
||||
public override ImageMetaData ReadMetaData (IBinaryStream stream)
|
||||
{
|
||||
var header = new byte[12];
|
||||
if (12 != stream.Read (header, 0, 12))
|
||||
return null;
|
||||
var header = stream.ReadHeader (12);
|
||||
return new ImageMetaData
|
||||
{
|
||||
Width = LittleEndian.ToUInt16 (header, 8),
|
||||
Height = LittleEndian.ToUInt16 (header, 10),
|
||||
OffsetX = LittleEndian.ToInt16 (header, 4),
|
||||
OffsetY = LittleEndian.ToInt16 (header, 6),
|
||||
Width = header.ToUInt16 (8),
|
||||
Height = header.ToUInt16 (10),
|
||||
OffsetX = header.ToInt16 (4),
|
||||
OffsetY = header.ToInt16 (6),
|
||||
BPP = 8,
|
||||
};
|
||||
}
|
||||
|
||||
public override ImageData Read (Stream stream, ImageMetaData info)
|
||||
public override ImageData Read (IBinaryStream stream, ImageMetaData info)
|
||||
{
|
||||
using (var reader = new RmskReader (stream, info))
|
||||
using (var reader = new RmskReader (stream.AsStream, info))
|
||||
{
|
||||
reader.Unpack();
|
||||
return ImageData.CreateFlipped (info, PixelFormats.Gray8, null, reader.Data, (int)info.Width);
|
||||
|
||||
@@ -49,22 +49,20 @@ namespace GameRes.Formats.Silky
|
||||
Signatures = new uint[] { 0x1803545A, 0x2084545A, 0x8803545A };
|
||||
}
|
||||
|
||||
public override ImageMetaData ReadMetaData (Stream stream)
|
||||
public override ImageMetaData ReadMetaData (IBinaryStream stream)
|
||||
{
|
||||
var header = new byte[0x10];
|
||||
if (header.Length != stream.Read (header, 0, header.Length))
|
||||
return null;
|
||||
var header = stream.ReadHeader (0x10);
|
||||
return new ZitMetaData
|
||||
{
|
||||
Type = LittleEndian.ToUInt16 (header, 2),
|
||||
Width = LittleEndian.ToUInt16 (header, 8),
|
||||
Height = LittleEndian.ToUInt16 (header, 10),
|
||||
Type = header.ToUInt16 (2),
|
||||
Width = header.ToUInt16 (8),
|
||||
Height = header.ToUInt16 (10),
|
||||
BPP = 32,
|
||||
Colors = LittleEndian.ToUInt16 (header, 4),
|
||||
Colors = header.ToUInt16 (4),
|
||||
};
|
||||
}
|
||||
|
||||
public override ImageData Read (Stream stream, ImageMetaData info)
|
||||
public override ImageData Read (IBinaryStream stream, ImageMetaData info)
|
||||
{
|
||||
using (var reader = new ZitReader (stream, (ZitMetaData)info))
|
||||
{
|
||||
@@ -81,7 +79,7 @@ namespace GameRes.Formats.Silky
|
||||
|
||||
internal class ZitReader : IDisposable
|
||||
{
|
||||
BinaryReader m_input;
|
||||
IBinaryStream m_input;
|
||||
byte[] m_output;
|
||||
int m_width;
|
||||
int m_height;
|
||||
@@ -90,9 +88,9 @@ namespace GameRes.Formats.Silky
|
||||
|
||||
public byte[] Data { get { return m_output; } }
|
||||
|
||||
public ZitReader (Stream input, ZitMetaData info)
|
||||
public ZitReader (IBinaryStream input, ZitMetaData info)
|
||||
{
|
||||
m_input = new ArcView.Reader (input);
|
||||
m_input = input;
|
||||
m_width = (int)info.Width;
|
||||
m_height = (int)info.Height;
|
||||
m_type = info.Type;
|
||||
@@ -102,7 +100,7 @@ namespace GameRes.Formats.Silky
|
||||
|
||||
public void Unpack ()
|
||||
{
|
||||
m_input.BaseStream.Position = 0x10;
|
||||
m_input.Position = 0x10;
|
||||
switch (m_type)
|
||||
{
|
||||
case 0x1803: Unpack1(); break;
|
||||
@@ -118,9 +116,9 @@ namespace GameRes.Formats.Silky
|
||||
int dst = 0;
|
||||
while (dst < m_output.Length)
|
||||
{
|
||||
byte b = m_input.ReadByte();
|
||||
byte g = m_input.ReadByte();
|
||||
byte r = m_input.ReadByte();
|
||||
byte b = m_input.ReadUInt8();
|
||||
byte g = m_input.ReadUInt8();
|
||||
byte r = m_input.ReadUInt8();
|
||||
if (b != 0 || g != 0xFF || r != 0)
|
||||
{
|
||||
m_output[dst++] = b;
|
||||
@@ -167,14 +165,8 @@ namespace GameRes.Formats.Silky
|
||||
}
|
||||
|
||||
#region IDisposable Members
|
||||
bool _disposed = false;
|
||||
public void Dispose ()
|
||||
{
|
||||
if (!_disposed)
|
||||
{
|
||||
m_input.Dispose();
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user