private void FixGhostTexture()
{
// textureOrig is the original greyscale image.
SurfaceDescription desc;
desc = textureOrig.GetLevelDescription(0);
Texture textureCopy = new Texture(dev, desc.Width, desc.Height, 1, 0, desc.Format, Pool.Managed);
Surface dst = textureCopy.GetSurfaceLevel(0);
Surface src = textureOrig.GetSurfaceLevel(0);
SurfaceLoader.FromSurface(dst, src, Filter.None, 0);
desc = textureOrig.GetLevelDescription(0);
// Get the bits for the surface and re-color them
ColorType[] c = (ColorType[])dst.LockRectangle(typeof(ColorType), LockFlags.None, desc.Width * desc.Height);
ColorType c1;
switch(ghost.Type)
{
case GhostType.Red: c1 = new ColorType(Color.Red); break;
case GhostType.Blue: c1 = new ColorType(Color.LightBlue); break;
case GhostType.Orange: c1 = new ColorType(Color.Orange); break;
default : c1 = new ColorType(Color.Pink); break;
}
// hard-code offsets of 56 and 96 because this UI class knows where the sprite lives in the bitmap
for(int y=56; y<56+Ghost.GhostPixelHeight; y++)
{
for(int x=96; x<96+(Ghost.GhostPixelWidth * 2); x++)
{
// The ghost consists of two colors, either all white (255, 255, 255)
// or all black(0, 0, 0). By checking the first byte, we
// know which color this pixel is and can choose the appropriate
// new color.
// Note that the pixels are stored in BGRA format (A is for Alpha)
if(c[y * desc.Width + x].r==255)
{
c[y * 256 + x] = c1;
}
} // for x
} // for y
dst.UnlockRectangle();
sprGhost.Texture = textureCopy;
}