(MAI4): try default decompression method, fall back to the second one on failure.

This commit is contained in:
morkt 2017-11-24 01:28:43 +04:00
parent 98288fdf1c
commit 74874e44cf

View File

@ -53,7 +53,14 @@ namespace GameRes.Formats.ShiinaRio
public override ImageData Read (IBinaryStream stream, ImageMetaData info)
{
var reader = new Reader (stream, (int)info.Width, (int)info.Height);
reader.Unpack();
try
{
reader.Unpack (MaiVersion.First);
}
catch
{
reader.Unpack (MaiVersion.Second);
}
return ImageData.Create (info, PixelFormats.Bgr24, null, reader.Data, reader.Stride);
}
@ -62,6 +69,11 @@ namespace GameRes.Formats.ShiinaRio
throw new System.NotImplementedException ("Mi4Format.Write not implemented");
}
internal enum MaiVersion
{
First, Second
}
internal sealed class Reader
{
IBinaryStream m_input;
@ -78,12 +90,15 @@ namespace GameRes.Formats.ShiinaRio
m_output = new byte[m_stride*height];
}
public void Unpack ()
public void Unpack (MaiVersion version = MaiVersion.First)
{
m_input.Position = 0x10;
m_bit_count = 0;
LoadBits();
UnpackV2();
if (MaiVersion.First == version)
UnpackV1();
else
UnpackV2();
}
int m_bit_count;