Merge pull request #7951 from RoosterDragon/fix-browser-images

Fix mod browser previews
This commit is contained in:
Oliver Brakmann
2015-04-17 21:52:38 +02:00
3 changed files with 24 additions and 26 deletions

View File

@@ -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()

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) { }