diff --git a/OpenRA.Editor/RenderUtils.cs b/OpenRA.Editor/RenderUtils.cs index cff5ad6b24..62b9d08e1b 100644 --- a/OpenRA.Editor/RenderUtils.cs +++ b/OpenRA.Editor/RenderUtils.cs @@ -18,17 +18,6 @@ namespace OpenRA.Editor { static class RenderUtils { - public static ColorPalette MakeSystemPalette(Palette p) - { - ColorPalette pal; - using (var b = new Bitmap(1, 1, PixelFormat.Format8bppIndexed)) - pal = b.Palette; - - for (var i = 0; i < 256; i++) - pal.Entries[i] = p.GetColor(i); - return pal; - } - public static Bitmap RenderTemplate(TileSet ts, ushort n, Palette p) { var template = ts.Templates[n]; @@ -37,7 +26,7 @@ namespace OpenRA.Editor var bitmap = new Bitmap(ts.TileSize * template.Size.X, ts.TileSize * template.Size.Y, PixelFormat.Format8bppIndexed); - bitmap.Palette = MakeSystemPalette(p); + bitmap.Palette = p.AsSystemPalette(); var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed); @@ -74,7 +63,7 @@ namespace OpenRA.Editor var bitmap = new Bitmap(shp.Width, shp.Height, PixelFormat.Format8bppIndexed); - bitmap.Palette = MakeSystemPalette(p); + bitmap.Palette = p.AsSystemPalette(); var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed); @@ -133,7 +122,7 @@ namespace OpenRA.Editor var frame = shp[shp.ImageCount - 1]; var bitmap = new Bitmap(shp.Width, shp.Height, PixelFormat.Format8bppIndexed); - bitmap.Palette = MakeSystemPalette(p); + bitmap.Palette = p.AsSystemPalette(); var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed); diff --git a/OpenRA.Editor/Surface.cs b/OpenRA.Editor/Surface.cs index 39b30747e9..e4150c825a 100755 --- a/OpenRA.Editor/Surface.cs +++ b/OpenRA.Editor/Surface.cs @@ -297,7 +297,7 @@ namespace OpenRA.Editor var pr = Map.Players[name]; var pcpi = Rules.Info["player"].Traits.Get(); var remap = new PlayerColorRemap(pr.ColorRamp, pcpi.PaletteFormat); - return RenderUtils.MakeSystemPalette(new Palette(Palette, remap)); + return new Palette(Palette, remap).AsSystemPalette(); } Cache PlayerPalettes; diff --git a/OpenRA.FileFormats/Palette.cs b/OpenRA.FileFormats/Palette.cs index b577fb56cc..8e1f1bc1cf 100644 --- a/OpenRA.FileFormats/Palette.cs +++ b/OpenRA.FileFormats/Palette.cs @@ -9,6 +9,7 @@ #endregion using System.Drawing; +using System.Drawing.Imaging; using System.IO; namespace OpenRA.FileFormats @@ -71,6 +72,17 @@ namespace OpenRA.FileFormats { colors = (uint[])p.colors.Clone(); } + + public ColorPalette AsSystemPalette() + { + ColorPalette pal; + using (var b = new Bitmap(1, 1, PixelFormat.Format8bppIndexed)) + pal = b.Palette; + + for (var i = 0; i < 256; i++) + pal.Entries[i] = GetColor(i); + return pal; + } } public interface IPaletteRemap { Color GetRemappedColor(Color original, int index); } diff --git a/OpenRA.Utility/Program.cs b/OpenRA.Utility/Program.cs index 49c3972986..58a24cef2c 100644 --- a/OpenRA.Utility/Program.cs +++ b/OpenRA.Utility/Program.cs @@ -58,7 +58,7 @@ namespace OpenRA.Utility Console.WriteLine(); Console.WriteLine(" --settings-value SUPPORTDIR KEY Get value of KEY in SUPPORTDIR/settings.yaml"); Console.WriteLine(" --shp PNGFILE FRAMEWIDTH Convert a PNG containing one or more frames to a SHP"); - Console.WriteLine(" --png SHPFILE Convert a SHP to a PNG containing all of its frames"); + Console.WriteLine(" --png SHPFILE PALETTE Convert a SHP to a PNG containing all of its frames"); } static T WithDefault(T def, Func f)