mirror of
https://github.com/crskycode/GARbro.git
synced 2026-07-08 01:30:18 +08:00
IBinaryStream migration.
This commit is contained in:
@@ -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