(AmFormat): fixed 8bpp images.

This commit is contained in:
morkt 2018-04-20 21:14:04 +04:00
parent 5e1f81b818
commit b5d3a09683

View File

@ -168,30 +168,29 @@ namespace GameRes.Formats.MAI
public override ImageMetaData ReadMetaData (IBinaryStream stream) public override ImageMetaData ReadMetaData (IBinaryStream stream)
{ {
if ('A' != stream.ReadByte() || 'M' != stream.ReadByte()) var header = stream.ReadHeader (0x30);
if ('A' != header[0] || 'M' != header[1])
return null; return null;
var header = new byte[0x30]; uint size = header.ToUInt32 (2);
if (0x2e != stream.Read (header, 2, 0x2e))
return null;
uint size = LittleEndian.ToUInt32 (header, 2);
if (size != stream.Length) if (size != stream.Length)
return null; return null;
int am_type = header[0x16]; int am_type = header[0x16];
if (am_type != 2 && am_type != 1 || header[0x18] != 1) if (am_type != 2 && am_type != 1 || header[0x18] != 1)
return null; return null;
var info = new AmMetaData(); var info = new AmMetaData {
info.Width = LittleEndian.ToUInt16 (header, 6); Width = header.ToUInt16 (6),
info.Height = LittleEndian.ToUInt16 (header, 8); Height = header.ToUInt16 (8),
info.MaskWidth = LittleEndian.ToUInt16 (header, 0x0a); MaskWidth = header.ToUInt16 (0x0A),
info.MaskHeight = LittleEndian.ToUInt16 (header, 0x0c); MaskHeight = header.ToUInt16 (0x0C),
info.Colors = LittleEndian.ToUInt16 (header, 0x12); Colors = header.ToUInt16 (0x12),
info.BPP = header[0x14]; BPP = header[0x14],
info.IsCompressed = 0 != header[0x15]; IsCompressed = 0 != header[0x15],
info.DataOffset = LittleEndian.ToUInt32 (header, 0x1a); DataOffset = header.ToUInt32 (0x1A),
info.DataLength = LittleEndian.ToUInt32 (header, 0x1e); DataLength = header.ToUInt32 (0x1E),
info.MaskOffset = LittleEndian.ToUInt32 (header, 0x22); MaskOffset = header.ToUInt32 (0x22),
info.MaskLength = LittleEndian.ToUInt32 (header, 0x26); MaskLength = header.ToUInt32 (0x26),
info.IsMaskCompressed = 0 != header[0x2a]; IsMaskCompressed = 0 != header[0x2A],
};
if (checked(info.DataLength + info.MaskLength) > size) if (checked(info.DataLength + info.MaskLength) > size)
return null; return null;
return info; return info;
@ -238,9 +237,12 @@ namespace GameRes.Formats.MAI
public void Unpack () public void Unpack ()
{ {
m_input.Position = m_info.DataOffset;
if (m_info.Colors > 0) if (m_info.Colors > 0)
{
m_input.Position = 0x30;
Palette = ImageFormat.ReadPalette (m_input, m_info.Colors, PaletteFormat.Bgr); Palette = ImageFormat.ReadPalette (m_input, m_info.Colors, PaletteFormat.Bgr);
}
m_input.Position = m_info.DataOffset;
if (m_info.IsCompressed) if (m_info.IsCompressed)
RleDecoder.Unpack (m_input, (int)m_info.DataLength, m_output, m_pixel_size); RleDecoder.Unpack (m_input, (int)m_info.DataLength, m_output, m_pixel_size);
else else