/// <summary>Converts a planar pic and caches it.</summary>
 /// <param name="index">The index of the pic.</param>
 /// <param name="grseg">The grseg for the pic.</param>
 /// <param name="picType">The pic type.</param>
 /// <returns>The converted pic.</returns>
 public byte[] CachePic(int index, memptr grseg, pictype picType)
 {
     return CachePic(index, grseg, picType.width * Display.ColumnScale, picType.height, 1);
 }
        //==========================================================================

        /////////////////////////////////////////////////////////
        //
        // InitGrFile
        //
        /////////////////////////////////////////////////////////
        private void InitGrFile()
        {
            //
            // calculate some offsets in the header
            //
            grhuffman = new huffnode(grhead);
            grstarts = new memptr(grhead.Buffer, grhead.dataoffsets);

            OptimizeNodes(grhuffman);

            //
            // Open the graphics file, leaving it open until the game is finished
            //
            grhandle = _sys.open("EGAGRAPH." + EXTENSION);
            if(grhandle.IsNull)
                Quit("Cannot open EGAGRAPH." + EXTENSION + "!");

            memptr buffer = new memptr();

            //
            // load the pic and sprite headers into the data segment
            //
            needgr[STRUCTPIC] = 1; // make sure this chunk never reloads
            grsegs[STRUCTPIC] = new memptr(null, 0xffff);
            GetChunkLength(STRUCTPIC); // position file pointer
            MMGetPtr(ref buffer, chunkcomplen);
            SegRead(ref grhandle, buffer, chunkcomplen);

            // as: Added temp pointer
            memptr temp = new memptr(new byte[pictable.Length * pictype.SizeOf], 0);

            HuffExpand(buffer.Buffer, buffer.BaseIndex, temp.Buffer, 0, temp.Buffer.Length, grhuffman);

            // as: Initialise pictypes
            for(int i = 0; i < pictable.Length; i++)
            {
                pictable[i] = new pictype(temp);
                temp.Offset(pictype.SizeOf);
            }

            MMFreePtr(ref buffer);
        }