From 2a16172a20e45669454d7698fad03d32b3e46dc0 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sun, 17 Jul 2011 18:37:12 +1200 Subject: [PATCH] add d2k -> ra shp conversion support to utility --- OpenRA.Utility/Command.cs | 20 ++++++++++++++++++++ OpenRA.Utility/Program.cs | 1 + 2 files changed, 21 insertions(+) diff --git a/OpenRA.Utility/Command.cs b/OpenRA.Utility/Command.cs index 7864f28d2f..7d75ec66da 100644 --- a/OpenRA.Utility/Command.cs +++ b/OpenRA.Utility/Command.cs @@ -13,6 +13,7 @@ using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; using System.IO; +using System.Linq; using System.Runtime.InteropServices; using System.Windows.Forms; using OpenRA.FileFormats; @@ -122,5 +123,24 @@ namespace OpenRA.Utility bitmap.Save(dest); } } + + public static void ConvertFormat2ToFormat80(string[] args) + { + var src = args[1]; + var dest = args[2]; + + Dune2ShpReader srcImage = null; + using( var s = File.OpenRead( src ) ) + srcImage = new Dune2ShpReader(s); + + var size = srcImage.First().Size; + + if (!srcImage.All( im => im.Size == size )) + throw new InvalidOperationException("All the frames must be the same size to convert from Dune2 to RA"); + + using( var destStream = File.Create(dest) ) + ShpWriter.Write(destStream, size.Width, size.Height, + srcImage.Select( im => im.Image )); + } } } diff --git a/OpenRA.Utility/Program.cs b/OpenRA.Utility/Program.cs index 58a24cef2c..91a13d19a4 100644 --- a/OpenRA.Utility/Program.cs +++ b/OpenRA.Utility/Program.cs @@ -25,6 +25,7 @@ namespace OpenRA.Utility { "--settings-value", Command.Settings }, { "--shp", Command.ConvertPngToShp }, { "--png", Command.ConvertShpToPng }, + { "--fromd2", Command.ConvertFormat2ToFormat80 }, }; if (args.Length == 0) { PrintUsage(); return; }