public static XgmiStruct ReadXgmi(this BufferedStreamReader streamReader) { XgmiStruct xgmiStr = new XgmiStruct(); xgmiStr.magic = streamReader.Read <int>(); xgmiStr.len = streamReader.Read <int>(); xgmiStr.int_08 = streamReader.Read <int>(); xgmiStr.paddingLen = streamReader.Read <int>(); xgmiStr.mipIdByte = streamReader.Read <byte>(); xgmiStr.idByte1 = streamReader.Read <byte>(); xgmiStr.idByte2 = streamReader.Read <byte>(); xgmiStr.idByte3 = streamReader.Read <byte>(); xgmiStr.texCatId = streamReader.Read <int>(); xgmiStr.int_18 = streamReader.Read <int>(); xgmiStr.int_1C = streamReader.Read <int>(); xgmiStr.dxtType = streamReader.Read <byte>(); xgmiStr.bt_21 = streamReader.Read <byte>(); xgmiStr.bt_22 = streamReader.Read <byte>(); xgmiStr.bt_23 = streamReader.Read <byte>(); xgmiStr.int_24 = streamReader.Read <int>(); xgmiStr.width = streamReader.Read <ushort>(); xgmiStr.height = streamReader.Read <ushort>(); xgmiStr.bt_2C = streamReader.Read <byte>(); xgmiStr.bt_2D = streamReader.Read <byte>(); xgmiStr.alphaTesting = streamReader.Read <byte>(); xgmiStr.bt_2F = streamReader.Read <byte>(); xgmiStr.int_30 = streamReader.Read <int>(); xgmiStr.int_34 = streamReader.Read <int>(); xgmiStr.int_38 = streamReader.Read <int>(); xgmiStr.int_3C = streamReader.Read <int>(); xgmiStr.md5_1 = streamReader.Read <long>(); xgmiStr.md5_2 = streamReader.Read <long>(); xgmiStr.int_50 = streamReader.Read <int>(); xgmiStr.int_54 = streamReader.Read <int>(); xgmiStr.int_58 = streamReader.Read <int>(); xgmiStr.int_5C = streamReader.Read <int>(); xgmiStr.int_60 = streamReader.Read <int>(); xgmiStr.int_64 = streamReader.Read <int>(); xgmiStr.int_68 = streamReader.Read <int>(); xgmiStr.int_6C = streamReader.Read <int>(); //Processed data int mipByteIdBit = 0; if ((xgmiStr.mipIdByte & 0x80) > 0) { mipByteIdBit = 0x80; } xgmiStr.stamCombinedId = mipByteIdBit.ToString("X2") + xgmiStr.idByte1.ToString("X2") + xgmiStr.idByte2.ToString("X2") + xgmiStr.idByte3.ToString("X2") + xgmiStr.texCatId.ToString("X"); xgmiStr.stamUniqueId = xgmiStr.mipIdByte.ToString("X2") + xgmiStr.idByte1.ToString("X2") + xgmiStr.idByte2.ToString("X2") + xgmiStr.idByte3.ToString("X2") + xgmiStr.texCatId.ToString("X"); return(xgmiStr); }
public static byte[] GetImage(XgmiStruct xgmiStr, byte[] buffer) { int sourceBytesPerPixel; switch (xgmiStr.dxtType) { case 0x10: sourceBytesPerPixel = 0x8; break; case 0x12: sourceBytesPerPixel = 0x10; break; case 0x14: sourceBytesPerPixel = 0x10; break; default: sourceBytesPerPixel = 0x8; break; } var processedBuffer = Unswizzle(buffer, xgmiStr.width >> 2, xgmiStr.height >> 2, sourceBytesPerPixel); var dds = AssembleDDS(processedBuffer, xgmiStr.height, xgmiStr.width, xgmiStr.alphaTesting, xgmiStr.dxtType); return(dds); /*using (var image = Pfim.Pfim.FromStream(new MemoryStream(dds))) * { * // Pin pfim's data array so that it doesn't get reaped by GC, unnecessary * // in this snippet but useful technique if the data was going to be used in * // control like a picture box * var bytes = (new MemoryStream(image.Data)).ToArray(); * Bitmap bmp = new Bitmap(xgmiStr.width, xgmiStr.height, PixelFormat.Format32bppArgb); * BitmapData currMip = bmp.LockBits(new Rectangle(0, 0, xgmiStr.width, xgmiStr.height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); * * Marshal.Copy(bytes, 0, currMip.Scan0, bytes.Length); * bytes = null; * bmp.UnlockBits(currMip); * * return bmp; * }*/ }