From 4e45160237fa2803244cc995977e8215effac3a1 Mon Sep 17 00:00:00 2001 From: morkt Date: Thu, 18 Jan 2018 07:18:03 +0400 Subject: [PATCH] implemented old GD format. --- ArcFormats/C4/ImageGD.cs | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/ArcFormats/C4/ImageGD.cs b/ArcFormats/C4/ImageGD.cs index 59bca854..e7189c64 100644 --- a/ArcFormats/C4/ImageGD.cs +++ b/ArcFormats/C4/ImageGD.cs @@ -74,8 +74,7 @@ namespace GameRes.Formats.C4 { var reader = new GdReader (file, (GdMetaData)info); var pixels = reader.Unpack(); - int stride = 3 * (int)info.Width; - return ImageData.CreateFlipped (info, PixelFormats.Bgr24, null, pixels, stride); + return ImageData.CreateFlipped (info, PixelFormats.Bgr24, null, pixels, reader.Stride); } public override void Write (Stream file, ImageData image) @@ -84,12 +83,49 @@ namespace GameRes.Formats.C4 } } + [Export(typeof(ImageFormat))] + public class XexGdFormat : ImageFormat + { + public override string Tag { get { return "GD/XEX"; } } + public override string Description { get { return "Complets XEX engine image format"; } } + public override uint Signature { get { return 0; } } + + public override ImageMetaData ReadMetaData (IBinaryStream file) + { + if (!file.Name.HasExtension (".GD")) + return null; + var header = file.ReadHeader (2); + int compression = header[0]; + if (compression != 'l' && compression != 'p' || header[1] != 0x1A) + return null; + return new GdMetaData { + Width = 640, Height = 480, BPP = 24, + Compression = compression, + DataOffset = 2, + }; + } + + public override ImageData Read (IBinaryStream file, ImageMetaData info) + { + var reader = new GdReader (file, (GdMetaData)info); + var pixels = reader.Unpack(); + return ImageData.CreateFlipped (info, PixelFormats.Bgr24, null, pixels, reader.Stride); + } + + public override void Write (Stream file, ImageData image) + { + throw new NotImplementedException ("XexGdFormat.Write not implemented"); + } + } + internal sealed class GdReader { IBinaryStream m_input; GdMetaData m_info; byte[] m_output; + public int Stride { get { return (int)m_info.Width * 3; } } + public GdReader (IBinaryStream input, GdMetaData info) { m_input = input;