public (SKBitmap, FilteringStatsModel) MakeNoisy(SKBitmap input, int sigma) { var inputChannels = BitmapModel.Create(input); var noisyChannels = BitmapModel.Create(inputChannels.Width, inputChannels.Height, inputChannels.ColorType, inputChannels.AlphaType); var watch = Stopwatch.StartNew(); this.Noise(inputChannels, noisyChannels, sigma); watch.Stop(); var noisy = noisyChannels.ToBitmap(); var stats = BitmapHelpers.CalculateStats(input, noisy, watch.ElapsedMilliseconds); return(noisy, stats); }
public override async Task <(SKBitmap, FilteringStatsModel)> Run(SKBitmap raw) { var filtered = (SKBitmap)null; var stats = (FilteringStatsModel)null; var runnerException = (Exception)null; var runConfig = this.PrepareConfig(); var runResult = (RunResultDto)null; var serverPipe = new ServerPipe("testpipe", x => x.StartObjectReaderAsync()); serverPipe.Connected += async(sndr, args) => { try { serverPipe.Flush(); await serverPipe.WriteObject(runConfig); serverPipe.Flush(); } catch (Exception exception) { runnerException = exception; } }; serverPipe.DataReceived += (sndr, args) => { if (args.Error == null) { runResult = (RunResultDto)args.ObjectData; } else { runnerException = args.Error; } }; this.runnerProcess = Process.Start(new ProcessStartInfo { #if Linux FileName = "dotnet", #if DEBUG Arguments = Path.Combine("bin", "Debug", "net5.0", "NLMRunner.dll"), #else Arguments = "NLMRunner.dll", #endif ErrorDialog = true, #elif Windows FileName = "NLMRunner.exe", #endif }); await this.runnerProcess.WaitForExitAsync(); if (runResult != null) { if (runResult.Exception != null) { runnerException = runResult.Exception; } else { using (var filteredFile = new MemoryStream(runResult.OutputFile)) { filtered = SKBitmap.Decode(filteredFile); } stats = BitmapHelpers.CalculateStats(raw, filtered, runResult.Time); } } else if (!this.cancelled) { runnerException = new ApplicationException("Wystąpił niemożliwy do obsłużenia błąd krytyczny."); } if (runnerException != null) { throw runnerException; } if (filtered == null || stats == null) { throw new ApplicationException("Proces zakończył się bez rezultatu."); } return(filtered, stats); }