From 4f1a7ff5fbea18cdb30c029fad487e9d61284c9f Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Mon, 18 Jun 2012 11:22:24 +1200 Subject: [PATCH] add --transpose option to utility --- OpenRA.Utility/Command.cs | 19 +++++++++++++++++++ OpenRA.Utility/Program.cs | 2 ++ 2 files changed, 21 insertions(+) diff --git a/OpenRA.Utility/Command.cs b/OpenRA.Utility/Command.cs index 0f89cf2ea3..345c4ce74b 100644 --- a/OpenRA.Utility/Command.cs +++ b/OpenRA.Utility/Command.cs @@ -398,5 +398,24 @@ namespace OpenRA.Utility ShpWriter.Write(destStream, srcImage.Width, srcImage.Height, srcImage.Frames.Select( im => im.Image.Select(px => (byte)remap[px]).ToArray() )); } + + public static void TransposeShp(string[] args) + { + var srcImage = ShpReader.Load(args[1]); + var start = int.Parse(args[3]); + var m = int.Parse(args[4]); + var n = int.Parse(args[5]); + + var srcFrames = srcImage.Frames.ToArray(); + var destFrames = srcImage.Frames.ToArray(); + + for( var i = 0; i < m; i++ ) + for( var j = 0; j < n; j++ ) + destFrames[ start + i*n + j ] = srcFrames[ start + j*m + i ]; + + using( var destStream = File.Create(args[2]) ) + ShpWriter.Write(destStream, srcImage.Width, srcImage.Height, + destFrames.Select(f => f.Image)); + } } } diff --git a/OpenRA.Utility/Program.cs b/OpenRA.Utility/Program.cs index 06e256fddb..47a386e92f 100644 --- a/OpenRA.Utility/Program.cs +++ b/OpenRA.Utility/Program.cs @@ -28,6 +28,7 @@ namespace OpenRA.Utility { "--tmp-png", Command.ConvertTmpToPng }, { "--remap", Command.RemapShp }, { "--r8", Command.ConvertR8ToPng }, + { "--transpose", Command.TransposeShp }, }; if (args.Length == 0) { PrintUsage(); return; } @@ -61,6 +62,7 @@ namespace OpenRA.Utility Console.WriteLine(" --tmp-png MOD[,MOD]* THEATER FILES Extract terrain tiles to PNG"); Console.WriteLine(" --remap SRCMOD:PAL DESTMOD:PAL SRCSHP DESTSHP Remap SHPs to another palette"); Console.WriteLine(" --r8 R8FILE PALETTE START END FILENAME [--transparent] [--infrantry] [--vehicle] [--projectile] [--building] [--wall] [--tileset] Convert Dune 2000 DATA.R8 to PNGs choosing start- and endframe as well as type for correct offset to append multiple frames to one PNG named by filename optionally setting up transparency."); + Console.WriteLine(" --transpose SRCSHP DESTSHP START N M Transpose the N*M block of frames starting at START."); } static string GetNamedArg(string[] args, string arg)