protected internal override void PostProcess(VoidPtr bresAddress, VoidPtr dataAddress, int dataLength, StringTable stringTable) { base.PostProcess(bresAddress, dataAddress, dataLength, stringTable); if (SharesData) { BRESCommonHeader *commonHeader = (BRESCommonHeader *)dataAddress; commonHeader->_size = InclusiveEntrySize(); } if (_version == 2) { TEX0v2 *header = (TEX0v2 *)dataAddress; header->ResourceStringAddress = stringTable[Name] + 4; if (!String.IsNullOrEmpty(_originalPath)) { header->OrigPathAddress = stringTable[_originalPath] + 4; } } else { TEX0v1 *header = (TEX0v1 *)dataAddress; header->ResourceStringAddress = stringTable[Name] + 4; if (!String.IsNullOrEmpty(_originalPath)) { header->OrigPathAddress = stringTable[_originalPath] + 4; } } }
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 unsafe static void WriteTEX0(this Stream outputStream, TEX0v1 header) { TEX0v1 *headerPtr = &header; using (var inputStream = new UnmanagedMemoryStream((byte *)headerPtr, sizeof(TEX0v1))) { inputStream.CopyTo(outputStream); } }
public virtual Bitmap DecodeTextureIndexed(TEX0v1 *texture, ColorPalette palette, int mipLevel) { _workingPalette = palette; try { return(DecodeTexture(texture, mipLevel)); } finally { _workingPalette = null; } }
protected internal override void PostProcess(VoidPtr bresAddress, VoidPtr dataAddress, int dataLength, StringTable stringTable) { base.PostProcess(bresAddress, dataAddress, dataLength, stringTable); TEX0v1 *header = (TEX0v1 *)dataAddress; header->ResourceStringAddress = stringTable[Name] + 4; if (!String.IsNullOrEmpty(_originalPath)) { header->OrigPathAddress = stringTable[_originalPath] + 4; } }
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 static Bitmap DecodeIndexed(TEX0v1 *texture, ColorPalette palette, int mipLevel) { return(Get(texture->PixelFormat).DecodeTextureIndexed(texture, palette, mipLevel)); }
public static Bitmap Decode(TEX0v1 *texture, int mipLevel) { return(Get(texture->PixelFormat).DecodeTexture(texture, mipLevel)); }
public virtual Bitmap DecodeTextureIndexed(TEX0v1 *texture, PLT0v1 *palette, int mipLevel) { return(DecodeTextureIndexed(texture, DecodePalette(palette), mipLevel)); }
public Bitmap DecodeTexture(TEX0v1 *texture) { return(DecodeTexture(texture, 1)); }