Beispiel #1
0
        private Rott2DPatchHeader _patchHeader; //patch header
        #endregion

        #region Constructor
        /// <summary>
        /// Constructor
        /// </summary>
        public Rott2DPatch(ref byte[] patchLumpData, ref Rott2DPalette palette)
        {
            this.isHeaderReady = false;
            this.isReady       = false;
            this._rawData      = patchLumpData;
            this._palette      = palette;

            //process header data first
            this._patchHeader = new Rott2DPatchHeader();
            this.ProcessPatchHeader();

            //create buffer from size
            if ((this._buffer == null) && (this.isHeaderReady))
            {
                this._buffer = new Bitmap(this._patchHeader.PatchWidth, this._patchHeader.PatchHeight, PixelFormat.Format24bppRgb);
            }

            //generate buffer bitmap
            this.ProcessLumpData();
        }
Beispiel #2
0
        /// <summary>
        /// Figure if we have a Patch (lpic_t; floor, ceiling and menu texures)
        /// </summary>
        public static bool isPatchTexture(byte[] lumpdata)
        {
            /*
             * Patches start always with 4 bytes (2x short) data for width and height.
             * Pixel count is mostly 16384 in size (total 16392 including the 4 bytes header data).
             *
             */

            bool isPatch = false;

            if (lumpdata.Length > Rott2DPatchHeader.PATCH_HEADER_SIZE)
            {
                Rott2DPatchHeader header = new Rott2DPatchHeader();

                header.PatchWidth  = BitConverter.ToUInt16(lumpdata, 0);  //width of texture
                header.PatchHeight = BitConverter.ToUInt16(lumpdata, 2);  //height of texture

                //measure total data size
                ushort pixelCount = (ushort)(header.PatchWidth * header.PatchHeight);  //calculate size of actual pixels, should be 16384



                //Note: needed strikt bounds checking or else some larger masked textures where recognized as patches.
                if (((pixelCount == PATCH_FC_SIZE) || (pixelCount == PATCH_PLANE_SIZE) || (pixelCount == PATCH_TRILOGO_SIZE)) && (header.PatchWidth <= 320) && (header.PatchHeight <= 200))
                {
                    //16-02-2012 new bug introduced again: some 128x128 masked textures are recognized as patches.
                    //we need to check first of we have a valid patch by calculating the byte size
                    //a (trans-)masked would result in a larger value
                    if (header.PatchWidth * header.PatchHeight + 8 == lumpdata.Length)
                    {
                        isPatch = true;
                    }
                }
            }

            return(isPatch);
        }