コード例 #1
0
ファイル: cipEffects.cs プロジェクト: kyzmitch/Cip
        /// <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;
        }
コード例 #2
0
ファイル: cipEffects.cs プロジェクト: kyzmitch/Cip
        /// <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;
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: kyzmitch/Cip
        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
            }
        }
コード例 #4
0
ファイル: FormSmoothing.cs プロジェクト: kyzmitch/Cip
 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;
             }
     }
 }
コード例 #5
0
ファイル: MainForm.cs プロジェクト: kyzmitch/Cip
 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();
     }
 }