/// <summary> /// Processing without background worker. /// </summary> public override Raster ProcessWithoutWorker(Raster rOriginal) { int width = rOriginal.Width; int height = rOriginal.Height; Raster raster = new Raster(width, height); byte threshold = (byte)(this.lightThreshold * 255); VectorRgb color; //bright pass for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { color = rOriginal[i, j]; if (color.R > threshold || color.G > threshold || color.B > threshold) raster[i, j] = color; else raster[i, j] = new VectorRgb(0, 0, 0); } } //blur SmoothingFilter filterSmoothing = new SmoothingFilter(ColorSpaceMode.RGB, this.blurRadius); raster = filterSmoothing.ProcessWithoutWorker(raster); //processing (mixing original raster with blured light raster) for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { color = raster[i, j] * this.bloomBlendFactor; raster[i, j] = rOriginal[i, j] + color; } } return raster; }
/// <summary> /// Function that apply bloom filter to raster. /// </summary> /// <param name="rOriginal">Original raster.</param> /// <param name="worker">Background worker.</param> /// <returns>Modifyed raster.</returns> public override Raster ProcessRaster(Raster rOriginal, System.ComponentModel.BackgroundWorker worker) { worker.WorkerReportsProgress = true; int width = rOriginal.Width; int height = rOriginal.Height; Raster raster = new Raster(width, height); DateTime startTime = DateTime.Now; byte threshold = (byte)(this.lightThreshold * 255); VectorRgb color; //bright pass for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { color = rOriginal[i, j]; if (color.R > threshold || color.G > threshold || color.B > threshold) raster[i, j] = color; else raster[i, j] = new VectorRgb(0, 0, 0); } worker.ReportProgress((int)(100f * i / width), DateTime.Now - startTime); } //blur SmoothingFilter filterSmoothing = new SmoothingFilter(ColorSpaceMode.RGB, this.blurRadius); raster = filterSmoothing.ProcessRaster(raster, worker); //processing (mixing original raster with blured light raster) for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { color = raster[i, j] * this.bloomBlendFactor; raster[i, j] = rOriginal[i, j] + color; } worker.ReportProgress((int)(100f * i / width), DateTime.Now - startTime); } return raster; }
private void smoothingToolStripMenuItem_Click(object sender, EventArgs e) { cipFormSmoothing form = new cipFormSmoothing(this.picBoxModifyed.Image,this.GetCurrentRaster()); if (form.ShowDialog()==DialogResult.OK) { Cip.Filters.ColorSpaceMode mode = form.GetMode(); Cip.Filters.SmoothingMode sMode = form.GetSMode(); float sigma = form.GetSigma(); int radius = form.GetRadius(); #region switch switch (sMode) { case SmoothingMode.Smoothing: { if (!backgroundWorkerCip.IsBusy) { ImageFilter filter = new Cip.Filters.SmoothingFilter(mode, radius); backgroundWorkerCip.RunWorkerAsync(filter); this.CalculateHistogram(); } break; } case SmoothingMode.Blur: { if (!backgroundWorkerCip.IsBusy) { ImageFilter filter = Cip.Filters.LinearFilter.SimpleBlurFilter(radius); backgroundWorkerCip.RunWorkerAsync(filter); this.CalculateHistogram(); } break; } case SmoothingMode.GaussianBlur: { if (!backgroundWorkerCip.IsBusy) { ImageFilter filter = Cip.Filters.LinearFilter.GaussianBlurFilter(radius, sigma); backgroundWorkerCip.RunWorkerAsync(filter); this.CalculateHistogram(); } break; } } #endregion } }
public void ReDraw() { this.Check(); switch (sMode) { case SmoothingMode.Smoothing: { SmoothingFilter filter = new Cip.Filters.SmoothingFilter(this.mode, this.radius); Raster result = filter.ProcessWithoutWorker(this.raster); result.ShowFilter(this.pBoxPreview); break; } case SmoothingMode.Blur: { LinearFilter filter = Cip.Filters.LinearFilter.SimpleBlurFilter(this.radius); Raster result = filter.ProcessWithoutWorker(this.raster); result.ShowFilter(this.pBoxPreview); break; } case SmoothingMode.GaussianBlur: { LinearFilter filter = Cip.Filters.LinearFilter.GaussianBlurFilter(this.radius, this.sigma); Raster result = filter.ProcessWithoutWorker(this.raster); result.ShowFilter(this.pBoxPreview); break; } } }
private void fastSmoothingToolStripMenuItem_Click(object sender, EventArgs e) { if (!backgroundWorkerCip.IsBusy) { ImageFilter filter = new Cip.Filters.SmoothingFilter(Cip.Filters.ColorSpaceMode.RGB, 1); backgroundWorkerCip.RunWorkerAsync(filter); this.CalculateHistogram(); } }