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 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, }; } }