Пример #1
0
        /// <summary>
        /// Instantiates a PckImage, based on an XCImage.
        /// </summary>
        /// <param name="bindata">the COMPRESSED source data</param>
        /// <param name="pal"></param>
        /// <param name="terrainId"></param>
        /// <param name="spriteset"></param>
        internal PckImage(
            byte[] bindata,
            Palette pal,
            int terrainId,
            SpriteCollection spriteset)
            :
            base(
                new byte[XCImage.SpriteWidth * XCImage.SpriteHeight], // new byte[]{}
                XCImage.SpriteWidth,                                  // 0
                XCImage.SpriteHeight,                                 // 0
                null,                                                 // do *not* pass 'pal' in here. See XCImage..cTor
                terrainId)
        {
            //LogFile.WriteLine("PckImage..cTor");

            _spriteset = spriteset;    // for ToString() only.
            SetId      = _id++;        // for 'MapInfoOutputBox' only.

            Pal = pal;

            _spriteset.BorkedBigobs = false;

            for (int id = 0; id != Bindata.Length; ++id)
            {
                Bindata[id] = Palette.TransparentId;                 // Safety: byte arrays get initialized w/ "0" by default
            }
            int posSrc = 0;
            int posDst = 0;

            if (bindata[0] != SpriteTransparencyByte)
            {
                posDst = bindata[posSrc++] * XCImage.SpriteWidth;
            }

            for (; posSrc != bindata.Length; ++posSrc)
            {
                switch (bindata[posSrc])
                {
                default:
                    //LogFile.WriteLine(". Bindata.Length= " + Bindata.Length + " dst= " + dst);
                    //LogFile.WriteLine(". bindata.Length= " + bindata.Length + " id= "  + id);

                    if (posDst < Bindata.Length)
                    {
                        Bindata[posDst++] = bindata[posSrc];
                        break;
                    }

                    // probly trying to load a 32x48 Bigobs pck in a 32x40 spriteset.
                    // Note that this cannot be resolved absolutely.
                    _spriteset.BorkedBigobs = true;
                    return;

                case SpriteTransparencyByte:                         // skip quantity of pixels
                    posDst += bindata[++posSrc];
                    break;

                case SpriteStopByte:                         // end of image
                    break;
                }
            }

//			if (!_spriteset.BorkedBigobs) // check if trying to load a 32x40 Terrain/Unit pck in a 32x48 spriteset.
//			{
//				// there's no way to determine this.
//			}
//			else
//			{
            Sprite = BitmapService.CreateColorized(
                XCImage.SpriteWidth,
                XCImage.SpriteHeight,
                Bindata,
                Pal.ColorTable);
            SpriteGr = BitmapService.CreateColorized(
                XCImage.SpriteWidth,
                XCImage.SpriteHeight,
                Bindata,
                Pal.Grayscale.ColorTable);
//			}
        }
Пример #2
0
        /// <summary>
        /// Instantiates a PckImage, based on an XCImage.
        /// </summary>
        /// <param name="bindata">the compressed source data</param>
        /// <param name="pal"></param>
        /// <param name="terrainId"></param>
        /// <param name="spriteset"></param>
        internal PckImage(
            byte[] bindata,
            Palette pal,
            int terrainId,
            SpriteCollection spriteset)
            :
            base(
//					new byte[]{},
                new byte[XCImage.SpriteWidth * XCImage.SpriteHeight],
//					0,0,
                XCImage.SpriteWidth,
                XCImage.SpriteHeight,
                null,                         // do *not* pass 'pal' in here. See XCImage..cTor
                terrainId)
        {
            //LogFile.WriteLine("PckImage..cTor");
//			Bindata = new byte[XCImage.SpriteWidth * XCImage.SpriteHeight];

            _spriteset = spriteset;             // for ToString() only.
            MapId      = _idCanonical++;        // for 'MapInfoOutputBox' only.

            Pal = pal;

            for (int id = 0; id != Bindata.Length; ++id)
            {
                Bindata[id] = Palette.TransparentId;
            }

            int posSrc = 0;
            int posDst = 0;

            if (bindata[0] != SpriteTransparencyByte)
            {
                posDst = bindata[posSrc++] * XCImage.SpriteWidth;
            }

            for (int id = posSrc; id != bindata.Length; ++id)
            {
                switch (bindata[id])
                {
                default:
                    //LogFile.WriteLine(". Bindata.Length= " + Bindata.Length + " / posDst= " + posDst);
                    //LogFile.WriteLine(". bindata.Length= " + bindata.Length + " / id= " + id);
                    Bindata[posDst++] = bindata[id];
                    break;

                case SpriteTransparencyByte:                         // skip quantity of pixels
                    posDst += bindata[++id];
                    break;

                case SpriteStopByte:                         // end of image
                    break;
                }
            }

            Image = BitmapService.MakeBitmapTrue(
                XCImage.SpriteWidth,
                XCImage.SpriteHeight,
                Bindata,
                Pal.ColorTable);
            SpriteGray = BitmapService.MakeBitmapTrue(
                XCImage.SpriteWidth,
                XCImage.SpriteHeight,
                Bindata,
                Pal.Grayscale.ColorTable);
        }