This commit is contained in:
Chris Forbes
2011-12-27 18:13:04 +13:00
parent f8122047b6
commit d57dfd1997
10 changed files with 20 additions and 19 deletions

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Editor
bitmap.Palette = p.AsSystemPalette(); 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); ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
unsafe unsafe
@@ -84,7 +84,7 @@ namespace OpenRA.Editor
var bitmap = new Bitmap(shp.Width, shp.Height, PixelFormat.Format8bppIndexed); var bitmap = new Bitmap(shp.Width, shp.Height, PixelFormat.Format8bppIndexed);
bitmap.Palette = p.AsSystemPalette(); 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); ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
unsafe unsafe

View File

@@ -212,7 +212,7 @@ namespace OpenRA.Editor
var bitmap = new Bitmap(ChunkSize * TileSet.TileSize, ChunkSize * TileSet.TileSize); 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); ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
unsafe unsafe
@@ -234,7 +234,7 @@ namespace OpenRA.Editor
if (Map.MapResources.Value[u * ChunkSize + i, v * ChunkSize + j].type != 0) 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 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); ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
int* q = (int*)srcdata.Scan0.ToPointer(); int* q = (int*)srcdata.Scan0.ToPointer();

View File

@@ -172,6 +172,8 @@ namespace OpenRA
return 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) public static string JoinWith<T>(this IEnumerable<T> ts, string j)
{ {
return string.Join(j, ts.Select(t => t.ToString()).ToArray()); return string.Join(j, ts.Select(t => t.ToString()).ToArray());
@@ -199,6 +201,8 @@ namespace OpenRA
return result; return result;
} }
public static Rectangle Bounds(this Bitmap b) { return new Rectangle(0, 0, b.Width, b.Height); }
} }
public static class Enum<T> public static class Enum<T>

View File

@@ -97,7 +97,7 @@ namespace OpenRA.FileFormats.Graphics
case "IEND": case "IEND":
{ {
var bits = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), var bits = bitmap.LockBits(bitmap.Bounds(),
ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed); ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
using (var ns = new MemoryStream(data.ToArray())) using (var ns = new MemoryStream(data.ToArray()))

View File

@@ -8,7 +8,6 @@
*/ */
#endregion #endregion
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;

View File

@@ -166,7 +166,7 @@ namespace OpenRA.FileFormats
bitmap.Palette = p.AsSystemPalette(); 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); ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
unsafe unsafe

View File

@@ -32,13 +32,11 @@ namespace OpenRA.Graphics
var height = map.Bounds.Height; var height = map.Bounds.Height;
if (!actualSize) if (!actualSize)
{
width = height = Exts.NextPowerOf2(Math.Max(map.Bounds.Width, map.Bounds.Height)); width = height = Exts.NextPowerOf2(Math.Max(map.Bounds.Width, map.Bounds.Height));
}
var terrain = new Bitmap(width, 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); ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
unsafe unsafe
@@ -69,7 +67,7 @@ namespace OpenRA.Graphics
Bitmap terrain = new Bitmap(terrainBitmap); Bitmap terrain = new Bitmap(terrainBitmap);
var tileset = Rules.TileSets[map.Tileset]; 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); ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
unsafe unsafe
@@ -104,7 +102,7 @@ namespace OpenRA.Graphics
var map = world.Map; var map = world.Map;
var size = Exts.NextPowerOf2(Math.Max(map.Bounds.Width, map.Bounds.Height)); var size = Exts.NextPowerOf2(Math.Max(map.Bounds.Width, map.Bounds.Height));
var bitmap = new Bitmap(size, size); 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); ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
unsafe unsafe
@@ -132,7 +130,7 @@ namespace OpenRA.Graphics
var map = world.Map; var map = world.Map;
var size = Exts.NextPowerOf2(Math.Max(map.Bounds.Width, map.Bounds.Height)); var size = Exts.NextPowerOf2(Math.Max(map.Bounds.Width, map.Bounds.Height));
var bitmap = new Bitmap(size, size); 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); ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
unsafe unsafe
@@ -163,7 +161,7 @@ namespace OpenRA.Graphics
if (world.LocalShroud.Disabled) if (world.LocalShroud.Disabled)
return bitmap; return bitmap;
var bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), var bitmapData = bitmap.LockBits(bitmap.Bounds(),
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
var shroud = Color.Black.ToArgb(); var shroud = Color.Black.ToArgb();

View File

@@ -100,6 +100,7 @@ namespace OpenRA
.Concat(mods.SelectMany(p => FindMapsIn("{1}maps{0}{2}{0}".F(Path.DirectorySeparatorChar, Platform.SupportDir, p)))); .Concat(mods.SelectMany(p => FindMapsIn("{1}maps{0}{2}{0}".F(Path.DirectorySeparatorChar, Platform.SupportDir, p))));
var ret = new Dictionary<string, Map>(); var ret = new Dictionary<string, Map>();
foreach (var path in paths) foreach (var path in paths)
{ {
try try
@@ -113,6 +114,7 @@ namespace OpenRA
Console.WriteLine("Details: {0}", e.ToString()); Console.WriteLine("Details: {0}", e.ToString());
} }
} }
return ret; return ret;
} }

View File

@@ -99,11 +99,10 @@ namespace OpenRA.Renderer.SdlCommon
if (!IsPowerOf2(bitmap.Width) || !IsPowerOf2(bitmap.Height)) if (!IsPowerOf2(bitmap.Width) || !IsPowerOf2(bitmap.Height))
{ {
//throw new InvalidOperationException( "non-power-of-2-texture" ); //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( var bits = bitmap.LockBits(bitmap.Bounds(),
new Rectangle(0, 0, bitmap.Width, bitmap.Height),
ImageLockMode.ReadOnly, ImageLockMode.ReadOnly,
PixelFormat.Format32bppArgb); PixelFormat.Format32bppArgb);

View File

@@ -219,8 +219,7 @@ namespace OpenRA.TilesetBuilder
var src = surface1.Image; var src = surface1.Image;
var data = src.LockBits(new Rectangle(0, 0, src.Width, src.Height), var data = src.LockBits(src.Bounds(), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
unsafe unsafe
{ {