コード例 #1
0
        internal virtual void EncodeLevel(TEX0 *header, DIB dib, Bitmap src, int dStep, int sStep, int level)
        {
            int     mw = dib.Width, mh = dib.Height, aw = mw.Align(BlockWidth);
            VoidPtr dstAddr = header->PixelData;

            if (level != 1)
            {
                dstAddr += GetMipOffset(ref mw, ref mh, level);
                using (Bitmap mip = src.GenerateMip(level))
                    dib.ReadBitmap(mip, mw, mh);
            }

            mw = mw.Align(BlockWidth);
            mh = mh.Align(BlockHeight);

            int bStride = mw * BitsPerPixel / 8;

            for (int y = 0; y < mh; y += BlockHeight)
            {
                VoidPtr sPtr = (int)dib.Scan0 + (y * dib.Stride);
                VoidPtr dPtr = dstAddr + (y * bStride);
                for (int x = 0; x < mw; x += BlockWidth, dPtr += dStep, sPtr += sStep)
                {
                    EncodeBlock((ARGBPixel *)sPtr, dPtr, aw);
                }
            }
        }
コード例 #2
0
        protected internal override void PostProcess(VoidPtr bresAddress, VoidPtr dataAddress, int dataLength, StringTable stringTable)
        {
            base.PostProcess(bresAddress, dataAddress, dataLength, stringTable);

            TEX0 *header = (TEX0 *)dataAddress;

            header->ResourceStringAddress = stringTable[Name] + 4;
        }
コード例 #3
0
        internal override void EncodeLevel(TEX0 *header, DIB dib, Bitmap src, int dStep, int sStep, int level)
        {
            if ((level == 1) && (_blockBuffer != null))
            {
                CMPRBlock *sPtr = (CMPRBlock *)_blockBuffer.Address;
                CMPRBlock *dPtr = (CMPRBlock *)header->PixelData;

                int blocks = _blockBuffer.Length / 8;
                for (int i = 0; i < blocks; i++)
                {
                    dPtr[i] = sPtr[i];
                }
            }
            else
            {
                base.EncodeLevel(header, dib, src, dStep, sStep, level);
            }
        }
コード例 #4
0
        public virtual Bitmap DecodeTexture(TEX0 *texture, int mipLevel)
        {
            int     w = (int)(ushort)texture->_width, h = (int)(ushort)texture->_height;
            VoidPtr addr = texture->PixelData + GetMipOffset(ref w, ref h, mipLevel);
            int     aw = w.Align(BlockWidth), ah = h.Align(BlockHeight);

            using (DIB dib = new DIB(w, h, BlockWidth, BlockHeight, PixelFormat.Format32bppArgb))
            {
                int sStep   = BlockWidth * BlockHeight * BitsPerPixel / 8;
                int bStride = aw * BitsPerPixel / 8;
                for (int y = 0; y < ah; y += BlockHeight)
                {
                    ARGBPixel *dPtr = (ARGBPixel *)dib.Scan0 + (y * aw);
                    VoidPtr    sPtr = addr + (y * bStride);
                    for (int x = 0; x < aw; x += BlockWidth, dPtr += BlockWidth, sPtr += sStep)
                    {
                        DecodeBlock(sPtr, dPtr, aw);
                    }
                }
                return(dib.ToBitmap());
            }
        }
コード例 #5
0
        public virtual FileMap EncodeTexture(Bitmap src, int mipLevels)
        {
            int w = src.Width, h = src.Height;
            int bw = BlockWidth, bh = BlockHeight;
            //int aw = w.Align(bw), ah = h.Align(bh);

            PixelFormat fmt = src.IsIndexed() ? src.PixelFormat : PixelFormat.Format32bppArgb;

            //int fileSize = GetMipOffset(w, h, mipLevels + 1) + 0x40;
            FileMap fileView = FileMap.FromTempFile(GetFileSize(w, h, mipLevels, false));

            //FileMap fileView = FileMap.FromTempFile(fileSize);
            try
            {
                //Build TEX header
                TEX0 *header = (TEX0 *)fileView.Address;
                *     header = new TEX0(w, h, RawFormat, mipLevels);

                int     sStep    = bw * Image.GetPixelFormatSize(fmt) / 8;
                int     dStep    = bw * bh * BitsPerPixel / 8;
                VoidPtr baseAddr = header->PixelData;

                using (DIB dib = DIB.FromBitmap(src, bw, bh, fmt))
                    for (int i = 1; i <= mipLevels; i++)
                    {
                        EncodeLevel(header, dib, src, dStep, sStep, i);
                    }

                return(fileView);
            }
            catch (Exception x)
            {
                //MessageBox.Show(x.ToString());
                fileView.Dispose();
                return(null);
            }
        }
コード例 #6
0
 public static Bitmap DecodeIndexed(TEX0 *texture, ColorPalette palette, int mipLevel)
 {
     return(Get(texture->PixelFormat).DecodeTextureIndexed(texture, palette, mipLevel));
 }
コード例 #7
0
 public static Bitmap Decode(TEX0 *texture, int mipLevel)
 {
     return(Get(texture->PixelFormat).DecodeTexture(texture, mipLevel));
 }
コード例 #8
0
 public virtual Bitmap DecodeTextureIndexed(TEX0 *texture, ColorPalette palette, int mipLevel)
 {
     _workingPalette = palette;
     try { return(DecodeTexture(texture, mipLevel)); }
     finally { _workingPalette = null; }
 }
コード例 #9
0
 public virtual Bitmap DecodeTextureIndexed(TEX0 *texture, PLT0 *palette, int mipLevel)
 {
     return(DecodeTextureIndexed(texture, DecodePalette(palette), mipLevel));
 }
コード例 #10
0
 public Bitmap DecodeTexture(TEX0 *texture)
 {
     return(DecodeTexture(texture, 1));
 }