From 6d36c55b45c49cc5bdf4c77847ba18493670ce68 Mon Sep 17 00:00:00 2001 From: morkt Date: Sat, 10 Nov 2018 22:14:33 +0400 Subject: [PATCH] (NBMP): support 8bpp bitmaps. --- Legacy/WestGate/ImageNBMP.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Legacy/WestGate/ImageNBMP.cs b/Legacy/WestGate/ImageNBMP.cs index c58f257d..736cf059 100644 --- a/Legacy/WestGate/ImageNBMP.cs +++ b/Legacy/WestGate/ImageNBMP.cs @@ -26,6 +26,7 @@ using System.ComponentModel.Composition; using System.IO; using System.Windows.Media; +using System.Windows.Media.Imaging; namespace GameRes.Formats.WestGate { @@ -42,7 +43,7 @@ namespace GameRes.Formats.WestGate if (header.ToInt32 (4) != 0x28) return null; int bpp = header.ToInt16 (0x12); - if (bpp != 24 && bpp != 32) + if (bpp != 24 && bpp != 32 && bpp != 8) return null; return new ImageMetaData { Width = header.ToUInt32 (8), @@ -55,9 +56,13 @@ namespace GameRes.Formats.WestGate { int stride = ((int)info.Width * info.BPP / 8 + 3) & ~3; file.Position = 0x2C; + BitmapPalette palette = null; + if (8 == info.BPP) + palette = ReadPalette (file.AsStream); var pixels = file.ReadBytes (stride * (int)info.Height); - PixelFormat format = 24 == info.BPP ? PixelFormats.Bgr24 : PixelFormats.Bgr32; - return ImageData.CreateFlipped (info, format, null, pixels, stride); + PixelFormat format = 8 == info.BPP ? PixelFormats.Indexed8 + : 24 == info.BPP ? PixelFormats.Bgr24 : PixelFormats.Bgr32; + return ImageData.CreateFlipped (info, format, palette, pixels, stride); } public override void Write (Stream file, ImageData image)