Ejemplo n.º 1
0
        private void ModdedTexOpen()
        {
            moddedTexPathBox.Text = moddedTexPath;
            moddedTexOpen         = true;
            if (!isWebImage)
            {
                texturePreview2.Image = null;
            }
            moddedFormat = "None";
            // Check if file is dds or png
            if (DDSFile.IsDDSFile(moddedTexPath) == true)
            {
                // Get dds data
                DDSContainer moddedTexture = DDSFile.Read(moddedTexPath);
                moddedFormat      = moddedTexture.Format.ToString();
                moddedDDS.MipMaps = moddedTexture.MipChains[0].Count;
                if (moddedFormat == "BC3_UNorm")
                {
                    moddedFormat = "DXT5";
                }
                else if (moddedFormat == "BC1_UNorm")
                {
                    moddedFormat = "DXT1";
                }
                moddedDDS.Format = moddedFormat;

                // Convert to png for preview
                DDSImage     modDDS    = new DDSImage(moddedTexPath);
                MemoryStream pngStream = new MemoryStream();
                modDDS.SaveAsPng(pngStream);
                var newPNG = Image.FromStream(pngStream);

                // Change labels
                moddedTexCompression.Text = moddedDDS.Format;
                mipMapCountLabel2.Text    = moddedDDS.MipMaps.ToString();
                texturePreview2.Image     = newPNG;
                previewLabel2.Text        = "Preview:";
                moddedDDS.ResX            = texturePreview2.Image.Width;
                moddedDDS.ResY            = texturePreview2.Image.Height;
                resolutionCheck2.Text     = moddedDDS.ResX.ToString() + "x" + moddedDDS.ResY.ToString();
                texturePreview2.SizeMode  = PictureBoxSizeMode.Zoom;

                // Dispose
                pngStream.Dispose();
                moddedTexture.Dispose();
            }
            else
            {
                // Bitmap/Png format
                if (moddedTexPath.Contains(".bmp"))
                {
                    moddedTexCompression.Text = "None (Bitmap)";
                }
                else if (moddedTexPath.Contains(".png"))
                {
                    moddedTexCompression.Text = "None (PNG)";
                }
                else
                {
                    moddedTexCompression.Text = "None";
                }
                mipMapCountLabel2.Text = "None";
                previewLabel2.Text     = "Preview:";
                if (!isWebImage)
                {
                    texturePreview2.Image    = new Bitmap(moddedTexPath);
                    texturePreview2.SizeMode = PictureBoxSizeMode.Zoom;
                }
                resolutionCheck2.Text = texturePreview2.Image.Width.ToString() + "x" + texturePreview2.Image.Height.ToString();
            }
            EnableButtons();
        }