예제 #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));
 }