[ContentProcessor] class BitmapTextureProcessor : ContentProcessor { public override TextureContent Process(TextureContent input, ContentProcessorContext context) { // Convert the input to standard Color format, for ease of processing. input.ConvertBitmapType(typeof(PixelBitmapContent)); foreach (MipmapChain imageFace in input.Faces) { for (int i = 0; i < imageFace.Count; i++) { PixelBitmapContent mip = (PixelBitmapContent)imageFace[i]; // Apply color keying. mip.ReplaceColor(Color.Black, Color.TransparentBlack); // Make sure the image is a power of two in size. int width = MakePowerOfTwo(mip.Width); int height = MakePowerOfTwo(mip.Height); if ((width != mip.Width) || (height != mip.Height)) { context.Logger.LogWarning(null, input.Identity, "Bitmap was not a power of two. Scaled from {0}x{1} to {2}x{3}.", mip.Width, mip.Height, width, height); PixelBitmapContent scaledMip; scaledMip = new PixelBitmapContent(width, height); BitmapContent.Copy(mip, scaledMip); imageFace[i] = scaledMip; } } } input.GenerateMipmaps(false); // Compress the output texture. // input.ConvertBitmapType(typeof(Dxt1BitmapContent)); return input; } /// /// builds an external reference to a texture /// internal static ExternalReference BuildTexture(string file, ContentProcessorContext context) { ExternalReference tex = new ExternalReference(file); tex.Name = Path.GetFileNameWithoutExtension(file); return context.BuildAsset( tex, "BitmapTextureProcessor"); } static int MakePowerOfTwo(int value) { int bit = 1; while (bit < value) bit *= 2; return bit; } }