Update Utility --shp to match.
This commit is contained in:
@@ -43,38 +43,32 @@ namespace OpenRA.Utility
|
|||||||
|
|
||||||
public static void ConvertPngToShp(string[] args)
|
public static void ConvertPngToShp(string[] args)
|
||||||
{
|
{
|
||||||
var src = args[1];
|
var dest = args[1].Split('-').First() + ".shp";
|
||||||
var dest = Path.ChangeExtension(src, ".shp");
|
var frames = args.Skip(1).Select(a => PngLoader.Load(a));
|
||||||
var width = int.Parse(args[2]);
|
|
||||||
|
|
||||||
var srcImage = PngLoader.Load(src);
|
var size = frames.First().Size;
|
||||||
|
if (frames.Any(f => f.Size != size))
|
||||||
if (srcImage.Width % width != 0)
|
throw new InvalidOperationException("All frames must be the same size");
|
||||||
throw new InvalidOperationException("Bogus width; not a whole number of frames");
|
|
||||||
|
|
||||||
using (var destStream = File.Create(dest))
|
using (var destStream = File.Create(dest))
|
||||||
ShpReader.Write(destStream, width, srcImage.Height,
|
ShpReader.Write(destStream, size.Width, size.Height, frames.Select(f => f.ToBytes()));
|
||||||
srcImage.ToFrames(width));
|
|
||||||
|
|
||||||
Console.WriteLine(dest + " saved.");
|
Console.WriteLine(dest + " saved.");
|
||||||
}
|
}
|
||||||
|
|
||||||
static IEnumerable<byte[]> ToFrames(this Bitmap bitmap, int width)
|
static byte[] ToBytes(this Bitmap bitmap)
|
||||||
{
|
{
|
||||||
for (var x = 0; x < bitmap.Width; x += width)
|
var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly,
|
||||||
{
|
PixelFormat.Format8bppIndexed);
|
||||||
var data = bitmap.LockBits(new Rectangle(x, 0, width, bitmap.Height), ImageLockMode.ReadOnly,
|
|
||||||
PixelFormat.Format8bppIndexed);
|
|
||||||
|
|
||||||
var bytes = new byte[width * bitmap.Height];
|
var bytes = new byte[bitmap.Width * bitmap.Height];
|
||||||
for (var i = 0; i < bitmap.Height; i++)
|
for (var i = 0; i < bitmap.Height; i++)
|
||||||
Marshal.Copy(new IntPtr(data.Scan0.ToInt64() + i * data.Stride),
|
Marshal.Copy(new IntPtr(data.Scan0.ToInt64() + i * data.Stride),
|
||||||
bytes, i * width, width);
|
bytes, i * bitmap.Width, bitmap.Width);
|
||||||
|
|
||||||
bitmap.UnlockBits(data);
|
bitmap.UnlockBits(data);
|
||||||
|
|
||||||
yield return bytes;
|
return bytes;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ConvertShpToPng(string[] args)
|
public static void ConvertShpToPng(string[] args)
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ namespace OpenRA.Utility
|
|||||||
Console.WriteLine("Usage: OpenRA.Utility.exe [OPTION] [ARGS]");
|
Console.WriteLine("Usage: OpenRA.Utility.exe [OPTION] [ARGS]");
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
Console.WriteLine(" --settings-value KEY Get value of KEY from settings.yaml");
|
Console.WriteLine(" --settings-value KEY Get value of KEY from settings.yaml");
|
||||||
Console.WriteLine(" --shp PNGFILE FRAMEWIDTH Convert a single PNG with multiple frames appended after another to a SHP");
|
Console.WriteLine(" --shp PNGFILE [PNGFILE ...] Combine a list of PNG images into a SHP");
|
||||||
Console.WriteLine(" --png SPRITEFILE PALETTE [--noshadow] [--nopadding] Convert a shp/tmp/R8 to a series of PNGs, optionally removing shadow");
|
Console.WriteLine(" --png SPRITEFILE PALETTE [--noshadow] [--nopadding] Convert a shp/tmp/R8 to a series of PNGs, optionally removing shadow");
|
||||||
Console.WriteLine(" --fromd2 DUNE2SHP C&CSHP Convert a Dune II SHP (C&C mouse cursor) to C&C SHP format.");
|
Console.WriteLine(" --fromd2 DUNE2SHP C&CSHP Convert a Dune II SHP (C&C mouse cursor) to C&C SHP format.");
|
||||||
Console.WriteLine(" --extract MOD[,MOD]* FILES [--userdir] Extract files from mod packages to the current (or user) directory");
|
Console.WriteLine(" --extract MOD[,MOD]* FILES [--userdir] Extract files from mod packages to the current (or user) directory");
|
||||||
|
|||||||
Reference in New Issue
Block a user