feat: LBG/PS2-SPC Image Format improvement

This commit is contained in:
ManicSteiner 2023-12-16 16:05:20 +08:00
parent da4b6574da
commit 30b875efe8

View File

@ -10,13 +10,14 @@ namespace GameRes.Formats.Kid
[Export(typeof(ImageFormat))] [Export(typeof(ImageFormat))]
public class LbgFormat : ImageFormat public class LbgFormat : ImageFormat
{ {
public override string Tag { get { return "LBG/PS2-SPC Image Format"; } } public override string Tag { get { return "LBG/PS2-SPC"; } }
public override string Description { get { return "KID PS2 SPC Image Format"; } } public override string Description { get { return "KID PS2 SPC Image Format"; } }
public override uint Signature { get { return 0; } } //0x10000000, real signature below public override uint Signature { get { return 0; } } //real signature may exist below
public LbgFormat() public LbgFormat()
{ {
Extensions = new string[] { "", "lbg" }; Extensions = new string[] { "", "lbg" };
// Actually LBG format can contain more than one image as lip for chara, well, "not implemented".
} }
public override ImageMetaData ReadMetaData(IBinaryStream file) public override ImageMetaData ReadMetaData(IBinaryStream file)
@ -27,11 +28,11 @@ namespace GameRes.Formats.Kid
if (header != 0x2047424C) //LBG\x20 if (header != 0x2047424C) //LBG\x20
{ {
overheader = header; overheader = header;
if (overheader > 0x100) if (overheader > 0x50) //usually 10 or 30, never seen any larger
return null; return null;
file.Seek(overheader, SeekOrigin.Begin); file.Seek(overheader, SeekOrigin.Begin);
header = file.ReadUInt32(); header = file.ReadUInt32();
if (header != 0x2047424C) if (header != 0x2047424C) //LBG\x20
return null; return null;
} }
@ -62,9 +63,15 @@ namespace GameRes.Formats.Kid
if (lbgheader.OverHeader != 0) if (lbgheader.OverHeader != 0)
{ {
file.Position = 4; file.Position = 4;
uint filesize = file.ReadUInt32() - 16; uint filesize = file.ReadUInt32();
if (filesize == 0)
oversize = 8;
else
{
filesize -= 16;
oversize = (filesize - info.Width * info.Height * 4) / info.Height / (blocknum + 1); oversize = (filesize - info.Width * info.Height * 4) / info.Height / (blocknum + 1);
} }
}
file.Position = lbgheader.OverHeader + 0x10; file.Position = lbgheader.OverHeader + 0x10;
//List<byte> pixels = new List<byte>(); //List<byte> pixels = new List<byte>();
byte[] pixels = new byte[info.Width * info.Height * 4]; byte[] pixels = new byte[info.Width * info.Height * 4];