public void Read(BinaryReader reader) { TestName = reader.ReadString(); CurrentVersion = reader.ReadString(); Frame = reader.ReadString(); // Read image header var width = reader.ReadInt32(); var height = reader.ReadInt32(); var format = (PixelFormat)reader.ReadInt32(); var textureSize = reader.ReadInt32(); // Read image data var imageData = new byte[textureSize]; using (var lz4Stream = new LZ4Stream(reader.BaseStream, CompressionMode.Decompress, false, textureSize)) { if (lz4Stream.Read(imageData, 0, textureSize) != textureSize) throw new EndOfStreamException("Unexpected end of stream"); } var pinnedImageData = GCHandle.Alloc(imageData, GCHandleType.Pinned); var description = new ImageDescription { Dimension = TextureDimension.Texture2D, Width = width, Height = height, ArraySize = 1, Depth = 1, Format = format, MipLevels = 1, }; Image = Image.New(description, pinnedImageData.AddrOfPinnedObject(), 0, pinnedImageData, false); }
public unsafe void Read(BinaryReader reader) { TestName = reader.ReadString(); CurrentVersion = reader.ReadString(); Frame = reader.ReadString(); // Read image header var width = reader.ReadInt32(); var height = reader.ReadInt32(); var format = (PixelFormat)reader.ReadInt32(); var textureSize = reader.ReadInt32(); // Read image data var imageData = new byte[textureSize]; var copiedSize = 0; using (var lz4Stream = new LZ4Stream(new BlockingBufferStream(reader.BaseStream), CompressionMode.Decompress, false, textureSize)) { lz4Stream.Read(imageData, copiedSize, textureSize - copiedSize); } var pinnedImageData = GCHandle.Alloc(imageData, GCHandleType.Pinned); var description = new ImageDescription { Dimension = TextureDimension.Texture2D, Width = width, Height = height, ArraySize = 1, Depth = 1, Format = format, MipLevels = 1, }; Image = Image.New(description, pinnedImageData.AddrOfPinnedObject(), 0, pinnedImageData, false); }