move MakeSystemPalette out of editor.RenderUtils; rename to Palette.AsSystemPalette()

This commit is contained in:
Chris Forbes
2011-05-07 18:18:32 +12:00
parent e839ae33d8
commit a0e015746f
4 changed files with 17 additions and 16 deletions

View File

@@ -18,17 +18,6 @@ namespace OpenRA.Editor
{ {
static class RenderUtils 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) public static Bitmap RenderTemplate(TileSet ts, ushort n, Palette p)
{ {
var template = ts.Templates[n]; 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, var bitmap = new Bitmap(ts.TileSize * template.Size.X, ts.TileSize * template.Size.Y,
PixelFormat.Format8bppIndexed); PixelFormat.Format8bppIndexed);
bitmap.Palette = MakeSystemPalette(p); bitmap.Palette = p.AsSystemPalette();
var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed); ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
@@ -74,7 +63,7 @@ namespace OpenRA.Editor
var bitmap = new Bitmap(shp.Width, shp.Height, PixelFormat.Format8bppIndexed); 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), var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed); ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
@@ -133,7 +122,7 @@ namespace OpenRA.Editor
var frame = shp[shp.ImageCount - 1]; var frame = shp[shp.ImageCount - 1];
var bitmap = new Bitmap(shp.Width, shp.Height, PixelFormat.Format8bppIndexed); 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), var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed); ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);

View File

@@ -297,7 +297,7 @@ namespace OpenRA.Editor
var pr = Map.Players[name]; var pr = Map.Players[name];
var pcpi = Rules.Info["player"].Traits.Get<PlayerColorPaletteInfo>(); var pcpi = Rules.Info["player"].Traits.Get<PlayerColorPaletteInfo>();
var remap = new PlayerColorRemap(pr.ColorRamp, pcpi.PaletteFormat); var remap = new PlayerColorRemap(pr.ColorRamp, pcpi.PaletteFormat);
return RenderUtils.MakeSystemPalette(new Palette(Palette, remap)); return new Palette(Palette, remap).AsSystemPalette();
} }
Cache<string, ColorPalette> PlayerPalettes; Cache<string, ColorPalette> PlayerPalettes;

View File

@@ -9,6 +9,7 @@
#endregion #endregion
using System.Drawing; using System.Drawing;
using System.Drawing.Imaging;
using System.IO; using System.IO;
namespace OpenRA.FileFormats namespace OpenRA.FileFormats
@@ -71,6 +72,17 @@ namespace OpenRA.FileFormats
{ {
colors = (uint[])p.colors.Clone(); 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); } public interface IPaletteRemap { Color GetRemappedColor(Color original, int index); }

View File

@@ -58,7 +58,7 @@ namespace OpenRA.Utility
Console.WriteLine(); Console.WriteLine();
Console.WriteLine(" --settings-value SUPPORTDIR KEY Get value of KEY in SUPPORTDIR/settings.yaml"); 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(" --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>(T def, Func<T> f) static T WithDefault<T>(T def, Func<T> f)