예제 #1
0
 public void Dispose()
 {
     _cl?.Dispose();
     _cl = null;
     morphology?.Dispose();
     morphology = null;
     blur?.Dispose();
     blur = null;
 }
예제 #2
0
 public void Dispose()
 {
     _cl?.Dispose();
     _cl = null;
     morphology?.Dispose();
     morphology = null;
     blur?.Dispose();
     blur = null;
 }
예제 #3
0
        public GlowEffectGraph()
        {
            Blur.BlurAmount = 10;
            Blur.BorderMode = EffectBorderMode.Soft;

            morphology = new MorphologyEffect
            {
                Mode   = MorphologyEffectMode.Dilate,
                Width  = 10,
                Height = 10
            };

            Blur.Source = morphology;
        }
예제 #4
0
        public ICanvasImage GetRegionMask()
        {
            // Do we already have a cached version of this mask?
            ICanvasImage mask = cachedRegionMask.Get(regionFeather, regionDilate);

            if (mask == null)
            {
                mask = regionMask;

                // Expand or contract the selection?
                if (regionDilate != 0)
                {
                    mask = new MorphologyEffect
                    {
                        Source = new BorderEffect {
                            Source = mask
                        },
                        Mode   = (regionDilate > 0) ? MorphologyEffectMode.Dilate : MorphologyEffectMode.Erode,
                        Height = Math.Abs(regionDilate),
                        Width  = Math.Abs(regionDilate)
                    };
                }

                // Feather the selection?
                if (regionFeather > 0)
                {
                    mask = new GaussianBlurEffect
                    {
                        Source     = mask,
                        BlurAmount = regionFeather,
                        BorderMode = EffectBorderMode.Hard
                    };
                }

                // If this mask was expensive to compute, cache it now.
                if (mask != regionMask)
                {
                    mask = cachedRegionMask.Cache(Parent, mask, regionFeather, regionDilate);
                }
            }

            return(mask);
        }
예제 #5
0
        private ICanvasImage CreateMorphology()
        {
            var morphologyEffect = new MorphologyEffect
            {
                Source = bitmapTiger,
            };

            // Animation changes the morphology filter kernel size, and switches back and forth between the two modes.
            animationFunction = elapsedTime =>
            {
                var t = (int)((elapsedTime * 10) % 50);

                morphologyEffect.Mode = (t < 25) ? MorphologyEffectMode.Erode :
                                        MorphologyEffectMode.Dilate;

                textLabel = "Mode: " + morphologyEffect.Mode;

                morphologyEffect.Width      =
                    morphologyEffect.Height = t % 25 + 1;
            };

            return(morphologyEffect);
        }
예제 #6
0
        /// <summary>
        /// Generate the flame effect graph. This method is called before the text command list
        /// (input) is created.
        /// </summary>
        private void CreateFlameEffect()
        {
            // Thicken the text.
            morphology = new MorphologyEffect
            {
                // The Source property is set by SetupText().
                Mode   = MorphologyEffectMode.Dilate,
                Width  = 7,
                Height = 1
            };

            // Blur, then colorize the text from black to red to orange as the alpha increases.
            var colorize = new ColorMatrixEffect
            {
                Source = new GaussianBlurEffect
                {
                    Source     = morphology,
                    BlurAmount = 3f
                },
                ColorMatrix = new Matrix5x4
                {
                    M11 = 0f,
                    M12 = 0f,
                    M13 = 0f,
                    M14 = 0f,
                    M21 = 0f,
                    M22 = 0f,
                    M23 = 0f,
                    M24 = 0f,
                    M31 = 0f,
                    M32 = 0f,
                    M33 = 0f,
                    M34 = 0f,
                    M41 = 0f,
                    M42 = 1f,
                    M43 = 0f,
                    M44 = 1f,
                    M51 = 1f,
                    M52 = -0.5f,
                    M53 = 0f,
                    M54 = 0f
                }
            };

            // Generate a Perlin noise field (see flamePosition).
            // Animate the noise by modifying flameAnimation's transform matrix at render time.
            flameAnimation = new Transform2DEffect
            {
                Source = new BorderEffect
                {
                    Source = new TurbulenceEffect
                    {
                        Frequency = new Vector2(0.109f, 0.109f),
                        Size      = new Vector2(500.0f, 80.0f)
                    },
                    // Use Mirror extend mode to allow us to spatially translate the noise
                    // without any visible seams.
                    ExtendX = CanvasEdgeBehavior.Mirror,
                    ExtendY = CanvasEdgeBehavior.Mirror
                }
            };

            // Give the flame its wavy appearance by generating a displacement map from the noise
            // (see flameAnimation) and applying this to the text.
            // Stretch and position this flame behind the original text.
            flamePosition = new Transform2DEffect
            {
                Source = new DisplacementMapEffect
                {
                    Source       = colorize,
                    Displacement = flameAnimation,
                    Amount       = 40.0f
                }
                // Set the transform matrix at render time as it depends on window size.
            };

            // Composite the text over the flames.
            composite = new CompositeEffect()
            {
                Sources = { flamePosition, null }
                // Replace null with the text command list when it is created.
            };
        }
예제 #7
0
        private ICanvasImage CreateMorphology()
        {
            var morphologyEffect = new MorphologyEffect
            {
                Source = bitmapTiger,
            };

            // Animation changes the morphology filter kernel size, and switches back and forth between the two modes.
            animationFunction = elapsedTime =>
            {
                var t = (int)((elapsedTime * 10) % 50);

                morphologyEffect.Mode = (t < 25) ? MorphologyEffectMode.Erode :
                                                   MorphologyEffectMode.Dilate;

                textLabel = "Mode: " + morphologyEffect.Mode;

                morphologyEffect.Width =
                morphologyEffect.Height = t % 25 + 1;
            };

            return morphologyEffect;
        }
예제 #8
0
        /// <summary>
        /// Generate the flame effect graph. This method is called before the text command list
        /// (input) is created.
        /// </summary>
        private void CreateFlameEffect()
        {
            // Thicken the text.
            morphology = new MorphologyEffect
            {
                // The Source property is set by SetupText().
                Mode = MorphologyEffectMode.Dilate,
                Width = 7,
                Height = 1
            };

            // Blur, then colorize the text from black to red to orange as the alpha increases.
            var colorize = new ColorMatrixEffect
            {
                Source = new GaussianBlurEffect
                {
                    Source = morphology,
                    BlurAmount = 3f
                },
                ColorMatrix = new Matrix5x4
                {
                    M11 = 0f, M12 = 0f, M13 = 0f, M14 = 0f,
                    M21 = 0f, M22 = 0f, M23 = 0f, M24 = 0f,
                    M31 = 0f, M32 = 0f, M33 = 0f, M34 = 0f,
                    M41 = 0f, M42 = 1f, M43 = 0f, M44 = 1f,
                    M51 = 1f, M52 = -0.5f, M53 = 0f, M54 = 0f
                }
            };

            // Generate a Perlin noise field (see flamePosition).
            // Animate the noise by modifying flameAnimation's transform matrix at render time.
            flameAnimation = new Transform2DEffect
            {
                Source = new BorderEffect
                {
                    Source = new TurbulenceEffect
                    {
                        Frequency = new Vector2(0.109f, 0.109f),
                        Size = new Vector2(500.0f, 80.0f)
                    },
                    // Use Mirror extend mode to allow us to spatially translate the noise
                    // without any visible seams.
                    ExtendX = CanvasEdgeBehavior.Mirror,
                    ExtendY = CanvasEdgeBehavior.Mirror
                }
            };

            // Give the flame its wavy appearance by generating a displacement map from the noise
            // (see flameAnimation) and applying this to the text.
            // Stretch and position this flame behind the original text.
            flamePosition = new Transform2DEffect
            {
                Source = new DisplacementMapEffect
                {
                    Source = colorize,
                    Displacement = flameAnimation,
                    Amount = 40.0f
                }
                // Set the transform matrix at render time as it depends on window size.
            };

            // Composite the text over the flames.
            composite = new CompositeEffect()
            {
                Sources = { flamePosition, null }
                // Replace null with the text command list when it is created.
            };
        }
예제 #9
0
        public ICanvasImage GetRegionMask()
        {
            // Do we already have a cached version of this mask?
            ICanvasImage mask = cachedRegionMask.Get(regionFeather, regionDilate);

            if (mask == null)
            {
                mask = regionMask;

                // Expand or contract the selection?
                if (regionDilate != 0)
                {
                    mask = new MorphologyEffect
                    {
                        Source = new BorderEffect { Source = mask },
                        Mode = (regionDilate > 0) ? MorphologyEffectMode.Dilate : MorphologyEffectMode.Erode,
                        Height = Math.Abs(regionDilate),
                        Width = Math.Abs(regionDilate)
                    };
                }

                // Feather the selection?
                if (regionFeather > 0)
                {
                    mask = new GaussianBlurEffect
                    {
                        Source = mask,
                        BlurAmount = regionFeather,
                        BorderMode = EffectBorderMode.Hard
                    };
                }

                // If this mask was expensive to compute, cache it now.
                if (mask != regionMask)
                {
                    mask = cachedRegionMask.Cache(Parent, mask, regionFeather, regionDilate);
                }
            }

            return mask;
        }