mirror of
https://github.com/crskycode/GARbro.git
synced 2026-07-08 01:30:18 +08:00
(EriFile): new wrapper class for Entis files reading.
This commit is contained in:
@@ -78,6 +78,45 @@ namespace GameRes.Formats.Entis
|
|||||||
SideBySide = 0x10000000,
|
SideBySide = 0x10000000,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal class EriFile : BinaryReader
|
||||||
|
{
|
||||||
|
internal struct Section
|
||||||
|
{
|
||||||
|
public AsciiString Id;
|
||||||
|
public long Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EriFile (Stream stream) : base (stream, System.Text.Encoding.ASCII, true)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public Section ReadSection ()
|
||||||
|
{
|
||||||
|
var section = new Section();
|
||||||
|
section.Id = new AsciiString (8);
|
||||||
|
if (8 != this.Read (section.Id.Value, 0, 8))
|
||||||
|
throw new EndOfStreamException();
|
||||||
|
section.Length = this.ReadInt64();
|
||||||
|
return section;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long FindSection (string name)
|
||||||
|
{
|
||||||
|
var id = new AsciiString (8);
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
if (8 != this.Read (id.Value, 0, 8))
|
||||||
|
throw new EndOfStreamException();
|
||||||
|
var length = this.ReadInt64();
|
||||||
|
if (length < 0)
|
||||||
|
throw new EndOfStreamException();
|
||||||
|
if (id == name)
|
||||||
|
return length;
|
||||||
|
this.BaseStream.Seek (length, SeekOrigin.Current);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Export(typeof(ImageFormat))]
|
[Export(typeof(ImageFormat))]
|
||||||
public class EriFormat : ImageFormat
|
public class EriFormat : ImageFormat
|
||||||
{
|
{
|
||||||
@@ -94,9 +133,9 @@ namespace GameRes.Formats.Entis
|
|||||||
return null;
|
return null;
|
||||||
if (!Binary.AsciiEqual (header, 0x10, "Entis Rasterized Image"))
|
if (!Binary.AsciiEqual (header, 0x10, "Entis Rasterized Image"))
|
||||||
return null;
|
return null;
|
||||||
using (var reader = new ArcView.Reader (stream))
|
using (var reader = new EriFile (stream))
|
||||||
{
|
{
|
||||||
var section = ReadEriSection (reader);
|
var section = reader.ReadSection();
|
||||||
if (section.Id != "Header " || section.Length <= 0)
|
if (section.Id != "Header " || section.Length <= 0)
|
||||||
return null;
|
return null;
|
||||||
int header_size = (int)section.Length;
|
int header_size = (int)section.Length;
|
||||||
@@ -104,7 +143,7 @@ namespace GameRes.Formats.Entis
|
|||||||
EriMetaData info = null;
|
EriMetaData info = null;
|
||||||
while (header_size > 8)
|
while (header_size > 8)
|
||||||
{
|
{
|
||||||
section = ReadEriSection (reader);
|
section = reader.ReadSection();
|
||||||
header_size -= 8;
|
header_size -= 8;
|
||||||
if (section.Length <= 0 || section.Length > header_size)
|
if (section.Length <= 0 || section.Length > header_size)
|
||||||
break;
|
break;
|
||||||
@@ -146,12 +185,12 @@ namespace GameRes.Formats.Entis
|
|||||||
if (null == meta)
|
if (null == meta)
|
||||||
throw new ArgumentException ("EriFormat.Read should be supplied with EriMetaData", "info");
|
throw new ArgumentException ("EriFormat.Read should be supplied with EriMetaData", "info");
|
||||||
stream.Position = meta.StreamPos;
|
stream.Position = meta.StreamPos;
|
||||||
using (var input = new ArcView.Reader (stream))
|
using (var input = new EriFile (stream))
|
||||||
{
|
{
|
||||||
Color[] palette = null;
|
Color[] palette = null;
|
||||||
for (;;) // ReadEriSection throws an exception in case of EOF
|
for (;;) // ReadSection throws an exception in case of EOF
|
||||||
{
|
{
|
||||||
var section = ReadEriSection (input);
|
var section = input.ReadSection();
|
||||||
if ("Stream " == section.Id)
|
if ("Stream " == section.Id)
|
||||||
continue;
|
continue;
|
||||||
if ("ImageFrm" == section.Id)
|
if ("ImageFrm" == section.Id)
|
||||||
@@ -192,20 +231,6 @@ namespace GameRes.Formats.Entis
|
|||||||
{
|
{
|
||||||
throw new NotImplementedException ("EriFormat.Write not implemented");
|
throw new NotImplementedException ("EriFormat.Write not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
internal struct Section
|
|
||||||
{
|
|
||||||
public string Id;
|
|
||||||
public long Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
static internal Section ReadEriSection (BinaryReader reader)
|
|
||||||
{
|
|
||||||
var section = new Section();
|
|
||||||
section.Id = new string (reader.ReadChars (8));
|
|
||||||
section.Length = reader.ReadInt64();
|
|
||||||
return section;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
|
|||||||
Reference in New Issue
Block a user