private void SelectMaskClick(object sender, RoutedEventArgs e) { string img4 = ImageTools.openFileSelectDialog("Select a PNG mask image"); MaskFileBox.Text = img4; maskMap = new DirectBitmap(ImageTools.loadImage(img4)); maskImage = ImageTools.BitmapToBitmapImage(maskMap.Bitmap); updatePreview(); }
private void SelectSmoothClick(object sender, RoutedEventArgs e) { string img3 = ImageTools.openFileSelectDialog("Select a PNG base image"); SmoothFileBox.Text = img3; smoothMap = new DirectBitmap(ImageTools.loadImage(img3)); smoothImage = ImageTools.BitmapToBitmapImage(smoothMap.Bitmap); updatePreview(); }
private void SelectSpecClick(object sender, RoutedEventArgs e) { string img2 = ImageTools.openFileSelectDialog("Select a PNG base image"); SpecFileBox.Text = img2; auxMap = new DirectBitmap(ImageTools.loadImage(img2)); auxImage = ImageTools.BitmapToBitmapImage(auxMap.Bitmap); updatePreview(); }
private void SelectBaseMapClik(object sender, RoutedEventArgs e) { string img1 = ImageTools.openFileSelectDialog("Select a PNG base image"); DiffFileBox.Text = img1; diffuseMap = new DirectBitmap(ImageTools.loadImage(img1)); diffuseImage = ImageTools.BitmapToBitmapImage(diffuseMap.Bitmap); updatePreview(); }
private void processEntry(TextureRemapEntry entry) { Bitmap image1 = ImageTools.loadImage(entry.Image1Name); 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(entry.Image2Name); 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; } } 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, entry.ImageR); g = ImageTools.getChannelSelection(color1, color2, entry.ImageG); b = ImageTools.getChannelSelection(color1, color2, entry.ImageB); a = ImageTools.getChannelSelection(color1, color2, entry.ImageA); output.SetPixel(x, y, Color.FromArgb(a, r, g, b)); } } if (image1 != null) { image1.Dispose(); } if (image2 != null) { image2.Dispose(); } output.Save(entry.OutputName); output.Dispose(); }
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 } }