public override ImageData Read(IBinaryStream stream, ImageMetaData info) { var meta = (HgMetaData)info; if (0x20 != meta.BPP) { throw new NotSupportedException("Not supported HG-3 color depth"); } using (var reg = new StreamRegion(stream.AsStream, 0x14, true)) using (var input = new BinaryStream(reg, stream.Name)) using (var reader = new Hg3Reader(input, meta)) { return(reader.Image); } }
public override Stream OpenEntry(ArcFile arc, Entry entry) { // emulate TGA image var offset = entry.Offset + 8; var info = new HgMetaData { HeaderSize = arc.File.View.ReadUInt32(offset), Width = arc.File.View.ReadUInt32(offset + 8), Height = arc.File.View.ReadUInt32(offset + 0xC), BPP = arc.File.View.ReadInt32(offset + 0x10), OffsetX = arc.File.View.ReadInt32(offset + 0x14), OffsetY = arc.File.View.ReadInt32(offset + 0x18), CanvasWidth = arc.File.View.ReadUInt32(offset + 0x1C), CanvasHeight = arc.File.View.ReadUInt32(offset + 0x20), }; using (var input = arc.File.CreateStream(entry.Offset, entry.Size)) using (var reader = new Hg3Reader(input, info)) { var pixels = reader.Unpack(); return(TgaStream.Create(info, pixels, reader.Flipped)); } }
public override ImageData Read(Stream stream, ImageMetaData info) { var meta = (HgMetaData)info; if (0x20 != meta.BPP) { throw new NotSupportedException("Not supported HG-3 color depth"); } using (var input = new StreamRegion(stream, 0x14, true)) using (var reader = new Hg3Reader(input, meta)) { var pixels = reader.Unpack(); if (reader.Flipped) { return(ImageData.CreateFlipped(info, PixelFormats.Bgra32, null, pixels, reader.Stride)); } else { return(ImageData.Create(info, PixelFormats.Bgra32, null, pixels, reader.Stride)); } } }