Example #1
0
        /// <inheritdoc />
        /// <summary>
        ///      Creates a new blur container
        /// </summary>
        public BlurContainer(BlurType blurType, float strength)
        {
            // ReSharper disable once ArrangeConstructorOrDestructorBody
            SpriteBatchOptions = new SpriteBatchOptions()
            {
                SortMode          = SpriteSortMode.Deferred,
                BlendState        = BlendState.NonPremultiplied,
                SamplerState      = SamplerState.PointClamp,
                DepthStencilState = DepthStencilState.Default,
                RasterizerState   = RasterizerState.CullNone,
            };

            // Load all three shaders.
            BlurEffects = new Dictionary <BlurType, Effect>
            {
                { BlurType.Gaussian, new Effect(GameBase.Game.GraphicsDevice, GameBase.Game.Resources.Get("Wobble.Resources/Shaders/gaussian-blur.mgfxo")) },
                { BlurType.Frosty, new Effect(GameBase.Game.GraphicsDevice, GameBase.Game.Resources.Get("Wobble.Resources/Shaders/frosty-blur.mgfxo")) },
                { BlurType.Fast, new Effect(GameBase.Game.GraphicsDevice, GameBase.Game.Resources.Get("Wobble.Resources/Shaders/fast-blur.mgfxo")) },
            };

            BlurType = blurType;
            Strength = strength;

            SpriteBatchOptions.Shader = new Shader(BlurEffects[BlurType], new Dictionary <string, object>
            {
                { "p_blurValues", new Vector3(Width, Height, Strength) }
            });
        }
Example #2
0
 public Blur()
 {
     downsample     = 1;
     blurSize       = 3f;
     blurIterations = 2;
     blurType       = BlurType.StandardGauss;
 }
Example #3
0
        internal static pTexture CreateBlurTexture(pTexture texture, int radius, BlurType type)
        {
            if (!ConfigManager.sShaders || radius == 0 || texture.TextureGl.IsTransparent)
            {
                return(texture);
            }

            List <BlurTexturePair> currentCache = null;

            if (!blurCache.TryGetValue(texture, out currentCache))
            {
                currentCache = new List <BlurTexturePair>();
            }

            int currentIndex = currentCache.FindIndex(c => c.Radius == radius && c.Type == type);

            if (currentIndex != -1)
            {
                return(currentCache[currentIndex].Texture);
            }

            if (vShader == null || hShader == null)
            {
                Initialize();
            }

            vShader.Properties[@"texSize"] = hShader.Properties[@"texSize"] = new OpenTK.Vector2(texture.Width, texture.Height);

            using (RenderTarget2D target = new RenderTarget2D(texture.Width, texture.Height))
            {
                target.Bind();

                texture.TextureGl.Draw(Vector2.Zero, Vector2.Zero, Color.White, new Vector2(1, -1), 0, null);

                for (int i = 0; i < (int)type; i++)
                {
                    hShader.Begin();
                    hShader.Properties[@"radius"] = radius;
                    target.Texture.Draw(Vector2.Zero, Vector2.Zero, Color.White, new Vector2(1, -1), 0, null);
                    hShader.End();

                    vShader.Begin();
                    vShader.Properties[@"radius"] = radius;
                    target.Texture.Draw(Vector2.Zero, Vector2.Zero, Color.White, new Vector2(1, -1), 0, null);
                    vShader.End();
                }

                target.Unbind();

                target.Texture.WrapMode = texture.TextureGl.WrapMode; // We want to retain the wrap mode we had prior to blurring.
                pTexture newTex = new pTexture(target.Texture);

                currentCache.Add(new BlurTexturePair()
                {
                    Type = type, Radius = radius, Texture = newTex
                });
                blurCache[texture] = currentCache;
                return(newTex);
            }
        }
Example #4
0
 public SvgGaussianBlur(float stdDeviation, BlurType blurType)
     : base()
 {
     _stdDeviation = stdDeviation;
     BlurType      = blurType;
     PreCalculate();
 }
        /// <inheritdoc />
        protected override void LoadContent()
        {
            // We load the city meshes into a model
            Model = Game.Content.Load <Model>(ContentFolder3D + "scene/city");

            // Load the post-processing effect
            Effect = Game.Content.Load <Effect>(ContentFolderEffects + "GaussianBlur");

            // Create a full screen quad to post-process
            FullScreenQuad = new FullScreenQuad(GraphicsDevice);

            // Create render targets. One can be used for simple gaussian blur
            // mainRenderTarget is also used as a render target in the separated filter
            // horizontalRenderTarget is used as the horizontal render target in the separated filter
            MainRenderTarget = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width,
                                                  GraphicsDevice.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 0,
                                                  RenderTargetUsage.DiscardContents);
            HorizontalRenderTarget = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width,
                                                        GraphicsDevice.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.None, 0,
                                                        RenderTargetUsage.DiscardContents);

            Effect.Parameters["screenSize"]
            .SetValue(new Vector2(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height));

            currentBlurType = BlurType.SEPARATED_PASSES;

            spriteFont = Game.Content.Load <SpriteFont>(ContentFolderSpriteFonts + "Arial");

            base.LoadContent();
        }
Example #6
0
 public void Clone(BloomByAlpha src)
 {
     threshold      = src.threshold;
     intensity      = src.intensity;
     blurSize       = src.blurSize;
     resolution     = src.resolution;
     blurIterations = src.blurIterations;
     blurType       = src.blurType;
 }
Example #7
0
 public FastBloom()
 {
     threshhold     = 0.25f;
     intensity      = 0.75f;
     blurSize       = 1f;
     resolution     = Resolution.Low;
     blurIterations = 1;
     blurType       = BlurType.Standard;
 }
 public override void OnEnable()
 {
     base.OnEnable();
     blurEffectModel = GetPostEffectModel <BlurEffectModel>();
     downsample      = blurEffectModel.downsample;
     blurSize        = blurEffectModel.blurSize;
     blurIterations  = blurEffectModel.blurIterations;
     blurType        = blurEffectModel.blurType;
     blurShader      = blurEffectModel.blur;
 }
Example #9
0
        public static Bitmap ImageBlurFilter(this Bitmap sourceBitmap, BlurType blurType)
        {
            Bitmap resultBitmap = null;

            switch (blurType)
            {
                case BlurType.Mean3x3:
                    {
                        resultBitmap = sourceBitmap.ConvolutionFilter(Matrix.Mean3x3, 1.0 / 9.0, 0);
                    } break;
                case BlurType.Mean5x5:
                    {
                        resultBitmap = sourceBitmap.ConvolutionFilter(Matrix.Mean5x5, 1.0 / 25.0, 0);
                    } break;
                case BlurType.Mean7x7:
                    {
                        resultBitmap = sourceBitmap.ConvolutionFilter(Matrix.Mean7x7, 1.0 / 49.0, 0);
                    } break;
                case BlurType.Modus3x3:
                    {
                        resultBitmap = sourceBitmap.ConvolutionFilter(Matrix.Modus3x3, 3.0 / 9.0, 0);
                    }break;
                case BlurType.Modus5x5:
                    {
                        resultBitmap = sourceBitmap.ConvolutionFilter(Matrix.Modus5x5, 3.0 / 25.0, 0);
                    } break;
                case BlurType.Modus7x7:
                    {
                        resultBitmap = sourceBitmap.ConvolutionFilter(Matrix.Modus7x7, 3.0 / 49.0, 0);
                    } break;
                case BlurType.Laplace:
                    {
                        resultBitmap = sourceBitmap.ConvolutionFilter(Matrix.LaplaceMask, 1.0 / 1.0, 0);
                    }break;
                case BlurType.Robert:
                    {
                        resultBitmap = sourceBitmap.ConvolutionFilter(Matrix.RobertMask, 1.0 / 1.0 , 0);
                    }break;
                case BlurType.Prewit:
                    {
                        resultBitmap = sourceBitmap.ConvolutionFilter(Matrix.PrewitMask, 1.0 / 1.0, 0);
                    }break;
                case BlurType.Sobel:
                    {
                        resultBitmap = sourceBitmap.ConvolutionFilter(Matrix.SobelMask, 1.0 / 1.0, 0);
                    } break;
                case BlurType.FreiChan:
                    {
                        resultBitmap = sourceBitmap.ConvolutionFilter(Matrix.FreiChanMask, 1.0 / 1.0, 0);
                    } break;

            }

            return resultBitmap;
        }
Example #10
0
        public void Render(
            RenderTexture source,
            RenderTexture destination,
            float blurSize,
            int downsample,
            int blurIterations,
            BlurType blurType)
        {
            float widthMod = 1.0f / (1.0f * (1 << downsample));

            blurMaterial.SetVector("_Parameter", new Vector4(blurSize * widthMod, -blurSize * widthMod, 0.0f, 0.0f));
            source.filterMode = FilterMode.Bilinear;

            int rtW = source.width >> downsample;
            int rtH = source.height >> downsample;

            // downsample
            RenderTexture rt = RenderTexture.GetTemporary(rtW, rtH, 0, source.format);

            rt.filterMode = FilterMode.Bilinear;
            Graphics.Blit(source, rt, blurMaterial, 0);

            var passOffs = blurType == BlurType.StandardGauss ? 0 : 2;

            for (int i = 0; i < blurIterations; i++)
            {
                float iterationOffs = (i * 1.0f);
                blurMaterial.SetVector("_Parameter", new Vector4(blurSize * widthMod + iterationOffs, -blurSize * widthMod - iterationOffs, 0.0f, 0.0f));

                // vertical blur
                RenderTexture rt2 = RenderTexture.GetTemporary(rtW, rtH, 0, source.format);
                rt2.filterMode = FilterMode.Bilinear;
                Graphics.Blit(rt, rt2, blurMaterial, 1 + passOffs);
                RenderTexture.ReleaseTemporary(rt);
                rt = rt2;

                // horizontal blur
                rt2            = RenderTexture.GetTemporary(rtW, rtH, 0, source.format);
                rt2.filterMode = FilterMode.Bilinear;
                Graphics.Blit(rt, rt2, blurMaterial, 2 + passOffs);
                RenderTexture.ReleaseTemporary(rt);
                rt = rt2;
            }

            Graphics.Blit(rt, destination);

            RenderTexture.ReleaseTemporary(rt);
        }
Example #11
0
 public DepthOfFieldScatter()
 {
     focalLength         = 10f;
     focalSize           = 0.05f;
     aperture            = 11.5f;
     maxBlurSize         = 2f;
     blurType            = BlurType.DiscBlur;
     blurSampleCount     = BlurSampleCount.High;
     foregroundOverlap   = 1f;
     dx11BokehThreshhold = 0.5f;
     dx11SpawnHeuristic  = 0.0875f;
     dx11BokehScale      = 1.2f;
     dx11BokehIntensity  = 2.5f;
     focalDistance01     = 10f;
     internalBlurWidth   = 1f;
 }
Example #12
0
        public RenderTexture Render(
            RenderTexture source,
            float blurSize,
            int downsample,
            int blurIterations,
            BlurType blurType)
        {
            int rtW = source.width >> downsample;
            int rtH = source.height >> downsample;

            // downsample
            RenderTexture rt = RenderTexture.GetTemporary(rtW, rtH, 0, source.format);

            Render(source, rt, blurSize, downsample, blurIterations, blurType);
            return(rt);
        }
Example #13
0
        private static Shader FindShaderByBlurType(BlurType type)
        {
            switch (type)
            {
            case BlurType.Box:
            case BlurType.BoxBilinear:
                return(Shader.Find("URPLearn/PostProcessing/BoxBlur"));

            case BlurType.Gaussian:
            case BlurType.GaussianBilinear:
                return(Shader.Find("URPLearn/PostProcessing/GaussianBlur"));

            default:
                return(null);
            }
        }
Example #14
0
    public override void Render(PostProcessRenderContext context)
    {
        CommandBuffer command = context.command;

        command.BeginSample("BlurOptimized");
        int           value         = base.settings.downsample.value;
        float         value2        = base.settings.fadeToBlurDistance.value;
        float         value3        = base.settings.blurSize.value;
        int           value4        = base.settings.blurIterations.value;
        BlurType      value5        = base.settings.blurType.value;
        float         num           = 1f / (1f * (float)(1 << value));
        float         z             = 1f / Mathf.Clamp(value2, 0.001f, 10000f);
        PropertySheet propertySheet = context.propertySheets.Get(blurShader);

        propertySheet.properties.SetVector("_Parameter", new Vector4(value3 * num, (0f - value3) * num, z, 0f));
        int width  = context.width >> value;
        int height = context.height >> value;
        int num2   = Shader.PropertyToID("_BlurRT1");
        int num3   = Shader.PropertyToID("_BlurRT2");

        command.GetTemporaryRT(num2, width, height, 0, FilterMode.Bilinear, context.sourceFormat, RenderTextureReadWrite.Default);
        RuntimeUtilities.BlitFullscreenTriangle(command, context.source, num2, propertySheet, 0);
        int num4 = ((value5 != 0) ? 2 : 0);

        for (int i = 0; i < value4; i++)
        {
            float num5 = (float)i * 1f;
            propertySheet.properties.SetVector("_Parameter", new Vector4(value3 * num + num5, (0f - value3) * num - num5, z, 0f));
            command.GetTemporaryRT(num3, width, height, 0, FilterMode.Bilinear, context.sourceFormat);
            RuntimeUtilities.BlitFullscreenTriangle(command, num2, num3, propertySheet, 1 + num4);
            command.ReleaseTemporaryRT(num2);
            command.GetTemporaryRT(num2, width, height, 0, FilterMode.Bilinear, context.sourceFormat);
            RuntimeUtilities.BlitFullscreenTriangle(command, num3, num2, propertySheet, 2 + num4);
            command.ReleaseTemporaryRT(num3);
        }
        if (value2 <= 0f)
        {
            RuntimeUtilities.BlitFullscreenTriangle(command, num2, context.destination);
        }
        else
        {
            command.SetGlobalTexture("_Source", context.source);
            RuntimeUtilities.BlitFullscreenTriangle(command, num2, context.destination, propertySheet, 5);
        }
        command.ReleaseTemporaryRT(num2);
        command.EndSample("BlurOptimized");
    }
        public static Bitmap BlurFilter(this Bitmap bSource,
                                        BlurType bType)
        {
            Bitmap bResult = null;

            switch (bType)
            {
            case BlurType.Average3x3:
            {
                bResult = bSource.ConvoFilter(
                    BlurMatrix.Average3x3, 1.0 / 9.0, 0);
            }
            break;

            case BlurType.Average5x5:
            {
                bResult = bSource.ConvoFilter(
                    BlurMatrix.Average5x5, 1.0 / 25.0, 0);
            }
            break;

            case BlurType.Average7x7:
            {
                bResult = bSource.ConvoFilter(
                    BlurMatrix.Average7x7, 1.0 / 49.0, 0);
            }
            break;

            case BlurType.Average9x9:
            {
                bResult = bSource.ConvoFilter(
                    BlurMatrix.Average9x9, 1.0 / 81.0, 0);
            }
            break;

            case BlurType.Average11x11:
            {
                bResult = bSource.ConvoFilter(
                    BlurMatrix.Average11x11, 1.0 / 121.0, 0);
            }
            break;
            }

            return(bResult);
        }
Example #16
0
        public void play(BlurType t)
        {
            if (_playing && t != BlurType.FINAL) return;

            if (t == BlurType.SOFT) {
                _currentMaxTime = _softTime;
                _currentCurve = _soft;
            } else if (t == BlurType.HARD) {
                _currentMaxTime = _hardTime;
                _currentCurve = _hard;
            } else if (t == BlurType.FINAL) {
                _currentMaxTime = _finalTime;
                _currentCurve = _final;
            }
            _playing = true;
            _currentTime = 0;
            amount = 0;
        }
        /// <inheritdoc />
        public override void Update(GameTime gameTime)
        {
            // Update the state of the camera
            Camera.Update(gameTime);

            if (Keyboard.GetState().IsKeyDown(Keys.J))
            {
                currentBlurType = BlurType.NONE;
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.K))
            {
                currentBlurType = BlurType.SIMPLE;
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.L))
            {
                currentBlurType = BlurType.SEPARATED_PASSES;
            }

            base.Update(gameTime);
        }
Example #18
0
    public Bitmap ProcessBitmap(Bitmap srcBitmap, BlurType blurType = BlurType.Both, Rectangle?notBlurArea = null)
    {
        Bitmap blurBitmap;

        switch (blurType)
        {
        case BlurType.HorizontalOnly:
        case BlurType.VerticalOnly:
            blurBitmap = ProcessBitmapComponents(srcBitmap, blurType, notBlurArea);
            return(blurBitmap);

        case BlurType.Both:
            Bitmap blurBitmap2;
            blurBitmap  = ProcessBitmapComponents(srcBitmap, BlurType.HorizontalOnly, notBlurArea);
            blurBitmap2 = ProcessBitmapComponents(blurBitmap, BlurType.VerticalOnly, notBlurArea);
            blurBitmap.Dispose();
            return(blurBitmap2);
        }

        return(null);
    }
Example #19
0
        private static float GetBlurShift(BlurType blurType, int iterrationsCount)
        {
            switch (blurType)
            {
            case BlurType.Anisotropic:
            case BlurType.Box:
                return((float)(iterrationsCount * 0.65f) + 1.0f);

            case BlurType.Gaussian5x5:
                return(3.0f *  +iterrationsCount);

            case BlurType.Gaussian9x9:
                return(5.0f + iterrationsCount);

            case BlurType.Gaussian13x13:
                return(7.0f + iterrationsCount);

            default:
                throw new ArgumentException("Unknown blur type");
            }
        }
Example #20
0
    public Bitmap ProcessBitmapComponents(Bitmap srcBitmap, BlurType blurType, Rectangle?notBlurArea)
    {
        unsafe
        {
            Bitmap dstBitmap = new Bitmap(srcBitmap.Width, srcBitmap.Height);

            int width  = srcBitmap.Width;
            int height = srcBitmap.Height;

            Rectangle bitmapRect = new Rectangle(0, 0, width, height);

            //将Bitmap锁定到系统内存中,获得BitmapData
            BitmapData srcBmData = srcBitmap.LockBits(bitmapRect,
                                                      ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);


            //将Bitmap锁定到系统内存中,获得BitmapData
            BitmapData dstBmData = dstBitmap.LockBits(bitmapRect,
                                                      ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);

            byte *srcScan = (byte *)(void *)(srcBmData.Scan0);
            byte *dstScan = (byte *)(void *)(dstBmData.Scan0);

            //位图中第一个像素数据的地址。它也可以看成是位图中的第一个扫描行
            byte *srcPtr = srcScan;
            byte *dstPtr = dstScan;
            int   pos;


            if (notBlurArea == null)
            {
                if (blurType == BlurType.HorizontalOnly)
                {
                    for (int i = 0; i < height; i++)
                    {
                        pos = i * dstBmData.Stride;

                        for (int j = 0; j < width; j++)
                        {
                            *((int *)(dstPtr + pos)) = ComputeBlurColorHorizontal(srcBmData, i, j);
                            pos += 4;
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < height; i++)
                    {
                        pos = i * dstBmData.Stride;

                        for (int j = 0; j < width; j++)
                        {
                            *((int *)(dstPtr + pos)) = ComputeBlurColorVertical(srcBmData, i, j);
                            pos += 4;
                        }
                    }
                }
            }
            else
            {
                Rectangle rc = notBlurArea.Value;

                if (blurType == BlurType.HorizontalOnly)
                {
                    for (int i = 0; i < height; i++)
                    {
                        pos = i * dstBmData.Stride;

                        for (int j = 0; j < width; j++)
                        {
                            if (j >= rc.Left && j <= rc.Right &&
                                i >= rc.Top && i <= rc.Bottom)
                            {
                                pos += 4;
                                continue;
                            }

                            *((int *)(dstPtr + pos)) = ComputeBlurColorHorizontal(srcBmData, i, j);
                            pos += 4;
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < height; i++)
                    {
                        pos = i * dstBmData.Stride;

                        for (int j = 0; j < width; j++)
                        {
                            if (j >= rc.Left && j <= rc.Right &&
                                i >= rc.Top && i <= rc.Bottom)
                            {
                                pos += 4;
                                continue;
                            }

                            *((int *)(dstPtr + pos)) = ComputeBlurColorVertical(srcBmData, i, j);
                            pos += 4;
                        }
                    }
                }
            }

            srcBitmap.UnlockBits(srcBmData);
            dstBitmap.UnlockBits(dstBmData);

            return(dstBitmap);
        }
    }
Example #21
0
 public Bitmap ProcessImage(Image srcBitmap, BlurType blurType = BlurType.Both, Rectangle?notBlurArea = null)
 {
     return(ProcessBitmap((Bitmap)srcBitmap, blurType, notBlurArea));
 }
Example #22
0
        public static Bitmap ImageBlurFilter(this Bitmap sourceBitmap,
                                             BlurType blurType)
        {
            Bitmap resultBitmap = null;

            switch (blurType)
            {
            case BlurType.Mean3x3:
            {
                resultBitmap = sourceBitmap.ConvolutionFilter(
                    Matrix.Mean3x3, 1.0 / 9.0, 0);
            } break;

            case BlurType.Mean5x5:
            {
                resultBitmap = sourceBitmap.ConvolutionFilter(
                    Matrix.Mean5x5, 1.0 / 25.0, 0);
            } break;

            case BlurType.Mean7x7:
            {
                resultBitmap = sourceBitmap.ConvolutionFilter(
                    Matrix.Mean7x7, 1.0 / 49.0, 0);
            } break;

            case BlurType.Mean9x9:
            {
                resultBitmap = sourceBitmap.ConvolutionFilter(
                    Matrix.Mean9x9, 1.0 / 81.0, 0);
            } break;

            case BlurType.GaussianBlur3x3:
            {
                resultBitmap = sourceBitmap.ConvolutionFilter(
                    Matrix.GaussianBlur3x3, 1.0 / 16.0, 0);
            } break;

            case BlurType.GaussianBlur5x5:
            {
                resultBitmap = sourceBitmap.ConvolutionFilter(
                    Matrix.GaussianBlur5x5, 1.0 / 159.0, 0);
            } break;

            case BlurType.MotionBlur5x5:
            {
                resultBitmap = sourceBitmap.ConvolutionFilter(
                    Matrix.MotionBlur5x5, 1.0 / 10.0, 0);
            } break;

            case BlurType.MotionBlur5x5At45Degrees:
            {
                resultBitmap = sourceBitmap.ConvolutionFilter(
                    Matrix.MotionBlur5x5At45Degrees, 1.0 / 5.0, 0);
            } break;

            case BlurType.MotionBlur5x5At135Degrees:
            {
                resultBitmap = sourceBitmap.ConvolutionFilter(
                    Matrix.MotionBlur5x5At135Degrees, 1.0 / 5.0, 0);
            } break;

            case BlurType.MotionBlur7x7:
            {
                resultBitmap = sourceBitmap.ConvolutionFilter(
                    Matrix.MotionBlur7x7, 1.0 / 14.0, 0);
            } break;

            case BlurType.MotionBlur7x7At45Degrees:
            {
                resultBitmap = sourceBitmap.ConvolutionFilter(
                    Matrix.MotionBlur7x7At45Degrees, 1.0 / 7.0, 0);
            } break;

            case BlurType.MotionBlur7x7At135Degrees:
            {
                resultBitmap = sourceBitmap.ConvolutionFilter(
                    Matrix.MotionBlur7x7At135Degrees, 1.0 / 7.0, 0);
            } break;

            case BlurType.MotionBlur9x9:
            {
                resultBitmap = sourceBitmap.ConvolutionFilter(
                    Matrix.MotionBlur9x9, 1.0 / 18.0, 0);
            } break;

            case BlurType.MotionBlur9x9At45Degrees:
            {
                resultBitmap = sourceBitmap.ConvolutionFilter(
                    Matrix.MotionBlur9x9At45Degrees, 1.0 / 9.0, 0);
            } break;

            case BlurType.MotionBlur9x9At135Degrees:
            {
                resultBitmap = sourceBitmap.ConvolutionFilter(
                    Matrix.MotionBlur9x9At135Degrees, 1.0 / 9.0, 0);
            } break;

            case BlurType.Median3x3:
            {
                resultBitmap = sourceBitmap.MedianFilter(3);
            } break;

            case BlurType.Median5x5:
            {
                resultBitmap = sourceBitmap.MedianFilter(5);
            } break;

            case BlurType.Median7x7:
            {
                resultBitmap = sourceBitmap.MedianFilter(7);
            } break;

            case BlurType.Median9x9:
            {
                resultBitmap = sourceBitmap.MedianFilter(9);
            } break;

            case BlurType.Median11x11:
            {
                resultBitmap = sourceBitmap.MedianFilter(11);
            } break;
            }

            return(resultBitmap);
        }
Example #23
0
        /// <summary>
        /// Blurs a bitmap image using a specific blurring method.
        /// </summary>
        /// <param name="sourceBitmap">The bitmap to apply the blur to.</param>
        /// <param name="blurType">The type of blur to apply.</param>
        /// <returns>A bitmap that has had the blur applied to it.</returns>
        public static Bitmap ImageBlurFilter(this Bitmap sourceBitmap, BlurType blurType)
        {
            switch (blurType)
            {
            case BlurType.Mean3x3:

                return(sourceBitmap.ConvolutionFilter(BlurringMatrices.Mean3x3, 1.0 / 9.0, 0));

            case BlurType.Mean5x5:

                return(sourceBitmap.ConvolutionFilter(BlurringMatrices.Mean5x5, 1.0 / 25.0, 0));

            case BlurType.Mean7x7:

                return(sourceBitmap.ConvolutionFilter(BlurringMatrices.Mean7x7, 1.0 / 49.0, 0));

            case BlurType.Mean9x9:

                return(sourceBitmap.ConvolutionFilter(BlurringMatrices.Mean9x9, 1.0 / 81.0, 0));

            case BlurType.GaussianBlur3x3:

                return(sourceBitmap.ConvolutionFilter(BlurringMatrices.GaussianBlur3x3, 1.0 / 16.0, 0));

            case BlurType.GaussianBlur5x5:

                return(sourceBitmap.ConvolutionFilter(BlurringMatrices.GaussianBlur5x5, 1.0 / 159.0, 0));

            case BlurType.MotionBlur5x5:

                return(sourceBitmap.ConvolutionFilter(BlurringMatrices.MotionBlur5x5, 1.0 / 10.0, 0));

            case BlurType.MotionBlur5x5At45Degrees:

                return(sourceBitmap.ConvolutionFilter(BlurringMatrices.MotionBlur5x5At45Degrees, 1.0 / 5.0, 0));

            case BlurType.MotionBlur5x5At135Degrees:

                return(sourceBitmap.ConvolutionFilter(BlurringMatrices.MotionBlur5x5At135Degrees, 1.0 / 5.0, 0));

            case BlurType.MotionBlur7x7:

                return(sourceBitmap.ConvolutionFilter(BlurringMatrices.MotionBlur7x7, 1.0 / 14.0, 0));

            case BlurType.MotionBlur7x7At45Degrees:

                return(sourceBitmap.ConvolutionFilter(BlurringMatrices.MotionBlur7x7At45Degrees, 1.0 / 7.0, 0));

            case BlurType.MotionBlur7x7At135Degrees:

                return(sourceBitmap.ConvolutionFilter(BlurringMatrices.MotionBlur7x7At135Degrees, 1.0 / 7.0, 0));

            case BlurType.MotionBlur9x9:

                return(sourceBitmap.ConvolutionFilter(BlurringMatrices.MotionBlur9x9, 1.0 / 18.0, 0));

            case BlurType.MotionBlur9x9At45Degrees:

                return(sourceBitmap.ConvolutionFilter(BlurringMatrices.MotionBlur9x9At45Degrees, 1.0 / 9.0, 0));

            case BlurType.MotionBlur9x9At135Degrees:

                return(sourceBitmap.ConvolutionFilter(BlurringMatrices.MotionBlur9x9At135Degrees, 1.0 / 9.0, 0));

            case BlurType.Median3x3:

                return(sourceBitmap.MedianFilter(3));

            case BlurType.Median5x5:

                return(sourceBitmap.MedianFilter(5));

            case BlurType.Median7x7:

                return(sourceBitmap.MedianFilter(7));

            case BlurType.Median9x9:

                return(sourceBitmap.MedianFilter(9));

            case BlurType.Median11x11:

                return(sourceBitmap.MedianFilter(11));

            default:

                throw new Exception(string.Format("Unsupported blur type {0}", blurType.ToString()));
            }
        }
Example #24
0
        public static Bitmap ImageBlurFilter(this Bitmap sourceBitmap, BlurType blurType)
        {
            Bitmap resultBitmap = null;

            switch (blurType)
            {
                case BlurType.Mean3x3:
                {
                    resultBitmap = sourceBitmap.ConvolutionFilter(
                        Matrix.Mean3x3, 1.0 / 9.0, 0);
                }
                    break;
                case BlurType.Mean5x5:
                {
                    resultBitmap = sourceBitmap.ConvolutionFilter(
                        Matrix.Mean5x5, 1.0 / 25.0, 0);
                }
                    break;
                case BlurType.Mean7x7:
                {
                    resultBitmap = sourceBitmap.ConvolutionFilter(
                        Matrix.Mean7x7, 1.0 / 49.0, 0);
                }
                    break;
                case BlurType.Mean9x9:
                {
                    resultBitmap = sourceBitmap.ConvolutionFilter(
                        Matrix.Mean9x9, 1.0 / 81.0, 0);
                }
                    break;
                case BlurType.GaussianBlur3x3:
                {
                    resultBitmap = sourceBitmap.ConvolutionFilter(
                        Matrix.GaussianBlur3x3, 1.0 / 16.0, 0);
                }
                    break;
                case BlurType.GaussianBlur5x5:
                {
                    resultBitmap = sourceBitmap.ConvolutionFilter(
                        Matrix.GaussianBlur5x5, 1.0 / 159.0, 0);
                }
                    break;
                case BlurType.MotionBlur5x5:
                {
                    resultBitmap = sourceBitmap.ConvolutionFilter(
                        Matrix.MotionBlur5x5, 1.0 / 10.0, 0);
                }
                    break;
                case BlurType.MotionBlur5x5At45Degrees:
                {
                    resultBitmap = sourceBitmap.ConvolutionFilter(
                        Matrix.MotionBlur5x5At45Degrees, 1.0 / 5.0, 0);
                }
                    break;
                case BlurType.MotionBlur5x5At135Degrees:
                {
                    resultBitmap = sourceBitmap.ConvolutionFilter(
                        Matrix.MotionBlur5x5At135Degrees, 1.0 / 5.0, 0);
                }
                    break;
                case BlurType.MotionBlur7x7:
                {
                    resultBitmap = sourceBitmap.ConvolutionFilter(
                        Matrix.MotionBlur7x7, 1.0 / 14.0, 0);
                }
                    break;
                case BlurType.MotionBlur7x7At45Degrees:
                {
                    resultBitmap = sourceBitmap.ConvolutionFilter(
                        Matrix.MotionBlur7x7At45Degrees, 1.0 / 7.0, 0);
                }
                    break;
                case BlurType.MotionBlur7x7At135Degrees:
                {
                    resultBitmap = sourceBitmap.ConvolutionFilter(
                        Matrix.MotionBlur7x7At135Degrees, 1.0 / 7.0, 0);
                }
                    break;
                case BlurType.MotionBlur9x9:
                {
                    resultBitmap = sourceBitmap.ConvolutionFilter(
                        Matrix.MotionBlur9x9, 1.0 / 18.0, 0);
                }
                    break;
                case BlurType.MotionBlur9x9At45Degrees:
                {
                    resultBitmap = sourceBitmap.ConvolutionFilter(
                        Matrix.MotionBlur9x9At45Degrees, 1.0 / 9.0, 0);
                }
                    break;
                case BlurType.MotionBlur9x9At135Degrees:
                {
                    resultBitmap = sourceBitmap.ConvolutionFilter(
                        Matrix.MotionBlur9x9At135Degrees, 1.0 / 9.0, 0);
                }
                    break;
                case BlurType.Median3x3:
                {
                    resultBitmap = sourceBitmap.MedianFilter(3);
                }
                    break;
                case BlurType.Median5x5:
                {
                    resultBitmap = sourceBitmap.MedianFilter(5);
                }
                    break;
                case BlurType.Median7x7:
                {
                    resultBitmap = sourceBitmap.MedianFilter(7);
                }
                    break;
                case BlurType.Median9x9:
                {
                    resultBitmap = sourceBitmap.MedianFilter(9);
                }
                    break;
                case BlurType.Median11x11:
                {
                    resultBitmap = sourceBitmap.MedianFilter(11);
                }
                    break;
            }

            return resultBitmap;
        }
        private Bitmap ImageBlurFilter(Bitmap sourceBitmap,
                                       BlurType blurType)
        {
            Bitmap resultBitmap = null;

            switch (blurType)
            {
            case BlurType.Mean3x3:
            {
                resultBitmap = ConvolutionFilter(sourceBitmap,
                                                 new Matrix().Mean3x3, 1.0 / 9.0, 0);
            }
            break;

            case BlurType.Mean5x5:
            {
                resultBitmap = ConvolutionFilter(sourceBitmap,
                                                 new Matrix().Mean5x5, 1.0 / 25.0, 0);
            }
            break;

            case BlurType.Mean7x7:
            {
                resultBitmap = ConvolutionFilter(sourceBitmap,
                                                 new Matrix().Mean7x7, 1.0 / 49.0, 0);
            }
            break;

            case BlurType.Mean9x9:
            {
                resultBitmap = ConvolutionFilter(sourceBitmap,
                                                 new Matrix().Mean9x9, 1.0 / 81.0, 0);
            }
            break;

            case BlurType.GaussianBlur3x3:
            {
                resultBitmap = ConvolutionFilter(sourceBitmap,
                                                 new Matrix().GaussianBlur3x3, 1.0 / 16.0, 0);
            }
            break;

            case BlurType.GaussianBlur5x5:
            {
                resultBitmap = ConvolutionFilter(sourceBitmap,
                                                 new Matrix().GaussianBlur5x5, 1.0 / 159.0, 0);
            }
            break;

            case BlurType.MotionBlur5x5:
            {
                resultBitmap = ConvolutionFilter(sourceBitmap,
                                                 new Matrix().MotionBlur5x5, 1.0 / 10.0, 0);
            }
            break;

            case BlurType.MotionBlur5x5At45Degrees:
            {
                resultBitmap = ConvolutionFilter(sourceBitmap,
                                                 new Matrix().MotionBlur5x5At45Degrees, 1.0 / 5.0, 0);
            }
            break;

            case BlurType.MotionBlur5x5At135Degrees:
            {
                resultBitmap = ConvolutionFilter(sourceBitmap,
                                                 new Matrix().MotionBlur5x5At135Degrees, 1.0 / 5.0, 0);
            }
            break;

            case BlurType.MotionBlur7x7:
            {
                resultBitmap = ConvolutionFilter(sourceBitmap,
                                                 new Matrix().MotionBlur7x7, 1.0 / 14.0, 0);
            }
            break;

                //case BlurType.MotionBlur7x7At45Degrees:
                //	{
                //		resultBitmap = sourceBitmap.ConvolutionFilter(
                //		Matrix.MotionBlur7x7At45Degrees, 1.0 / 7.0, 0);
                //	}
                //	break;

                //case BlurType.MotionBlur7x7At135Degrees:
                //	{
                //		resultBitmap = sourceBitmap.ConvolutionFilter(
                //		Matrix.MotionBlur7x7At135Degrees, 1.0 / 7.0, 0);
                //	}
                //	break;

                //case BlurType.MotionBlur9x9:
                //	{
                //		resultBitmap = sourceBitmap.ConvolutionFilter(
                //		Matrix.MotionBlur9x9, 1.0 / 18.0, 0);
                //	}
                //	break;

                //case BlurType.MotionBlur9x9At45Degrees:
                //	{
                //		resultBitmap = sourceBitmap.ConvolutionFilter(
                //		Matrix.MotionBlur9x9At45Degrees, 1.0 / 9.0, 0);
                //	}
                //	break;

                //case BlurType.MotionBlur9x9At135Degrees:
                //	{
                //		resultBitmap = sourceBitmap.ConvolutionFilter(
                //		Matrix.MotionBlur9x9At135Degrees, 1.0 / 9.0, 0);
                //	}
                //	break;

                //case BlurType.Median3x3:
                //	{
                //		resultBitmap = sourceBitmap.MedianFilter(3);
                //	}
                //	break;

                //case BlurType.Median5x5:
                //	{
                //		resultBitmap = sourceBitmap.MedianFilter(5);
                //	}
                //	break;

                //case BlurType.Median7x7:
                //	{
                //		resultBitmap = sourceBitmap.MedianFilter(7);
                //	}
                //	break;

                //case BlurType.Median9x9:
                //	{
                //		resultBitmap = sourceBitmap.MedianFilter(9);
                //	}
                //	break;

                //case BlurType.Median11x11:
                //	{
                //		resultBitmap = sourceBitmap.MedianFilter(11);
                //	}
                break;
            }

            return(resultBitmap);
        }
Example #26
0
        public async Task <CommandResult> RunImageCommandAsync([Implicit] Image <Rgba32> image, int radius = 10, BlurType type = BlurType.Gaussian)
        {
            if (radius <= 250)
            {
                if ((image.Width > 8192 && image.Height > 8192) || radius > 100)
                {
                    decimal thing = (((decimal)(image.Width + image.Height + (radius * 2))) / 2M) / short.MaxValue;
                    await AccountsIntergration.EnsureBallanceAsync(Context, 8 *thing);
                }

                image.Mutate(m =>
                {
                    if (type == BlurType.Box)
                    {
                        m.BoxBlur(radius);
                    }
                    else
                    {
                        m.GaussianBlur(radius);
                    }
                });

                return(image.ToResult(Context));
            }
            else
            {
                throw new ArgumentOutOfRangeException();
            }
        }
Example #27
0
 public void SetBlurType(BlurType blurType)
 {
     this.blurType.Override(blurType);
 }
 public SvgGaussianBlur(int radius, BlurType blurType)
 {
     _radius = radius;
     _blurType = blurType;
     PreCalculate();
 }
Example #29
0
 public SvgGaussianBlur(int radius, BlurType blurType)
 {
     _radius   = radius;
     _blurType = blurType;
     PreCalculate();
 }
Example #30
0
 public static string GetBlurKeyword(BlurType type)
 {
     return(BlurTypes[type]);
 }
        private static void BlurBehindInternal(Form window, Color backgroundColor, double blurOpacity, BlurType intBlurType)
        {
            var blurType = (BlurType)intBlurType;

            if (blurType == BlurType.AcrylicBlur && !Helpers.AcrylicBlurAvailable())
            {
                return;
            }

            var accentState = AccentState.ACCENT_DISABLED;

            switch (blurType)
            {
            case BlurType.GaussianBlur:
                accentState = AccentState.ACCENT_ENABLE_BLURBEHIND;
                break;

            case BlurType.AcrylicBlur:
                accentState = AccentState.ACCENT_ENABLE_ACRYLICBLURBEHIND;
                break;

            default:
                accentState = AccentState.ACCENT_DISABLED;
                break;
            }

            uint backgroundColorValue = 0xFFFFFF; // ((uint)backgroundColor.B << 16) + ((uint)backgroundColor.G << 8) + ((uint)backgroundColor.R);
            uint blurOpacityValue     = 0;        // (uint)(blurOpacity * 255);

            var accent = new AccentPolicy()
            {
                AccentState   = accentState,
                GradientColor = (blurOpacityValue << 24) | (backgroundColorValue & 0xFFFFFF),
            };

            var accentStructSize = Marshal.SizeOf(accent);

            var accentPtr = Marshal.AllocHGlobal(accentStructSize);

            Marshal.StructureToPtr(accent, accentPtr, false);

            var data = new WindowCompositionAttributeData()
            {
                Attribute  = WindowCompositionAttribute.WCA_ACCENT_POLICY,
                SizeOfData = accentStructSize,
                Data       = accentPtr,
            };

            SetWindowCompositionAttribute(window.Handle, ref data);

            Marshal.FreeHGlobal(accentPtr);
        }
 public static Blur BLUR(BlurType type) => new Blur(type);
Example #33
0
        private void CreateVisuals(ITextViewLine line)
        {
            // Grab a reference to the lines in the current TextView
            IWpfTextViewLineCollection textViewLines = textView.TextViewLines;
            int             start      = line.Start;
            int             end        = line.End;
            List <Geometry> geometries = new List <Geometry>();

            var keywordFirstLetters = Lighthouse.keywordFormats.Keys
                                      .Select(k => k[0])
                                      .Distinct()
                                      .ToArray();

            char[] escapes =
            {
                ' ',
                '!',
                '"',
                '@',
                '$',
                '(',
                ')',
                '[',
                ']',
                '*',
                '-',
                '.',
                '/',
                '>',
                '<',
                '"',
                ':',
                ';',
                ',',
                '?',
                '\'',
                '\n',
                '\r',
                '\t',
                '='
            };
            isBlurred = Lighthouse.Options.Blurred;

            // ~~ Main Loop
            for (int i = start; i < end; i++)
            {
                if (keywordFirstLetters.Contains(textView.TextSnapshot[i]))
                {
                    foreach (var kvp in Lighthouse.keywordFormats)
                    {
                        string keyword = kvp.Key.Trim();

                        if (textView.TextSnapshot[i] == keyword[0] &&
                            i <= end - keyword.Length &&
                            textView.TextSnapshot.GetText(i, keyword.Length) == keyword &&
                            escapes.Contains(Convert.ToChar(textView.TextSnapshot.GetText(i - 1, 1))) &&
                            escapes.Contains(Convert.ToChar(textView.TextSnapshot.GetText(i + keyword.Length, 1)))
                            )
                        {
                            SnapshotSpan span =
                                new SnapshotSpan(textView.TextSnapshot, Span.FromBounds(i, i + keyword.Length));

                            Thickness t = new Thickness(2, 0, 2, 0);

                            switch (isBlurred)
                            {
                            case BlurType.BlurAll:
                                t = new Thickness(2, -3, 2, -3);

                                break;

                            case BlurType.Selective:
                                t = new Thickness(2,
                                                  kvp.Value.Blur != BlurIntensity.None ? -3 : 0,
                                                  2,
                                                  kvp.Value.Blur != BlurIntensity.None ? -3 : 0);
                                break;
                            }

                            Geometry markerGeometry = textViewLines.GetMarkerGeometry(span, true, t);
                            if (markerGeometry != null)
                            {
                                if (!geometries.Any(g => g.FillContainsWithDetail(markerGeometry) >
                                                    IntersectionDetail.Empty))
                                {
                                    geometries.Add(markerGeometry);
                                    AddMarker(span,
                                              markerGeometry,
                                              kvp.Value);
                                }
                            }
                        }
                    }
                }
            }
        }
 /// <summary>
 /// 블러
 /// </summary>
 /// <param name="sourceImage"></param>
 /// <param name="blurtype"></param>
 /// <returns></returns>
 public Bitmap GaussianBlurByType(Bitmap sourceImage, BlurType blurtype)
 {
     return(ImageBlurFilter(sourceImage, blurtype));
 }