Convert to 32bbp internally in FastCopyIntoSprite.

This avoids the need for callers to ensure the pixel format is correct, but ensures that the copying succeeds when the format is different.
This commit is contained in:
RoosterDragon
2015-04-17 18:44:17 +01:00
parent f77d6f6044
commit 9c93001c84
3 changed files with 24 additions and 26 deletions

View File

@@ -64,9 +64,15 @@ namespace OpenRA.Graphics
public static void FastCopyIntoSprite(Sprite dest, Bitmap src)
{
var createdTempBitmap = false;
if (src.PixelFormat != PixelFormat.Format32bppArgb)
throw new ArgumentException("src must have a PixelFormat of Format32bppArgb", "src");
{
src = src.CloneWith32bbpArgbPixelFormat();
createdTempBitmap = true;
}
try
{
var data = dest.Sheet.GetData();
var dataStride = dest.Sheet.Size.Width * 4;
var x = dest.Bounds.Left * 4;
@@ -80,6 +86,12 @@ namespace OpenRA.Graphics
Marshal.Copy(IntPtr.Add(bd.Scan0, row * bd.Stride), data, (y + row) * dataStride + x, width);
src.UnlockBits(bd);
}
finally
{
if (createdTempBitmap)
src.Dispose();
}
}
public static float[] IdentityMatrix()
{

View File

@@ -392,16 +392,8 @@ namespace OpenRA
DefaultSubCell = (SubCell)Game.ModData.Manifest.SubCellDefaultIndex;
if (Container.Exists("map.png"))
{
using (var dataStream = Container.GetContent("map.png"))
CustomPreview = new Bitmap(dataStream);
if (CustomPreview.PixelFormat != PixelFormat.Format32bppArgb)
{
var original = CustomPreview;
CustomPreview = original.CloneWith32bbpArgbPixelFormat();
original.Dispose();
}
}
PostInit();

View File

@@ -156,12 +156,6 @@ namespace OpenRA
SpawnPoints = spawns;
CustomPreview = new Bitmap(new MemoryStream(Convert.FromBase64String(r.minimap)));
if (CustomPreview.PixelFormat != PixelFormat.Format32bppArgb)
{
var original = CustomPreview;
CustomPreview = original.CloneWith32bbpArgbPixelFormat();
original.Dispose();
}
}
catch (Exception) { }