public override ImageMetaData ReadMetaData(IBinaryStream stream) { var header = stream.ReadHeader(0x24); CrxdMetaData info = null; if (header.AsciiEqual(0x20, "CRXJ")) { stream.Position = 0x28; uint diff_offset = stream.ReadUInt32(); using (var crx = OpenByOffset(diff_offset)) { if (null == crx) { return(null); } info = ReadMetaData(crx) as CrxdMetaData; if (info != null) { info.DiffOffset = diff_offset; } } } else if (header.AsciiEqual(0x20, "CRXG")) { using (var crx_input = new StreamRegion(stream.AsStream, 0x20, true)) using (var crx = new BinaryStream(crx_input, stream.Name)) { var diff_info = base.ReadMetaData(crx) as CrxMetaData; if (null == diff_info) { return(null); } info = new CrxdMetaData { Width = diff_info.Width, Height = diff_info.Height, OffsetX = diff_info.OffsetX, OffsetY = diff_info.OffsetY, BPP = diff_info.BPP, DiffInfo = diff_info, DiffOffset = 0, }; } } if (info != null) { info.BaseOffset = header.ToUInt32(8); info.BaseFileName = header.GetCString(0xC, 0x14); } return(info); }
IBinaryStream OpenDiffStream(IBinaryStream diff, CrxdMetaData info) { Stream input; if (0 == info.DiffOffset) { input = new StreamRegion(diff.AsStream, 0x20, true); } else { diff = OpenByOffset(info.DiffOffset); if (null == diff) { throw new FileNotFoundException("Referenced diff image not found"); } input = new StreamRegion(diff.AsStream, 0x20); } return(new BinaryStream(input, diff.Name)); }