public static long FindChunk(Stream stream, string chunk) { long found_offset = -1; var file = new ArcView.Reader(stream); try { char[] buf = new char[4]; file.BaseStream.Position = 8; while (-1 != file.PeekChar()) { long chunk_offset = file.BaseStream.Position; uint chunk_size = Binary.BigEndian(file.ReadUInt32()); if (4 != file.Read(buf, 0, 4)) { break; } if (chunk.SequenceEqual(buf)) { found_offset = chunk_offset; break; } file.BaseStream.Position += chunk_size + 4; } } catch { // ignore errors } finally { file.Dispose(); } return(found_offset); }
public override ImageMetaData ReadMetaData(Stream stream) { if (0xff != stream.ReadByte() || 0xd8 != stream.ReadByte()) { return(null); } using (var file = new ArcView.Reader(stream)) { while (-1 != file.PeekChar()) { ushort marker = Binary.BigEndian(file.ReadUInt16()); if ((marker & 0xff00) != 0xff00) { break; } int length = Binary.BigEndian(file.ReadUInt16()); if ((marker & 0x00f0) == 0xc0 && marker != 0xffc4) { if (length < 8) { break; } int bits = file.ReadByte(); uint height = Binary.BigEndian(file.ReadUInt16()); uint width = Binary.BigEndian(file.ReadUInt16()); int components = file.ReadByte(); return(new ImageMetaData { Width = width, Height = height, BPP = bits * components, }); } file.BaseStream.Seek(length - 2, SeekOrigin.Current); } return(null); } }
public override ImageMetaData ReadMetaData(Stream stream) { if (0xff != stream.ReadByte() || 0xd8 != stream.ReadByte()) return null; using (var file = new ArcView.Reader (stream)) { while (-1 != file.PeekChar()) { ushort marker = Binary.BigEndian (file.ReadUInt16()); if ((marker & 0xff00) != 0xff00) break; int length = Binary.BigEndian (file.ReadUInt16()); if ((marker & 0x00f0) == 0xc0 && marker != 0xffc4) { if (length < 8) break; int bits = file.ReadByte(); uint height = Binary.BigEndian (file.ReadUInt16()); uint width = Binary.BigEndian (file.ReadUInt16()); int components = file.ReadByte(); return new ImageMetaData { Width = width, Height = height, BPP = bits * components, }; } file.BaseStream.Seek (length-2, SeekOrigin.Current); } return null; } }