public PipelineBuilder Blend(PipelineBuilder pipeline, BlendEffectMode mode, Placement placement = Placement.Foreground)
        {
            var pipelines = GetMergePipeline(this, pipeline, placement);

            async ValueTask <IGraphicsEffectSource> Factory() => new BlendEffect
            {
                Foreground = await pipelines.Foreground.sourceProducer(),
                Background = await pipelines.Background.sourceProducer(),
                Mode       = mode
            };

            return(new PipelineBuilder(Factory, pipelines.Foreground, pipelines.Background));
        }
Esempio n. 2
0
        /// <summary>
        /// Blends two pipelines using a <see cref="BlendEffect"/> instance with the specified mode
        /// </summary>
        /// <param name="pipeline">The second <see cref="PipelineBuilder"/> instance to blend</param>
        /// <param name="mode">The desired <see cref="BlendEffectMode"/> to use to blend the input pipelines</param>
        /// <param name="sorting">The sorting mode to use with the two input pipelines</param>

        public PipelineBuilder Blend(PipelineBuilder pipeline, BlendEffectMode mode, Placement sorting = Placement.Foreground)
        {
            var(foreground, background) = sorting == Placement.Foreground ? (this, pipeline) : (pipeline, this);

            async Task <IGraphicsEffectSource> Factory() => new BlendEffect
            {
                Foreground = await foreground.SourceProducer(),
                Background = await background.SourceProducer(),
                Mode       = mode
            };

            return(new PipelineBuilder(Factory, foreground, background));
        }
Esempio n. 3
0
        private void BlendComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //throw new NotImplementedException();
            //object item = ((ComboBox)sender).SelectedValue;

            BlendEffectMode selmode = (BlendEffectMode)Enum.Parse(typeof(BlendEffectMode), ((ComboBox)sender).SelectedItem.ToString());

            simplePhotoEditor.edgeDetectionBlendEffectMode = selmode;

            StartWritingOutput("Blend Mode :" + selmode.ToString());

            simplePhotoEditor.applyEdgeDetectionEffects();
            canvas2d.Invalidate();
        }
Esempio n. 4
0
        private void BlendSelection_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBoxItem    item      = BlendSelection.SelectedValue as ComboBoxItem;
            BlendEffectMode blendmode = (BlendEffectMode)item.Tag;

            // Create a chained effect graph using a BlendEffect, blending color and blur
            var graphicsEffect = new BlendEffect
            {
                Mode       = blendmode,
                Background = new ColorSourceEffect()
                {
                    Name  = "Tint",
                    Color = Tint.Color,
                },

                Foreground = new GaussianBlurEffect()
                {
                    Name       = "Blur",
                    Source     = new CompositionEffectSourceParameter("Backdrop"),
                    BlurAmount = (float)BlurAmount.Value,
                    BorderMode = EffectBorderMode.Hard,
                }
            };

            var blurEffectFactory = _compositor.CreateEffectFactory(graphicsEffect,
                                                                    new[] { "Blur.BlurAmount", "Tint.Color" });

            // Create EffectBrush, BackdropBrush and SpriteVisual
            _brush = blurEffectFactory.CreateBrush();

            SetUpAnimationBehavior();

            // If the animation is running, restart it on the new brush
            if (AnimateToggle.IsOn)
            {
                StartBlurAnimation();
            }

            var destinationBrush = _compositor.CreateBackdropBrush();

            _brush.SetSourceParameter("Backdrop", destinationBrush);

            var blurSprite = _compositor.CreateSpriteVisual();

            blurSprite.Size  = new Vector2((float)BackgroundImage.ActualWidth, (float)BackgroundImage.ActualHeight);
            blurSprite.Brush = _brush;

            ElementCompositionPreview.SetElementChildVisual(BackgroundImage, blurSprite);
        }
Esempio n. 5
0
        private void Favorites_Loaded(object sender, RoutedEventArgs e)
        {
            if (BuildInfo.BeforeAprilUpdate)
            {
                return;
            }

            selectionLabelBackground.Opacity = 0.5;

            BlendEffectMode blendmode = BlendEffectMode.Overlay;

            // Create a chained effect graph using a BlendEffect, blending color and blur
            var graphicsEffect = new BlendEffect
            {
                Mode       = blendmode,
                Background = new ColorSourceEffect()
                {
                    Name  = "Tint",
                    Color = Colors.Transparent,
                },

                Foreground = new GaussianBlurEffect()
                {
                    Name       = "Blur",
                    Source     = new CompositionEffectSourceParameter("Backdrop"),
                    BlurAmount = 18.0f,
                    BorderMode = EffectBorderMode.Hard,
                }
            };

            var blurEffectFactory = _compositor.CreateEffectFactory(graphicsEffect,
                                                                    new[] { "Blur.BlurAmount", "Tint.Color" });

            // Create EffectBrush, BackdropBrush and SpriteVisual
            _brush = blurEffectFactory.CreateBrush();

            var destinationBrush = _compositor.CreateBackdropBrush();

            _brush.SetSourceParameter("Backdrop", destinationBrush);

            selectionBlurSprite       = _compositor.CreateSpriteVisual();
            selectionBlurSprite.Size  = new Vector2((float)0, (float)0);
            selectionBlurSprite.Brush = _brush;

            ElementCompositionPreview.SetElementChildVisual(selectionBlur, selectionBlurSprite);
        }
Esempio n. 6
0
        public PipelineBuilder Blend(PipelineBuilder pipeline, BlendEffectMode mode, Placement placement = Placement.Foreground)
        {
            var(foreground, background) = placement switch
            {
                Placement.Foreground => (pipeline, this),
                Placement.Background => (this, pipeline),
                _ => throw new ArgumentException($"Invalid placement value: {placement}")
            };

            async ValueTask <IGraphicsEffectSource> Factory() => new CanvasBlendEffect
            {
                Foreground = await foreground.sourceProducer(),
                Background = await background.sourceProducer(),
                Mode       = mode
            };

            return(new PipelineBuilder(Factory, foreground, background));
        }
        private void AddTextToRoot(BlendEffectMode blendEffectMode)
        {
            var redBrushWrapper  = CreateTextToBrushWrapper(blendEffectMode.ToString(), Colors.Red);
            var blueBrushWrapper = CreateTextToBrushWrapper(blendEffectMode.ToString(), Colors.Cyan);

            blueBrushWrapper.Brush.Offset = new Vector2(-4f, 0);
            var blueMaskBrush = CreateGradientBrush();

            var textVisual = Compositor.CreateSpriteVisual();

            textVisual.Brush = CreateBrush(blueBrushWrapper.Brush, redBrushWrapper.Brush, blendEffectMode);
            textVisual.Size  = new Vector2(400, 70);
            var background = new Rectangle {
                Height = 70, Width = 400
            };

            ElementCompositionPreview.SetElementChildVisual(background, textVisual);
            Root.Children.Add(background);
        }
Esempio n. 8
0
        public void AddTextBlendBlock(StackPanel stackPanel, string text, BlendEffectMode blendEffectMode, SelectionChangedEventHandler selectionChangedEventHandler)
        {
            TextBlock textBlock = new TextBlock();

            textBlock.Text   = text;
            textBlock.Margin = new Thickness(10, 10, 10, 10);

            ComboBox comboBox = new ComboBox();

            foreach (BlendEffectMode blendmode in Enum.GetValues(typeof(BlendEffectMode)))
            {
                comboBox.Items.Add(blendmode.ToString());
            }
            comboBox.SelectedItem      = blendEffectMode.ToString();
            comboBox.SelectionChanged += selectionChangedEventHandler;

            stackPanel.Children.Add(textBlock);
            stackPanel.Children.Add(comboBox);
        }
Esempio n. 9
0
        private void BlendSelection_SelectionChanged()
        {
            BlendEffectMode blendmode = BlendEffectMode.Multiply;

            // Create a chained effect graph using a BlendEffect, blending color and blur
            var graphicsEffect = new BlendEffect
            {
                Mode       = blendmode,
                Background = new ColorSourceEffect()
                {
                    Name  = "Tint",
                    Color = Color.FromArgb(0, 255, 0, 0),
                },

                Foreground = new GaussianBlurEffect()
                {
                    Name       = "Blur",
                    Source     = new CompositionEffectSourceParameter("Backdrop"),
                    BlurAmount = 100,
                    BorderMode = EffectBorderMode.Hard,
                }
            };

            var blurEffectFactory = this.compositor.CreateEffectFactory(graphicsEffect,
                                                                        new[] { "Blur.BlurAmount", "Tint.Color" });

            // Create EffectBrush, BackdropBrush and SpriteVisual
            this.brush = blurEffectFactory.CreateBrush();

            var destinationBrush = this.compositor.CreateBackdropBrush();

            this.brush.SetSourceParameter("Backdrop", destinationBrush);
            this.brush.Properties.InsertScalar("Blur.BlurAmount", 100);

            var blurSprite = this.compositor.CreateSpriteVisual();

            blurSprite.Size  = new Vector2((float)this.BackgroundImage.ActualWidth, (float)this.BackgroundImage.ActualHeight);
            blurSprite.Brush = this.brush;

            ElementCompositionPreview.SetElementChildVisual(this.BackgroundImage, blurSprite);
        }
Esempio n. 10
0
        private void AlbumHeader_Loaded(object sender, RoutedEventArgs e)
        {
            headerSprite = _compositor.CreateSpriteVisual();

            BlendEffectMode blendmode = BlendEffectMode.Overlay;

            // Create a chained effect graph using a BlendEffect, blending color and blur
            var graphicsEffect = new BlendEffect
            {
                Mode       = blendmode,
                Background = new ColorSourceEffect()
                {
                    Name  = "Tint",
                    Color = Colors.Transparent,
                },

                Foreground = new GaussianBlurEffect()
                {
                    Name       = "Blur",
                    Source     = new CompositionEffectSourceParameter("Backdrop"),
                    BlurAmount = 10.0f,
                    BorderMode = EffectBorderMode.Hard,
                }
            };

            var blurEffectFactory = _compositor.CreateEffectFactory(graphicsEffect,
                                                                    new[] { "Blur.BlurAmount", "Tint.Color" });

            // Create EffectBrush, BackdropBrush and SpriteVisual
            _brush = blurEffectFactory.CreateBrush();

            var destinationBrush = _compositor.CreateBackdropBrush();

            _brush.SetSourceParameter("Backdrop", destinationBrush);

            headerSprite.Size  = new Vector2((float)blurGlass.ActualWidth, (float)blurGlass.ActualHeight);
            headerSprite.Brush = _brush;

            ElementCompositionPreview.SetElementChildVisual(blurGlass, headerSprite);
        }
Esempio n. 11
0
        private void BlendSelection_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBoxItem    item      = BlendSelection.SelectedValue as ComboBoxItem;
            BlendEffectMode blendmode = (BlendEffectMode)item.Tag;

            // Create a chained effect graph using a BlendEffect, blending color and blur
            var graphicsEffect = new BlendEffect
            {
                Mode       = blendmode,
                Background = new ColorSourceEffect()
                {
                    Name  = "Tint",
                    Color = Tint.Color,
                },

                Foreground = new GaussianBlurEffect()
                {
                    Name       = "Blur",
                    Source     = new CompositionEffectSourceParameter("ImageSource"),
                    BlurAmount = (float)BlurAmount.Value,
                    BorderMode = EffectBorderMode.Hard,
                }
            };


            var blurEffectFactory = _compositor.CreateEffectFactory(graphicsEffect,
                                                                    new[] { "Blur.BlurAmount", "Tint.Color" });

            // Create EffectBrush to be painted on CompositionImage Control’s SpriteVisual
            _brush = blurEffectFactory.CreateBrush();
            _brush.SetSourceParameter("ImageSource", CatImage.SurfaceBrush);
            CatImage.Brush = _brush;

            //If the animation is running, restart it on the new brush
            if (AnimateToggle.IsOn)
            {
                StartBlurAnimation();
            }
        }
        private CompositionBrush CreateBrush(CompositionBrush foreground, CompositionBrush background, BlendEffectMode blendEffectMode)
        {
            var compositor = Window.Current.Compositor;
            var effect     = new BlendEffect()
            {
                Mode       = blendEffectMode,
                Foreground = new CompositionEffectSourceParameter("Main"),
                Background = new CompositionEffectSourceParameter("Tint"),
            };
            var effectFactory    = compositor.CreateEffectFactory(effect);
            var compositionBrush = effectFactory.CreateBrush();

            compositionBrush.SetSourceParameter("Main", foreground);
            compositionBrush.SetSourceParameter("Tint", background);

            return(compositionBrush);
        }