public override SoundInput TryOpen(IBinaryStream file) { var header = ResourceHeader.Read(file); if (null == header) { return(null); } AudioFormat format; int offset; if (0 == header.PackType) { if (4 != file.Read(header.Bytes, 0, 4)) { return(null); } if (!Binary.AsciiEqual(header.Bytes, "RIFF")) { return(null); } format = Wav; offset = 0x40; } else if (1 == header.PackType) { return(Unpack(file)); } else if (2 == header.PackType) { format = OggAudio.Instance; offset = 0x6C; } else if (6 == header.PackType && Binary.AsciiEqual(header.Bytes, 0x10, "OGG ")) { format = OggAudio.Instance; offset = 0x40; } else { return(null); } var input = new StreamRegion(file.AsStream, offset, file.Length - offset); return(format.TryOpen(new BinaryStream(input, file.Name))); }
public override ImageMetaData ReadMetaData(IBinaryStream file) { var header = ResourceHeader.Read(file); if (null == header) { return(null); } if (Binary.AsciiEqual(header.Bytes, "IF PACKTYPE==")) { if (!Binary.AsciiEqual(header.Bytes, 0x0D, "0 ") || !Binary.AsciiEqual(header.Bytes, 0x2C, "BMP ") || header.PackType != 0 && header.PackType != 1) { return(null); } using (var reg = new StreamRegion(file.AsStream, 0x40, true)) using (var bmp = new BinaryStream(reg, file.Name)) { var info = Bmp.ReadMetaData(bmp); if (null == info) { return(null); } return(new DwqMetaData { Width = info.Width, Height = info.Height, BPP = info.BPP, BaseType = "BMP", PackedSize = (int)(file.Length - 0x40), PackType = header.PackType, HasAlpha = header.AType, }); } } int packed_size; switch (header.PackType) { case 0: // BMP case 5: // JPEG case 8: // PNG packed_size = (int)(file.Length - 0x40); break; case 2: // BMP+MASK case 3: // PACKBMP+MASK case 7: // JPEG+MASK packed_size = LittleEndian.ToInt32(header.Bytes, 0x20); break; default: // unknown format return(null); } return(new DwqMetaData { Width = LittleEndian.ToUInt32(header.Bytes, 0x24), Height = LittleEndian.ToUInt32(header.Bytes, 0x28), BPP = 32, BaseType = Encoding.ASCII.GetString(header.Bytes, 0, 0x10).TrimEnd(), PackedSize = packed_size, PackType = header.PackType, HasAlpha = header.AType || 7 == header.PackType || 3 == header.PackType, }); }