diff --git a/OpenRA.Editor/RenderUtils.cs b/OpenRA.Editor/RenderUtils.cs index df62f0730f..6b29709bfc 100644 --- a/OpenRA.Editor/RenderUtils.cs +++ b/OpenRA.Editor/RenderUtils.cs @@ -26,7 +26,7 @@ namespace OpenRA.Editor bitmap.Palette = p.AsSystemPalette(); - var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), + var data = bitmap.LockBits(bitmap.Bounds(), ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed); unsafe @@ -84,7 +84,7 @@ namespace OpenRA.Editor var bitmap = new Bitmap(shp.Width, shp.Height, PixelFormat.Format8bppIndexed); bitmap.Palette = p.AsSystemPalette(); - var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), + var data = bitmap.LockBits(bitmap.Bounds(), ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed); unsafe diff --git a/OpenRA.Editor/Surface.cs b/OpenRA.Editor/Surface.cs index de3bf46db5..7cad793e53 100755 --- a/OpenRA.Editor/Surface.cs +++ b/OpenRA.Editor/Surface.cs @@ -212,7 +212,7 @@ namespace OpenRA.Editor var bitmap = new Bitmap(ChunkSize * TileSet.TileSize, ChunkSize * TileSet.TileSize); - var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), + var data = bitmap.LockBits(bitmap.Bounds(), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); unsafe @@ -234,7 +234,7 @@ namespace OpenRA.Editor if (Map.MapResources.Value[u * ChunkSize + i, v * ChunkSize + j].type != 0) { var resourceImage = ResourceTemplates[Map.MapResources.Value[u * ChunkSize + i, v * ChunkSize + j].type].Bitmap; - var srcdata = resourceImage.LockBits(new Rectangle(0, 0, resourceImage.Width, resourceImage.Height), + var srcdata = resourceImage.LockBits(resourceImage.Bounds(), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); int* q = (int*)srcdata.Scan0.ToPointer(); diff --git a/OpenRA.FileFormats/Exts.cs b/OpenRA.FileFormats/Exts.cs index 65a05b8423..af4321cb39 100755 --- a/OpenRA.FileFormats/Exts.cs +++ b/OpenRA.FileFormats/Exts.cs @@ -172,6 +172,8 @@ namespace OpenRA return v; } + public static Size NextPowerOf2(this Size s) { return new Size(NextPowerOf2(s.Width), NextPowerOf2(s.Height)); } + public static string JoinWith(this IEnumerable ts, string j) { return string.Join(j, ts.Select(t => t.ToString()).ToArray()); @@ -199,6 +201,8 @@ namespace OpenRA return result; } + + public static Rectangle Bounds(this Bitmap b) { return new Rectangle(0, 0, b.Width, b.Height); } } public static class Enum diff --git a/OpenRA.FileFormats/Graphics/PngLoader.cs b/OpenRA.FileFormats/Graphics/PngLoader.cs index cb77264513..6b7b0e75cb 100644 --- a/OpenRA.FileFormats/Graphics/PngLoader.cs +++ b/OpenRA.FileFormats/Graphics/PngLoader.cs @@ -97,7 +97,7 @@ namespace OpenRA.FileFormats.Graphics case "IEND": { - var bits = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), + var bits = bitmap.LockBits(bitmap.Bounds(), ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed); using (var ns = new MemoryStream(data.ToArray())) diff --git a/OpenRA.FileFormats/Graphics/ShpReader.cs b/OpenRA.FileFormats/Graphics/ShpReader.cs index 7b610140b2..2ccf5d76e1 100644 --- a/OpenRA.FileFormats/Graphics/ShpReader.cs +++ b/OpenRA.FileFormats/Graphics/ShpReader.cs @@ -8,7 +8,6 @@ */ #endregion -using System.Collections; using System.Collections.Generic; using System.Drawing; using System.IO; diff --git a/OpenRA.FileFormats/Map/TileSet.cs b/OpenRA.FileFormats/Map/TileSet.cs index c1dd4a3925..c6a030b5f0 100644 --- a/OpenRA.FileFormats/Map/TileSet.cs +++ b/OpenRA.FileFormats/Map/TileSet.cs @@ -166,7 +166,7 @@ namespace OpenRA.FileFormats bitmap.Palette = p.AsSystemPalette(); - var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), + var data = bitmap.LockBits(bitmap.Bounds(), ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed); unsafe diff --git a/OpenRA.Game/Graphics/Minimap.cs b/OpenRA.Game/Graphics/Minimap.cs index 6569663898..deb50a8494 100644 --- a/OpenRA.Game/Graphics/Minimap.cs +++ b/OpenRA.Game/Graphics/Minimap.cs @@ -32,13 +32,11 @@ namespace OpenRA.Graphics var height = map.Bounds.Height; if (!actualSize) - { width = height = Exts.NextPowerOf2(Math.Max(map.Bounds.Width, map.Bounds.Height)); - } var terrain = new Bitmap(width, height); - var bitmapData = terrain.LockBits(new Rectangle(0, 0, terrain.Width, terrain.Height), + var bitmapData = terrain.LockBits(terrain.Bounds(), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); unsafe @@ -69,7 +67,7 @@ namespace OpenRA.Graphics Bitmap terrain = new Bitmap(terrainBitmap); var tileset = Rules.TileSets[map.Tileset]; - var bitmapData = terrain.LockBits(new Rectangle(0, 0, terrain.Width, terrain.Height), + var bitmapData = terrain.LockBits(terrain.Bounds(), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); unsafe @@ -104,7 +102,7 @@ namespace OpenRA.Graphics var map = world.Map; var size = Exts.NextPowerOf2(Math.Max(map.Bounds.Width, map.Bounds.Height)); var bitmap = new Bitmap(size, size); - var bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), + var bitmapData = bitmap.LockBits(bitmap.Bounds(), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); unsafe @@ -132,7 +130,7 @@ namespace OpenRA.Graphics var map = world.Map; var size = Exts.NextPowerOf2(Math.Max(map.Bounds.Width, map.Bounds.Height)); var bitmap = new Bitmap(size, size); - var bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), + var bitmapData = bitmap.LockBits(bitmap.Bounds(), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); unsafe @@ -163,7 +161,7 @@ namespace OpenRA.Graphics if (world.LocalShroud.Disabled) return bitmap; - var bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), + var bitmapData = bitmap.LockBits(bitmap.Bounds(), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); var shroud = Color.Black.ToArgb(); diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs index 04e088b8b1..c8770da6b5 100755 --- a/OpenRA.Game/ModData.cs +++ b/OpenRA.Game/ModData.cs @@ -100,6 +100,7 @@ namespace OpenRA .Concat(mods.SelectMany(p => FindMapsIn("{1}maps{0}{2}{0}".F(Path.DirectorySeparatorChar, Platform.SupportDir, p)))); var ret = new Dictionary(); + foreach (var path in paths) { try @@ -113,6 +114,7 @@ namespace OpenRA Console.WriteLine("Details: {0}", e.ToString()); } } + return ret; } diff --git a/OpenRA.Renderer.SdlCommon/Texture.cs b/OpenRA.Renderer.SdlCommon/Texture.cs index 85b87d5f55..82a34af274 100644 --- a/OpenRA.Renderer.SdlCommon/Texture.cs +++ b/OpenRA.Renderer.SdlCommon/Texture.cs @@ -99,11 +99,10 @@ namespace OpenRA.Renderer.SdlCommon if (!IsPowerOf2(bitmap.Width) || !IsPowerOf2(bitmap.Height)) { //throw new InvalidOperationException( "non-power-of-2-texture" ); - bitmap = new Bitmap(bitmap, new Size(Exts.NextPowerOf2(bitmap.Width), Exts.NextPowerOf2(bitmap.Height))); + bitmap = new Bitmap(bitmap, bitmap.Size.NextPowerOf2()); } - var bits = bitmap.LockBits( - new Rectangle(0, 0, bitmap.Width, bitmap.Height), + var bits = bitmap.LockBits(bitmap.Bounds(), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); diff --git a/OpenRA.TilesetBuilder/Form1.cs b/OpenRA.TilesetBuilder/Form1.cs index 8147f7aa25..1c1c084360 100644 --- a/OpenRA.TilesetBuilder/Form1.cs +++ b/OpenRA.TilesetBuilder/Form1.cs @@ -219,8 +219,7 @@ namespace OpenRA.TilesetBuilder var src = surface1.Image; - var data = src.LockBits(new Rectangle(0, 0, src.Width, src.Height), - ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed); + var data = src.LockBits(src.Bounds(), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed); unsafe {