Exemplo n.º 1
0
            private static DDS.DXGI_FORMAT GetCompressedDXGI_FORMAT(NUTEXImageFormat Format)
            {
                switch (Format)
                {
                case NUTEXImageFormat.BC1_UNORM: return(DDS.DXGI_FORMAT.DXGI_FORMAT_BC1_UNORM);

                case NUTEXImageFormat.BC1_SRGB: return(DDS.DXGI_FORMAT.DXGI_FORMAT_BC1_UNORM_SRGB);

                case NUTEXImageFormat.BC2_UNORM: return(DDS.DXGI_FORMAT.DXGI_FORMAT_BC2_UNORM);

                case NUTEXImageFormat.BC2_SRGB: return(DDS.DXGI_FORMAT.DXGI_FORMAT_BC2_UNORM_SRGB);

                case NUTEXImageFormat.BC3_UNORM: return(DDS.DXGI_FORMAT.DXGI_FORMAT_BC3_UNORM);

                case NUTEXImageFormat.BC3_SRGB: return(DDS.DXGI_FORMAT.DXGI_FORMAT_BC3_UNORM_SRGB);

                case NUTEXImageFormat.BC4_UNORM: return(DDS.DXGI_FORMAT.DXGI_FORMAT_BC4_UNORM);

                case NUTEXImageFormat.BC4_SNORM: return(DDS.DXGI_FORMAT.DXGI_FORMAT_BC4_SNORM);

                case NUTEXImageFormat.BC5_UNORM: return(DDS.DXGI_FORMAT.DXGI_FORMAT_BC5_UNORM);

                case NUTEXImageFormat.BC5_SNORM: return(DDS.DXGI_FORMAT.DXGI_FORMAT_BC5_SNORM);

                case NUTEXImageFormat.BC6_UFLOAT: return(DDS.DXGI_FORMAT.DXGI_FORMAT_BC6H_UF16);

                case NUTEXImageFormat.BC7_UNORM: return(DDS.DXGI_FORMAT.DXGI_FORMAT_BC7_UNORM);

                case NUTEXImageFormat.BC7_SRGB: return(DDS.DXGI_FORMAT.DXGI_FORMAT_BC7_UNORM_SRGB);

                default:
                    throw new Exception($"Cannot convert format {Format}");
                }
            }
Exemplo n.º 2
0
        public void Read(FileReader reader)
        {
            ImageKey         = "Texture";
            SelectedImageKey = "Texture";

            long   pos   = reader.BaseStream.Length;
            string magic = reader.ReadMagic((int)pos - 7, 3);//Check magic first!

            if (magic != "XET")
            {
                throw new Exception($"Invalid magic! Expected XET but got {magic}");
            }

            reader.Seek(pos - 112, System.IO.SeekOrigin.Begin); //Subtract size where the name occurs
            byte   padding  = reader.ReadByte();
            string StrMagic = reader.ReadString(3);

            TextureName = reader.ReadString(Syroot.BinaryData.BinaryStringFormat.ZeroTerminated);
            Text        = TextureName;

            //We cannot check if it's swizzled properly
            //So far if this part is blank, it's for Taiko No Tatsujin "Drum 'n' Fun
            if (StrMagic != "XNT")
            {
                IsSwizzled = false;
            }

            reader.Seek(pos - 48, System.IO.SeekOrigin.Begin); //Subtract size of header
            uint padding2 = reader.ReadUInt32();

            Width     = reader.ReadUInt32();
            Height    = reader.ReadUInt32();
            Depth     = reader.ReadUInt32(); //3d textures
            NutFormat = reader.ReadEnum <NUTEXImageFormat>(true);
            unk       = reader.ReadByte();   //Related to pixel type??
            ushort padding3 = reader.ReadUInt16();

            unk2       = reader.ReadInt32();
            MipCount   = reader.ReadUInt32();
            Alignment  = reader.ReadInt32();
            ArrayCount = reader.ReadUInt32(); //6 for cubemaps
            int imagesize = reader.ReadInt32();

            Format = ConvertFormat(NutFormat);

            reader.Seek(imagesize, System.IO.SeekOrigin.Begin); //Get mipmap sizes
            for (int arrayLevel = 0; arrayLevel < ArrayCount; arrayLevel++)
            {
                long   mipPos = reader.Position;
                uint[] mips   = reader.ReadUInt32s((int)MipCount);
                mipSizes.Add(mips);

                //Each mip section is 0x40 size for each array
                //Seek to next one
                reader.Seek(mipPos + 0x40, System.IO.SeekOrigin.Begin);
            }

            reader.Seek(0, System.IO.SeekOrigin.Begin);
            ImageData = reader.ReadBytes(imagesize);
        }
Exemplo n.º 3
0
            public static Bitmap DecodeBlock(byte[] data, uint Width, uint Height, NUTEXImageFormat Format)
            {
                Bitmap decomp;

                if (Format == NUTEXImageFormat.BC5_SNORM)
                {
                    return(DDSCompressor.DecompressBC5(data, (int)Width, (int)Height, true));
                }

                byte[] d = null;
                if (IsCompressedFormat(Format))
                {
                    d = DDSCompressor.DecompressBlock(data, (int)Width, (int)Height, GetCompressedDXGI_FORMAT(Format));
                }
                else
                {
                    d = DDSCompressor.DecodePixelBlock(data, (int)Width, (int)Height, GetUncompressedDXGI_FORMAT(Format));
                }

                if (d != null)
                {
                    decomp = BitmapExtension.GetBitmap(d, (int)Width, (int)Height);
                    return(TextureData.SwapBlueRedChannels(decomp));
                }
                return(null);
            }
Exemplo n.º 4
0
        public override void Replace(string FileName)
        {
            var bntxFile = new BNTX();
            var tex      = new TextureData();

            tex.Replace(FileName, MipCount, 0, Format);

            //If it's null, the operation is cancelled
            if (tex.Texture == null)
            {
                return;
            }

            var surfacesNew = tex.GetSurfaces();
            var surfaces    = GetSurfaces();

            if (LimitFileSize)
            {
                if (surfaces[0].mipmaps[0].Length != surfacesNew[0].mipmaps[0].Length)
                {
                    throw new Exception($"Image must be the same size! {surfaces[0].mipmaps[0].Length}");
                }

                if (mipSizes[0].Length != surfacesNew[0].mipmaps.Count)
                {
                    throw new Exception($"Mip map count must be the same! {mipSizes[0].Length}");
                }

                if (Width != tex.Texture.Width || Height != tex.Texture.Height)
                {
                    throw new Exception("Image size must be the same!");
                }

                ImageData = tex.Texture.TextureData[0][0];

                Width    = tex.Texture.Width;
                Height   = tex.Texture.Height;
                MipCount = tex.Texture.MipCount;
            }
            else
            {
                ImageData = tex.Texture.TextureData[0][0];

                Width    = tex.Texture.Width;
                Height   = tex.Texture.Height;
                MipCount = tex.Texture.MipCount;

                Format    = tex.Format;
                NutFormat = ConvertGenericToNutFormat(tex.Format);

                mipSizes = TegraX1Swizzle.GenerateMipSizes(tex.Format, tex.Width, tex.Height, tex.Depth, tex.ArrayCount, tex.MipCount, (uint)ImageData.Length);
            }

            surfacesNew.Clear();
            surfaces.Clear();

            UpdateEditor();
        }
Exemplo n.º 5
0
 private void ApplySettings(GenericTextureImporterSettings settings)
 {
     //Combine all arrays
     this.ImageData  = Utils.CombineByteArray(settings.DataBlockOutput.ToArray());
     this.Width      = settings.TexWidth;
     this.Height     = settings.TexHeight;
     this.Format     = settings.Format;
     this.MipCount   = settings.MipCount;
     this.Depth      = settings.Depth;
     this.ArrayCount = (uint)settings.DataBlockOutput.Count;
     NutFormat       = ConvertGenericToNutFormat(this.Format);
 }
Exemplo n.º 6
0
        public void Read(FileReader reader)
        {
            ImageKey         = "Texture";
            SelectedImageKey = "Texture";

            long   pos   = reader.BaseStream.Length;
            string magic = reader.ReadMagic((int)pos - 7, 3);//Check magic first!

            if (magic != "XET")
            {
                throw new Exception($"Invalid magic! Expected XET but got {magic}");
            }

            reader.Seek(pos - 112, System.IO.SeekOrigin.Begin); //Subtract size where the name occurs
            byte padding = reader.ReadByte();

            Text = reader.ReadString(Syroot.BinaryData.BinaryStringFormat.ZeroTerminated);

            reader.Seek(pos - 48, System.IO.SeekOrigin.Begin); //Subtract size of header
            uint padding2 = reader.ReadUInt32();

            Width  = reader.ReadUInt32();
            Height = reader.ReadUInt32();
            unk3   = reader.ReadInt32();
            Format = reader.ReadEnum <NUTEXImageFormat>(true);
            unk    = reader.ReadByte(); //Related to pixel size??
            ushort padding3 = reader.ReadUInt16();

            unk2 = reader.ReadInt32();
            uint mipCount = reader.ReadUInt32();

            Alignment = reader.ReadInt32();
            uint ArrayCount = reader.ReadUInt32(); //6 for cubemaps
            int  imagesize  = reader.ReadInt32();

            reader.Seek(imagesize, System.IO.SeekOrigin.Begin); //Get mipmap sizes
            for (int arrayLevel = 0; arrayLevel < ArrayCount; arrayLevel++)
            {
                long   mipPos = reader.Position;
                uint[] mips   = reader.ReadUInt32s((int)mipCount);
                mipSizes.Add(mips);

                //Each mip section is 0x40 size for each array
                //Seek to next one
                reader.Seek(mipPos + 0x40, System.IO.SeekOrigin.Begin);
            }
            reader.Seek(0, System.IO.SeekOrigin.Begin);
            ImageData = reader.ReadBytes(imagesize);

            LoadTexture();
        }
Exemplo n.º 7
0
            private static DDS.DXGI_FORMAT GetUncompressedDXGI_FORMAT(NUTEXImageFormat Format)
            {
                switch (Format)
                {
                case NUTEXImageFormat.R8G8B8A8_UNORM: return(DDS.DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM);

                case NUTEXImageFormat.R8G8B8A8_SRGB: return(DDS.DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM_SRGB);

                case NUTEXImageFormat.B8G8R8A8_UNORM: return(DDS.DXGI_FORMAT.DXGI_FORMAT_B8G8R8A8_UNORM);

                case NUTEXImageFormat.B8G8R8A8_SRGB: return(DDS.DXGI_FORMAT.DXGI_FORMAT_B8G8R8A8_UNORM_SRGB);

                default:
                    throw new Exception($"Cannot convert format {Format}");
                }
            }
Exemplo n.º 8
0
        public static TEX_FORMAT ConvertFormat(NUTEXImageFormat nutFormat)
        {
            switch (nutFormat)
            {
            case NUTEXImageFormat.B8G8R8A8_SRGB: return(TEX_FORMAT.B8G8R8A8_UNORM_SRGB);

            case NUTEXImageFormat.B8G8R8A8_UNORM: return(TEX_FORMAT.B8G8R8A8_UNORM);

            case NUTEXImageFormat.BC1_SRGB: return(TEX_FORMAT.BC1_UNORM_SRGB);

            case NUTEXImageFormat.BC1_UNORM: return(TEX_FORMAT.BC1_UNORM);

            case NUTEXImageFormat.BC2_UNORM: return(TEX_FORMAT.BC2_UNORM);

            case NUTEXImageFormat.BC2_SRGB: return(TEX_FORMAT.BC2_UNORM_SRGB);

            case NUTEXImageFormat.BC3_UNORM: return(TEX_FORMAT.BC3_UNORM);

            case NUTEXImageFormat.BC3_SRGB: return(TEX_FORMAT.BC3_UNORM_SRGB);

            case NUTEXImageFormat.BC4_UNORM: return(TEX_FORMAT.BC4_UNORM);

            case NUTEXImageFormat.BC4_SNORM: return(TEX_FORMAT.BC4_SNORM);

            case NUTEXImageFormat.BC5_UNORM: return(TEX_FORMAT.BC5_UNORM);

            case NUTEXImageFormat.BC5_SNORM: return(TEX_FORMAT.BC5_SNORM);

            case NUTEXImageFormat.BC6_UFLOAT: return(TEX_FORMAT.BC6H_UF16);

            case NUTEXImageFormat.BC6_SFLOAT: return(TEX_FORMAT.BC6H_SF16);

            case NUTEXImageFormat.BC7_UNORM: return(TEX_FORMAT.BC7_UNORM);

            case NUTEXImageFormat.BC7_SRGB: return(TEX_FORMAT.BC7_UNORM_SRGB);

            case NUTEXImageFormat.R32G32B32A32_FLOAT: return(TEX_FORMAT.R32G32B32A32_FLOAT);

            case NUTEXImageFormat.R8G8B8A8_SRGB: return(TEX_FORMAT.R8G8B8A8_UNORM_SRGB);

            case NUTEXImageFormat.R8G8B8A8_UNORM: return(TEX_FORMAT.R8G8B8A8_UNORM);

            default:
                throw new Exception($"Cannot convert format {nutFormat}");
            }
        }
Exemplo n.º 9
0
        public override void Replace(string FileName)
        {
            var bntxFile = new BNTX();
            var tex      = new TextureData();

            tex.Replace(FileName, MipCount, 0, Format);

            //If it's null, the operation is cancelled
            if (tex.Texture == null)
            {
                return;
            }

            List <byte[]> data = new List <byte[]>();

            foreach (var array in tex.Texture.TextureData)
            {
                data.Add(array[0]);
            }

            var output = Utils.CombineByteArray(data.ToArray());

            Width    = tex.Texture.Width;
            Height   = tex.Texture.Height;
            MipCount = tex.Texture.MipCount;
            // ArrayCount = tex.Texture.ArrayLength;
            // Depth = tex.Texture.Depth;

            Format    = tex.Format;
            NutFormat = ConvertGenericToNutFormat(tex.Format);

            mipSizes = TegraX1Swizzle.GenerateMipSizes(tex.Format, tex.Width, tex.Height, tex.Depth, tex.ArrayCount, tex.MipCount, (uint)ImageData.Length);

            ImageData = SetImageData(output);

            data.Clear();
            UpdateEditor();
        }
Exemplo n.º 10
0
            private static bool IsCompressedFormat(NUTEXImageFormat Format)
            {
                switch (Format)
                {
                case NUTEXImageFormat.BC1_UNORM:
                case NUTEXImageFormat.BC1_SRGB:
                case NUTEXImageFormat.BC2_UNORM:
                case NUTEXImageFormat.BC2_SRGB:
                case NUTEXImageFormat.BC3_UNORM:
                case NUTEXImageFormat.BC3_SRGB:
                case NUTEXImageFormat.BC4_UNORM:
                case NUTEXImageFormat.BC4_SNORM:
                case NUTEXImageFormat.BC5_UNORM:
                case NUTEXImageFormat.BC5_SNORM:
                case NUTEXImageFormat.BC6_UFLOAT:
                case NUTEXImageFormat.BC7_UNORM:
                case NUTEXImageFormat.BC7_SRGB:
                    return(true);

                default:
                    return(false);
                }
            }
Exemplo n.º 11
0
        public override void Replace(string FileName)
        {
            if (Runtime.NUTEXBSettings.IsSwizzled)
            {
                var tex = new TextureData();
                tex.Replace(FileName, MipCount, 0, Format);

                //If it's null, the operation is cancelled
                if (tex.Texture == null)
                {
                    return;
                }

                List <byte[]> data = new List <byte[]>();
                foreach (var array in tex.Texture.TextureData)
                {
                    data.Add(array[0]);
                }

                var output = CreateBuffer(data);

                Width    = tex.Texture.Width;
                Height   = tex.Texture.Height;
                MipCount = tex.Texture.MipCount;
                // ArrayCount = tex.Texture.ArrayLength;
                // Depth = tex.Texture.Depth;

                Format    = tex.Format;
                NutFormat = ConvertGenericToNutFormat(tex.Format);

                mipSizes = TegraX1Swizzle.GenerateMipSizes(tex.Format, tex.Width, tex.Height, tex.Depth, tex.ArrayCount, tex.MipCount, (uint)ImageData.Length);

                ImageData = SetImageData(output);

                data.Clear();
            }
            else
            {
                GenericTextureImporterList     importer = new GenericTextureImporterList(SupportedFormats);
                GenericTextureImporterSettings settings = new GenericTextureImporterSettings();

                if (Utils.GetExtension(FileName) == ".dds" ||
                    Utils.GetExtension(FileName) == ".dds2")
                {
                    settings.LoadDDS(FileName);
                    importer.LoadSettings(new List <GenericTextureImporterSettings>()
                    {
                        settings,
                    });
                    ApplySettings(settings);
                    UpdateEditor();
                }
                else
                {
                    settings.LoadBitMap(FileName);
                    importer.LoadSettings(new List <GenericTextureImporterSettings>()
                    {
                        settings,
                    });

                    if (importer.ShowDialog() == DialogResult.OK)
                    {
                        if (settings.GenerateMipmaps && !settings.IsFinishedCompressing)
                        {
                            settings.DataBlockOutput.Clear();
                            settings.DataBlockOutput.Add(settings.GenerateMips(importer.CompressionMode, importer.MultiThreading));
                        }

                        ApplySettings(settings);
                        UpdateEditor();
                    }
                }
            }

            UpdateEditor();
        }
Exemplo n.º 12
0
        public override void Replace(string FileName)
        {
            var bntxFile = new BNTX();
            var tex      = new TextureData();

            tex.Replace(FileName, MipCount, 0, Format);

            //If it's null, the operation is cancelled
            if (tex.Texture == null)
            {
                return;
            }

            var surfacesNew = tex.GetSurfaces();
            var surfaces    = GetSurfaces();

            if (LimitFileSize)
            {
                if (surfaces[0].mipmaps[0].Length < surfacesNew[0].mipmaps[0].Length)
                {
                    if (surfaces[0].mipmaps[0].Length != surfacesNew[0].mipmaps[0].Length)
                    {
                        throw new Exception($"Image must be the same size! {surfaces[0].mipmaps[0].Length}");
                    }

                    if (mipSizes[0].Length != surfacesNew[0].mipmaps.Count)
                    {
                        throw new Exception($"Mip map count must be the same! {mipSizes[0].Length}");
                    }

                    if (Width != tex.Texture.Width || Height != tex.Texture.Height)
                    {
                        throw new Exception("Image size must be the same!");
                    }
                }

                Width    = tex.Texture.Width;
                Height   = tex.Texture.Height;
                MipCount = tex.Texture.MipCount;
            }
            else
            {
                Width      = tex.Texture.Width;
                Height     = tex.Texture.Height;
                MipCount   = tex.Texture.MipCount;
                ArrayCount = tex.Texture.ArrayLength;
                Depth      = tex.Texture.Depth;

                Format    = tex.Format;
                NutFormat = ConvertGenericToNutFormat(tex.Format);

                mipSizes = TegraX1Swizzle.GenerateMipSizes(tex.Format, tex.Width, tex.Height, tex.Depth, tex.ArrayCount, tex.MipCount, (uint)ImageData.Length);
            }

            List <byte[]> data = new List <byte[]>();

            foreach (var array in tex.Texture.TextureData)
            {
                data.Add(array[0]);
            }

            var output = Utils.CombineByteArray(data.ToArray());

            ImageData = SetImageData(output);

            data.Clear();
            surfacesNew.Clear();
            surfaces.Clear();

            UpdateEditor();
        }
Exemplo n.º 13
0
        private void Replace(object sender, EventArgs args)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = FileFilters.NUTEXB;

            ofd.Multiselect = false;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                var bntxFile = new BNTX();
                var tex      = new TextureData();
                tex.Replace(ofd.FileName, MipCount, Format);

                //If it's null, the operation is cancelled
                if (tex.Texture == null)
                {
                    return;
                }

                var surfacesNew = tex.GetSurfaces();
                var surfaces    = GetSurfaces();

                if (LimitFileSize)
                {
                    if (surfaces[0].mipmaps[0].Length != surfacesNew[0].mipmaps[0].Length)
                    {
                        throw new Exception($"Image must be the same size! {surfaces[0].mipmaps[0].Length}");
                    }

                    if (mipSizes[0].Length != surfacesNew[0].mipmaps.Count)
                    {
                        throw new Exception($"Mip map count must be the same! {mipSizes[0].Length}");
                    }

                    if (Width != tex.Texture.Width || Height != tex.Texture.Height)
                    {
                        throw new Exception("Image size must be the same!");
                    }

                    ImageData = tex.Texture.TextureData[0][0];

                    Width    = tex.Texture.Width;
                    Height   = tex.Texture.Height;
                    MipCount = tex.Texture.MipCount;
                }
                else
                {
                    ImageData = tex.Texture.TextureData[0][0];

                    Width    = tex.Texture.Width;
                    Height   = tex.Texture.Height;
                    MipCount = tex.Texture.MipCount;

                    Format    = tex.Format;
                    NutFormat = ConvertGenericToNutFormat(tex.Format);

                    mipSizes = TegraX1Swizzle.GenerateMipSizes(tex.Format, tex.Width, tex.Height, tex.Depth, tex.ArrayCount, tex.MipCount, (uint)ImageData.Length);
                }

                surfacesNew.Clear();
                surfaces.Clear();

                UpdateEditor();
            }
        }
Exemplo n.º 14
0
        public string ArcOffset; //Temp for exporting in batch

        private void Replace(object sender, EventArgs args)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "Supported Formats|*.dds; *.png;*.tga;*.jpg;*.tiff|" +
                         "Microsoft DDS |*.dds|" +
                         "Portable Network Graphics |*.png|" +
                         "Joint Photographic Experts Group |*.jpg|" +
                         "Bitmap Image |*.bmp|" +
                         "Tagged Image File Format |*.tiff|" +
                         "All files(*.*)|*.*";

            ofd.Multiselect = false;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                var bntxFile = new BNTX();
                var tex      = new TextureData();
                tex.Replace(ofd.FileName, MipCount, Format);

                //If it's null, the operation is cancelled
                if (tex.Texture == null)
                {
                    return;
                }

                var surfacesNew = tex.GetSurfaces();
                var surfaces    = GetSurfaces();

                if (LimitFileSize)
                {
                    if (surfaces[0].mipmaps[0].Length != surfacesNew[0].mipmaps[0].Length)
                    {
                        throw new Exception($"Image must be the same size! {surfaces[0].mipmaps[0].Length}");
                    }

                    if (mipSizes[0].Length != surfacesNew[0].mipmaps.Count)
                    {
                        throw new Exception($"Mip map count must be the same! {mipSizes[0].Length}");
                    }

                    if (Width != tex.Texture.Width || Height != tex.Texture.Height)
                    {
                        throw new Exception("Image size must be the same!");
                    }

                    ImageData = tex.Texture.TextureData[0][0];

                    Width    = tex.Texture.Width;
                    Height   = tex.Texture.Height;
                    MipCount = tex.Texture.MipCount;
                }
                else
                {
                    ImageData = tex.Texture.TextureData[0][0];

                    Width    = tex.Texture.Width;
                    Height   = tex.Texture.Height;
                    MipCount = tex.Texture.MipCount;

                    Format    = tex.Format;
                    NutFormat = ConvertGenericToNutFormat(tex.Format);

                    mipSizes = GenerateMipSizes();
                }

                surfacesNew.Clear();
                surfaces.Clear();

                UpdateEditor();
            }
        }