mirror of
https://github.com/crskycode/GARbro.git
synced 2026-07-08 01:30:18 +08:00
IBinaryStream migration.
This commit is contained in:
@@ -38,33 +38,30 @@ namespace GameRes.Formats.Elf
|
||||
public override string Description { get { return "Ai5 engine RGB image format"; } }
|
||||
public override uint Signature { get { return 0; } }
|
||||
|
||||
public override ImageMetaData ReadMetaData (Stream stream)
|
||||
public override ImageMetaData ReadMetaData (IBinaryStream input)
|
||||
{
|
||||
using (var input = new ArcView.Reader (stream))
|
||||
{
|
||||
int x = input.ReadInt16();
|
||||
int y = input.ReadInt16();
|
||||
int w = input.ReadInt16();
|
||||
int h = input.ReadInt16();
|
||||
if (w <= 0 || w > 0x1000 || h <= 0 || h > 0x1000
|
||||
|| x < 0 || x > 0x800 || y < 0 || y > 0x800)
|
||||
return null;
|
||||
return new ImageMetaData {
|
||||
Width = (uint)w,
|
||||
Height = (uint)h,
|
||||
OffsetX = x,
|
||||
OffsetY = y,
|
||||
BPP = 24,
|
||||
};
|
||||
}
|
||||
int x = input.ReadInt16();
|
||||
int y = input.ReadInt16();
|
||||
int w = input.ReadInt16();
|
||||
int h = input.ReadInt16();
|
||||
if (w <= 0 || w > 0x1000 || h <= 0 || h > 0x1000
|
||||
|| x < 0 || x > 0x800 || y < 0 || y > 0x800)
|
||||
return null;
|
||||
return new ImageMetaData {
|
||||
Width = (uint)w,
|
||||
Height = (uint)h,
|
||||
OffsetX = x,
|
||||
OffsetY = y,
|
||||
BPP = 24,
|
||||
};
|
||||
}
|
||||
|
||||
public override ImageData Read (Stream stream, ImageMetaData info)
|
||||
public override ImageData Read (IBinaryStream stream, ImageMetaData info)
|
||||
{
|
||||
stream.Position = 8;
|
||||
int stride = (((int)info.Width * 3 + 3) & -4);
|
||||
var pixels = new byte[stride * (int)info.Height];
|
||||
using (var reader = new LzssStream (stream, LzssMode.Decompress, true))
|
||||
using (var reader = new LzssStream (stream.AsStream, LzssMode.Decompress, true))
|
||||
{
|
||||
if (pixels.Length != reader.Read (pixels, 0, pixels.Length))
|
||||
throw new InvalidFormatException();
|
||||
|
||||
@@ -52,34 +52,26 @@ namespace GameRes.Formats.Elf
|
||||
Signatures = new uint[] { 0x6d343252, 0x6E343252, 0x6D343247, 0x6E343247 };
|
||||
}
|
||||
|
||||
public override ImageMetaData ReadMetaData (Stream stream)
|
||||
public override ImageMetaData ReadMetaData (IBinaryStream stream)
|
||||
{
|
||||
var header = new byte[12];
|
||||
if (header.Length != stream.Read (header, 0, header.Length))
|
||||
return null;
|
||||
|
||||
var header = stream.ReadHeader (12);
|
||||
return new GccMetaData
|
||||
{
|
||||
Width = LittleEndian.ToUInt16 (header, 8),
|
||||
Height = LittleEndian.ToUInt16 (header, 10),
|
||||
Width = header.ToUInt16 (8),
|
||||
Height = header.ToUInt16 (10),
|
||||
BPP = 'm' == header[3] ? 32 : 24,
|
||||
OffsetX = LittleEndian.ToInt16 (header, 4),
|
||||
OffsetY = LittleEndian.ToInt16 (header, 6),
|
||||
Signature = LittleEndian.ToUInt32 (header, 0),
|
||||
OffsetX = header.ToInt16 (4),
|
||||
OffsetY = header.ToInt16 (6),
|
||||
Signature = header.ToUInt32 (0),
|
||||
};
|
||||
}
|
||||
|
||||
public override ImageData Read (Stream stream, ImageMetaData info)
|
||||
public override ImageData Read (IBinaryStream stream, ImageMetaData info)
|
||||
{
|
||||
var meta = info as GccMetaData;
|
||||
if (null == meta)
|
||||
throw new ArgumentException ("GccFormat.Read should be supplied with GccMetaData", "info");
|
||||
|
||||
var reader = new Reader (stream, meta);
|
||||
{
|
||||
reader.Unpack();
|
||||
return ImageData.Create (info, reader.Format, null, reader.Data);
|
||||
}
|
||||
var meta = (GccMetaData)info;
|
||||
var reader = new Reader (stream.AsStream, meta);
|
||||
reader.Unpack();
|
||||
return ImageData.Create (info, reader.Format, null, reader.Data);
|
||||
}
|
||||
|
||||
public override void Write (Stream file, ImageData image)
|
||||
|
||||
@@ -39,16 +39,14 @@ namespace GameRes.Formats.Elf
|
||||
public override string Description { get { return "Ai5 engine indexed image format"; } }
|
||||
public override uint Signature { get { return 0; } }
|
||||
|
||||
public override ImageMetaData ReadMetaData (Stream stream)
|
||||
public override ImageMetaData ReadMetaData (IBinaryStream file)
|
||||
{
|
||||
if (stream.Length <= 0x408)
|
||||
if (file.Length <= 0x408)
|
||||
return null;
|
||||
var header = new byte[8];
|
||||
stream.Read (header, 0, 8);
|
||||
if (0 != LittleEndian.ToInt32 (header, 0))
|
||||
if (0 != file.ReadInt32())
|
||||
return null;
|
||||
int w = LittleEndian.ToInt16 (header, 4);
|
||||
int h = LittleEndian.ToInt16 (header, 6);
|
||||
int w = file.ReadInt16();
|
||||
int h = file.ReadInt16();
|
||||
if (w <= 0 || w > 0x1000 || h <= 0 || h > 0x1000)
|
||||
return null;
|
||||
return new ImageMetaData {
|
||||
@@ -58,12 +56,12 @@ namespace GameRes.Formats.Elf
|
||||
};
|
||||
}
|
||||
|
||||
public override ImageData Read (Stream stream, ImageMetaData info)
|
||||
public override ImageData Read (IBinaryStream stream, ImageMetaData info)
|
||||
{
|
||||
stream.Position = 8;
|
||||
var palette = ReadPalette (stream);
|
||||
var palette = ReadPalette (stream.AsStream);
|
||||
var pixels = new byte[info.Width * info.Height];
|
||||
using (var reader = new LzssStream (stream, LzssMode.Decompress, true))
|
||||
using (var reader = new LzssStream (stream.AsStream, LzssMode.Decompress, true))
|
||||
{
|
||||
if (pixels.Length != reader.Read (pixels, 0, pixels.Length))
|
||||
throw new InvalidFormatException();
|
||||
@@ -103,32 +101,29 @@ namespace GameRes.Formats.Elf
|
||||
Extensions = new string[] { "msk" };
|
||||
}
|
||||
|
||||
public override ImageMetaData ReadMetaData (Stream stream)
|
||||
public override ImageMetaData ReadMetaData (IBinaryStream input)
|
||||
{
|
||||
using (var input = new ArcView.Reader (stream))
|
||||
{
|
||||
int x = input.ReadInt16();
|
||||
int y = input.ReadInt16();
|
||||
int w = input.ReadInt16();
|
||||
int h = input.ReadInt16();
|
||||
if (w <= 0 || w > 0x1000 || h <= 0 || h > 0x1000
|
||||
|| x < 0 || x > 0x800 || y < 0 || y > 0x800)
|
||||
return null;
|
||||
return new ImageMetaData {
|
||||
Width = (uint)w,
|
||||
Height = (uint)h,
|
||||
OffsetX = x,
|
||||
OffsetY = y,
|
||||
BPP = 8,
|
||||
};
|
||||
}
|
||||
int x = input.ReadInt16();
|
||||
int y = input.ReadInt16();
|
||||
int w = input.ReadInt16();
|
||||
int h = input.ReadInt16();
|
||||
if (w <= 0 || w > 0x1000 || h <= 0 || h > 0x1000
|
||||
|| x < 0 || x > 0x800 || y < 0 || y > 0x800)
|
||||
return null;
|
||||
return new ImageMetaData {
|
||||
Width = (uint)w,
|
||||
Height = (uint)h,
|
||||
OffsetX = x,
|
||||
OffsetY = y,
|
||||
BPP = 8,
|
||||
};
|
||||
}
|
||||
|
||||
public override ImageData Read (Stream stream, ImageMetaData info)
|
||||
public override ImageData Read (IBinaryStream stream, ImageMetaData info)
|
||||
{
|
||||
stream.Position = 8;
|
||||
var pixels = new byte[info.Width * info.Height];
|
||||
using (var reader = new LzssStream (stream, LzssMode.Decompress, true))
|
||||
using (var reader = new LzssStream (stream.AsStream, LzssMode.Decompress, true))
|
||||
{
|
||||
if (pixels.Length != reader.Read (pixels, 0, pixels.Length))
|
||||
throw new InvalidFormatException();
|
||||
|
||||
@@ -119,12 +119,12 @@ namespace GameRes.Formats.Elf
|
||||
|
||||
public void Unpack ()
|
||||
{
|
||||
m_input.BaseStream.Position = m_info.DataOffset+2;
|
||||
m_input.Position = m_info.DataOffset+2;
|
||||
if (0 == (m_info.Flags & 4))
|
||||
ReadPalette();
|
||||
else
|
||||
SetDefaultPalette();
|
||||
m_input.BaseStream.Seek (8, SeekOrigin.Current);
|
||||
m_input.Seek (8, SeekOrigin.Current);
|
||||
|
||||
int stride = Stride;
|
||||
if (stride <= 0x10)
|
||||
@@ -379,7 +379,7 @@ namespace GameRes.Formats.Elf
|
||||
void ReadNext ()
|
||||
{
|
||||
bits &= 0xFF00;
|
||||
int b = m_input.BaseStream.ReadByte();
|
||||
int b = m_input.ReadByte();
|
||||
if (-1 != b)
|
||||
bits |= b;
|
||||
}
|
||||
|
||||
@@ -46,43 +46,38 @@ namespace GameRes.Formats.Elf
|
||||
public override string Description { get { return "elf bitmap format"; } }
|
||||
public override uint Signature { get { return 0x007A6968; } } // 'hiz'
|
||||
|
||||
public override ImageMetaData ReadMetaData (Stream stream)
|
||||
public override ImageMetaData ReadMetaData (IBinaryStream file)
|
||||
{
|
||||
using (var input = new ArcView.Reader (stream)) // sub_4BF900
|
||||
file.Position = 4;
|
||||
int n = file.ReadInt32();
|
||||
if (100 != n)
|
||||
return null;
|
||||
uint right = file.ReadUInt32() ^ 0xAA5A5A5A;
|
||||
uint bottom = file.ReadUInt32() ^ 0xAC9326AF;
|
||||
int unknown1 = file.ReadInt32(); // @0x10
|
||||
if (unknown1 == 0x375A8436)
|
||||
return null;
|
||||
uint unpacked_size = file.ReadUInt32() ^ 0x19739D6A; // @0x14
|
||||
if (unpacked_size != right*bottom*4)
|
||||
return null;
|
||||
return new HizMetaData
|
||||
{
|
||||
input.ReadInt32();
|
||||
int n = input.ReadInt32();
|
||||
if (100 != n)
|
||||
return null;
|
||||
uint right = input.ReadUInt32() ^ 0xAA5A5A5A;
|
||||
uint bottom = input.ReadUInt32() ^ 0xAC9326AF;
|
||||
int unknown1 = input.ReadInt32(); // @0x10
|
||||
if (unknown1 == 0x375A8436)
|
||||
return null;
|
||||
uint unpacked_size = input.ReadUInt32() ^ 0x19739D6A; // @0x14
|
||||
if (unpacked_size != right*bottom*4)
|
||||
return null;
|
||||
return new HizMetaData
|
||||
{
|
||||
Width = right,
|
||||
Height = bottom,
|
||||
BPP = 32,
|
||||
IsPacked = true,
|
||||
DataOffset = 0x4c,
|
||||
UnpackedSize = unpacked_size,
|
||||
};
|
||||
}
|
||||
Width = right,
|
||||
Height = bottom,
|
||||
BPP = 32,
|
||||
IsPacked = true,
|
||||
DataOffset = 0x4c,
|
||||
UnpackedSize = unpacked_size,
|
||||
};
|
||||
}
|
||||
|
||||
public override ImageData Read (Stream stream, ImageMetaData info)
|
||||
public override ImageData Read (IBinaryStream stream, ImageMetaData info)
|
||||
{
|
||||
var meta = info as HizMetaData;
|
||||
if (null == meta)
|
||||
throw new ArgumentException ("HizFormat.Read should be supplied with HizMetaData", "info");
|
||||
var meta = (HizMetaData)info;
|
||||
|
||||
var pixels = new byte[meta.UnpackedSize];
|
||||
stream.Position = meta.DataOffset;
|
||||
using (var lzss = new LzssStream (stream, LzssMode.Decompress, true))
|
||||
using (var lzss = new LzssStream (stream.AsStream, LzssMode.Decompress, true))
|
||||
{
|
||||
var channel = new byte[info.Width*info.Height];
|
||||
for (int p = 0; p < 4; ++p)
|
||||
@@ -110,24 +105,22 @@ namespace GameRes.Formats.Elf
|
||||
public override string Description { get { return "elf composite image format"; } }
|
||||
public override uint Signature { get { return 0x00706968; } } // 'hip'
|
||||
|
||||
public override ImageMetaData ReadMetaData (Stream stream)
|
||||
public override ImageMetaData ReadMetaData (IBinaryStream stream)
|
||||
{
|
||||
byte[] header = new byte[0x18];
|
||||
if (0x18 != stream.Read (header, 0, 0x18))
|
||||
return null;
|
||||
var header = stream.ReadHeader (0x18);
|
||||
int index_offset = 0xC;
|
||||
uint first_offset = LittleEndian.ToUInt32 (header, index_offset);
|
||||
uint first_offset = header.ToUInt32 (index_offset);
|
||||
if (0 == first_offset)
|
||||
{
|
||||
index_offset += 4;
|
||||
first_offset = LittleEndian.ToUInt32 (header, index_offset);
|
||||
first_offset = header.ToUInt32 (index_offset);
|
||||
if (0 == first_offset)
|
||||
return null;
|
||||
}
|
||||
index_offset += 4;
|
||||
|
||||
long first_length;
|
||||
uint second_offset = LittleEndian.ToUInt32 (header, index_offset);
|
||||
uint second_offset = header.ToUInt32 (index_offset);
|
||||
if (0 == second_offset)
|
||||
first_length = stream.Length - first_offset;
|
||||
else if (second_offset < first_offset)
|
||||
@@ -135,7 +128,8 @@ namespace GameRes.Formats.Elf
|
||||
else
|
||||
first_length = second_offset - first_offset;
|
||||
|
||||
using (var hiz = new StreamRegion (stream, first_offset, first_length, true))
|
||||
using (var reg = new StreamRegion (stream.AsStream, first_offset, first_length, true))
|
||||
using (var hiz = new BinaryStream (reg, stream.Name))
|
||||
{
|
||||
var info = base.ReadMetaData (hiz);
|
||||
(info as HizMetaData).DataOffset += 0x18;
|
||||
|
||||
Reference in New Issue
Block a user