public override ImageMetaData ReadMetaData(Stream stream) { int c1 = stream.ReadByte(); int c2 = stream.ReadByte(); if (0x42 != c1 || 0x4d != c2) { return(null); } using (var file = new ArcView.Reader(stream)) { uint size = file.ReadUInt32(); if (size < 14 + 40) { return(null); } SkipBytes(file, 8); uint header_size = file.ReadUInt32(); if (header_size < 40 || size - 14 < header_size) { return(null); } uint width = file.ReadUInt32(); uint height = file.ReadUInt32(); file.ReadInt16(); int bpp = file.ReadInt16(); return(new ImageMetaData { Width = width, Height = height, OffsetX = 0, OffsetY = 0, BPP = bpp }); } }
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; } }
public override ImageMetaData ReadMetaData(Stream stream) { using (var file = new ArcView.Reader(stream)) { short id_length = file.ReadByte(); short colormap_type = file.ReadByte(); if (colormap_type > 1) { return(null); } short image_type = file.ReadByte(); ushort colormap_first = file.ReadUInt16(); ushort colormap_length = file.ReadUInt16(); short colormap_depth = file.ReadByte(); int pos_x = file.ReadInt16(); int pos_y = file.ReadInt16(); uint width = file.ReadUInt16(); uint height = file.ReadUInt16(); int bpp = file.ReadByte(); if (bpp != 32 && bpp != 24 && bpp != 16 && bpp != 15 && bpp != 8) { return(null); } short descriptor = file.ReadByte(); uint colormap_offset = (uint)(18 + id_length); switch (image_type) { default: return(null); case 1: // Uncompressed, color-mapped images. case 9: // Runlength encoded color-mapped images. case 32: // Compressed color-mapped data, using Huffman, Delta, and // runlength encoding. case 33: // Compressed color-mapped data, using Huffman, Delta, and // runlength encoding. 4-pass quadtree-type process. if (colormap_depth != 24 && colormap_depth != 32) { return(null); } break; case 2: // Uncompressed, RGB images. case 3: // Uncompressed, black and white images. case 10: // Runlength encoded RGB images. case 11: // Compressed, black and white images. break; } return(new TgaMetaData { OffsetX = pos_x, OffsetY = pos_y, Width = width, Height = height, BPP = bpp, ImageType = image_type, ColormapType = colormap_type, ColormapOffset = colormap_offset, ColormapFirst = colormap_first, ColormapLength = colormap_length, ColormapDepth = colormap_depth, Descriptor = descriptor, }); } }
public override ImageMetaData ReadMetaData(Stream stream) { int c1 = stream.ReadByte(); int c2 = stream.ReadByte(); if (0x42 != c1 || 0x4d != c2) return null; using (var file = new ArcView.Reader (stream)) { uint size = file.ReadUInt32(); if (size < 14+40) return null; SkipBytes (file, 8); uint header_size = file.ReadUInt32(); if (header_size < 40 || size-14 < header_size) return null; uint width = file.ReadUInt32(); uint height = file.ReadUInt32(); file.ReadInt16(); int bpp = file.ReadInt16(); return new BmpMetaData { Width = width, Height = height, OffsetX = 0, OffsetY = 0, BPP = bpp, ImageLength = size, HeaderLength = header_size + 14, }; } }
public override ImageMetaData ReadMetaData(Stream stream) { ImageMetaData meta = null; var file = new ArcView.Reader(stream); try { file.ReadUInt32(); if (file.ReadUInt32() != 0x0a1a0a0d) { return(null); } uint chunk_size = Binary.BigEndian(file.ReadUInt32()); char[] chunk_type = new char[4]; file.Read(chunk_type, 0, 4); if (!chunk_type.SequenceEqual("IHDR")) { return(null); } meta = new ImageMetaData(); meta.Width = Binary.BigEndian(file.ReadUInt32()); meta.Height = Binary.BigEndian(file.ReadUInt32()); int bpp = file.ReadByte(); int color_type = file.ReadByte(); switch (color_type) { case 2: meta.BPP = bpp * 3; break; case 3: meta.BPP = 24; break; case 4: meta.BPP = bpp * 2; break; case 6: meta.BPP = bpp * 4; break; default: meta.BPP = bpp; break; } SkipBytes(file, 7); for (;;) { chunk_size = Binary.BigEndian(file.ReadUInt32()); file.Read(chunk_type, 0, 4); if (chunk_type.SequenceEqual("IDAT") || chunk_type.SequenceEqual("IEND")) { break; } if (chunk_type.SequenceEqual("oFFs")) { int x = Binary.BigEndian(file.ReadInt32()); int y = Binary.BigEndian(file.ReadInt32()); if (0 == file.ReadByte()) { meta.OffsetX = x; meta.OffsetY = y; } break; } SkipBytes(file, chunk_size + 4); } } catch { meta = null; } finally { file.Dispose(); if (stream.CanSeek) { stream.Position = 0; } } return(meta); }