예제 #1
0
 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);
     }
 }
예제 #2
0
파일: ImageJPEG.cs 프로젝트: Casidi/GARbro
 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;
     }
 }
예제 #3
0
        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,
                });
            }
        }