Skip to content

Commit

Permalink
tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisforbes committed Dec 27, 2011
1 parent f812204 commit d57dfd1
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 19 deletions.
4 changes: 2 additions & 2 deletions OpenRA.Editor/RenderUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static Bitmap RenderShp(ShpReader shp, Palette p)

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
Expand Down Expand Up @@ -84,7 +84,7 @@ public static ResourceTemplate RenderResourceType(ResourceTypeInfo info, string[

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
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Editor/Surface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ Bitmap RenderChunk(int u, int v)

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
Expand All @@ -234,7 +234,7 @@ Bitmap RenderChunk(int u, int v)
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();
Expand Down
4 changes: 4 additions & 0 deletions OpenRA.FileFormats/Exts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ public static int NextPowerOf2(int v)
return v;
}

public static Size NextPowerOf2(this Size s) { return new Size(NextPowerOf2(s.Width), NextPowerOf2(s.Height)); }

public static string JoinWith<T>(this IEnumerable<T> ts, string j)
{
return string.Join(j, ts.Select(t => t.ToString()).ToArray());
Expand Down Expand Up @@ -199,6 +201,8 @@ public static T[] MakeArray<T>(int count, Func<int, T> f)

return result;
}

public static Rectangle Bounds(this Bitmap b) { return new Rectangle(0, 0, b.Width, b.Height); }
}

public static class Enum<T>
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.FileFormats/Graphics/PngLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static Bitmap Load(Stream s)

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()))
Expand Down
1 change: 0 additions & 1 deletion OpenRA.FileFormats/Graphics/ShpReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/
#endregion

using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.FileFormats/Map/TileSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public Bitmap RenderTemplate(ushort n, Palette p)

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
Expand Down
12 changes: 5 additions & 7 deletions OpenRA.Game/Graphics/Minimap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ public static Bitmap TerrainBitmap(Map map, bool actualSize)
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
Expand Down Expand Up @@ -69,7 +67,7 @@ public static Bitmap AddStaticResources(Map map, Bitmap terrainBitmap)
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
Expand Down Expand Up @@ -104,7 +102,7 @@ public static Bitmap CustomTerrainBitmap(World world)
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
Expand Down Expand Up @@ -132,7 +130,7 @@ public static Bitmap ActorsBitmap(World world)
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
Expand Down Expand Up @@ -163,7 +161,7 @@ public static Bitmap ShroudBitmap(World world)
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();
Expand Down
2 changes: 2 additions & 0 deletions OpenRA.Game/ModData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ Dictionary<string, Map> FindMaps(string[] mods)
.Concat(mods.SelectMany(p => FindMapsIn("{1}maps{0}{2}{0}".F(Path.DirectorySeparatorChar, Platform.SupportDir, p))));

var ret = new Dictionary<string, Map>();

foreach (var path in paths)
{
try
Expand All @@ -113,6 +114,7 @@ Dictionary<string, Map> FindMaps(string[] mods)
Console.WriteLine("Details: {0}", e.ToString());
}
}

return ret;
}

Expand Down
5 changes: 2 additions & 3 deletions OpenRA.Renderer.SdlCommon/Texture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,10 @@ public void SetData(Bitmap bitmap)
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);

Expand Down
3 changes: 1 addition & 2 deletions OpenRA.TilesetBuilder/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,7 @@ string ExportTemplate(Template t, int n, string suffix, string dir)

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
{
Expand Down

0 comments on commit d57dfd1

Please sign in to comment.