(G24): recognize 16bpp images.

This commit is contained in:
morkt 2017-12-08 14:44:27 +04:00
parent cb000d2e50
commit 8fbc8d4723

View File

@ -38,6 +38,11 @@ namespace GameRes.Formats.Elf
public override string Description { get { return "Ai5 engine RGB image format"; } } public override string Description { get { return "Ai5 engine RGB image format"; } }
public override uint Signature { get { return 0; } } public override uint Signature { get { return 0; } }
public G24Format ()
{
Extensions = new string[] { "G24", "G16" };
}
public override ImageMetaData ReadMetaData (IBinaryStream input) public override ImageMetaData ReadMetaData (IBinaryStream input)
{ {
int x = input.ReadInt16(); int x = input.ReadInt16();
@ -52,20 +57,21 @@ namespace GameRes.Formats.Elf
Height = (uint)h, Height = (uint)h,
OffsetX = x, OffsetX = x,
OffsetY = y, OffsetY = y,
BPP = 24, BPP = input.Name.HasExtension (".G16") ? 16 : 24
}; };
} }
public override ImageData Read (IBinaryStream stream, ImageMetaData info) public override ImageData Read (IBinaryStream stream, ImageMetaData info)
{ {
stream.Position = 8; stream.Position = 8;
int stride = (((int)info.Width * 3 + 3) & -4); int stride = (((int)info.Width * info.BPP / 8 + 3) & -4);
var pixels = new byte[stride * (int)info.Height]; var pixels = new byte[stride * (int)info.Height];
using (var reader = new LzssStream (stream.AsStream, LzssMode.Decompress, true)) using (var reader = new LzssStream (stream.AsStream, LzssMode.Decompress, true))
{ {
if (pixels.Length != reader.Read (pixels, 0, pixels.Length)) if (pixels.Length != reader.Read (pixels, 0, pixels.Length))
throw new InvalidFormatException(); throw new InvalidFormatException();
return ImageData.CreateFlipped (info, PixelFormats.Bgr24, null, pixels, stride); var format = 24 == info.BPP ? PixelFormats.Bgr24 : PixelFormats.Bgr555;
return ImageData.CreateFlipped (info, format, null, pixels, stride);
} }
} }
@ -74,4 +80,44 @@ namespace GameRes.Formats.Elf
throw new System.NotImplementedException ("G24Format.Write not implemented"); throw new System.NotImplementedException ("G24Format.Write not implemented");
} }
} }
[Export(typeof(ImageFormat))]
public class Msk16Format : ImageFormat
{
public override string Tag { get { return "MSK/G16"; } }
public override string Description { get { return "Ai5 engine image mask"; } }
public override uint Signature { get { return 0; } }
public override ImageMetaData ReadMetaData (IBinaryStream input)
{
if (!input.Name.HasExtension (".MSK"))
return null;
var header = input.ReadHeader (4);
int w = header.ToInt16 (0);
int h = header.ToInt16 (2);
if (w * h + 4 != input.Length || w <= 0 || w > 0x1000 || h <= 0 || h > 0x1000)
return null;
return new ImageMetaData {
Width = (uint)w,
Height = (uint)h,
BPP = 8,
};
}
public override ImageData Read (IBinaryStream stream, ImageMetaData info)
{
stream.Position = 4;
var pixels = stream.ReadBytes ((int)info.Width * (int)info.Height);
for (int i = 0; i < pixels.Length; ++i)
{
pixels[i] = (byte)(pixels[i] * 0xFF / 8);
}
return ImageData.Create (info, PixelFormats.Gray8, null, pixels, (int)info.Width);
}
public override void Write (Stream file, ImageData image)
{
throw new System.NotImplementedException ("Msk16Format.Write not implemented");
}
}
} }