public static unsafe Bitmap Decode(SubTexture subTexture) { var bitmap = new Bitmap(subTexture.Width, subTexture.Height); var rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height); if (subTexture.Format == TextureFormat.RGB) { var bitmapData = bitmap.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb); fixed(byte *ptr = subTexture.Data) { RGBtoBGR(ptr, ( byte * )bitmapData.Scan0, subTexture.Data.Length); } bitmap.UnlockBits(bitmapData); } else if (subTexture.Format == TextureFormat.RGBA) { var bitmapData = bitmap.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); fixed(byte *ptr = subTexture.Data) { ByteRGBAToInt32(ptr, ( int * )bitmapData.Scan0, subTexture.Data.Length); } bitmap.UnlockBits(bitmapData); } else if (subTexture.Format == TextureFormat.RGBA4) { var bitmapData = bitmap.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); fixed(byte *ptr = subTexture.Data) { RGBA4toRGBA(ptr, ( int * )bitmapData.Scan0, subTexture.Data.Length); } bitmap.UnlockBits(bitmapData); } else { var buffer = DDSCodec.DecompressPixelDataToRGBA(subTexture.Data, subTexture.Width, subTexture.Height, TextureUtilities.GetDDSPixelFormat(subTexture.Format)); var bitmapData = bitmap.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); Marshal.Copy(buffer, 0, bitmapData.Scan0, buffer.Length); bitmap.UnlockBits(bitmapData); } return(bitmap); }
public static unsafe Bitmap Decode(Texture texture) { if (texture.IsYCbCr) { var bitmap = new Bitmap(texture[0].Width, texture[0].Height); var rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height); var lumBuffer = DDSCodec.DecompressPixelDataToRGBA( texture[0].Data, texture[0].Width, texture[0].Height, TextureUtilities.GetDDSPixelFormat(texture.Format)); var cbrBuffer = DDSCodec.DecompressPixelDataToRGBA( texture[1].Data, texture[1].Width, texture[1].Height, TextureUtilities.GetDDSPixelFormat(texture.Format)); var bitmapData = bitmap.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); fixed(byte *lumPtr = lumBuffer) fixed(byte *cbrPtr = cbrBuffer) { var lumIntPtr = ( int * )lumPtr; var cbrIntPtr = ( int * )cbrPtr; ConvertYCbCrToRGBA(lumIntPtr, cbrIntPtr, ( int * )bitmapData.Scan0, bitmap.Width, bitmap.Height); } bitmap.UnlockBits(bitmapData); return(bitmap); } if (texture.UsesDepth) { var bitmap = new Bitmap(texture.Width * texture.Depth, texture.Height); using (var gfx = Graphics.FromImage(bitmap)) { int currentIndex = 0; foreach (int i in CubeMapToDDSCubeMap()) { gfx.DrawImageUnscaled(Decode(texture[i, 0]), currentIndex++ *texture.Width, 0); } } return(bitmap); } return(Decode(texture[0])); }