Exemplo n.º 1
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var input = new ArcView.Reader(stream))
     {
         int width  = input.ReadInt16();
         int height = input.ReadInt16();
         if (width <= 0 || height <= 0)
         {
             return(null);
         }
         int bpp = input.ReadInt32();
         if (24 != bpp && 32 != bpp && 8 != bpp)
         {
             return(null);
         }
         if (0 != input.ReadInt64())
         {
             return(null);
         }
         return(new ImageMetaData
         {
             Width = (uint)width,
             Height = (uint)height,
             BPP = bpp,
         });
     }
 }
Exemplo n.º 2
0
        }                                                               // 'YGP'

        public override ImageMetaData ReadMetaData(Stream stream)
        {
            stream.Position = 4;
            using (var reader = new ArcView.Reader(stream))
            {
                int  mask_pos = reader.ReadUInt16();        // 04
                byte type     = reader.ReadByte();          // 06
                if (type != 1 && type != 2)
                {
                    return(null);
                }
                var info = new YgpMetaData {
                    Type = type, BPP = 32
                };
                info.Flags = reader.ReadByte();             // 07
                int header_size = reader.ReadInt32();       // 08
                stream.Position = header_size;
                info.DataSize   = reader.ReadInt32();       // XX+00
                info.Width      = reader.ReadUInt16();      // XX+04
                info.Height     = reader.ReadUInt16();      // XX+06
                info.DataOffset = header_size + 8;
                if (0 != (info.Flags & 4))
                {
                    stream.Position = 0x14;
                    info.OffsetX    = reader.ReadInt16();
                    info.OffsetY    = reader.ReadInt16();
                }
                return(info);
            }
        }
Exemplo n.º 3
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     stream.Seek(3, SeekOrigin.Current);
     using (var input = new ArcView.Reader(stream))
     {
         int bpp         = input.ReadByte();
         int x           = 0;
         int y           = 0;
         int type        = bpp;
         int header_size = 8;
         if (2 == type)
         {
             bpp         = input.ReadByte();
             header_size = 13;
         }
         else if (1 == type)
         {
             bpp         = input.ReadByte();
             x           = input.ReadInt16();
             y           = input.ReadInt16();
             header_size = 13;
         }
         else
         {
             type = 0;
         }
         if (8 != bpp && 24 != bpp && 32 != bpp)
         {
             return(null);
         }
         uint w = input.ReadUInt16();
         uint h = input.ReadUInt16();
         if (2 == type)
         {
             x = input.ReadInt16();
             y = input.ReadInt16();
         }
         return(new ElgMetaData
         {
             Width = w,
             Height = h,
             OffsetX = x,
             OffsetY = y,
             BPP = bpp,
             Type = type,
             HeaderSize = header_size,
         });
     }
 }
Exemplo n.º 4
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     stream.Position = 4;
     using (var reader = new ArcView.Reader(stream))
     {
         int version = reader.ReadInt16();
         if (version != 1)
         {
             return(null);
         }
         int unpacked_size = reader.ReadInt32();
         int data_offset   = reader.ReadInt32();
         if (unpacked_size < 0x36 || data_offset < stream.Position)
         {
             return(null);
         }
         var header = new byte[0x20];
         stream.Position = data_offset;
         Unpack(stream, header);
         if ('B' != header[0] || 'M' != header[1])
         {
             return(null);
         }
         return(new ZbmMetaData
         {
             Width = LittleEndian.ToUInt32(header, 0x12),
             Height = LittleEndian.ToUInt32(header, 0x16),
             BPP = LittleEndian.ToInt16(header, 0x1C),
             UnpackedSize = unpacked_size,
             DataOffset = data_offset,
         });
     }
 }
Exemplo n.º 5
0
        public override ImageMetaData ReadMetaData(Stream stream)
        {
            stream.Seek(5, SeekOrigin.Current);
            int bpp = stream.ReadByte();

            if (24 != bpp && 32 != bpp)
            {
                throw new NotSupportedException("Not supported CPB image format");
            }
            using (var input = new ArcView.Reader(stream))
            {
                int version = input.ReadInt16();
                if (1 != version)
                {
                    throw new NotSupportedException("Not supported CPB image version");
                }
                var info = new CpbMetaData();
                info.BPP = bpp;
                input.ReadUInt32();
                info.Width      = input.ReadUInt16();
                info.Height     = input.ReadUInt16();
                info.Channel[0] = input.ReadUInt32(); // Alpha
                info.Channel[1] = input.ReadUInt32();
                info.Channel[2] = input.ReadUInt32();
                info.Channel[3] = input.ReadUInt32();
                return(info);
            }
        }
Exemplo n.º 6
0
        protected List <Entry> ReadIndex(Stream file)
        {
            long base_offset = file.Position;

            using (var input = new ArcView.Reader(file))
            {
                int count = Binary.BigEndian(input.ReadInt16());
                if (!IsSaneCount(count))
                {
                    return(null);
                }
                base_offset += Binary.BigEndian(input.ReadUInt32());
                if (base_offset >= file.Length || base_offset < 15 * count)
                {
                    return(null);
                }

                var dir = new List <Entry>();
                for (int i = 0; i < count; ++i)
                {
                    if (base_offset - file.Position < 15)
                    {
                        return(null);
                    }
                    var name = file.ReadCString();
                    if (base_offset - file.Position < 13 || 0 == name.Length)
                    {
                        return(null);
                    }

                    var  entry            = FormatCatalog.Instance.Create <NsaEntry> (name);
                    byte compression_type = input.ReadByte();
                    entry.Offset = Binary.BigEndian(input.ReadUInt32()) + base_offset;
                    entry.Size   = Binary.BigEndian(input.ReadUInt32());
                    if (!entry.CheckPlacement(file.Length))
                    {
                        return(null);
                    }
                    entry.UnpackedSize = Binary.BigEndian(input.ReadUInt32());
                    entry.IsPacked     = compression_type != 0;
                    switch (compression_type)
                    {
                    case 0:  entry.CompressionType = Compression.None; break;

                    case 1:  entry.CompressionType = Compression.SPB; break;

                    case 2:  entry.CompressionType = Compression.LZSS; break;

                    case 4:  entry.CompressionType = Compression.NBZ; break;

                    default: entry.CompressionType = Compression.Unknown; break;
                    }
                    dir.Add(entry);
                }
                return(dir);
            }
        }
Exemplo n.º 7
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var reader = new ArcView.Reader(stream))
     {
         int name_count = reader.ReadInt16();
         if (name_count <= 0 || name_count > 1000)
         {
             return(null);
         }
         for (int i = 0; i < name_count; ++i)
         {
             int name_length = reader.ReadInt32();
             if (name_length <= 0 || name_length > 260)
             {
                 return(null);
             }
             stream.Seek(name_length, SeekOrigin.Current);
         }
         int tile_count = reader.ReadInt16();
         if (tile_count <= 0 || tile_count > 1000)
         {
             return(null);
         }
         var rect = new Rectangle(0, 0, 0, 0);
         for (int i = 0; i < tile_count; ++i)
         {
             int name_length = reader.ReadInt32();
             if (name_length <= 0 || name_length > 260)
             {
                 return(null);
             }
             stream.Seek(name_length + 0xC, SeekOrigin.Current);
             int x         = reader.ReadInt32();
             int y         = reader.ReadInt32();
             int w         = reader.ReadInt32() - x;
             int h         = reader.ReadInt32() - y;
             var part_rect = new Rectangle(x, y, w, h);
             rect = Rectangle.Union(rect, part_rect);
             stream.Seek(0x28, SeekOrigin.Current);
         }
         return(ReadCompressionMetaData(reader, rect));
     }
 }
Exemplo n.º 8
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var reader = new ArcView.Reader(stream))
     {
         int count = reader.ReadInt16();
         if (count <= 0 || count >= 0x100)
         {
             return(null);
         }
         int offset;
         if (count > 1)
         {
             offset = reader.ReadInt32();
             if (offset != 2 + count * 4)
             {
                 return(null);
             }
         }
         else
         {
             offset = 2;
         }
         stream.Position = offset;
         int unpacked_size = reader.ReadInt32();
         int packed_size   = reader.ReadInt32();
         offset += 8;
         if (offset + packed_size > stream.Length)
         {
             return(null);
         }
         byte[] header = new byte[0x36];
         if (0x36 != MgrOpener.Decompress(stream, header) ||
             header[0] != 'B' || header[1] != 'M')
         {
             return(null);
         }
         using (var bmp = new MemoryStream(header))
         {
             var info = Bmp.ReadMetaData(bmp);
             if (null == info)
             {
                 return(null);
             }
             return(new MgrMetaData
             {
                 Width = info.Width,
                 Height = info.Height,
                 BPP = info.BPP,
                 Offset = offset,
                 PackedSize = packed_size,
                 UnpackedSize = unpacked_size,
             });
         }
     }
 }
Exemplo n.º 9
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var input = new ArcView.Reader(stream))
     {
         int x = input.ReadInt16();
         int y = input.ReadInt16();
         int w = input.ReadInt16();
         int h = input.ReadInt16();
         if (w <= 0 || w > 0x1000 || h <= 0 || h > 0x1000 ||
             x < 0 || x > 0x800 || y < 0 || y > 0x800)
         {
             return(null);
         }
         return(new ImageMetaData {
             Width = (uint)w,
             Height = (uint)h,
             OffsetX = x,
             OffsetY = y,
             BPP = 8,
         });
     }
 }
Exemplo n.º 10
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var reader = new ArcView.Reader(stream))
     {
         int count = reader.ReadInt16();
         if (count <= 0)
         {
             return(null);
         }
         var tiles = new Tile[count];
         for (int i = 0; i < count; ++i)
         {
             var tile = new Tile();
             tile.Left = reader.ReadInt16();
             tile.Top  = reader.ReadInt16();
             if (tile.Left < 0 || tile.Top < 0)
             {
                 return(null);
             }
             tile.Right  = reader.ReadInt16();
             tile.Bottom = reader.ReadInt16();
             if (tile.Right <= tile.Left || tile.Bottom <= tile.Top)
             {
                 return(null);
             }
             tiles[i] = tile;
         }
         int width  = reader.ReadInt16();
         int height = reader.ReadInt16();
         if (width <= 0 || height <= 0)
         {
             return(null);
         }
         foreach (var tile in tiles)
         {
             if (tile.Right > width || tile.Bottom > height)
             {
                 return(null);
             }
         }
         return(new SplMetaData
         {
             Width = (uint)width,
             Height = (uint)height,
             BPP = 24,
             Tiles = tiles,
             DataOffset = stream.Position,
         });
     }
 }
Exemplo n.º 11
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     stream.Seek (4, SeekOrigin.Current);
     int type = stream.ReadByte();
     int bpp = stream.ReadByte();
     if (24 != bpp && 32 != bpp)
         throw new NotSupportedException ("Not supported CPB image format");
     using (var input = new ArcView.Reader (stream))
     {
         int version = input.ReadInt16 ();
         if (1 != version && 0 != version)
             throw new NotSupportedException ("Not supported CPB image version");
         var info = new CpbMetaData {
             Type = type,
             Version = version,
             BPP = bpp,
         };
         if (1 == version)
         {
             input.ReadUInt32();
             info.Width  = input.ReadUInt16();
             info.Height = input.ReadUInt16();
             info.Channel[0] = input.ReadUInt32();
             info.Channel[1] = input.ReadUInt32();
             info.Channel[2] = input.ReadUInt32();
             info.Channel[3] = input.ReadUInt32();
         }
         else
         {
             info.Width  = input.ReadUInt16();
             info.Height = input.ReadUInt16();
             input.ReadUInt32();
             info.Channel[0] = input.ReadUInt32();
             info.Channel[1] = input.ReadUInt32();
             info.Channel[2] = input.ReadUInt32();
             info.Channel[3] = input.ReadUInt32();
         }
         info.DataOffset = (uint)stream.Position;
         return info;
     }
 }
Exemplo n.º 12
0
        public override ImageMetaData ReadMetaData(Stream stream)
        {
            int A = stream.ReadByte();
            int P = stream.ReadByte();

            if ('A' != A || 'P' != P)
            {
                return(null);
            }
            using (var file = new ArcView.Reader(stream))
            {
                var info = new ImageMetaData();
                info.Width  = file.ReadUInt32();
                info.Height = file.ReadUInt32();
                info.BPP    = file.ReadInt16();
                if (info.Width > 0x8000 || info.Height > 0x8000 || !(32 == info.BPP || 24 == info.BPP))
                {
                    return(null);
                }
                return(info);
            }
        }
Exemplo n.º 13
0
        }                                                        // 'RIFF'

        public override ImageMetaData ReadMetaData(Stream stream)
        {
            // 'RIFF' isn't included into signature to avoid auto-detection of the WAV files as IPH images.
            if (0x46464952 != FormatCatalog.ReadSignature(stream))  // 'RIFF'
            {
                return(null);
            }
            using (var reader = new ArcView.Reader(stream))
            {
                if (0x38 != reader.ReadInt32())
                {
                    return(null);
                }
                var signature = reader.ReadInt32();
                if (signature != 0x20485049 && signature != 0x00485049) // 'IPH'
                {
                    return(null);
                }
                if (0x20746D66 != reader.ReadInt32()) // 'fmt '
                {
                    return(null);
                }
                reader.BaseStream.Position = 0x38;
                if (0x20706D62 != reader.ReadInt32()) // 'bmp '
                {
                    return(null);
                }
                var info = new IphMetaData();
                info.PackedSize            = reader.ReadInt32();
                info.Width                 = reader.ReadUInt16();
                info.Height                = reader.ReadUInt16();
                reader.BaseStream.Position = 0x50;
                info.BPP          = reader.ReadUInt16();
                info.IsCompressed = 0 != reader.ReadInt16();
                // XXX int16@[0x54] is a transparency color or 0xFFFF if image is not transparent
                return(info);
            }
        }
Exemplo n.º 14
0
        public override ImageMetaData ReadMetaData(Stream stream)
        {
            int sig = stream.ReadByte();

            if (sig >= 0x20)
            {
                return(null);
            }
            using (var input = new ArcView.Reader(stream))
            {
                int width  = input.ReadInt16();
                int height = input.ReadInt16();
                if (width <= 0 || height <= 0 || width > 4096 || height > 4096)
                {
                    return(null);
                }
                var meta = new CgMetaData
                {
                    Width  = (uint)width,
                    Height = (uint)height,
                    BPP    = 24,
                    Type   = sig,
                };
                if (0 != (sig & 7))
                {
                    meta.OffsetX = input.ReadInt16();
                    meta.OffsetY = input.ReadInt16();
                    meta.Right   = input.ReadInt16();
                    meta.Bottom  = input.ReadInt16();
                    if (meta.OffsetX > meta.Right || meta.OffsetY > meta.Bottom ||
                        meta.Right > width || meta.Bottom > height ||
                        meta.OffsetX < 0 || meta.OffsetY < 0)
                    {
                        return(null);
                    }
                }
                return(meta);
            }
        }
Exemplo n.º 15
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     stream.Position = 4;
     using (var reader = new ArcView.Reader (stream))
     {
         int mask_pos = reader.ReadUInt16();         // 04
         byte type = reader.ReadByte();              // 06
         if (type != 1 && type != 2)
             return null;
         var info = new YgpMetaData { Type = type, BPP = 32 };
         info.Flags = reader.ReadByte();             // 07
         int header_size = reader.ReadInt32();       // 08
         stream.Position = header_size;
         info.DataSize = reader.ReadInt32();         // XX+00
         info.Width = reader.ReadUInt16();           // XX+04
         info.Height = reader.ReadUInt16();          // XX+06
         info.DataOffset = header_size+8;
         if (0 != (info.Flags & 4))
         {
             stream.Position = 0x14;
             info.OffsetX = reader.ReadInt16();
             info.OffsetY = reader.ReadInt16();
         }
         return info;
     }
 }
Exemplo n.º 16
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     stream.Seek (3, SeekOrigin.Current);
     using (var input = new ArcView.Reader (stream))
     {
         int bpp = input.ReadByte();
         int x = 0;
         int y = 0;
         int type = bpp;
         int header_size = 8;
         if (2 == type)
         {
             bpp = input.ReadByte();
             header_size = 13;
         }
         else if (1 == type)
         {
             bpp = input.ReadByte();
             x = input.ReadInt16();
             y = input.ReadInt16();
             header_size = 13;
         }
         else
             type = 0;
         if (8 != bpp && 24 != bpp && 32 != bpp)
             return null;
         uint w = input.ReadUInt16();
         uint h = input.ReadUInt16();
         if (2 == type)
         {
             x = input.ReadInt16();
             y = input.ReadInt16();
         }
         return new ElgMetaData
         {
             Width = w,
             Height = h,
             OffsetX = x,
             OffsetY = y,
             BPP = bpp,
             Type = type,
             HeaderSize = header_size,
         };
     }
 }
Exemplo n.º 17
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var input = new ArcView.Reader (stream))
     {
         int width  = input.ReadInt16();
         int height = input.ReadInt16();
         if (width <= 0 || height <= 0)
             return null;
         int bpp = input.ReadInt32();
         if (24 != bpp && 32 != bpp && 8 != bpp)
             return null;
         if (0 != input.ReadInt64())
             return null;
         return new ImageMetaData
         {
             Width = (uint)width,
             Height = (uint)height,
             BPP = bpp,
         };
     }
 }
Exemplo n.º 18
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     int A = stream.ReadByte();
     int O = stream.ReadByte();
     if ('A' != A || 'O' != O)
         return null;
     using (var file = new ArcView.Reader (stream))
     {
         var info = new ImageMetaData();
         info.Width = file.ReadUInt32();
         info.Height = file.ReadUInt32();
         info.BPP = file.ReadInt16();
         info.OffsetX = file.ReadInt32();
         info.OffsetY = file.ReadInt32();
         if (info.Width > 0x8000 || info.Height > 0x8000 || !(32 == info.BPP || 24 == info.BPP))
             return null;
         return info;
     }
 }
Exemplo n.º 19
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var reader = new ArcView.Reader (stream))
     {
         int count = reader.ReadInt16();
         if (count <= 0 || count >= 0x100)
             return null;
         int offset;
         if (count > 1)
         {
             offset = reader.ReadInt32();
             if (offset != 2 + count * 4)
                 return null;
         }
         else
             offset = 2;
         stream.Position = offset;
         int unpacked_size = reader.ReadInt32();
         int packed_size = reader.ReadInt32();
         offset += 8;
         if (offset + packed_size > stream.Length)
             return null;
         byte[] header = new byte[0x36];
         if (0x36 != MgrOpener.Decompress (stream, header)
             || header[0] != 'B' || header[1] != 'M')
             return null;
         using (var bmp = new MemoryStream (header))
         {
             var info = Bmp.ReadMetaData (bmp);
             if (null == info)
                 return null;
             return new MgrMetaData
             {
                 Width = info.Width,
                 Height = info.Height,
                 BPP = info.BPP,
                 Offset = offset,
                 PackedSize = packed_size,
                 UnpackedSize = unpacked_size,
             };
         }
     }
 }
Exemplo n.º 20
0
        protected List<Entry> ReadIndex(Stream file)
        {
            long base_offset = file.Position;
            using (var input = new ArcView.Reader (file))
            {
                int count = Binary.BigEndian (input.ReadInt16());
                if (!IsSaneCount (count))
                    return null;
                base_offset += Binary.BigEndian (input.ReadUInt32());
                if (base_offset >= file.Length || base_offset < 15 * count)
                    return null;

                var dir = new List<Entry>();
                for (int i = 0; i < count; ++i)
                {
                    if (base_offset - file.Position < 15)
                        return null;
                    var name = file.ReadCString();
                    if (base_offset - file.Position < 13 || 0 == name.Length)
                        return null;

                    var entry = FormatCatalog.Instance.Create<NsaEntry> (name);
                    byte compression_type = input.ReadByte();
                    entry.Offset = Binary.BigEndian (input.ReadUInt32()) + base_offset;
                    entry.Size   = Binary.BigEndian (input.ReadUInt32());
                    if (!entry.CheckPlacement (file.Length))
                        return null;
                    entry.UnpackedSize = Binary.BigEndian (input.ReadUInt32());
                    entry.IsPacked = compression_type != 0;
                    switch (compression_type)
                    {
                    case 0:  entry.CompressionType = Compression.None; break;
                    case 1:  entry.CompressionType = Compression.SPB; break;
                    case 2:  entry.CompressionType = Compression.LZSS; break;
                    case 4:  entry.CompressionType = Compression.NBZ; break;
                    default: entry.CompressionType = Compression.Unknown; break;
                    }
                    dir.Add (entry);
                }
                return dir;
            }
        }
Exemplo n.º 21
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     int sig = stream.ReadByte();
     if (sig >= 0x20)
         return null;
     using (var input = new ArcView.Reader (stream))
     {
         int width  = input.ReadInt16();
         int height = input.ReadInt16();
         if (width <= 0 || height <= 0 || width > 4096 || height > 4096)
             return null;
         var meta = new CgMetaData
         {
             Width = (uint)width,
             Height = (uint)height,
             BPP = 24,
             Type = sig,
         };
         if (0 != (sig & 7))
         {
             meta.OffsetX = input.ReadInt16();
             meta.OffsetY = input.ReadInt16();
             meta.Right   = input.ReadInt16();
             meta.Bottom  = input.ReadInt16();
             if (meta.OffsetX > meta.Right || meta.OffsetY > meta.Bottom ||
                 meta.Right > width || meta.Bottom > height ||
                 meta.OffsetX < 0 || meta.OffsetY < 0)
                 return null;
         }
         return meta;
     }
 }
Exemplo n.º 22
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var input = new ArcView.Reader (stream))
     {
         int x = input.ReadInt16();
         int y = input.ReadInt16();
         int w = input.ReadInt16();
         int h = input.ReadInt16();
         if (w <= 0 || w > 0x1000 || h <= 0 || h > 0x1000
             || x < 0 || x > 0x800 || y < 0 || y > 0x800)
             return null;
         return new ImageMetaData {
             Width = (uint)w,
             Height = (uint)h,
             OffsetX = x,
             OffsetY = y,
             BPP = 8,
         };
     }
 }