public static Bitmap Decode(TEX0v1* texture, int mipLevel)
 {
     return Get(texture->PixelFormat).DecodeTexture(texture, mipLevel);
 }
 public static Bitmap DecodeIndexed(TEX0v1* texture, ColorPalette palette, int mipLevel)
 {
     return Get(texture->PixelFormat).DecodeTextureIndexed(texture, palette, mipLevel);
 }
        public virtual FileMap EncodeTEX0Texture(Bitmap src, int mipLevels)
        {
            int w = src.Width, h = src.Height;
            int bw = BlockWidth, bh = BlockHeight;

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

            FileMap fileView = FileMap.FromTempFile(GetFileSize(w, h, mipLevels) + 0x40);
            try
            {
                //Build TEX header
                TEX0v1* header = (TEX0v1*)fileView.Address;
                *header = new TEX0v1(w, h, RawFormat, mipLevels);

                int sStep = bw * Image.GetPixelFormatSize(fmt) / 8;
                int dStep = bw * bh * BitsPerPixel / 8;

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

                return fileView;
            }
            catch (Exception x)
            {
                MessageBox.Show(x.ToString());
                fileView.Dispose();
                return null;
            }
        }
 public virtual Bitmap DecodeTextureIndexed(TEX0v1* texture, ColorPalette palette, int mipLevel)
 {
     _workingPalette = palette;
     try { return DecodeTexture(texture, mipLevel); }
     finally { _workingPalette = null; }
 }
 public virtual Bitmap DecodeTextureIndexed(TEX0v1* texture, PLT0v1* palette, int mipLevel)
 {
     return DecodeTextureIndexed(texture, DecodePalette(palette), mipLevel);
 }
        public virtual Bitmap DecodeTexture(TEX0v1* 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();
            }
        }
 public Bitmap DecodeTexture(TEX0v1* texture)
 {
     return DecodeTexture(texture, 1);
 }