public void SaveTest(string input, string extension, PixelFormat compressionFormat, int minimumMipmapSize) { TexImage image = texTool.Load(TestTools.InputTestFolder + input); string output = Path.GetFileNameWithoutExtension(input) + extension; if (compressionFormat == PixelFormat.None) { texTool.Save(image, TestTools.TempFolder + output, minimumMipmapSize); } else { texTool.Save(image, TestTools.TempFolder + output, compressionFormat, minimumMipmapSize); } Assert.IsTrue(File.Exists(TestTools.TempFolder + output)); var loaded = texTool.Load(TestTools.TempFolder + output); Assert.IsTrue(TestTools.ComputeSHA1(loaded.Data, loaded.DataSize).Equals(TestTools.GetInstance().Checksum["TextureTool_Save_" + compressionFormat + "_" + minimumMipmapSize + "_" + loaded.Name])); //Console.WriteLine("TextureTool_Save_" + compressionFormat + "_" + minimumMipmapSize + "_" + loaded.Name + "." + TestTools.ComputeSHA1(loaded.Data, loaded.DataSize)); File.Delete(TestTools.TempFolder + output); loaded.Dispose(); image.Dispose(); }
public void Process() { TexImage image; foreach (string filePath in fileList) { Console.WriteLine(@"\n Thread # " + num + @" ---------------------------------------- PROCESSING " + filePath); image = texTool.Load(filePath); texTool.Rescale(image, 0.5f, 0.5f, Filter.Rescaling.Bicubic); if (image.MipmapCount <= 1) { texTool.GenerateMipMaps(image, Filter.MipMapGeneration.Cubic); } string outFile = Path.GetDirectoryName(filePath) + "\\out\\" + Path.GetFileName(filePath); outFile = Path.ChangeExtension(outFile, ".dds"); texTool.Save(image, outFile, Stride.Graphics.PixelFormat.BC3_UNorm); image.Dispose(); } }
public void Run(string[] args) { // Print the exe header PrintHeader(); foreach (String s in args) { Console.WriteLine(s); } Console.WriteLine(""); // Parse the command line if (!ParseCommandLine(args)) { Environment.Exit(-1); } // Check if we have a pattern InputPatternFile = Path.Combine(Environment.CurrentDirectory, InputPatternFile); int indexOfPattern = InputPatternFile.IndexOf('*'); bool isPattern = indexOfPattern >= 0; if (!isPattern) { InputPatternFile = Path.GetFullPath(InputPatternFile); } OutputFileOrDirectory = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, OutputFileOrDirectory)); var inputOutputFiles = new List <Tuple <string, string> >(); if (isPattern) { if (!Directory.Exists(OutputFileOrDirectory)) { Directory.CreateDirectory(OutputFileOrDirectory); } var directory = InputPatternFile.Substring(0, indexOfPattern); var pattern = InputPatternFile.Substring(indexOfPattern, InputPatternFile.Length - indexOfPattern); foreach (var file in Directory.EnumerateFiles(directory, pattern, SearchOption.AllDirectories)) { var outputFile = Path.Combine(OutputFileOrDirectory, file.Substring(directory.Length, file.Length - directory.Length)); bool excludeFile = false; foreach (var excludeItem in ExcludeList) { if (file.IndexOf(excludeItem, StringComparison.InvariantCultureIgnoreCase) >= 0) { excludeFile = true; break; } } if (!excludeFile) { inputOutputFiles.Add(new Tuple <string, string>(file, outputFile)); } } } else { inputOutputFiles.Add(new Tuple <string, string>(InputPatternFile, OutputFileOrDirectory)); } var texTool = new TextureTool(); GlobalLogger.GlobalMessageLogged += new ConsoleLogListener(); bool hasErrors = false; foreach (var inputOutputFile in inputOutputFiles) { var inputFile = inputOutputFile.Item1; var outputFile = inputOutputFile.Item2; TexImage image = null; try { image = texTool.Load(inputFile, IsSRgb); HandleResizing(texTool, image); if (FlipOrientation.HasValue) { texTool.Flip(image, FlipOrientation.Value); } if (MipMap) { texTool.GenerateMipMaps(image, MipMapFilter); } if (PreMulAlpha) { texTool.PreMultiplyAlpha(image); } if (TextureFormat.HasValue) { texTool.Compress(image, TextureFormat.Value); } texTool.Save(image, outputFile, MipMapSize); } catch (TextureToolsException) { hasErrors = true; } finally { if (image != null) { image.Dispose(); } } } texTool.Dispose(); if (hasErrors) { //Environment.Exit(-1); } }