示例#1
0
        public Bitmap(CacheArchive archive, string imageArchive, int fileIndex)
        {
            JagexBuffer data = new DefaultJagexBuffer(archive.GetFile(imageArchive + ".dat"));
            JagexBuffer idx  = new DefaultJagexBuffer(archive.GetFile("index.dat"));

            idx.Position(data.ReadUShort());

            this.CropWidth  = idx.ReadUShort();
            this.CropHeight = idx.ReadUShort();

            this.Palette = new int[idx.ReadUByte()];

            for (int i = 0; i < this.Palette.Length - 1; i++)
            {
                this.Palette[i + 1] = idx.ReadTriByte();
            }

            for (int l = 0; l < fileIndex; l++)
            {
                idx.Position(idx.Position() + 2);
                data.Position(data.Position() + idx.ReadUShort() * idx.ReadUShort());
                idx.Position(idx.Position() + 1);
            }

            this.OffsetX = idx.ReadUByte();
            this.OffsetY = idx.ReadUByte();
            this.Width   = idx.ReadUShort();
            this.Height  = idx.ReadUShort();
            int type = idx.ReadUByte();

            this.Pixels = new sbyte[this.Width * this.Height];

            if (type == 0)
            {
                for (int i = 0; i < this.Pixels.Length; i++)
                {
                    this.Pixels[i] = (sbyte)data.ReadByte();
                    if (this.Palette[this.Pixels[i]] == 0)
                    {
                        HadTransparent = true;
                    }
                }
            }
            else if (type == 1)
            {
                for (int x = 0; x < this.Width; x++)
                {
                    for (int y = 0; y < this.Height; y++)
                    {
                        this.Pixels[x + (y * this.Width)] = (sbyte)data.ReadByte();
                        if (this.Palette[this.Pixels[x + (y * this.Width)]] == 0)
                        {
                            HadTransparent = true;
                        }
                    }
                }
            }
        }