コード例 #1
0
        public void UpdateImage(TexturePack containingPack, bool hasTransparency, Bitmap bitmap)
        {
            if ((bitmap.Size.Width & (bitmap.Size.Width - 1)) != 0)
            {
                throw new ArgumentException("Bitmap width must be a power of two");
            }
            if ((bitmap.Size.Height & (bitmap.Size.Height - 1)) != 0)
            {
                throw new ArgumentException("Bitmap height must be a power of two");
            }

            int  level      = (int)Math.Log(Math.Max(bitmap.Size.Width, bitmap.Size.Height), 2);
            Size mipmapSize = bitmap.Size;
            int  mipLevel   = 0;

            HasTransparency = hasTransparency;

            Mipmaps = new List <MipMap>(level - 1);
            for (int i = 0; i < level; i++)
            {
                MipMap mipmap = new MipMap(level--, mipmapSize);
                using (Bitmap scaledBitmap = ScaleBitmap(bitmap, mipLevel))
                {
                    mipmap.UpdateImage(scaledBitmap, mipLevel, HasTransparency, containingPack.TransparentPaletteIndex);
                    mipLevel++;
                }
                Mipmaps.Add(mipmap);

                mipmapSize = new Size(mipmapSize.Width >> 1, mipmapSize.Height >> 1);
            }
        }
コード例 #2
0
        public override void Deserialise(MfcDeserialiser archive)
        {
            base.Deserialise(archive);

            var flags = archive.DeserialiseUInt16();

            this.HasTransparency = (flags & 1) != 0;
            if ((flags & ~1) != 0)
            {
                throw new NotImplementedException("Unexpected flag set in texture header");
            }

            ushort mipmapCount = archive.DeserialiseUInt16();

            this.Mipmaps = new List <MipMap>(mipmapCount);
            for (int i = 0; i < mipmapCount; i++)
            {
                MipMap mipmap            = new MipMap();
                var    nextLargestHeight = archive.DeserialiseUInt16();
                var    imageHeight       = archive.DeserialiseUInt16();
                var    nextLargestWidth  = archive.DeserialiseUInt16();
                var    imageWidth        = archive.DeserialiseUInt16();

                mipmap.ImageDimensionsMinusOne = new Size(imageWidth, imageHeight);
                mipmap.ImageDimensions         = new Size(nextLargestWidth, nextLargestHeight);
                mipmap.Level = archive.DeserialiseUInt16();

                var imageDataLength = archive.DeserialiseUInt32();
                mipmap.ImageData = archive.DeserialiseBytes((int)imageDataLength);

                int totalSpanCount = (int)archive.DeserialiseUInt32();
                mipmap.PixelSpans = new List <List <PixelSpan> >(totalSpanCount);
                for (int y = 0; y < nextLargestHeight; y++)
                {
                    ushort rowSpanCount = archive.DeserialiseUInt16();
                    var    rowSpans     = new List <PixelSpan>(rowSpanCount);
                    for (int k = 0; k < rowSpanCount; k++)
                    {
                        ushort startIndex = archive.DeserialiseUInt16();
                        ushort endIndex   = archive.DeserialiseUInt16();
                        rowSpans.Add(new PixelSpan(startIndex, endIndex));
                    }
                    mipmap.PixelSpans.Add(rowSpans);
                }

                archive.DeserialiseObjectNoHeader <TrailingBytes>();

                this.Mipmaps.Add(mipmap);
            }
        }