MOAR PERF
git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1929 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
@@ -27,6 +27,9 @@ namespace OpenRa.FileFormats
|
||||
|
||||
bool ProcessSection( string line )
|
||||
{
|
||||
if (string.IsNullOrEmpty(line) || line.StartsWith(";"))
|
||||
return false;
|
||||
|
||||
Match m = sectionPattern.Match( line );
|
||||
if( m == null || !m.Success )
|
||||
return false;
|
||||
|
||||
@@ -89,7 +89,10 @@ namespace OpenRa.Game
|
||||
var bitmap = dest.sheet.Bitmap;
|
||||
BitmapData bits = null;
|
||||
uint[] channelMasks = { 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 };
|
||||
int[] shifts = { 16, 8, 0, 24 };
|
||||
|
||||
uint mask = channelMasks[(int)dest.channel];
|
||||
int shift = shifts[(int)dest.channel];
|
||||
|
||||
try
|
||||
{
|
||||
@@ -98,13 +101,24 @@ namespace OpenRa.Game
|
||||
int width = dest.bounds.Width;
|
||||
int height = dest.bounds.Height;
|
||||
|
||||
unsafe
|
||||
{
|
||||
fixed (byte* srcbase = &src[0])
|
||||
{
|
||||
byte* s = srcbase;
|
||||
uint * t = (uint*)bits.Scan0.ToPointer();
|
||||
int stride = bits.Stride >> 2;
|
||||
|
||||
for (int j = 0; j < height; j++)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
uint* p = (uint*)(bits.Scan0.ToInt32() + j * bits.Stride);
|
||||
uint* p = t;
|
||||
for (int i = 0; i < width; i++, p++)
|
||||
*p = ReplaceChannel(*p, mask, src[i + width * j]);
|
||||
*p = (*p & ~mask) | ((mask & ((uint)*s++) << shift));
|
||||
t += stride;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -113,18 +127,5 @@ namespace OpenRa.Game
|
||||
bitmap.UnlockBits(bits);
|
||||
}
|
||||
}
|
||||
|
||||
static uint ReplaceChannel(uint o, uint mask, byte p)
|
||||
{
|
||||
uint pp = (uint)p;
|
||||
|
||||
pp |= pp << 8; // copy into all channels
|
||||
pp |= pp << 16;
|
||||
|
||||
o &= ~mask;
|
||||
o |= (mask & pp);
|
||||
|
||||
return o;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user