diff --git a/OpenRA.Game/FileFormats/R8Reader.cs b/OpenRA.Game/FileFormats/R8Reader.cs index 1448ee25b6..fdb6c78623 100644 --- a/OpenRA.Game/FileFormats/R8Reader.cs +++ b/OpenRA.Game/FileFormats/R8Reader.cs @@ -23,6 +23,7 @@ namespace OpenRA.FileFormats public Size FrameSize { get; private set; } public float2 Offset { get; private set; } public byte[] Data { get; set; } + public bool DisableExportPadding { get { return true; } } public R8Image(Stream s) { diff --git a/OpenRA.Game/FileFormats/ShpD2Reader.cs b/OpenRA.Game/FileFormats/ShpD2Reader.cs index 51231eb618..eb90db60ad 100644 --- a/OpenRA.Game/FileFormats/ShpD2Reader.cs +++ b/OpenRA.Game/FileFormats/ShpD2Reader.cs @@ -30,6 +30,7 @@ namespace OpenRA.FileFormats public Size FrameSize { get { return Size; } } public float2 Offset { get { return float2.Zero; } } public byte[] Data { get; set; } + public bool DisableExportPadding { get { return false; } } public Frame(Stream s) { diff --git a/OpenRA.Game/FileFormats/ShpReader.cs b/OpenRA.Game/FileFormats/ShpReader.cs index 173deb5ed6..87da8a92ef 100644 --- a/OpenRA.Game/FileFormats/ShpReader.cs +++ b/OpenRA.Game/FileFormats/ShpReader.cs @@ -27,6 +27,7 @@ namespace OpenRA.FileFormats public Size FrameSize { get { return reader.Size; } } public float2 Offset { get { return float2.Zero; } } public byte[] Data { get; set; } + public bool DisableExportPadding { get { return false; } } public uint FileOffset; public Format Format; diff --git a/OpenRA.Game/FileFormats/ShpTSReader.cs b/OpenRA.Game/FileFormats/ShpTSReader.cs index 6b067f0fcb..f45a412323 100644 --- a/OpenRA.Game/FileFormats/ShpTSReader.cs +++ b/OpenRA.Game/FileFormats/ShpTSReader.cs @@ -22,6 +22,7 @@ namespace OpenRA.FileFormats public Size FrameSize { get; private set; } public float2 Offset { get; private set; } public byte[] Data { get; set; } + public bool DisableExportPadding { get { return false; } } public readonly uint FileOffset; public readonly byte Format; diff --git a/OpenRA.Game/FileFormats/TmpTDReader.cs b/OpenRA.Game/FileFormats/TmpTDReader.cs index 540d63c6af..44e8ca0872 100644 --- a/OpenRA.Game/FileFormats/TmpTDReader.cs +++ b/OpenRA.Game/FileFormats/TmpTDReader.cs @@ -20,6 +20,7 @@ namespace OpenRA.FileFormats public Size FrameSize { get; private set; } public float2 Offset { get { return float2.Zero; } } public byte[] Data { get; set; } + public bool DisableExportPadding { get { return false; } } public TmpTile(byte[] data, Size size) { diff --git a/OpenRA.Game/FileFormats/TmpTSReader.cs b/OpenRA.Game/FileFormats/TmpTSReader.cs index e6fdb4a7b9..6ad7f6388d 100644 --- a/OpenRA.Game/FileFormats/TmpTSReader.cs +++ b/OpenRA.Game/FileFormats/TmpTSReader.cs @@ -21,6 +21,7 @@ namespace OpenRA.FileFormats public Size FrameSize { get { return Size; } } public float2 Offset { get { return float2.Zero; } } public byte[] Data { get; set; } + public bool DisableExportPadding { get { return false; } } public TmpTSTile(Stream s, Size size) { diff --git a/OpenRA.Game/Graphics/SpriteSource.cs b/OpenRA.Game/Graphics/SpriteSource.cs index 0434fd1bde..e930660e49 100644 --- a/OpenRA.Game/Graphics/SpriteSource.cs +++ b/OpenRA.Game/Graphics/SpriteSource.cs @@ -20,6 +20,7 @@ namespace OpenRA.Graphics Size FrameSize { get; } float2 Offset { get; } byte[] Data { get; } + bool DisableExportPadding { get; } } public interface ISpriteSource diff --git a/OpenRA.Mods.Common/UtilityCommands/ConvertSpriteToPngCommand.cs b/OpenRA.Mods.Common/UtilityCommands/ConvertSpriteToPngCommand.cs index 16fac878aa..7b6d1ba2cf 100644 --- a/OpenRA.Mods.Common/UtilityCommands/ConvertSpriteToPngCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/ConvertSpriteToPngCommand.cs @@ -41,19 +41,17 @@ namespace OpenRA.Mods.Common.UtilityCommands var palette = new ImmutablePalette(args[2], shadowIndex); - ISpriteSource source; - using (var stream = File.OpenRead(src)) - source = SpriteSource.LoadSpriteSource(stream, src); + var frames = new SpriteLoader(new string[0], null) + .LoadAllFrames(src); - // The r8 padding requires external information that we can't access here. - var usePadding = !(args.Contains("--nopadding") || source is R8Reader); + var usePadding = !args.Contains("--nopadding"); var count = 0; var prefix = Path.GetFileNameWithoutExtension(src); - foreach (var frame in source.Frames) + foreach (var frame in frames) { - var frameSize = usePadding ? frame.FrameSize : frame.Size; - var offset = usePadding ? (frame.Offset - 0.5f * new float2(frame.Size - frame.FrameSize)).ToInt2() : int2.Zero; + var frameSize = usePadding && !frame.DisableExportPadding ? frame.FrameSize : frame.Size; + var offset = usePadding && !frame.DisableExportPadding ? (frame.Offset - 0.5f * new float2(frame.Size - frame.FrameSize)).ToInt2() : int2.Zero; // shp(ts) may define empty frames if (frameSize.Width == 0 && frameSize.Height == 0) @@ -69,7 +67,7 @@ namespace OpenRA.Mods.Common.UtilityCommands ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed); // Clear the frame - if (usePadding) + if (usePadding && !frame.DisableExportPadding) { var clearRow = new byte[data.Stride]; for (var i = 0; i < frameSize.Height; i++)