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:
@@ -64,21 +64,33 @@ 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;
|
||||
}
|
||||
|
||||
var data = dest.Sheet.GetData();
|
||||
var dataStride = dest.Sheet.Size.Width * 4;
|
||||
var x = dest.Bounds.Left * 4;
|
||||
var width = dest.Bounds.Width * 4;
|
||||
var y = dest.Bounds.Top;
|
||||
var height = dest.Bounds.Height;
|
||||
try
|
||||
{
|
||||
var data = dest.Sheet.GetData();
|
||||
var dataStride = dest.Sheet.Size.Width * 4;
|
||||
var x = dest.Bounds.Left * 4;
|
||||
var width = dest.Bounds.Width * 4;
|
||||
var y = dest.Bounds.Top;
|
||||
var height = dest.Bounds.Height;
|
||||
|
||||
var bd = src.LockBits(src.Bounds(),
|
||||
ImageLockMode.ReadWrite, src.PixelFormat);
|
||||
for (var row = 0; row < height; row++)
|
||||
Marshal.Copy(IntPtr.Add(bd.Scan0, row * bd.Stride), data, (y + row) * dataStride + x, width);
|
||||
src.UnlockBits(bd);
|
||||
var bd = src.LockBits(src.Bounds(),
|
||||
ImageLockMode.ReadWrite, src.PixelFormat);
|
||||
for (var row = 0; row < height; row++)
|
||||
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()
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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) { }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user