mirror of
https://github.com/lifegpc/GARbro.git
synced 2026-06-06 05:28:49 +08:00
bunch of stuff.
This commit is contained in:
@@ -38,12 +38,23 @@ namespace GameRes.Formats.Airyu
|
||||
public override bool IsHierarchic { get { return false; } }
|
||||
public override bool CanWrite { get { return false; } }
|
||||
|
||||
static readonly uint[] ImageSizes = new[] { 0x96000u, 0x4B000u, 0x19000u };
|
||||
|
||||
public override ArcFile TryOpen (ArcView file)
|
||||
{
|
||||
if (!file.Name.HasExtension (".chr"))
|
||||
return null;
|
||||
int count = (int)(file.MaxOffset / 0x96000);
|
||||
if (!IsSaneCount (count) || count * 0x96000 != file.MaxOffset)
|
||||
int count = 0;
|
||||
uint image_size = 1;
|
||||
for (int i = 0; i < ImageSizes.Length; ++i)
|
||||
{
|
||||
image_size = ImageSizes[i];
|
||||
count = (int)(file.MaxOffset / image_size);
|
||||
if (IsSaneCount (count) && count * image_size == file.MaxOffset)
|
||||
break;
|
||||
count = 0;
|
||||
}
|
||||
if (0 == count)
|
||||
return null;
|
||||
|
||||
uint offset = 0;
|
||||
@@ -54,10 +65,10 @@ namespace GameRes.Formats.Airyu
|
||||
Name = i.ToString ("D5"),
|
||||
Type = "image",
|
||||
Offset = offset,
|
||||
Size = 0x96000,
|
||||
Size = image_size,
|
||||
};
|
||||
dir.Add (entry);
|
||||
offset += 0x96000;
|
||||
offset += image_size;
|
||||
}
|
||||
return new ArcFile (file, this, dir);
|
||||
}
|
||||
@@ -65,21 +76,32 @@ namespace GameRes.Formats.Airyu
|
||||
public override IImageDecoder OpenImage (ArcFile arc, Entry entry)
|
||||
{
|
||||
var input = arc.File.CreateStream (entry.Offset, entry.Size);
|
||||
return new ChrImageDecoder (input);
|
||||
return new ChrImageDecoder (input, entry.Size);
|
||||
}
|
||||
}
|
||||
|
||||
internal class ChrImageDecoder : BinaryImageDecoder
|
||||
{
|
||||
public ChrImageDecoder (IBinaryStream input) : base (input)
|
||||
int m_image_size;
|
||||
int m_stride;
|
||||
|
||||
public ChrImageDecoder (IBinaryStream input, uint size) : base (input)
|
||||
{
|
||||
Info = new ImageMetaData { Width = 640, Height = 480, BPP = 16 };
|
||||
m_image_size = (int)size;
|
||||
switch (size)
|
||||
{
|
||||
case 0x19000: Info = new ImageMetaData { Width = 200, Height = 256, BPP = 16 }; break;
|
||||
case 0x4B000: Info = new ImageMetaData { Width = 320, Height = 480, BPP = 16 }; break;
|
||||
case 0x96000: Info = new ImageMetaData { Width = 640, Height = 480, BPP = 16 }; break;
|
||||
default: throw new InvalidFormatException ("Invalid image size.");
|
||||
}
|
||||
m_stride = Info.iWidth * 2;
|
||||
}
|
||||
|
||||
protected override ImageData GetImageData ()
|
||||
{
|
||||
var pixels = m_input.ReadBytes (0x96000);
|
||||
return ImageData.CreateFlipped (Info, PixelFormats.Bgr555, null, pixels, 640*2);
|
||||
var pixels = m_input.ReadBytes (m_image_size);
|
||||
return ImageData.CreateFlipped (Info, PixelFormats.Bgr555, null, pixels, m_stride);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user