/// <summary> /// Permite dirigir el programa al filtro que el usuario quiere aplicar. /// </summary> private void filterTypeImage() { MessageBox.Show(" Aplicando filtro ", "Notificación", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); Bitmap imagePixels = new Bitmap(imageContainer.Image); Stopwatch watch = new Stopwatch(); bool local = simpleModeB.Checked; updateTime(0, " "); updateTime(1, " "); Image newImage; if (local) { Console.WriteLine(filterIndex); switch (filterIndex) { case 0: watch.Start(); newImage = traditionalFilter.sepiaFilter(imagePixels); watch.Stop(); this.updateTime(1, watch.Elapsed.TotalSeconds.ToString() + " s"); watch.Start(); optimizedFilter.sepiaFilter(imagePixels); watch.Stop(); this.updateTime(2, watch.Elapsed.TotalSeconds.ToString() + " s"); this.imageContainer.Image = newImage; break; case 1: watch.Start(); newImage = traditionalFilter.grayScaleFilter(imagePixels); watch.Stop(); this.updateTime(1, watch.Elapsed.TotalSeconds.ToString() + " s"); watch.Start(); optimizedFilter.grayScaleFilter(imagePixels); watch.Stop(); this.updateTime(2, watch.Elapsed.TotalSeconds.ToString() + " s"); this.imageContainer.Image = newImage; break; case 2: try { watch.Start(); newImage = traditionalFilter.opacityFilter(imagePixels, Convert.ToDouble(filterPercentage.Text)); watch.Stop(); this.updateTime(1, watch.Elapsed.TotalSeconds.ToString() + " s"); watch.Start(); optimizedFilter.opacityFilter(imagePixels, Convert.ToDouble(filterPercentage.Text)); watch.Stop(); this.updateTime(2, watch.Elapsed.TotalSeconds.ToString() + " s"); this.imageContainer.Image = newImage; } catch { MessageBox.Show("Verifica el dato de entrada", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } break; case 3: watch.Start(); newImage = traditionalFilter.invertColorsFilter(imagePixels); watch.Stop(); this.updateTime(1, watch.Elapsed.TotalSeconds.ToString() + " s"); watch.Start(); optimizedFilter.invertColorsFilter(imagePixels); watch.Stop(); this.updateTime(2, watch.Elapsed.TotalSeconds.ToString() + " s"); this.imageContainer.Image = newImage; break; case 4: watch.Start(); newImage = traditionalFilter.GaussinBlurFilter(imagePixels, new Rectangle(0, 0, imagePixels.Width, imagePixels.Height), 4); watch.Stop(); this.updateTime(1, watch.Elapsed.TotalSeconds.ToString() + " s"); watch.Start(); GaussianBlur gaussian = new GaussianBlur(imagePixels); gaussian.Process(3); watch.Stop(); this.updateTime(2, watch.Elapsed.TotalSeconds.ToString() + " s"); this.imageContainer.Image = newImage; break; case 5: try { watch.Start(); newImage = traditionalFilter.brightFilter(imagePixels, Convert.ToDouble(filterPercentage.Text) / 100); watch.Stop(); this.updateTime(1, watch.Elapsed.TotalSeconds.ToString() + " s"); watch.Start(); optimizedFilter.brightFilter(imagePixels, Convert.ToDouble(filterPercentage.Text) / 100); watch.Stop(); this.updateTime(2, watch.Elapsed.TotalSeconds.ToString() + " s"); this.imageContainer.Image = newImage; } catch { MessageBox.Show("Verifica el dato de entrada", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } break; case 6: watch.Start(); newImage = traditionalFilter.colorsBalance(imagePixels); watch.Stop(); this.updateTime(1, watch.Elapsed.TotalSeconds.ToString() + " s"); watch.Start(); optimizedFilter.colorsBalance(imagePixels); watch.Stop(); this.updateTime(2, watch.Elapsed.TotalSeconds.ToString() + " s"); this.imageContainer.Image = newImage; break; case 7: watch.Start(); newImage = traditionalFilter.colorSubstitution(imagePixels, colorSubstitution); watch.Stop(); this.updateTime(1, watch.Elapsed.TotalSeconds.ToString() + " s"); watch.Start(); //esperar un segundo Thread.Sleep(1000); optimizedFilter.colorSubstitution(imagePixels, colorSubstitution); watch.Stop(); this.updateTime(2, watch.Elapsed.TotalSeconds.ToString() + " s"); this.imageContainer.Image = newImage; break; case 8: try { watch.Start(); newImage = traditionalFilter.CrudeHighPass(imagePixels, Convert.ToInt32(filterPercentage.Text) / 100); watch.Stop(); this.updateTime(1, watch.Elapsed.TotalSeconds.ToString() + " s"); watch.Start(); optimizedFilter.CrudeHighPass(imagePixels, Convert.ToInt32(filterPercentage.Text) / 100); watch.Stop(); this.updateTime(2, watch.Elapsed.TotalSeconds.ToString() + " s"); this.imageContainer.Image = newImage; } catch { MessageBox.Show("Verifica el dato de entrada", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } break; case 9: watch.Start(); newImage = traditionalFilter.EdgeFilter(imagePixels); watch.Stop(); this.updateTime(1, watch.Elapsed.TotalSeconds.ToString() + " s"); watch.Start(); optimizedFilter.EdgeFilter(imagePixels); watch.Stop(); this.updateTime(2, watch.Elapsed.TotalSeconds.ToString() + " s"); this.imageContainer.Image = newImage; break; case 10: watch.Start(); newImage = traditionalFilter.solariseFilter(imagePixels, 25, 40, 52); watch.Stop(); this.updateTime(1, watch.Elapsed.TotalSeconds.ToString() + " s"); watch.Start(); optimizedFilter.solariseFilter(imagePixels, 25, 40, 52); watch.Stop(); this.updateTime(2, watch.Elapsed.TotalSeconds.ToString() + " s"); this.imageContainer.Image = newImage; break; default: break; } } else { switch (filterIndex) { case 0: watch.Start(); ConnectionManager.FilterName = "Sepia"; ConnectionManager.Bitmap = imagePixels; ConnectionManager.AddConnections(servers); newImage = ConnectionManager.ApplyFilter(); watch.Stop(); this.updateTime(1, watch.Elapsed.TotalSeconds.ToString() + " s"); this.imageContainer.Image = newImage; break; case 1: watch.Start(); ConnectionManager.FilterName = "GrayScale"; ConnectionManager.Bitmap = imagePixels; ConnectionManager.AddConnections(servers); newImage = ConnectionManager.ApplyFilter(); watch.Stop(); this.updateTime(1, watch.Elapsed.TotalSeconds.ToString() + " s"); this.imageContainer.Image = newImage; break; case 2: double opacityValue = 0; try { opacityValue = double.Parse(filterPercentage.Text); if (opacityValue <= 0 || opacityValue > 255) { MessageBox.Show("Error: el numero debe ser un entero de 0 a 255", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } catch (Exception e) { MessageBox.Show("Error: el numero debe ser un entero de 0 a 255", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } watch.Start(); ConnectionManager.ParamValue = opacityValue; ConnectionManager.FilterName = "Opacity"; ConnectionManager.Bitmap = imagePixels; ConnectionManager.AddConnections(servers); newImage = ConnectionManager.ApplyFilter(); watch.Stop(); this.updateTime(1, watch.Elapsed.TotalSeconds.ToString() + " s"); this.imageContainer.Image = newImage; break; case 3: watch.Start(); ConnectionManager.FilterName = "InvertColors"; ConnectionManager.Bitmap = imagePixels; ConnectionManager.AddConnections(servers); newImage = ConnectionManager.ApplyFilter(); watch.Stop(); this.updateTime(1, watch.Elapsed.TotalSeconds.ToString() + " s"); this.imageContainer.Image = newImage; break; case 4: watch.Start(); ConnectionManager.FilterName = "GaussianBlur"; ConnectionManager.Bitmap = imagePixels; ConnectionManager.AddConnections(servers); newImage = ConnectionManager.ApplyFilter(); watch.Stop(); this.updateTime(1, watch.Elapsed.TotalSeconds.ToString() + " s"); this.imageContainer.Image = newImage; break; case 5: watch.Start(); double BrightValue = 0; try { BrightValue = double.Parse(filterPercentage.Text); if (BrightValue < 0 || BrightValue > 255) { MessageBox.Show("Error: Debe ser un numero entero", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } catch (Exception e) { MessageBox.Show("Error: el numero debe ser un entero", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ConnectionManager.ParamValue = BrightValue; ConnectionManager.FilterName = "Bright"; ConnectionManager.Bitmap = imagePixels; ConnectionManager.AddConnections(servers); newImage = ConnectionManager.ApplyFilter(); watch.Stop(); this.updateTime(1, watch.Elapsed.TotalSeconds.ToString() + " s"); this.imageContainer.Image = newImage; break; case 6: watch.Start(); ConnectionManager.FilterName = "ColorsBalance"; ConnectionManager.Bitmap = imagePixels; ConnectionManager.AddConnections(servers); newImage = ConnectionManager.ApplyFilter(); watch.Stop(); this.updateTime(1, watch.Elapsed.TotalSeconds.ToString() + " s"); this.imageContainer.Image = newImage; break; case 7: Color sourceColor = colorSubstitution.getSourceColor(); Color newColor = colorSubstitution.getNewColor(); int colorThreshold = colorSubstitution.getThreshold(); watch.Start(); ConnectionManager.FilterName = "ColorSubstitution"; ConnectionManager.Bitmap = imagePixels; ConnectionManager.Colors.Clear(); ConnectionManager.Colors.Add(sourceColor); ConnectionManager.Colors.Add(newColor); ConnectionManager.ParamValue = colorThreshold; ConnectionManager.AddConnections(servers); newImage = ConnectionManager.ApplyFilter(); watch.Stop(); updateTime(1, watch.Elapsed.TotalSeconds.ToString() + " s"); this.imageContainer.Image = newImage; break; case 8: watch.Start(); ConnectionManager.FilterName = "SolariseFilter"; ConnectionManager.Bitmap = imagePixels; ConnectionManager.AddConnections(servers); newImage = ConnectionManager.ApplyFilter(); watch.Stop(); updateTime(1, watch.Elapsed.TotalSeconds.ToString() + " s"); this.imageContainer.Image = newImage; break; case 9: watch.Start(); ConnectionManager.FilterName = "EdgeDetection"; ConnectionManager.Bitmap = imagePixels; ConnectionManager.AddConnections(servers); newImage = ConnectionManager.ApplyFilter(); watch.Stop(); updateTime(1, watch.Elapsed.TotalSeconds.ToString() + " s"); this.imageContainer.Image = newImage; break; case 10: ConnectionManager.FilterName = "CrudeHighPass"; double darknessValue = 0; Console.WriteLine(darknessValue); try { darknessValue = double.Parse(filterPercentage.Text); if (darknessValue <= 0 || darknessValue > 255) { MessageBox.Show("Error: el numero debe ser un entero de 0 a 255", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } catch (Exception e) { MessageBox.Show("Error: el numero debe ser un entero de 0 a 255", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ConnectionManager.ParamValue = darknessValue; ConnectionManager.Bitmap = imagePixels; watch.Start(); ConnectionManager.AddConnections(servers); newImage = ConnectionManager.ApplyFilter(); watch.Stop(); updateTime(1, watch.Elapsed.TotalSeconds.ToString() + " s"); this.imageContainer.Image = newImage; break; default: break; } } }