use byte[] backing for Sheet. bitmap backing is still available for Chrome RGBA hack.

This commit is contained in:
Chris Forbes
2010-08-19 19:22:03 +12:00
parent 1595c6a0ed
commit 0a041fe425
4 changed files with 23 additions and 40 deletions

View File

@@ -52,7 +52,7 @@ namespace OpenRA.Graphics
} }
else if (bitmap != null) else if (bitmap != null)
{ {
texture.SetData(Bitmap); texture.SetData(bitmap);
dirty = false; dirty = false;
} }
} }
@@ -61,9 +61,7 @@ namespace OpenRA.Graphics
} }
} }
public Bitmap Bitmap { get { if (bitmap == null) bitmap = new Bitmap(Size.Width, Size.Height); return bitmap; } }
public byte[] Data { get { if (data == null) data = new byte[4 * Size.Width * Size.Height]; return data; } } public byte[] Data { get { if (data == null) data = new byte[4 * Size.Width * Size.Height]; return data; } }
public void MakeDirty() { dirty = true; } public void MakeDirty() { dirty = true; }
} }
} }

View File

@@ -68,8 +68,6 @@ namespace OpenRA.Graphics
"chrome"); "chrome");
p.X += g.Advance; p.X += g.Advance;
} }
// r.Flush();
} }
public int2 Measure(string text) public int2 Measure(string text)
@@ -100,13 +98,20 @@ namespace OpenRA.Graphics
unsafe unsafe
{ {
var p = (byte*)_glyph.bitmap.buffer; var p = (byte*)_glyph.bitmap.buffer;
var dest = s.sheet.Data;
var destStride = s.sheet.Size.Width * 4;
for (var j = 0; j < s.size.Y; j++) for (var j = 0; j < s.size.Y; j++)
{ {
for (var i = 0; i < s.size.X; i++) for (var i = 0; i < s.size.X; i++)
if (p[i] != 0) if (p[i] != 0)
s.sheet.Bitmap.SetPixel(i + s.bounds.Left, j + s.bounds.Top, {
Color.FromArgb(p[i], c.Second.R, c.Second.G, c.Second.B)); var q = destStride * (j + s.bounds.Top) + 4 * (i + s.bounds.Left);
dest[q] = c.Second.B;
dest[q + 1] = c.Second.G;
dest[q + 2] = c.Second.R;
dest[q + 3] = p[i];
}
p += _glyph.bitmap.pitch; p += _glyph.bitmap.pitch;
} }

View File

@@ -17,7 +17,6 @@ namespace OpenRA.Graphics
{ {
public static void Initialize( TileSet tileset ) public static void Initialize( TileSet tileset )
{ {
/* .tem: hack to allow incomplete theaters (interior) to work, falling back to temperate for the missing art */
exts = tileset.Extensions; exts = tileset.Extensions;
sprites = new Cache<string, Sprite[]>( LoadSprites ); sprites = new Cache<string, Sprite[]>( LoadSprites );
} }

View File

@@ -65,42 +65,23 @@ namespace OpenRA.Graphics
public static void FastCopyIntoChannel(Sprite dest, byte[] src) public static void FastCopyIntoChannel(Sprite dest, byte[] src)
{ {
var bitmap = dest.sheet.Bitmap; var masks = new int[] { 2, 1, 0, 3 }; // hack, our channel order is nuts.
BitmapData bits = null; var data = dest.sheet.Data;
uint[] channelMasks = { 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }; var srcStride = dest.bounds.Width;
int[] shifts = { 16, 8, 0, 24 }; var destStride = dest.sheet.Size.Width * 4;
var destOffset = destStride * dest.bounds.Top + dest.bounds.Left * 4 + masks[(int)dest.channel];
var destSkip = destStride - 4 * srcStride;
var height = dest.bounds.Height;
uint mask = channelMasks[(int)dest.channel]; var srcOffset = 0;
int shift = shifts[(int)dest.channel]; for (var j = 0; j < height; j++)
try
{ {
bits = bitmap.LockBits(dest.bounds, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); for (int i = 0; i < srcStride; i++, srcOffset++)
int width = dest.bounds.Width;
int height = dest.bounds.Height;
unsafe
{ {
fixed (byte* srcbase = &src[0]) data[destOffset] = src[srcOffset];
{ destOffset += 4;
byte* s = srcbase;
uint* t = (uint*)bits.Scan0.ToPointer();
int stride = bits.Stride >> 2;
for (int j = 0; j < height; j++)
{
uint* p = t;
for (int i = 0; i < width; i++, p++)
*p = (*p & ~mask) | ((mask & ((uint)*s++) << shift));
t += stride;
} }
} destOffset += destSkip;
}
}
finally
{
bitmap.UnlockBits(bits);
} }
} }