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(); } }
private void HandleResizing(TextureTool texTool, TexImage image) { if (Width != null && Height != null) { bool targetInPercent; var width = ParsePixelSize(Width, out targetInPercent); var height = ParsePixelSize(Height, out targetInPercent); if (targetInPercent) { texTool.Rescale(image, width / 100f, height / 100f, RescalingFilter); } else { texTool.Resize(image, width, height, RescalingFilter); } } else if (Width != null && Height == null) { bool targetInPercent; var width = ParsePixelSize(Width, out targetInPercent); if (targetInPercent) { texTool.Rescale(image, width / 100f, 1, RescalingFilter); } else { texTool.Resize(image, width, image.Height, RescalingFilter); } } else if (Width == null && Height != null) { bool targetInPercent; var height = ParsePixelSize(Height, out targetInPercent); if (targetInPercent) { texTool.Rescale(image, 1, height / 100f, RescalingFilter); } else { texTool.Resize(image, image.Width, height, RescalingFilter); } } }
public void RescaleTest(string file) { TexImage image = texTool.Load(TestTools.InputTestFolder + file); int width = image.Width; int height = image.Height; Assert.IsTrue(image.MipmapCount > 1); texTool.Rescale(image, 0.5f, 0.5f, Filter.Rescaling.Bicubic); Assert.IsTrue(image.Width == width / 2); Assert.IsTrue(image.Height == height / 2); Assert.IsTrue(image.MipmapCount == 1); Assert.IsTrue(TestTools.ComputeSHA1(image.Data, image.DataSize).Equals(TestTools.GetInstance().Checksum["TextureTool_Rescale_" + image.Name])); //Console.WriteLine("TextureTool_Rescale_" + image.Name + "." + TestTools.ComputeSHA1(image.Data, image.DataSize)); image.Dispose(); }
protected override Task <ResultStatus> DoCommandOverride(ICommandContext commandContext) { var assetManager = new AssetManager(); // Load image var image = assetManager.Load <Image>(InputUrl); // Initialize TextureTool library using (var texTool = new TextureTool()) using (var texImage = texTool.Load(image)) { var outputFormat = Format.HasValue ? Format.Value : image.Description.Format; // Apply transformations texTool.Decompress(texImage); if (IsAbsolute) { texTool.Resize(texImage, (int)Width, (int)Height, Filter.Rescaling.Lanczos3); } else { texTool.Rescale(texImage, Width / 100.0f, Height / 100.0f, Filter.Rescaling.Lanczos3); } // Generate mipmaps if (GenerateMipmaps) { texTool.GenerateMipMaps(texImage, Filter.MipMapGeneration.Box); } // Convert/Compress to output format texTool.Compress(texImage, outputFormat); // Save using (var outputImage = texTool.ConvertToParadoxImage(texImage)) { assetManager.Save(OutputUrl, outputImage); commandContext.Logger.Verbose("Compression successful [{3}] to ({0}x{1},{2})", outputImage.Description.Width, outputImage.Description.Height, outputImage.Description.Format, OutputUrl); } } return(Task.FromResult(ResultStatus.Successful)); }
public static ResultStatus ImportAndSaveTextureImage(UFile sourcePath, string outputUrl, TextureAsset textureAsset, TextureConvertParameters parameters, bool separateAlpha, CancellationToken cancellationToken, Logger logger) { var assetManager = new AssetManager(); using (var texTool = new TextureTool()) using (var texImage = texTool.Load(sourcePath)) { // Apply transformations texTool.Decompress(texImage); if (cancellationToken.IsCancellationRequested) // abort the process if cancellation is demanded { return(ResultStatus.Cancelled); } // Resize the image if (textureAsset.IsSizeInPercentage) { texTool.Rescale(texImage, textureAsset.Width / 100.0f, textureAsset.Height / 100.0f, Filter.Rescaling.Lanczos3); } else { texTool.Resize(texImage, (int)textureAsset.Width, (int)textureAsset.Height, Filter.Rescaling.Lanczos3); } if (cancellationToken.IsCancellationRequested) // abort the process if cancellation is demanded { return(ResultStatus.Cancelled); } // texture size is now determined, we can cache it var textureSize = new Int2(texImage.Width, texImage.Height); // Check that the resulting texture size is supported by the targeted graphics profile if (!TextureSizeSupported(textureAsset.Format, parameters.GraphicsPlatform, parameters.GraphicsProfile, textureSize, textureAsset.GenerateMipmaps, logger)) { return(ResultStatus.Failed); } // Apply the color key if (textureAsset.ColorKeyEnabled) { texTool.ColorKey(texImage, textureAsset.ColorKeyColor); } if (cancellationToken.IsCancellationRequested) // abort the process if cancellation is demanded { return(ResultStatus.Cancelled); } // Pre-multiply alpha if (textureAsset.PremultiplyAlpha) { texTool.PreMultiplyAlpha(texImage); } if (cancellationToken.IsCancellationRequested) // abort the process if cancellation is demanded { return(ResultStatus.Cancelled); } // Generate mipmaps if (textureAsset.GenerateMipmaps) { texTool.GenerateMipMaps(texImage, Filter.MipMapGeneration.Box); } if (cancellationToken.IsCancellationRequested) // abort the process if cancellation is demanded { return(ResultStatus.Cancelled); } // Convert/Compress to output format // TODO: Change alphaFormat depending on actual image content (auto-detection)? var outputFormat = DetermineOutputFormat(textureAsset.Format, textureAsset.Alpha, parameters.Platform, parameters.GraphicsPlatform, parameters.GraphicsProfile, textureSize, texImage.Format); texTool.Compress(texImage, outputFormat, (TextureConverter.Requests.TextureQuality)parameters.TextureQuality); if (cancellationToken.IsCancellationRequested) // abort the process if cancellation is demanded { return(ResultStatus.Cancelled); } // Save the texture if (separateAlpha) { TextureAlphaComponentSplitter.CreateAndSaveSeparateTextures(texTool, texImage, outputUrl, textureAsset.GenerateMipmaps); } else { using (var outputImage = texTool.ConvertToParadoxImage(texImage)) { if (cancellationToken.IsCancellationRequested) // abort the process if cancellation is demanded { return(ResultStatus.Cancelled); } assetManager.Save(outputUrl, outputImage); logger.Info("Compression successful [{3}] to ({0}x{1},{2})", outputImage.Description.Width, outputImage.Description.Height, outputImage.Description.Format, outputUrl); } } } return(ResultStatus.Successful); }