private static PixelType GetPixelType(NUTEX_FORMAT format) { return(format switch { NUTEX_FORMAT.R32G32B32A32_FLOAT => PixelType.Float, _ => PixelType.UnsignedByte, });
private static PixelType GetPixelType(NUTEX_FORMAT format) { switch (format) { case NUTEX_FORMAT.R32G32B32A32_FLOAT: return(PixelType.Float); default: return(PixelType.Byte); } }
public static uint GetBpps(NUTEX_FORMAT format) { switch (format) { case NUTEX_FORMAT.R8G8B8A8_UNORM: case NUTEX_FORMAT.R8G8B8A8_SRGB: case NUTEX_FORMAT.B8G8R8A8_UNORM: return(4); case NUTEX_FORMAT.BC1_UNORM: return(8); case NUTEX_FORMAT.BC1_SRGB: return(8); case NUTEX_FORMAT.BC4_UNORM: return(8); case NUTEX_FORMAT.BC4_SNORM: return(8); case NUTEX_FORMAT.R32G32B32A32_FLOAT: case NUTEX_FORMAT.BC2_UNORM: return(8); case NUTEX_FORMAT.BC2_SRGB: return(8); case NUTEX_FORMAT.BC3_UNORM: return(16); case NUTEX_FORMAT.BC3_SRGB: return(16); case NUTEX_FORMAT.BC5_UNORM: return(16); case NUTEX_FORMAT.BC5_SNORM: return(16); case NUTEX_FORMAT.BC6_UFLOAT: return(16); case NUTEX_FORMAT.BC7_UNORM: return(16); case NUTEX_FORMAT.BC7_SRGB: return(16); default: return(0); } }
public override void Open(string Path) { //hingadingadurgan using (BinaryReader R = new BinaryReader(new FileStream(Path, FileMode.Open))) { Mipmaps = new List <byte[]>(); // TODO: Why are there empty streams? if (R.BaseStream.Length == 0) { return; } R.BaseStream.Position = R.BaseStream.Length - 0xB0; int[] MipSizes = new int[16]; for (int i = 0; i < MipSizes.Length; i++) { MipSizes[i] = R.ReadInt32(); } R.ReadChars(4); // TNX magic TexName = ""; for (int i = 0; i < 0x40; i++) { byte b = R.ReadByte(); if (b != 0) { TexName += (char)b; } } Width = R.ReadInt32(); Height = R.ReadInt32(); int Unk = R.ReadInt32(); Format = (NUTEX_FORMAT)R.ReadByte(); R.ReadByte(); ushort Padding = R.ReadUInt16(); R.ReadUInt32(); int MipCount = R.ReadInt32(); int Alignment = R.ReadInt32(); int ArrayCount = R.ReadInt32(); int ImageSize = R.ReadInt32(); char[] Magic = R.ReadChars(4); int MajorVersion = R.ReadInt16(); int MinorVersion = R.ReadInt16(); uint blkWidth = (uint)blkDims[Format].X; uint blkHeight = (uint)blkDims[Format].Y; uint blockHeight = SwitchSwizzler.GetBlockHeight(SwitchSwizzler.DIV_ROUND_UP((uint)Height, blkHeight)); uint BlockHeightLog2 = (uint)Convert.ToString(blockHeight, 2).Length - 1; uint tileMode = 0; uint bpp = GetBpps(Format); R.BaseStream.Position = 0; int blockHeightShift = 0; for (int i = 0; i < 1; i++) { int size = MipSizes[i]; if (i == 0) { if (size % Alignment != 0) { size = size + (Alignment - (size % Alignment)); } } try { byte[] deswiz = SwitchSwizzler.deswizzle((uint)Width, (uint)Height, blkWidth, blkHeight, 0, bpp, tileMode, (int)Math.Max(0, BlockHeightLog2 - blockHeightShift), R.ReadBytes(ImageSize)); byte[] trimmed = new byte[MipSizes[0]]; Array.Copy(deswiz, 0, trimmed, 0, trimmed.Length); Mipmaps.Add(trimmed); } catch { } } } }
public override void Open() { using (BinaryReader reader = new BinaryReader(new FileStream(AbsolutePath, FileMode.Open))) { Mipmaps = new List <byte[]>(); // TODO: Why are there empty streams? if (reader.BaseStream.Length == 0) { return; } reader.BaseStream.Position = reader.BaseStream.Length - 0xB0; int[] mipmapSizes = new int[16]; for (int i = 0; i < mipmapSizes.Length; i++) { mipmapSizes[i] = reader.ReadInt32(); } reader.ReadChars(4); // TNX magic TexName = ReadTexName(reader); Width = reader.ReadInt32(); Height = reader.ReadInt32(); Depth = reader.ReadInt32(); Format = (NUTEX_FORMAT)reader.ReadByte(); reader.ReadByte(); ushort Padding = reader.ReadUInt16(); reader.ReadUInt32(); int MipCount = reader.ReadInt32(); int Alignment = reader.ReadInt32(); int ArrayCount = reader.ReadInt32(); int ImageSize = reader.ReadInt32(); char[] Magic = reader.ReadChars(4); int MajorVersion = reader.ReadInt16(); int MinorVersion = reader.ReadInt16(); uint blkWidth = (uint)blkDims[Format].X; uint blkHeight = (uint)blkDims[Format].Y; uint blockHeight = SwitchSwizzler.GetBlockHeight(SwitchSwizzler.DivRoundUp((uint)Height, blkHeight)); uint BlockHeightLog2 = (uint)Convert.ToString(blockHeight, 2).Length - 1; uint tileMode = 0; uint bpp = GetBpps(Format); reader.BaseStream.Position = 0; int blockHeightShift = 0; for (int i = 0; i < 1; i++) { int size = mipmapSizes[i]; if (i == 0 && size % Alignment != 0) { size += Alignment - (size % Alignment); } byte[] deswiz = SwitchSwizzler.Deswizzle((uint)Width, (uint)Height, blkWidth, blkHeight, 0, bpp, tileMode, (int)Math.Max(0, BlockHeightLog2 - blockHeightShift), reader.ReadBytes(ImageSize)); byte[] trimmed = new byte[mipmapSizes[0]]; Array.Copy(deswiz, 0, trimmed, 0, trimmed.Length); Mipmaps.Add(trimmed); } } }