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,9 +64,15 @@ namespace OpenRA.Graphics
public static void FastCopyIntoSprite(Sprite dest, Bitmap src) public static void FastCopyIntoSprite(Sprite dest, Bitmap src)
{ {
var createdTempBitmap = false;
if (src.PixelFormat != PixelFormat.Format32bppArgb) 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 data = dest.Sheet.GetData();
var dataStride = dest.Sheet.Size.Width * 4; var dataStride = dest.Sheet.Size.Width * 4;
var x = dest.Bounds.Left * 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); Marshal.Copy(IntPtr.Add(bd.Scan0, row * bd.Stride), data, (y + row) * dataStride + x, width);
src.UnlockBits(bd); src.UnlockBits(bd);
} }
finally
{
if (createdTempBitmap)
src.Dispose();
}
}
public static float[] IdentityMatrix() public static float[] IdentityMatrix()
{ {

View File

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

View File

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