示例#1
0
        }                                                                 // 'NGP '

        public override ImageMetaData ReadMetaData(Stream stream)
        {
            stream.Position = 0x12;
            using (var reader = new ArcView.Reader(stream))
            {
                int  packed_size = reader.ReadInt32();
                uint width       = reader.ReadUInt32();
                uint height      = reader.ReadUInt32();
                int  bpp         = reader.ReadUInt16() * 8;
                reader.BaseStream.Position = 0x100;
                int unpacked_size = reader.ReadInt32();
                if (packed_size <= 0 || unpacked_size <= 0)
                {
                    return(null);
                }
                return(new NgpMetaData
                {
                    Width = width,
                    Height = height,
                    BPP = bpp,
                    PackedSize = packed_size,
                    UnpackedSize = unpacked_size,
                });
            }
        }
示例#2
0
        }                                                                 // 'HG-2'

        public override ImageMetaData ReadMetaData(Stream stream)
        {
            stream.Position = 8;
            using (var header = new ArcView.Reader(stream))
            {
                var info = new Hg2MetaData();
                int type = header.ReadInt32();
                if (0x25 == type)
                {
                    info.HeaderSize = 0x58;
                }
                else if (0x20 == type)
                {
                    info.HeaderSize = 0x50;
                }
                else
                {
                    return(null);
                }
                info.Width  = header.ReadUInt32();
                info.Height = header.ReadUInt32();
                info.BPP    = header.ReadInt32();
                header.BaseStream.Seek(8, SeekOrigin.Current);
                info.DataPacked   = header.ReadInt32();
                info.DataUnpacked = header.ReadInt32();
                info.CtlPacked    = header.ReadInt32();
                info.CtlUnpacked  = header.ReadInt32();
                header.BaseStream.Seek(8, SeekOrigin.Current);
                info.CanvasWidth  = header.ReadUInt32();
                info.CanvasHeight = header.ReadUInt32();
                info.OffsetX      = header.ReadInt32();
                info.OffsetY      = header.ReadInt32();
                return(info);
            }
        }
示例#3
0
 bool ReadFromStream(Stream input, int name_length)
 {
     m_dir.Clear();
     using (var index = new ArcView.Reader(input))
     {
         for (int i = 0; i < m_count; ++i)
         {
             if (name_length != index.Read(m_name_buffer, 0, name_length))
             {
                 return(false);
             }
             var name = Binary.GetCString(m_name_buffer, 0, name_length);
             if (string.IsNullOrWhiteSpace(name))
             {
                 return(false);
             }
             var entry = FormatCatalog.Instance.Create <PackedEntry> (name);
             entry.Offset       = index.ReadUInt32();
             entry.UnpackedSize = index.ReadUInt32();
             entry.Size         = index.ReadUInt32();
             if (!entry.CheckPlacement(m_file.MaxOffset))
             {
                 return(false);
             }
             entry.IsPacked = m_pack_type != 0 && (m_pack_type != 4 || entry.Size != entry.UnpackedSize);
             m_dir.Add(entry);
         }
         return(true);
     }
 }
示例#4
0
        }                                                                 // 'CWDP'

        public override ImageMetaData ReadMetaData(Stream stream)
        {
            using (var input = new ArcView.Reader(stream))
            {
                input.ReadInt32();
                uint width  = Binary.BigEndian(input.ReadUInt32());
                uint height = Binary.BigEndian(input.ReadUInt32());
                if (0 == width || 0 == height)
                {
                    return(null);
                }
                int bpp        = input.ReadByte();
                int color_type = input.ReadByte();
                switch (color_type)
                {
                case 2: bpp *= 3; break;

                case 4: bpp *= 2; break;

                case 6: bpp *= 4; break;

                case 3:
                case 0: break;

                default: return(null);
                }
                return(new ImageMetaData
                {
                    Width = width,
                    Height = height,
                    BPP = bpp,
                });
            }
        }
示例#5
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var file = new ArcView.Reader(stream))
     {
         stream.Seek(3, SeekOrigin.Current);
         byte id        = file.ReadByte();
         uint data_size = file.ReadUInt32();
         uint width     = file.ReadUInt32();
         uint height    = file.ReadUInt32();
         uint stride    = file.ReadUInt32();
         if (stride < width)
         {
             throw new NotSupportedException();
         }
         if (stride * height != data_size)
         {
             return(null);
         }
         return(new MfgMetaData
         {
             Width = width,
             Height = height,
             BPP = (int)(stride * 8 / width),
             Type = id,
             Stride = (int)stride,
         });
     }
 }
示例#6
0
        public override ImageMetaData ReadMetaData(Stream stream)
        {
            using (var header = new ArcView.Reader(stream))
            {
                var info = new EpaMetaData();
                info.Mode      = header.ReadInt32() >> 24;
                info.ColorType = header.ReadInt32() & 0xff;
                switch (info.ColorType)
                {
                case 0: info.BPP = 8; break;

                case 1: info.BPP = 24; break;

                case 2: info.BPP = 32; break;

                case 3: info.BPP = 15; break;

                case 4: info.BPP = 8; break;

                default: return(null);
                }
                info.Width  = header.ReadUInt32();
                info.Height = header.ReadUInt32();
                if (2 == info.Mode)
                {
                    info.OffsetX = header.ReadInt32();
                    info.OffsetY = header.ReadInt32();
                }
                return(info);
            }
        }
示例#7
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var input = new ArcView.Reader(stream))
     {
         int type = input.ReadInt32();
         if (type < 0 || type > 3)
         {
             return(null);
         }
         if (-1 != input.ReadInt32())
         {
             return(null);
         }
         int  x           = input.ReadInt32();
         int  y           = input.ReadInt32();
         uint width       = input.ReadUInt32();
         uint height      = input.ReadUInt32();
         uint comp_size   = input.ReadUInt32();
         uint uncomp_size = input.ReadUInt32();
         if (uncomp_size != width * height * 3u)
         {
             return(null);
         }
         return(new Pt1MetaData {
             Width = width,
             Height = height,
             OffsetX = x,
             OffsetY = y,
             BPP = 3 == type ? 32 : 24,
             Type = type,
             PackedSize = comp_size,
             UnpackedSize = uncomp_size
         });
     }
 }
示例#8
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);
            }
        }
示例#9
0
        }                                                                 // 'S25'

        // in current implementation, only the first frame is returned.
        // per-frame access is provided by S25Opener class.

        public override ImageMetaData ReadMetaData(Stream stream)
        {
            using (var input = new ArcView.Reader(stream))
            {
                input.ReadUInt32();
                int count = input.ReadInt32();
                if (count < 0 || count > 0xfffff)
                {
                    return(null);
                }
                uint first_offset = input.ReadUInt32();
                if (0 == first_offset)
                {
                    return(null);
                }
                input.BaseStream.Position = first_offset;
                var info = new S25MetaData();
                info.Width       = input.ReadUInt32();
                info.Height      = input.ReadUInt32();
                info.OffsetX     = input.ReadInt32();
                info.OffsetY     = input.ReadInt32();
                info.FirstOffset = first_offset + 0x14;
                info.Incremental = 0 != (input.ReadUInt32() & 0x80000000u);
                info.BPP         = 32;
                return(info);
            }
        }
示例#10
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var input = new ArcView.Reader(stream))
     {
         uint size = input.ReadUInt32();
         if (size != stream.Length)
         {
             return(null);
         }
         uint width      = input.ReadUInt32();
         uint height     = input.ReadUInt32();
         int  compressed = input.ReadInt32();
         if (compressed > 1 || 0 == compressed && (width * height + 0x410) != size)
         {
             return(null);
         }
         return(new CmMetaData {
             Width = width,
             Height = height,
             BPP = 8,
             IsCompressed = 1 == compressed,
             DataOffset = 0x10,
             DataLength = size,
         });
     }
 }
示例#11
0
        }                                                                 // 'hiz'

        public override ImageMetaData ReadMetaData(Stream stream)
        {
            using (var input = new ArcView.Reader(stream))  // sub_4BF900
            {
                input.ReadInt32();
                int n = input.ReadInt32();
                if (100 != n)
                {
                    return(null);
                }
                uint right    = input.ReadUInt32() ^ 0xAA5A5A5A;
                uint bottom   = input.ReadUInt32() ^ 0xAC9326AF;
                int  unknown1 = input.ReadInt32(); // @0x10
                if (unknown1 == 0x375A8436)
                {
                    return(null);
                }
                uint unpacked_size = input.ReadUInt32() ^ 0x19739D6A; // @0x14
                if (unpacked_size != right * bottom * 4)
                {
                    return(null);
                }
                return(new HizMetaData
                {
                    Width = right,
                    Height = bottom,
                    BPP = 32,
                    IsPacked = true,
                    DataOffset = 0x4c,
                    UnpackedSize = unpacked_size,
                });
            }
        }
示例#12
0
文件: ArcNSA.cs 项目: uboaa/GARbro
        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);
            }
        }
示例#13
0
文件: ArcADS.cs 项目: zxc120/GARbro
 List <Entry> ReadIndex(Stream arc, byte[] key, string arc_name)
 {
     arc.Position = 8;
     using (var reader = new ArcView.Reader(arc))
     {
         int count = reader.ReadInt32();
         if (!IsSaneCount(count))
         {
             return(null);
         }
         uint base_offset = reader.ReadUInt32();
         uint index_size  = 4u * (uint)count;
         var  max_offset  = arc.Length;
         if (base_offset >= max_offset || base_offset < (0x10 + index_size))
         {
             return(null);
         }
         var index = new List <uint> (count);
         for (int i = 0; i < count; ++i)
         {
             uint offset = reader.ReadUInt32();
             if (offset != 0xffffffff)
             {
                 if (offset >= max_offset - base_offset)
                 {
                     return(null);
                 }
                 index.Add(base_offset + offset);
             }
         }
         var name_buffer = new byte[0x20];
         var dir         = new List <Entry> (index.Count);
         for (int i = 0; i < index.Count; ++i)
         {
             long offset = index[i];
             reader.BaseStream.Position = offset;
             reader.Read(name_buffer, 0, 0x20);
             string name = Binary.GetCString(name_buffer, 0, 0x20);
             Entry  entry;
             if (0 == name.Length)
             {
                 entry = new Entry {
                     Name = string.Format("{0}#{1:D5}", arc_name, i), Type = "image"
                 }
             }
             ;
             else
             {
                 entry = FormatCatalog.Instance.Create <Entry> (name);
             }
             entry.Offset = offset + 0x24;
             entry.Size   = reader.ReadUInt32();
             dir.Add(entry);
         }
         return(dir);
     }
 }
示例#14
0
 void DetectFileTypes(ArcView file, List <Entry> dir)
 {
     using (var input = file.CreateStream())
         using (var reader = new ArcView.Reader(input))
         {
             var buffer = new byte[0x10];
             foreach (PackedEntry entry in dir)
             {
                 input.Position = entry.Offset;
                 uint packed_size = reader.ReadUInt32();
                 entry.UnpackedSize = reader.ReadUInt32();
                 entry.Offset      += 8;
                 if (0 == packed_size)
                 {
                     entry.Size = entry.UnpackedSize;
                 }
                 else
                 {
                     entry.IsPacked = true;
                     entry.Size     = packed_size;
                 }
                 if (entry.Size < 0x10)
                 {
                     continue;
                 }
                 uint signature;
                 if (entry.IsPacked)
                 {
                     UnpackEntry(input, buffer);
                     signature = LittleEndian.ToUInt32(buffer, 0);
                 }
                 else
                 {
                     signature = reader.ReadUInt32();
                 }
                 IResource res;
                 if (0x020000 == signature || 0x0A0000 == signature)
                 {
                     res = ImageFormat.Tga;
                 }
                 else
                 {
                     res = AutoEntry.DetectFileType(signature);
                 }
                 if (null != res)
                 {
                     entry.Type = res.Type;
                     var ext = res.Extensions.FirstOrDefault();
                     if (!string.IsNullOrEmpty(ext))
                     {
                         entry.Name = Path.ChangeExtension(entry.Name, ext);
                     }
                 }
             }
         }
 }
示例#15
0
        public override ArcFile TryOpen(ArcView file)
        {
            int count = file.View.ReadInt32(8);

            if (!IsSaneCount(count))
            {
                return(null);
            }
            uint base_offset = file.View.ReadUInt32(0xC);

            if (base_offset <= 0x18 || base_offset >= file.MaxOffset)
            {
                return(null);
            }
            uint packed_size = file.View.ReadUInt32(0x10);
            int  index_size  = file.View.ReadInt32(0x14);

            if (packed_size > file.MaxOffset || index_size / IndexEntrySize != count)
            {
                return(null);
            }
            var name_buffer = new byte[30];

            using (var packed = file.CreateStream(0x18, packed_size))
                using (var lzss = new LzssStream(packed))
                    using (var index = new ArcView.Reader(lzss))
                    {
                        var dir = new List <Entry> (count);
                        for (int i = 0; i < count; ++i)
                        {
                            if (name_buffer.Length != index.Read(name_buffer, 0, name_buffer.Length))
                            {
                                return(null);
                            }
                            var name  = Binary.GetCString(name_buffer, 0, name_buffer.Length);
                            var entry = FormatCatalog.Instance.Create <Entry> (name);
                            if (name.EndsWith(".acd", StringComparison.InvariantCultureIgnoreCase))
                            {
                                entry.Type = "script";
                            }
                            entry.Offset = index.ReadUInt32() + base_offset;
                            entry.Size   = index.ReadUInt32();
                            if (!entry.CheckPlacement(file.MaxOffset))
                            {
                                return(null);
                            }
                            dir.Add(entry);
                        }
                        return(new ArcFile(file, this, dir));
                    }
        }
示例#16
0
        }                                                                  // 'AGd'

        public override ImageMetaData ReadMetaData(Stream stream)
        {
            using (var file = new ArcView.Reader(stream))
            {
                file.ReadUInt32();
                var info = new ImageMetaData();
                info.Width  = file.ReadUInt32();
                info.Height = file.ReadUInt32();
                file.BaseStream.Position = 0x38;
                int alpha_size = file.ReadInt32();
                info.BPP = 0 == alpha_size ? 24 : 32;
                return(info);
            }
        }
示例#17
0
        static WaveFormat ReadFormat(Stream file)
        {
            var format = new WaveFormat();

            using (var input = new ArcView.Reader(file))
            {
                format.FormatTag             = input.ReadUInt16();
                format.Channels              = input.ReadUInt16();
                format.SamplesPerSecond      = input.ReadUInt32();
                format.AverageBytesPerSecond = input.ReadUInt32();
                format.BlockAlign            = input.ReadUInt16();
                format.BitsPerSample         = input.ReadUInt16();
            }
            return(format);
        }
示例#18
0
        }                                                                 // 'MAI4'

        public override ImageMetaData ReadMetaData(Stream stream)
        {
            stream.Seek(8, SeekOrigin.Current);
            using (var input = new ArcView.Reader(stream))
            {
                uint width  = input.ReadUInt32();
                uint height = input.ReadUInt32();
                return(new ImageMetaData
                {
                    Width = width,
                    Height = height,
                    BPP = 24,
                });
            }
        }
示例#19
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var reader = new ArcView.Reader(stream))
     {
         stream.Seek(4, SeekOrigin.Current);
         int offset = reader.ReadInt32();
         if (offset <= 8)
         {
             return(null);
         }
         stream.Position = offset;
         uint signature = reader.ReadUInt32();
         if (signature != base.Signature)
         {
             return(null);
         }
         stream.Seek(-4, SeekOrigin.Current);
         var info = base.ReadMetaData(stream) as GrxMetaData;
         if (null == info)
         {
             return(null);
         }
         if (info.AlphaOffset > 0)
         {
             info.AlphaOffset += offset;
         }
         return(new SgxMetaData {
             GrxOffset = offset, GrxInfo = info
         });
     }
 }
示例#20
0
        HuffmanNode[] CreateHuffmanTree(Stream input)
        {
            var nodes = new HuffmanNode[0x200];
            var tree  = new List <int> (0x100);

            using (var reader = new ArcView.Reader(input))
            {
                m_huffman_unpacked = reader.ReadInt32();
                reader.ReadInt32(); // packed_size

                for (int i = 0; i < 0x100; i++)
                {
                    nodes[i].Freq = reader.ReadUInt32();
                    AddNode(tree, nodes, i);
                }
            }
            int last_node = 0x100;

            while (tree.Count > 1)
            {
                int l = tree[0];
                tree.RemoveAt(0);
                int r = tree[0];
                tree.RemoveAt(0);
                nodes[last_node].Freq  = nodes[l].Freq + nodes[r].Freq;
                nodes[last_node].Left  = l;
                nodes[last_node].Right = r;
                AddNode(tree, nodes, last_node++);
            }
            return(nodes);
        }
示例#21
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var input = new ArcView.Reader(stream))
     {
         var info = new PicMetaData();
         input.ReadUInt32();
         info.PackedSize   = input.ReadUInt32();
         info.UnpackedSize = input.ReadUInt32();
         info.HeaderSize   = input.ReadUInt32();
         if (info.HeaderSize >= stream.Length || info.PackedSize + info.HeaderSize > stream.Length)
         {
             return(null);
         }
         input.ReadUInt32();
         info.Width  = input.ReadUInt32();
         info.Height = input.ReadUInt32();
         info.BPP    = input.ReadInt32();
         if (info.HeaderSize >= 0x2C)
         {
             input.ReadInt32();
             info.OffsetX = input.ReadInt32();
             info.OffsetY = input.ReadInt32();
         }
         return(info);
     }
 }
示例#22
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     stream.Position = 4;
     using (var file = new ArcView.Reader(stream))
     {
         var info = new ImageMetaData();
         info.OffsetX = file.ReadInt32();
         info.OffsetY = file.ReadInt32();
         info.Width   = file.ReadUInt32();
         info.Height  = file.ReadUInt32();
         info.BPP     = 32;
         if (info.Width > 0x8000 || info.Height > 0x8000)
         {
             return(null);
         }
         return(info);
     }
 }
示例#23
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     stream.Position = 8;
     using (var header = new ArcView.Reader(stream))
     {
         var info = new DpngMetaData {
             BPP = 32
         };
         info.TileCount = header.ReadInt32();
         if (info.TileCount <= 0)
         {
             return(null);
         }
         info.Width  = header.ReadUInt32();
         info.Height = header.ReadUInt32();
         return(info);
     }
 }
示例#24
0
        }                                                                 // 'GYU'

        public override ImageMetaData ReadMetaData(Stream stream)
        {
            using (var reader = new ArcView.Reader(stream))
            {
                reader.ReadInt32();
                return(new GyuMetaData
                {
                    Flags = reader.ReadUInt16(),
                    CompressionMode = reader.ReadUInt16(),
                    Key = reader.ReadUInt32(),
                    BPP = reader.ReadInt32(),
                    Width = reader.ReadUInt32(),
                    Height = reader.ReadUInt32(),
                    DataSize = reader.ReadInt32(),
                    AlphaSize = reader.ReadInt32(),
                    PaletteSize = reader.ReadInt32(),
                });
            }
        }
示例#25
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var input = new ArcView.Reader(stream))
     {
         uint sign        = input.ReadUInt32();
         uint width       = input.ReadUInt32();
         uint height      = input.ReadUInt32();
         int  packed_size = input.ReadInt32();
         int  data_size   = input.ReadInt32();
         return(new GraMetaData
         {
             Width = width,
             Height = height,
             PackedSize = packed_size,
             UnpackedSize = data_size,
             BPP = 0x617267 == sign ? 24 : 8,
         });
     }
 }
示例#26
0
        public override ImageMetaData ReadMetaData(Stream stream)
        {
            stream.Position = 4;
            int  bpp         = stream.ReadByte();
            bool has_palette = stream.ReadByte() != 0;

            using (var input = new ArcView.Reader(stream))
            {
                var info = new Typ1MetaData {
                    BPP = bpp, HasPalette = has_palette
                };
                info.Width  = input.ReadUInt16();
                info.Height = input.ReadUInt16();
                input.ReadInt32();
                info.Channel[0] = input.ReadUInt32();
                info.Channel[1] = input.ReadUInt32();
                info.Channel[2] = input.ReadUInt32();
                info.Channel[3] = input.ReadUInt32();
                return(info);
            }
        }
示例#27
0
        }                                                                   // '256G'

        public override ImageMetaData ReadMetaData(Stream stream)
        {
            using (var input = new ArcView.Reader(stream))
            {
                input.ReadUInt32();
                var info = new GgdMetaData {
                    BPP = 8
                };
                info.HeaderSize = input.ReadUInt32();
                info.Width      = input.ReadUInt32();
                int height = input.ReadInt32();
                if (height < 0)
                {
                    height       = -height;
                    info.Flipped = true;
                }
                info.Height = (uint)height;
                input.ReadInt64();
                info.BitmapSize = input.ReadUInt32();
                return(info);
            }
        }
示例#28
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);
            }
        }
示例#29
0
 public PcmInput(Stream file) : base(null)
 {
     file.Position = 4;
     using (var input = new ArcView.Reader(file))
     {
         int src_size = input.ReadInt32();
         if (src_size <= 0)
         {
             throw new InvalidFormatException();
         }
         int mode  = input.ReadInt32();
         int extra = (mode >> 8) & 0xff;
         mode &= 0xff;
         var format = new WaveFormat();
         format.FormatTag             = input.ReadUInt16();
         format.Channels              = input.ReadUInt16();
         format.SamplesPerSecond      = input.ReadUInt32();
         format.AverageBytesPerSecond = input.ReadUInt32();
         format.BlockAlign            = input.ReadUInt16();
         format.BitsPerSample         = input.ReadUInt16();
         this.Format  = format;
         this.PcmSize = src_size;
         if (0 == mode)
         {
             this.Source = new StreamRegion(file, file.Position, src_size);
         }
         else if (1 == mode || 3 == mode)
         {
             var decoder = new PcmDecoder(input, src_size, extra, (XpcmCompression)mode);
             this.Source = new MemoryStream(decoder.Unpack(), 0, src_size);
             file.Dispose();
         }
         else
         {
             throw new NotSupportedException("Not supported Circus PCM audio compression");
         }
     }
 }
示例#30
0
        public override ImageMetaData ReadMetaData(Stream stream)
        {
            if (0x4C != stream.ReadByte() || 0x4D != stream.ReadByte())
            {
                return(null);
            }
            int flag = stream.ReadByte() & 0xF;

            if (flag != 2 && flag != 3)
            {
                return(null);
            }
            stream.Seek(5, SeekOrigin.Current);
            using (var file = new ArcView.Reader(stream))
            {
                var meta = new ImageMetaData {
                    BPP = 32
                };
                meta.Width  = file.ReadUInt32();
                meta.Height = file.ReadUInt32();
                return(meta);
            }
        }
示例#31
0
文件: ImageDGC.cs 项目: Casidi/GARbro
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var input = new ArcView.Reader (stream))
     {
         input.ReadInt32();
         var info = new DgcMetaData();
         info.Flags  = input.ReadUInt32();
         info.Width  = input.ReadUInt16();
         info.Height = input.ReadUInt16();
         if (info.Width > 0x7fff || info.Height > 0x7fff)
             return null;
         info.BPP    = 0 == (info.Flags & Reader.FlagAlphaChannel) ? 24 : 32;
         return info;
     }
 }
示例#32
0
文件: ImageS25.cs 项目: Casidi/GARbro
 // in current implementation, only the first frame is returned.
 // per-frame access is provided by S25Opener class.
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var input = new ArcView.Reader (stream))
     {
         input.ReadUInt32();
         int count = input.ReadInt32();
         if (count < 0 || count > 0xfffff)
             return null;
         uint first_offset = input.ReadUInt32();
         if (0 == first_offset)
             return null;
         input.BaseStream.Position = first_offset;
         var info = new S25MetaData();
         info.Width = input.ReadUInt32();
         info.Height = input.ReadUInt32();
         info.OffsetX = input.ReadInt32();
         info.OffsetY = input.ReadInt32();
         info.FirstOffset = first_offset+0x14;
         info.Incremental = 0 != (input.ReadUInt32() & 0x80000000u);
         info.BPP = 32;
         return info;
     }
 }
示例#33
0
文件: ImageCPB.cs 项目: Casidi/GARbro
 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;
     }
 }
示例#34
0
文件: ArcNSA.cs 项目: Casidi/GARbro
        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;
            }
        }
示例#35
0
文件: ArcGPC.cs 项目: Casidi/GARbro
 void DetectFileTypes(ArcView file, List<Entry> dir)
 {
     using (var input = file.CreateStream())
     using (var reader = new ArcView.Reader (input))
     {
         var buffer = new byte[0x10];
         foreach (PackedEntry entry in dir)
         {
             input.Position = entry.Offset;
             uint packed_size = reader.ReadUInt32();
             entry.UnpackedSize = reader.ReadUInt32();
             entry.Offset += 8;
             if (0 == packed_size)
             {
                 entry.Size = entry.UnpackedSize;
             }
             else
             {
                 entry.IsPacked = true;
                 entry.Size = packed_size;
             }
             if (entry.Size < 0x10)
                 continue;
             uint signature;
             if (entry.IsPacked)
             {
                 UnpackEntry (input, buffer);
                 signature = LittleEndian.ToUInt32 (buffer, 0);
             }
             else
                 signature = reader.ReadUInt32();
             IResource res;
             if (0x020000 == signature || 0x0A0000 == signature)
                 res = ImageFormat.Tga;
             else
                 res = AutoEntry.DetectFileType (signature);
             if (null != res)
             {
                 entry.Type = res.Type;
                 var ext = res.Extensions.FirstOrDefault();
                 if (!string.IsNullOrEmpty (ext))
                     entry.Name = Path.ChangeExtension (entry.Name, ext);
             }
         }
     }
 }
示例#36
0
文件: ImageEPA.cs 项目: Casidi/GARbro
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var header = new ArcView.Reader (stream))
     {
         var info = new EpaMetaData();
         info.Mode = header.ReadInt32() >> 24;
         info.ColorType = header.ReadInt32() & 0xff;
         switch (info.ColorType)
         {
         case 0: info.BPP = 8; break;
         case 1: info.BPP = 24; break;
         case 2: info.BPP = 32; break;
         case 3: info.BPP = 15; break;
         case 4: info.BPP = 8; break;
         default: return null;
         }
         info.Width = header.ReadUInt32();
         info.Height = header.ReadUInt32();
         if (2 == info.Mode)
         {
             info.OffsetX = header.ReadInt32();
             info.OffsetY = header.ReadInt32();
         }
         return info;
     }
 }
示例#37
0
文件: ArcDX.cs 项目: Casidi/GARbro
        byte[] Unpack(Stream stream)
        {
            using (var input = new ArcView.Reader (stream))
            {
                uint unpacked_size = input.ReadUInt32();
                int remaining = input.ReadInt32() - 9;
                var output = new byte[unpacked_size];
                byte control_code = input.ReadByte();
                int dst = 0;
                while (remaining > 0)
                {
                    byte b = input.ReadByte();
                    --remaining;
                    if (b != control_code)
                    {
                        output[dst++] = b;
                        continue;
                    }
                    b = input.ReadByte();
                    --remaining;
                    if (b == control_code)
                    {
                        output[dst++] = b;
                        continue;
                    }
                    if (b > control_code)
                        --b;
                    int count = b >> 3;
                    if (0 != (b & 4))
                    {
                        count |= input.ReadByte() << 5;
                        --remaining;
                    }
                    count += 4;
                    int offset;
                    switch (b & 3)
                    {
                    case 0:
                        offset = input.ReadByte();
                        --remaining;
                        break;

                    case 1:
                        offset = input.ReadUInt16();
                        remaining -= 2;
                        break;

                    case 2:
                        offset = input.ReadUInt16();
                        offset |= input.ReadByte() << 16;
                        remaining -= 3;
                        break;

                    default:
                        throw new InvalidFormatException ("DX decompression failed");
                    }
                    ++offset;
                    Binary.CopyOverlapped (output, dst - offset, dst, count);
                    dst += count;
                }
                return output;
            }
        }
示例#38
0
文件: ImageNGP.cs 项目: Casidi/GARbro
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     stream.Position = 0x12;
     using (var reader = new ArcView.Reader (stream))
     {
         int packed_size = reader.ReadInt32();
         uint width      = reader.ReadUInt32();
         uint height     = reader.ReadUInt32();
         int bpp         = reader.ReadUInt16() * 8;
         reader.BaseStream.Position = 0x100;
         int unpacked_size = reader.ReadInt32();
         if (packed_size <= 0 || unpacked_size <= 0)
             return null;
         return new NgpMetaData
         {
             Width = width,
             Height = height,
             BPP = bpp,
             PackedSize = packed_size,
             UnpackedSize = unpacked_size,
         };
     }
 }
示例#39
0
文件: ImageAO.cs 项目: Casidi/GARbro
 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;
     }
 }
示例#40
0
文件: ImageHIZ.cs 项目: Casidi/GARbro
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var input = new ArcView.Reader (stream)) // sub_4BF900
     {
         input.ReadInt32();
         int n = input.ReadInt32();
         if (100 != n)
             return null;
         uint right = input.ReadUInt32() ^ 0xAA5A5A5A;
         uint bottom = input.ReadUInt32() ^ 0xAC9326AF;
         int unknown1 = input.ReadInt32(); // @0x10
         if (unknown1 == 0x375A8436)
             return null;
         uint unpacked_size = input.ReadUInt32() ^ 0x19739D6A; // @0x14
         if (unpacked_size != right*bottom*4)
             return null;
         return new HizMetaData
         {
             Width = right,
             Height = bottom,
             BPP = 32,
             IsPacked = true,
             DataOffset = 0x4c,
             UnpackedSize = unpacked_size,
         };
     }
 }
示例#41
0
文件: ImageMFG.cs 项目: Casidi/GARbro
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var file = new ArcView.Reader (stream))
     {
         stream.Seek (3, SeekOrigin.Current);
         byte id = file.ReadByte();
         uint data_size = file.ReadUInt32();
         uint width = file.ReadUInt32();
         uint height = file.ReadUInt32();
         uint stride = file.ReadUInt32();
         if (stride < width)
             throw new NotSupportedException();
         if (stride*height != data_size)
             return null;
         return new MfgMetaData
         {
             Width = width,
             Height = height,
             BPP = (int)(stride*8/width),
             Type = id,
             Stride = (int)stride,
         };
     }
 }
示例#42
0
文件: ImageMFG.cs 项目: Casidi/GARbro
        public override ImageData Read(Stream stream, ImageMetaData info)
        {
            var meta = info as MfgMetaData;
            if (null == meta)
                throw new ArgumentException ("MfgFormat.Read should be supplied with MfgMetaData", "info");

            stream.Position = 0x14;
            if ('_' != meta.Type)
                using (var file = new ArcView.Reader (stream))
                {
                    for (uint i = 0; i < meta.Height; ++i)
                    {
                        uint n = file.ReadUInt32();
                        file.BaseStream.Seek (n*8, SeekOrigin.Current);
                    }
                }
            byte[] pixels = new byte[meta.Stride*info.Height];
            if (pixels.Length != stream.Read (pixels, 0, pixels.Length))
                throw new InvalidFormatException ("Unexpected end of file");
            PixelFormat format;
            if (24 == meta.BPP)
                format = PixelFormats.Bgr24;
            else
                format = PixelFormats.Bgra32;
            return ImageData.Create (info, format, null, pixels, meta.Stride);
        }
示例#43
0
文件: ImageMAI.cs 项目: Casidi/GARbro
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var input = new ArcView.Reader (stream))
     {
         uint size = input.ReadUInt32();
         if (size != stream.Length)
             return null;
         uint width = input.ReadUInt32();
         uint height = input.ReadUInt32();
         int compressed = input.ReadInt32();
         if (compressed > 1 || 0 == compressed && (width*height + 0x410) != size)
             return null;
         return new CmMetaData {
             Width = width,
             Height = height,
             BPP = 8,
             IsCompressed = 1 == compressed,
             DataOffset = 0x10,
             DataLength = size,
         };
     }
 }
示例#44
0
文件: ImageGS.cs 项目: Casidi/GARbro
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var input = new ArcView.Reader (stream))
     {
         var info = new PicMetaData();
         input.ReadUInt32();
         info.PackedSize = input.ReadUInt32();
         info.UnpackedSize = input.ReadUInt32();
         info.HeaderSize = input.ReadUInt32();
         if (info.HeaderSize >= stream.Length || info.PackedSize + info.HeaderSize > stream.Length)
             return null;
         input.ReadUInt32();
         info.Width = input.ReadUInt32();
         info.Height = input.ReadUInt32();
         info.BPP = input.ReadInt32();
         if (info.HeaderSize >= 0x2C)
         {
             input.ReadInt32();
             info.OffsetX = input.ReadInt32();
             info.OffsetY = input.ReadInt32();
         }
         return info;
     }
 }
示例#45
0
文件: ImageDRG.cs 项目: Casidi/GARbro
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     using (var input = new ArcView.Reader (stream))
     {
         input.ReadUInt32();
         var info = new GgdMetaData { BPP = 8 };
         info.HeaderSize = input.ReadUInt32();
         info.Width = input.ReadUInt32();
         int height = input.ReadInt32();
         if (height < 0)
         {
             height = -height;
             info.Flipped = true;
         }
         info.Height = (uint)height;
         input.ReadInt64();
         info.BitmapSize = input.ReadUInt32();
         return info;
     }
 }