public FieldTexturePS3(Bitmap bitmap) { Field00 = 0x020200FF; Field08 = 0x00000001; Field0C = 0x00000000; Flags = FieldTextureFlags.Flag2 | FieldTextureFlags.Flag4 | FieldTextureFlags.Flag80; var ddsFormat = DDSCodec.DetermineBestCompressedFormat(bitmap); var data = DDSCodec.CompressPixelData(bitmap, ddsFormat); if (ddsFormat == DDSPixelFormatFourCC.DXT3) { Flags |= FieldTextureFlags.DXT3; } else if (ddsFormat == DDSPixelFormatFourCC.DXT5) { Flags |= FieldTextureFlags.DXT5; } MipMapCount = ( byte )1; Field1A = 2; Field1B = 0; Field1C = 0xAAE4; Width = ( short )bitmap.Width; Height = ( short )bitmap.Height; Field24 = 1; Data = data; }
private static unsafe void Encode(SubTexture subTexture, Bitmap bitmap) { bool ownsBitmap = false; if (subTexture.Width != bitmap.Width || subTexture.Height != bitmap.Height) { ownsBitmap = true; bitmap = new Bitmap(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.ReadOnly, PixelFormat.Format24bppRgb); fixed(byte *ptr = subTexture.Data) { BGRtoRGB(( byte * )bitmapData.Scan0, ptr, subTexture.Data.Length); } bitmap.UnlockBits(bitmapData); } else if (subTexture.Format == TextureFormat.RGBA) { var bitmapData = bitmap.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); fixed(byte *ptr = subTexture.Data) { Int32RGBAToByte(( int * )bitmapData.Scan0, ptr, subTexture.Data.Length); } bitmap.UnlockBits(bitmapData); } else { var compressedPixels = DDSCodec.CompressPixelData(bitmap, TextureUtilities.GetDDSPixelFormat(subTexture.Format)); Array.Copy(compressedPixels, subTexture.Data, subTexture.Data.Length); } if (ownsBitmap) { bitmap.Dispose(); } }