コード例 #1
0
ファイル: ImageBIP.cs プロジェクト: tenyuhuang/GARbro
        public override ImageMetaData ReadMetaData(Stream stream)
        {
            using (var input = new BinaryReader(stream, Encoding.ASCII, true))
            {
                int sig = input.ReadInt32();
                if (sig != 5 && sig != 10)
                {
                    return(null);
                }
                uint header_end   = (uint)sig * 4;
                uint index_offset = input.ReadUInt32();

                input.BaseStream.Position = header_end - 4;
                uint data_offset = input.ReadUInt32() + 8;
                if (index_offset >= data_offset || index_offset < header_end)
                {
                    return(null);
                }
                input.BaseStream.Position = index_offset;
                int tile_count = input.ReadInt16();
                int flag       = input.ReadInt16();
                if (tile_count <= 0 || 0 != flag)
                {
                    return(null);
                }
                input.ReadInt32();
                uint w = input.ReadUInt16();
                uint h = input.ReadUInt16();
                if (0 == w || 0 == h)
                {
                    return(null);
                }
                var meta = new BipMetaData {
                    Width = w, Height = h, BPP = 32
                };
                meta.Tiles.Capacity = tile_count;
                for (int i = 0; i < tile_count; ++i)
                {
                    input.ReadInt64();
                    var tile = new BipTile();
                    tile.Left   = input.ReadUInt16();
                    tile.Top    = input.ReadUInt16();
                    tile.Width  = input.ReadUInt16();
                    tile.Height = input.ReadUInt16();
                    if (tile.Left + tile.Width > meta.Width)
                    {
                        meta.Width = (uint)(tile.Left + tile.Width);
                    }
                    if (tile.Top + tile.Height > meta.Height)
                    {
                        meta.Height = (uint)(tile.Top + tile.Height);
                    }
                    input.ReadInt64();
                    tile.Offset = input.ReadUInt32() + data_offset;
                    meta.Tiles.Add(tile);
                }
                return(meta);
            }
        }
コード例 #2
0
ファイル: ImageBIP.cs プロジェクト: Casidi/GARbro
        public override ImageMetaData ReadMetaData(Stream stream)
        {
            using (var input = new BinaryReader (stream, Encoding.ASCII, true))
            {
                int sig = input.ReadInt32();
                if (sig != 5 && sig != 10)
                    return null;
                uint header_end = (uint)sig*4;
                uint index_offset = input.ReadUInt32();

                input.BaseStream.Position = header_end-4;
                uint data_offset = input.ReadUInt32() + 8;
                if (index_offset >= data_offset || index_offset < header_end)
                    return null;
                input.BaseStream.Position = index_offset;
                int tile_count = input.ReadInt16();
                int flag = input.ReadInt16();
                if (tile_count <= 0 || 0 != flag)
                    return null;
                input.ReadInt32();
                uint w = input.ReadUInt16();
                uint h = input.ReadUInt16();
                if (0 == w || 0 == h)
                    return null;
                var meta = new BipMetaData { Width = w, Height = h, BPP = 32 };
                meta.Tiles.Capacity = tile_count;
                for (int i = 0; i < tile_count; ++i)
                {
                    input.ReadInt64();
                    var tile = new BipTile();
                    tile.Left   = input.ReadUInt16();
                    tile.Top    = input.ReadUInt16();
                    tile.Width  = input.ReadUInt16();
                    tile.Height = input.ReadUInt16();
                    if (tile.Left + tile.Width > meta.Width)
                        meta.Width = (uint)(tile.Left + tile.Width);
                    if (tile.Top  + tile.Height > meta.Height)
                        meta.Height = (uint)(tile.Top + tile.Height);
                    input.ReadInt64();
                    tile.Offset = input.ReadUInt32() + data_offset;
                    meta.Tiles.Add (tile);
                }
                return meta;
            }
        }