mirror of
https://github.com/lifegpc/GARbro.git
synced 2026-07-08 01:31:41 +08:00
IBinaryStream migration.
This commit is contained in:
@@ -248,7 +248,7 @@ namespace GameRes.Formats.AZSys
|
||||
Buffer.BlockCopy (data, 0, header, 0, 0x10);
|
||||
return new PrefixStream (header, asb);
|
||||
}
|
||||
return new MemoryStream (data);
|
||||
return new BinMemoryStream (data, entry.Name);
|
||||
}
|
||||
|
||||
uint ReadSysenvSeed (ArcView file, IEnumerable<Entry> dir, uint key)
|
||||
|
||||
@@ -54,51 +54,48 @@ namespace GameRes.Formats.AZSys
|
||||
throw new System.NotImplementedException ("CpbFormat.Write not implemented");
|
||||
}
|
||||
|
||||
public override ImageMetaData ReadMetaData (Stream stream)
|
||||
public override ImageMetaData ReadMetaData (IBinaryStream file)
|
||||
{
|
||||
stream.Seek (4, SeekOrigin.Current);
|
||||
int type = stream.ReadByte();
|
||||
int bpp = stream.ReadByte();
|
||||
file.Position = 4;
|
||||
int type = file.ReadByte();
|
||||
int bpp = file.ReadByte();
|
||||
if (24 != bpp && 32 != bpp)
|
||||
throw new NotSupportedException ("Not supported CPB image format");
|
||||
using (var input = new ArcView.Reader (stream))
|
||||
int version = file.ReadInt16();
|
||||
if (1 != version && 0 != version)
|
||||
throw new NotSupportedException ("Not supported CPB image version");
|
||||
var info = new CpbMetaData {
|
||||
Type = type,
|
||||
Version = version,
|
||||
BPP = bpp,
|
||||
};
|
||||
if (1 == version)
|
||||
{
|
||||
int version = input.ReadInt16 ();
|
||||
if (1 != version && 0 != version)
|
||||
throw new NotSupportedException ("Not supported CPB image version");
|
||||
var info = new CpbMetaData {
|
||||
Type = type,
|
||||
Version = version,
|
||||
BPP = bpp,
|
||||
};
|
||||
if (1 == version)
|
||||
{
|
||||
input.ReadUInt32();
|
||||
info.Width = input.ReadUInt16();
|
||||
info.Height = input.ReadUInt16();
|
||||
info.Channel[0] = input.ReadUInt32();
|
||||
info.Channel[1] = input.ReadUInt32();
|
||||
info.Channel[2] = input.ReadUInt32();
|
||||
info.Channel[3] = input.ReadUInt32();
|
||||
}
|
||||
else
|
||||
{
|
||||
info.Width = input.ReadUInt16();
|
||||
info.Height = input.ReadUInt16();
|
||||
input.ReadUInt32();
|
||||
info.Channel[0] = input.ReadUInt32();
|
||||
info.Channel[1] = input.ReadUInt32();
|
||||
info.Channel[2] = input.ReadUInt32();
|
||||
info.Channel[3] = input.ReadUInt32();
|
||||
}
|
||||
info.DataOffset = (uint)stream.Position;
|
||||
return info;
|
||||
file.ReadUInt32();
|
||||
info.Width = file.ReadUInt16();
|
||||
info.Height = file.ReadUInt16();
|
||||
info.Channel[0] = file.ReadUInt32();
|
||||
info.Channel[1] = file.ReadUInt32();
|
||||
info.Channel[2] = file.ReadUInt32();
|
||||
info.Channel[3] = file.ReadUInt32();
|
||||
}
|
||||
else
|
||||
{
|
||||
info.Width = file.ReadUInt16();
|
||||
info.Height = file.ReadUInt16();
|
||||
file.ReadUInt32();
|
||||
info.Channel[0] = file.ReadUInt32();
|
||||
info.Channel[1] = file.ReadUInt32();
|
||||
info.Channel[2] = file.ReadUInt32();
|
||||
info.Channel[3] = file.ReadUInt32();
|
||||
}
|
||||
info.DataOffset = (uint)file.Position;
|
||||
return info;
|
||||
}
|
||||
|
||||
public override ImageData Read (Stream stream, ImageMetaData info)
|
||||
public override ImageData Read (IBinaryStream stream, ImageMetaData info)
|
||||
{
|
||||
var reader = new Reader (stream, (CpbMetaData)info);
|
||||
var reader = new Reader (stream.AsStream, (CpbMetaData)info);
|
||||
reader.Unpack();
|
||||
return ImageData.Create (info, reader.Format, reader.Palette, reader.Data);
|
||||
}
|
||||
|
||||
@@ -45,46 +45,38 @@ namespace GameRes.Formats.AZSys
|
||||
public override string Description { get { return "AZ system image format"; } }
|
||||
public override uint Signature { get { return 0x31505954; } } // 'TYP1'
|
||||
|
||||
public Typ1Format ()
|
||||
{
|
||||
Extensions = new string[] { "cpb" };
|
||||
}
|
||||
|
||||
public override ImageMetaData ReadMetaData (Stream stream)
|
||||
public override ImageMetaData ReadMetaData (IBinaryStream stream)
|
||||
{
|
||||
stream.Position = 4;
|
||||
int bpp = stream.ReadByte();
|
||||
bool has_palette = stream.ReadByte() != 0;
|
||||
using (var input = new ArcView.Reader (stream))
|
||||
var info = new Typ1MetaData { BPP = bpp };
|
||||
info.Width = stream.ReadUInt16();
|
||||
info.Height = stream.ReadUInt16();
|
||||
uint packed_size = stream.ReadUInt32();
|
||||
uint palette_size = 8 == bpp ? 0x400u : 0u;
|
||||
if (packed_size+palette_size+0xE == stream.Length)
|
||||
{
|
||||
var info = new Typ1MetaData { BPP = bpp };
|
||||
info.Width = input.ReadUInt16();
|
||||
info.Height = input.ReadUInt16();
|
||||
uint packed_size = input.ReadUInt32();
|
||||
uint palette_size = 8 == bpp ? 0x400u : 0u;
|
||||
if (packed_size+palette_size+0xE == stream.Length)
|
||||
{
|
||||
info.SeparateChannels = false;
|
||||
info.HasPalette = palette_size > 0;
|
||||
info.PackedSize = packed_size;
|
||||
}
|
||||
else
|
||||
{
|
||||
info.SeparateChannels = true;
|
||||
info.HasPalette = has_palette;
|
||||
info.Channel[0] = input.ReadUInt32();
|
||||
info.Channel[1] = input.ReadUInt32();
|
||||
info.Channel[2] = input.ReadUInt32();
|
||||
info.Channel[3] = input.ReadUInt32();
|
||||
}
|
||||
return info;
|
||||
info.SeparateChannels = false;
|
||||
info.HasPalette = palette_size > 0;
|
||||
info.PackedSize = packed_size;
|
||||
}
|
||||
else
|
||||
{
|
||||
info.SeparateChannels = true;
|
||||
info.HasPalette = has_palette;
|
||||
info.Channel[0] = stream.ReadUInt32();
|
||||
info.Channel[1] = stream.ReadUInt32();
|
||||
info.Channel[2] = stream.ReadUInt32();
|
||||
info.Channel[3] = stream.ReadUInt32();
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
public override ImageData Read (Stream stream, ImageMetaData info)
|
||||
public override ImageData Read (IBinaryStream stream, ImageMetaData info)
|
||||
{
|
||||
var meta = (Typ1MetaData)info;
|
||||
var reader = new Reader (stream, meta);
|
||||
var reader = new Reader (stream.AsStream, meta);
|
||||
reader.Unpack();
|
||||
return ImageData.Create (meta, reader.Format, reader.Palette, reader.Data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user