private void Export(object sender, EventArgs args) { BNTX bn = this; SaveFileDialog sfd = new SaveFileDialog(); sfd.FileName = "textures.bntx"; sfd.Filter = "Supported Formats|*.bntx;|" + "All files(*.*)|*.*"; if (sfd.ShowDialog() == DialogResult.OK) { File.WriteAllBytes(sfd.FileName, BNTXFile); } }
private void Replace(object sender, EventArgs args) { BNTX bn = this; OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Supported Formats|*.bntx;|" + "All files(*.*)|*.*"; if (ofd.ShowDialog() == DialogResult.OK) { byte[] newBntx = File.ReadAllBytes(ofd.FileName); FileData f = new FileData(newBntx); f.endian = Endianness.Little; bn.Nodes.Clear(); bn.Read(f); } }
public BntxEditor(BNTX bntx) : this() { SelectBntx(bntx); }
public void SelectBntx(BNTX b) { bntx = b; FillForm(); }
public void Read(FileData f, BNTX bntx) //Docs thanks to AboodXD!! { ImageKey = "texture"; SelectedImageKey = "texture"; f.Skip(4); int BRTISize1 = f.ReadInt(); long BRTISize2 = f.ReadInt64(); surf = new TegraX1Swizzle.Surface(); ushort Flags = (ushort)f.ReadShort(); surf.dim = (sbyte)f.ReadByte(); surf.tileMode = (sbyte)f.ReadByte(); surf.swizzle = (ushort)f.ReadShort(); surf.numMips = (ushort)f.ReadShort(); uint numSamples = (uint)f.ReadInt(); surf.format = (uint)f.ReadInt(); DataType = (byte)(surf.format & 0xFF); uint accessFlags = (uint)f.ReadInt(); surf.width = f.ReadInt(); surf.height = f.ReadInt(); surf.depth = f.ReadInt(); int FaceCount = f.ReadInt(); surf.sizeRange = f.ReadInt(); uint unk38 = (uint)f.ReadInt(); uint unk3C = (uint)f.ReadInt(); uint unk40 = (uint)f.ReadInt(); uint unk44 = (uint)f.ReadInt(); uint unk48 = (uint)f.ReadInt(); uint unk4C = (uint)f.ReadInt(); surf.imageSize = f.ReadInt(); surf.alignment = f.ReadInt(); int ChannelType = f.ReadInt(); int TextureType = f.ReadInt(); Text = f.ReadString((int)f.ReadInt64() + BNTX.temp + 2, -1); long ParentOffset = f.ReadInt64(); long PtrsOffset = f.ReadInt64(); format = surf.format; surf.data = new List <byte[]>(); uint blk_dim = Formats.blk_dims(surf.format >> 8); blkWidth = blk_dim >> 4; blkHeight = blk_dim & 0xF; f.Seek((int)PtrsOffset + BNTX.temp); long firstMipOffset = f.ReadInt64(); surf.data.Add(f.GetSection((int)firstMipOffset + BNTX.temp, surf.imageSize)); for (int mipLevel = 1; mipLevel < surf.numMips; mipLevel++) { long dataOff = f.ReadInt64(); surf.data.Add(f.GetSection((int)dataOff + BNTX.temp, (int)firstMipOffset + surf.imageSize - (int)dataOff)); // Debug.WriteLine($"{Name} Height {surf.height}wdith = {surf.width}allignment = {surf.alignment}blkwidth = {blkWidth}blkheight = {blkHeight}blkdims = {blk_dim} format = {surf.format} datatype = {DataType} dataoffset = {dataOff}"); } bpp = Formats.bpps(surf.format >> 8); int target = 0; if (bntx.target == "NX ") { target = 1; } int blockHeightLog2 = surf.sizeRange & 7; int linesPerBlockHeight = (1 << blockHeightLog2) * 8; int blockHeightShift = 0; for (int mipLevel = 0; mipLevel < surf.numMips; mipLevel++) { uint width = (uint)Math.Max(1, surf.width >> mipLevel); uint height = (uint)Math.Max(1, surf.height >> mipLevel); uint size = TegraX1Swizzle.DIV_ROUND_UP(width, blkWidth) * TegraX1Swizzle.DIV_ROUND_UP(height, blkHeight) * bpp; if (TegraX1Swizzle.pow2_round_up(TegraX1Swizzle.DIV_ROUND_UP(height, blkWidth)) < linesPerBlockHeight) { blockHeightShift += 1; } byte[] result = TegraX1Swizzle.deswizzle(width, height, blkWidth, blkHeight, target, bpp, (uint)surf.tileMode, (uint)surf.alignment, Math.Max(0, blockHeightLog2 - blockHeightShift), surf.data[mipLevel], 0); //Create a copy and use that to remove uneeded data result_ = new byte[size]; Array.Copy(result, 0, result_, 0, size); texture.mipmaps.Add(result_); } LoadFormats(texture, surf.format, 0, surf.width, surf.height); texture.width = surf.width; texture.height = surf.height; Width = surf.width; Height = surf.height; }