public void start(DoWorkEventHandler work, Action onFinish) { this.onFinish = onFinish; ImageTools.startWorker(work, progressChanged, close); this.ShowDialog(); }
private void generateFinished() { diffText = string.Empty; auxText = string.Empty; smoothText = string.Empty; if (generatorDiff != null) { diffuseNormMap = (DirectBitmap)generatorDiff.dest; diffuseDiffMap = (DirectBitmap)generatorDiff.difference; diffuseColDiffMap = (DirectBitmap)generatorDiff.coloredDiff; diffuseNormImage = ImageTools.BitmapToBitmapImage(diffuseNormMap.Bitmap); diffuseDiffImage = ImageTools.BitmapToBitmapImage(diffuseDiffMap.Bitmap); diffuseColDiffImage = ImageTools.BitmapToBitmapImage(diffuseColDiffMap.Bitmap); diffText = generatorDiff.outText; } if (generatorAux != null) { auxNormMap = (DirectBitmap)generatorAux.dest; auxDiffMap = (DirectBitmap)generatorAux.difference; auxColDiffMap = (DirectBitmap)generatorAux.coloredDiff; auxNormImage = ImageTools.BitmapToBitmapImage(auxNormMap.Bitmap); auxDiffImage = ImageTools.BitmapToBitmapImage(auxDiffMap.Bitmap); auxColDiffImage = ImageTools.BitmapToBitmapImage(auxColDiffMap.Bitmap); auxText = generatorAux.outText; if (string.IsNullOrEmpty(auxText)) { auxText = "0,0,0"; } } else { auxText = "0,0,0"; } if (generatorSmooth != null) { smoothNormMap = (DirectBitmap)generatorSmooth.dest; smoothDiffMap = (DirectBitmap)generatorSmooth.difference; smoothColDiffMap = (DirectBitmap)generatorSmooth.coloredDiff; smoothNormImage = ImageTools.BitmapToBitmapImage(smoothNormMap.Bitmap); smoothDiffImage = ImageTools.BitmapToBitmapImage(smoothDiffMap.Bitmap); smoothColDiffImage = ImageTools.BitmapToBitmapImage(smoothColDiffMap.Bitmap); smoothText = generatorSmooth.outText; if (string.IsNullOrEmpty(smoothText)) { smoothText = "0,0,0"; } } else { smoothText = "0,0,0"; } generatorDiff = null; generatorAux = null; generatorSmooth = null; //dispose of all of the Bitmaps used for processing diffuseNormMap?.Dispose(); diffuseNormMap = null; diffuseDiffMap?.Dispose(); diffuseDiffMap = null; diffuseColDiffMap?.Dispose(); diffuseColDiffMap = null; auxNormMap?.Dispose(); auxNormMap = null; auxDiffMap?.Dispose(); auxDiffMap = null; auxColDiffMap?.Dispose(); auxColDiffMap = null; smoothNormMap?.Dispose(); smoothNormMap = null; smoothDiffMap?.Dispose(); smoothDiffMap = null; smoothColDiffMap?.Dispose(); smoothColDiffMap = null; updatePreview(); }
private double getChannelLuminance(System.Drawing.Color color) { return(ImageTools.getChannelSelection(color, sourceChannel)); }
public void performConversion(string exportFolder) { Bitmap image1 = ImageTools.loadImage(Image1Path); if (image1 == null) { MessageBox.Show("Cannot process pair; first image is null"); return; } int width = image1.Width; int height = image1.Height; Bitmap image2 = ImageTools.loadImage(Image2Path); if (image2 != null) { if (image2.Width != width || image2.Height != height) { image1.Dispose(); image2.Dispose(); MessageBox.Show("Cannot convert images, they must be the same width and height"); return; } } else { MessageBox.Show("Cannot process pair; second image is null"); image1.Dispose(); return; } Bitmap output = new Bitmap(width, height); Color color1, color2; byte r, g, b, a; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { color1 = image1.GetPixel(x, y); color2 = image2 == null ? Color.White : image2.GetPixel(x, y); r = ImageTools.getChannelSelection(color1, color2, OutRChannel); g = ImageTools.getChannelSelection(color1, color2, OutGChannel); b = ImageTools.getChannelSelection(color1, color2, OutBChannel); a = ImageTools.getChannelSelection(color1, color2, OutAChannel); output.SetPixel(x, y, Color.FromArgb(a, r, g, b)); } } if (image1 != null) { image1.Dispose(); } if (image2 != null) { image2.Dispose(); } string fileName = System.IO.Path.GetFileName(Image1Path);//get just the filename from the image string exportFilePath = exportFolder + System.IO.Path.DirectorySeparatorChar + fileName; //TODO -- display error message if the output destination file already exists, prompt for overwrite? output.Save(exportFilePath);//append to the export path for save operations output.Dispose(); //if something other than PNG was specified for the output, //convert it using NVDXT tools to the specified format and delete the PNG if (OutputFormat != ImageFormat.PNG) { string inputPath = exportFilePath; string outputPath = inputPath.Substring(0, inputPath.LastIndexOf('.')) + ".dds";//strip file extension from the input, replace with '.dds' Process process = new Process(); process.StartInfo.FileName = "nvdxt.exe"; int format = OutputFormat == ImageFormat.DXT1 ? 1 : OutputFormat == ImageFormat.DXT5 ? 5 : 6; process.StartInfo.Arguments = getDDSCommand(inputPath, outputPath, format); process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.CreateNoWindow = true; process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.Start(); process.WaitForExit(); process.Close(); System.IO.File.Delete(exportFilePath);//remove the combined PNG, leave the converted DDS } }