Exemple #1
0
        public static uint GetBpps(NutexFormat format)
        {
            switch (format)
            {
            case NutexFormat.R8G8B8A8Unorm:
            case NutexFormat.R8G8B8A8Srgb:
            case NutexFormat.B8G8R8A8Unorm:
                return(4);

            case NutexFormat.Bc1Unorm:
                return(8);

            case NutexFormat.Bc1Srgb:
                return(8);

            case NutexFormat.Bc4Unorm:
                return(8);

            case NutexFormat.Bc4Snorm:
                return(8);

            case NutexFormat.R32G32B32A32Float:
            case NutexFormat.Bc2Unorm:
                return(8);

            case NutexFormat.Bc2Srgb:
                return(8);

            case NutexFormat.Bc3Unorm:
                return(16);

            case NutexFormat.Bc3Srgb:
                return(16);

            case NutexFormat.Bc5Unorm:
            case NutexFormat.Bc5Snorm:
            case NutexFormat.Bc6Ufloat:
            case NutexFormat.Bc7Unorm:
            case NutexFormat.Bc7Srgb:
                return(16);

            default:
                return(0);
            }
        }
Exemple #2
0
        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 = (NutexFormat)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);
                }
            }
        }