(SeraphReader): added Info property, cosmetic changes.

This commit is contained in:
morkt 2017-12-14 10:54:17 +04:00
parent ea8cd8a420
commit dfb56d21ce

View File

@ -45,6 +45,11 @@ namespace GameRes.Formats.Seraphim
public override string Description { get { return "Seraphim engine image format"; } } public override string Description { get { return "Seraphim engine image format"; } }
public override uint Signature { get { return 0x4643; } } public override uint Signature { get { return 0x4643; } }
public SeraphCfImage ()
{
Extensions = new string[] { "cts" };
}
public override ImageMetaData ReadMetaData (IBinaryStream stream) public override ImageMetaData ReadMetaData (IBinaryStream stream)
{ {
var header = stream.ReadHeader (0x10); var header = stream.ReadHeader (0x10);
@ -166,9 +171,11 @@ namespace GameRes.Formats.Seraphim
public byte[] Data { get { return m_output; } } public byte[] Data { get { return m_output; } }
public PixelFormat Format { get; private set; } public PixelFormat Format { get; private set; }
public BitmapPalette Palette { get; private set; } public BitmapPalette Palette { get; private set; }
public ImageMetaData Info { get; private set; }
public SeraphReader (Stream input, SeraphMetaData info, int pixel_size = 3) public SeraphReader (Stream input, SeraphMetaData info, int pixel_size = 3)
{ {
Info = info;
m_input = input; m_input = input;
m_input.Position = 0x10; m_input.Position = 0x10;
m_width = (int)info.Width; m_width = (int)info.Width;
@ -235,33 +242,33 @@ namespace GameRes.Formats.Seraphim
while (dst < m_output.Length) while (dst < m_output.Length)
{ {
int count; int count;
int v1 = m_input.ReadByte(); int ctl = m_input.ReadByte();
if (-1 == v1) if (-1 == ctl)
break; break;
if ((v1 & 0xF0) == 0xF0) if ((ctl & 0xF0) == 0xF0)
throw new InvalidFormatException(); throw new InvalidFormatException();
if (0 == (v1 & 0x80)) if (0 == (ctl & 0x80))
{ {
if (0 != (v1 & 0x40)) if (0 != (ctl & 0x40))
{ {
count = (v1 & 0x3F) + 2; count = (ctl & 0x3F) + 2;
int v2 = m_input.ReadByte(); int v2 = m_input.ReadByte();
for (int i = 0; i < count; ++i) for (int i = 0; i < count; ++i)
m_output[dst+i] = (byte)v2; m_output[dst+i] = (byte)v2;
} }
else else
{ {
count = (v1 & 0x3F) + 1; count = (ctl & 0x3F) + 1;
if (count != m_input.Read (m_output, dst, count)) if (count != m_input.Read (m_output, dst, count))
break; break;
} }
} }
else if (0 == (v1 & 0x40)) else if (0 == (ctl & 0x40))
{ {
int v2 = m_input.ReadByte(); int v2 = m_input.ReadByte();
count = v2 | ((v1 & 0xF) << 8); count = v2 | ((ctl & 0xF) << 8);
switch ((v1 >> 4) & 3) switch ((ctl >> 4) & 3)
{ {
case 0: case 0:
count += 2; count += 2;
@ -283,12 +290,11 @@ namespace GameRes.Formats.Seraphim
break; break;
} }
} }
else if (0 == (v1 & 0x30)) else if (0 == (ctl & 0x30))
{ {
int v2 = m_input.ReadByte(); int v2 = m_input.ReadByte();
int v19 = (v1 >> 3) & 1; count = v2 + ((ctl & 7) << 8) + 1;
count = v2 + ((v1 & 7) << 8) + 1; if (0 != (ctl & 8))
if (0 != v19)
{ {
m_input.Read (m_output, dst, 6); m_input.Read (m_output, dst, 6);
Binary.CopyOverlapped (m_output, dst, dst+6, count*6); Binary.CopyOverlapped (m_output, dst, dst+6, count*6);
@ -303,19 +309,18 @@ namespace GameRes.Formats.Seraphim
count *= 3; count *= 3;
} }
} }
else if (0 == (v1 & 0x20)) else if (0 == (ctl & 0x20))
{ {
int v30 = m_input.ReadByte(); int offset = m_input.ReadByte() + ((ctl & 0xF) << 8);
int v31 = v30 + ((v1 & 0xF) << 8);
count = m_input.ReadByte() + 1; count = m_input.ReadByte() + 1;
int src = dst - 3 - 3 * v31; // auto v34 = &unpacked[dst - 3] - 3 * v31; int src = dst - 3 - 3 * offset; // auto v34 = &unpacked[dst - 3] - 3 * offset;
count *= 3; count *= 3;
Binary.CopyOverlapped (m_output, src, dst, count); Binary.CopyOverlapped (m_output, src, dst, count);
} }
else else
{ {
int v37 = m_input.ReadByte(); int v37 = m_input.ReadByte();
int v38 = v37 + ((v1 & 0xF) << 8); int v38 = v37 + ((ctl & 0xF) << 8);
count = m_input.ReadByte() + 1; count = m_input.ReadByte() + 1;
int src = dst - 1 - v38; // auto v40 = &unpacked[dst - 1] - v38; int src = dst - 1 - v38; // auto v40 = &unpacked[dst - 1] - v38;
Binary.CopyOverlapped (m_output, src, dst, count); Binary.CopyOverlapped (m_output, src, dst, count);