Ejemplo n.º 1
0
        public void ColorMatrixEffectCustomizations()
        {
            const uint D2D1_COLORMATRIX_ALPHA_MODE_PREMULTIPLIED = 1;
            const uint D2D1_COLORMATRIX_ALPHA_MODE_STRAIGHT      = 2;

            var effect = new ColorMatrixEffect();

            // Verify defaults.
            Assert.AreEqual(CanvasAlphaMode.Premultiplied, effect.AlphaMode);
            Assert.AreEqual(D2D1_COLORMATRIX_ALPHA_MODE_PREMULTIPLIED, effect.Properties[1]);

            // Changing the boxed value should change the associated property.
            effect.Properties[1] = D2D1_COLORMATRIX_ALPHA_MODE_STRAIGHT;
            Assert.AreEqual(CanvasAlphaMode.Straight, effect.AlphaMode);

            effect.Properties[1] = D2D1_COLORMATRIX_ALPHA_MODE_PREMULTIPLIED;
            Assert.AreEqual(CanvasAlphaMode.Premultiplied, effect.AlphaMode);

            // Change the property, and verify that the boxed value changes to match.
            effect.AlphaMode = CanvasAlphaMode.Straight;
            Assert.AreEqual(D2D1_COLORMATRIX_ALPHA_MODE_STRAIGHT, effect.Properties[1]);

            effect.AlphaMode = CanvasAlphaMode.Premultiplied;
            Assert.AreEqual(D2D1_COLORMATRIX_ALPHA_MODE_PREMULTIPLIED, effect.Properties[1]);

            // Verify unsupported value throws.
            Assert.ThrowsException <ArgumentException>(() => { effect.AlphaMode = CanvasAlphaMode.Ignore; });
            Assert.AreEqual(CanvasAlphaMode.Premultiplied, effect.AlphaMode);
        }
        private static ICanvasImage CreateColorMatrixEffect(ICanvasImage canvasImage, float coeff)
        {
            var ef = new ColorMatrixEffect
            {
                Source = canvasImage
            };

            var matrix = new Matrix5x4();

            matrix.M11 = (float)Math.Sin(coeff * 1.5);
            matrix.M21 = (float)Math.Sin(coeff * 1.4);
            matrix.M31 = (float)Math.Sin(coeff * 1.3);
            matrix.M51 = (1 - matrix.M11 - matrix.M21 - matrix.M31) / 2;

            matrix.M12 = (float)Math.Sin(coeff * 1.2);
            matrix.M22 = (float)Math.Sin(coeff * 1.1);
            matrix.M32 = (float)Math.Sin(coeff * 1.0);
            matrix.M52 = (1 - matrix.M12 - matrix.M22 - matrix.M32) / 2;

            matrix.M13 = (float)Math.Sin(coeff * 0.9);
            matrix.M23 = (float)Math.Sin(coeff * 0.8);
            matrix.M33 = (float)Math.Sin(coeff * 0.7);
            matrix.M53 = (1 - matrix.M13 - matrix.M23 - matrix.M33) / 2;

            matrix.M44 = 1;

            ef.ColorMatrix = matrix;

            return(ef);
        }
Ejemplo n.º 3
0
        public void ColorMatrixEffectCustomizations()
        {
            var effect = new ColorMatrixEffect();

            // Verify defaults.
            Assert.AreEqual(CanvasAlphaMode.Premultiplied, effect.AlphaMode);
            Assert.AreEqual(D2D1_ALPHA_MODE_PREMULTIPLIED, EffectAccessor.GetProperty(effect, 1));

            // Change the property, and verify that the boxed value changes to match.
            effect.AlphaMode = CanvasAlphaMode.Straight;
            Assert.AreEqual(D2D1_ALPHA_MODE_STRAIGHT, EffectAccessor.GetProperty(effect, 1));

            effect.AlphaMode = CanvasAlphaMode.Premultiplied;
            Assert.AreEqual(D2D1_ALPHA_MODE_PREMULTIPLIED, EffectAccessor.GetProperty(effect, 1));

            // Verify unsupported value throws.
            Assert.ThrowsException <ArgumentException>(() => { effect.AlphaMode = CanvasAlphaMode.Ignore; });
            Assert.AreEqual(CanvasAlphaMode.Premultiplied, effect.AlphaMode);

            // Validate that IGraphicsEffectD2D1Interop reports the right customizations.
            int index;
            EffectPropertyMapping mapping;

            EffectAccessor.GetNamedPropertyMapping(effect, "AlphaMode", out index, out mapping);
            Assert.AreEqual(1, index);
            Assert.AreEqual(EffectPropertyMapping.ColorMatrixAlphaMode, mapping);
        }
Ejemplo n.º 4
0
        internal void DrawImage(
            CanvasBitmap nativeBitmap,
            Rectangle destinationRectangle,
            Color tint)
        {
            if (null == nativeBitmap)
            {
                throw new ArgumentNullException(nameof(nativeBitmap));
            }

            var destinationRect = new global::Windows.Foundation.Rect(destinationRectangle.X, destinationRectangle.Y, destinationRectangle.Width, destinationRectangle.Height);

            var sourceRect = new global::Windows.Foundation.Rect(0, 0, nativeBitmap.Size.Width, nativeBitmap.Size.Height);

            if (tint.IsTransparent)
            {
                this._session.DrawImage(nativeBitmap, destinationRect, sourceRect);
            }
            else
            {
                // TODO: An Effect parameter that wraps this matrix so it doesn't have to be created repeatedly
                ColorMatrixEffect tintEffect = new ColorMatrixEffect();
                tintEffect.Source      = nativeBitmap;
                tintEffect.ColorMatrix = new Matrix5x4()
                {
                    M11 = (float)tint.R / 255f, M12 = 0, M13 = 0, M14 = 0,
                    M21 = 0, M22 = (float)tint.G / 255f, M23 = 0, M24 = 0,
                    M31 = 0, M32 = 0, M33 = (float)tint.B / 255f, M34 = 0,
                    M41 = 0, M42 = 0, M43 = 0, M44 = 1.0f,
                    M51 = 0, M52 = 0, M53 = 0, M54 = 0,
                };

                this._session.DrawImage(tintEffect, destinationRect, sourceRect);
            }
        }
Ejemplo n.º 5
0
        private IGraphicsEffect _createRevealBorderEffect()
        {
            var sceneLightingEffect = new Windows.UI.Composition.Effects.SceneLightingEffect();

            sceneLightingEffect.AmbientAmount  = 0f;
            sceneLightingEffect.DiffuseAmount  = sc_diffuseAmountBorder;
            sceneLightingEffect.SpecularAmount = sc_specularAmountBorder;
            sceneLightingEffect.SpecularShine  = sc_specularShineBorder;

            var colorMatrixEffect = new ColorMatrixEffect();

            colorMatrixEffect.ColorMatrix = sc_revealInvertedBorderColorMatrix;
            colorMatrixEffect.AlphaMode   = Microsoft.Graphics.Canvas.CanvasAlphaMode.Straight;
            colorMatrixEffect.Source      = sceneLightingEffect;

            var baseColorEffect = new ColorSourceEffect();

            baseColorEffect.Name  = "BaseColorEffect";
            baseColorEffect.Color = Color.FromArgb(0, 0, 0, 0);

            var compositeEffect = new CompositeEffect();

            compositeEffect.Mode = Microsoft.Graphics.Canvas.CanvasComposite.SourceOver;
            //	Union of source and destination bitmaps. Equation: O = S + (1 - SA) * D.
            compositeEffect.Sources.Add(baseColorEffect);   //Destination
            compositeEffect.Sources.Add(colorMatrixEffect); //Source
            return(compositeEffect);
        }
Ejemplo n.º 6
0
        public ColorChangeableCanvas()
        {
            this.InitializeComponent();

            var watcher = new DependencyPropertyWatcher <Brush>(this, "Foreground");

            watcher.PropertyChanged += (s, e) =>
            {
                if (s is DependencyPropertyWatcher <Brush> w)
                {
                    ForegroundPropertyChanged(w.Value);
                }
            };

            win2DCanvas.CreateResources += (s, e) =>
            {
                // s is CanvasControl
                // e is CanvasCreateResourcesEventArgs
                e.TrackAsyncAction(CreateResourcesAsync(s).AsAsyncAction());
            };

            win2DCanvas.Draw += (s, e) =>
            {
                // s is CanvasControl
                // e is CanvasDrawEventArgs
                if (_bitmap is null)
                {
                    return;
                }
                if (IsLoadInProgress())
                {
                    return;
                }

                // ビットマップにエフェクトを掛ける
                Color c = _foreground; //colorPicker.Color;
                float r = c.R / 255.0f;
                float g = c.G / 255.0f;
                float b = c.B / 255.0f;
                var   colorMatrixEffect = new ColorMatrixEffect
                {
                    Source      = _bitmap,
                    ColorMatrix = new Matrix5x4
                    {
                        M11 = r, M12 = 0, M13 = 0, M14 = 0,
                        M21 = 0, M22 = g, M23 = 0, M24 = 0,
                        M31 = 0, M32 = 0, M33 = b, M34 = 0,
                        M41 = 0, M42 = 0, M43 = 0, M44 = 1,
                        M51 = 0, M52 = 0, M53 = 0, M54 = 0
                    },
                };

                // エフェクトを掛けた結果を表示する
                e.DrawingSession.DrawImage(colorMatrixEffect, 0, 0);

                // ※ ここでは、Win2D Canvas を UserControl の中に入れているため、表示サイズの調整が必要。
                this.Width  = _bitmap.Size.Width;
                this.Height = _bitmap.Size.Height;
            };
        }
Ejemplo n.º 7
0
        private ICanvasImage CreateColorMatrix()
        {
            var colorMatrixEffect = new ColorMatrixEffect
            {
                Source = bitmapTiger
            };

            // Animation cycles through different color settings.
            animationFunction = elapsedTime =>
            {
                var matrix = new Matrix5x4();

                matrix.M11 = (float)Math.Sin(elapsedTime * 1.5);
                matrix.M21 = (float)Math.Sin(elapsedTime * 1.4);
                matrix.M31 = (float)Math.Sin(elapsedTime * 1.3);
                matrix.M51 = (1 - matrix.M11 - matrix.M21 - matrix.M31) / 2;

                matrix.M12 = (float)Math.Sin(elapsedTime * 1.2);
                matrix.M22 = (float)Math.Sin(elapsedTime * 1.1);
                matrix.M32 = (float)Math.Sin(elapsedTime * 1.0);
                matrix.M52 = (1 - matrix.M12 - matrix.M22 - matrix.M32) / 2;

                matrix.M13 = (float)Math.Sin(elapsedTime * 0.9);
                matrix.M23 = (float)Math.Sin(elapsedTime * 0.8);
                matrix.M33 = (float)Math.Sin(elapsedTime * 0.7);
                matrix.M53 = (1 - matrix.M13 - matrix.M23 - matrix.M33) / 2;

                matrix.M44 = 1;

                colorMatrixEffect.ColorMatrix = matrix;
            };

            return(colorMatrixEffect);
        }
Ejemplo n.º 8
0
        public void ProcessFrameGPU(ProcessVideoFrameContext context)
        {
            var inputSurface  = context.InputFrame.Direct3DSurface;
            var outputSurface = context.OutputFrame.Direct3DSurface;

            using (var inputBitmap = CanvasBitmap.CreateFromDirect3D11Surface(m_canvasDevice, inputSurface))
                using (var renderTarget = CanvasRenderTarget.CreateFromDirect3D11Surface(m_canvasDevice, outputSurface))
                    using (var drawingSession = renderTarget.CreateDrawingSession())
                    {
                        var normalize = new Matrix5x4()
                        {
                            M11 = 1f, M22 = 1f, M33 = 1f, M44 = 1f, M51 = -m_mean.X, M52 = -m_mean.Y, M53 = -m_mean.Z
                        };
                        var normalize2 = new Matrix5x4()
                        {
                            M11 = 1 / m_std.X, M22 = 1 / m_std.Y, M33 = 1 / m_std.Z, M44 = 1.0f
                        };

                        // https://microsoft.github.io/Win2D/html/T_Microsoft_Graphics_Canvas_Effects_ColorMatrixEffect.htm
                        var PreprocessTransfrom = new ColorMatrixEffect()
                        {
                            ColorMatrix = normalize2,
                            Source      = new ColorMatrixEffect()
                            {
                                ColorMatrix = normalize,
                                Source      = inputBitmap
                            }
                        };

                        drawingSession.DrawImage(PreprocessTransfrom);
                    }
        }
        public Image Create(Image img)
        {
            var    effect = new ColorMatrixEffect();
            Bitmap newImg = new Bitmap(img);

            newImg.ApplyEffect(effect, Rectangle.Empty);
            return(newImg);
        }
Ejemplo n.º 10
0
        public void ProcessFrame(ProcessVideoFrameContext context)
        {
            bool skipMaskPred = false;

            if (context.InputFrame.IsDiscontinuous)
            {
                streamStartDelta = TimeSpan.FromTicks(DateTime.Now.Ticks) - context.InputFrame.SystemRelativeTime.Value;
            }
            else
            {
                if ((TimeSpan.FromTicks(DateTime.Now.Ticks) - context.InputFrame.SystemRelativeTime.Value - streamStartDelta) > TimeSpan.FromMilliseconds(maxDelay))
                {
                    skipMaskPred = true;
                }
            }

            if (!skipMaskPred)
            {
                frameCount++;
                features["0"] = context.InputFrame;
                var resTask   = _learningModel.EvaluateFeaturesAsync(features, string.Empty).AsTask();
                var startTime = DateTime.Now.Ticks;
                resTask.Wait();
                Debug.WriteLine("delta {0}", TimeSpan.FromTicks(DateTime.Now.Ticks - startTime));
            }

            using (CanvasBitmap inputBitmap = CanvasBitmap.CreateFromDirect3D11Surface(canvasDevice, context.InputFrame.Direct3DSurface))
                using (CanvasBitmap inputMask = CanvasBitmap.CreateFromDirect3D11Surface(canvasDevice, output.Direct3DSurface))
                    using (CanvasRenderTarget renderTarget = CanvasRenderTarget.CreateFromDirect3D11Surface(canvasDevice, context.OutputFrame.Direct3DSurface))
                        using (CanvasDrawingSession ds = renderTarget.CreateDrawingSession())
                        {
                            ds.Clear(Colors.Green);

                            var addAlpha = new ColorMatrixEffect()
                            {
                                Source      = inputMask,
                                ColorMatrix = RToAlpha
                            };

                            var resize = new ScaleEffect()
                            {
                                Source = addAlpha,
                                Scale  = new Vector2(((float)inputBitmap.SizeInPixels.Width / inputMask.SizeInPixels.Width), ((float)inputBitmap.SizeInPixels.Height / inputMask.SizeInPixels.Height))
                            };

                            var blend = new AlphaMaskEffect()
                            {
                                Source    = inputBitmap,
                                AlphaMask = resize
                            };

                            ds.DrawImage(blend);
                            ds.DrawText(String.Format("FPS: {0:f1}", currentFPS), fpsLabelOffset, fpsLabelColor);
                        }
        }
Ejemplo n.º 11
0
        public void ProcessFrame(ProcessVideoFrameContext context)
        {
            using (CanvasBitmap inputBitmap = CanvasBitmap.CreateFromDirect3D11Surface(canvasDevice, context.InputFrame.Direct3DSurface))
                using (CanvasRenderTarget renderTarget = CanvasRenderTarget.CreateFromDirect3D11Surface(canvasDevice, context.OutputFrame.Direct3DSurface))
                    using (CanvasDrawingSession ds = renderTarget.CreateDrawingSession())
                    {
                        ColorMatrixEffect colorMatrixEffect = new ColorMatrixEffect
                        {
                            Source = inputBitmap
                        };

                        colorMatrixEffect.ColorMatrix = ColorMatrix;

                        ds.DrawImage(colorMatrixEffect);
                    }
        }
Ejemplo n.º 12
0
        private static CompositionBrush CreateGrayscaleBrush()
        {
            Matrix5x4 grayscaleMatrix = CreateGrayscaleMatrix();

            ColorMatrixEffect grayscaleMatrixEffect = new ColorMatrixEffect
            {
                ColorMatrix = grayscaleMatrix,
                Source      = new CompositionEffectSourceParameter("source")
            };

            CompositionEffectFactory grayscaleEffectFactory = _compositor.CreateEffectFactory(grayscaleMatrixEffect);
            var backdropBrush = grayscaleEffectFactory.CreateBrush();

            backdropBrush.SetSourceParameter("source", _compositor.CreateBackdropBrush());

            return(backdropBrush);
        }
Ejemplo n.º 13
0
        public bool DisplayRegionMask(CanvasDrawingSession drawingSession, float zoomFactor, bool editInProgress)
        {
            if (!IsEnabled || !IsEditingRegion || !ShowRegion || regionMask == null)
            {
                return(false);
            }

            if (editInProgress && RegionSelectionOperation == SelectionOperation.Replace)
            {
                return(false);
            }

            drawingSession.Blend = CanvasBlend.SourceOver;

            if (!editInProgress)
            {
                // Gray out everything outside the region.
                var mask = new ColorMatrixEffect
                {
                    Source = GetRegionMask(),

                    ColorMatrix = new Matrix5x4
                    {
                        // Set RGB = gray.
                        M51 = 0.5f,
                        M52 = 0.5f,
                        M53 = 0.5f,

                        // Invert and scale the mask alpha.
                        M44 = -0.75f,
                        M54 = 0.75f,
                    }
                };

                drawingSession.DrawImage(mask);
            }

            // Magenta region border.
            var border = GetSelectionBorder(regionMask, zoomFactor);

            drawingSession.DrawImage(border);

            return(true);
        }
Ejemplo n.º 14
0
        private ICanvasImage CreateRgbToHue()
        {
            textLabel = requiresWin10;

            // Convert the input image from RGB to HSV color space.
            var rgbToHueEffect = new RgbToHueEffect
            {
                Source = bitmapTiger
            };

            // This color matrix will operate on HSV values.
            var colorMatrixEffect = new ColorMatrixEffect
            {
                Source = rgbToHueEffect
            };

            // Convert the result back to RGB format.
            var hueToRgbEffect = new HueToRgbEffect
            {
                Source = colorMatrixEffect
            };

            // Animation changes the hue, saturation, and value (brightness) of the image.
            // In HSV format, the red channel indicates hue, green is saturation, and blue is brightness.
            // Altering these values changes the image in very different ways than if we did the same thing to RGB data!
            animationFunction = elapsedTime =>
            {
                colorMatrixEffect.ColorMatrix = new Matrix5x4
                {
                    M11 = 1,
                    M22 = 1,
                    M33 = 1,
                    M44 = 1,

                    M51 = (float)Math.Sin(elapsedTime / 17) * 0.2f,
                    M52 = (float)Math.Sin(elapsedTime * 1.3) * 0.5f,
                    M53 = (float)Math.Sin(elapsedTime / 2) * 0.5f,
                };
            };

            return(hueToRgbEffect);
        }
Ejemplo n.º 15
0
        public void Ctor_Reader()
        {
            var reader = new MetafileReader(new byte[]
            {
                /* Matrix_N_0 */ 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
                /* Matrix_N_1 */ 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00,
                /* Matrix_N_2 */ 0x0A, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00,
                /* Matrix_N_3 */ 0x0F, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
                /* Matrix_N_4 */ 0x14, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
            }, 0);

            var effect = new ColorMatrixEffect(reader);

            Assert.Equal(0, effect.Matrix0.Matrix0);
            Assert.Equal(1, effect.Matrix0.Matrix1);
            Assert.Equal(2, effect.Matrix0.Matrix2);
            Assert.Equal(3, effect.Matrix0.Matrix3);
            Assert.Equal(4, effect.Matrix0.Matrix4);
            Assert.Equal(5, effect.Matrix1.Matrix0);
            Assert.Equal(6, effect.Matrix1.Matrix1);
            Assert.Equal(7, effect.Matrix1.Matrix2);
            Assert.Equal(8, effect.Matrix1.Matrix3);
            Assert.Equal(9, effect.Matrix1.Matrix4);
            Assert.Equal(10, effect.Matrix2.Matrix0);
            Assert.Equal(11, effect.Matrix2.Matrix1);
            Assert.Equal(12, effect.Matrix2.Matrix2);
            Assert.Equal(13, effect.Matrix2.Matrix3);
            Assert.Equal(14, effect.Matrix2.Matrix4);
            Assert.Equal(15, effect.Matrix3.Matrix0);
            Assert.Equal(16, effect.Matrix3.Matrix1);
            Assert.Equal(17, effect.Matrix3.Matrix2);
            Assert.Equal(18, effect.Matrix3.Matrix3);
            Assert.Equal(19, effect.Matrix3.Matrix4);
            Assert.Equal(20, effect.Matrix4.Matrix0);
            Assert.Equal(21, effect.Matrix4.Matrix1);
            Assert.Equal(22, effect.Matrix4.Matrix2);
            Assert.Equal(23, effect.Matrix4.Matrix3);
            Assert.Equal(24, effect.Matrix4.Matrix4);
            Assert.Equal(100u, effect.Size);
            Assert.Equal(new Guid("{718F2615-7933-40E3-A511-5F68FE14DD74}"), effect.Identifier);
        }
        private void OnWin2DCreateResources(CanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args)
        {
            var effect1 = new GaussianBlurEffect()
            {
                BlurAmount = 20f,
            };

            effect = effect1;

            var effect2 = new ColorMatrixEffect()
            {
                ColorMatrix = new Matrix5x4()
                {
                    M11 = 1,
                    M12 = 0,
                    M13 = 0,
                    M14 = 0,
                    M21 = 0,
                    M22 = 1,
                    M23 = 0,
                    M24 = 0,
                    M31 = 0,
                    M32 = 0,
                    M33 = 1,
                    M34 = 0,
                    M41 = 0,
                    M42 = 0,
                    M43 = 0,
                    M44 = 18,
                    M51 = 0,
                    M52 = 0,
                    M53 = 0,
                    M54 = -7,
                },
                Source = effect1
            };


            image = effect2;
        }
Ejemplo n.º 17
0
        private void BuildBrush()
        {
            if (_compositor == null)
            {
                return;
            }

            // adding a grey tint to the background
            var colorMatrix = TintColor.ToMatrix5X4();

            var graphicsEffect = new ColorMatrixEffect
            {
                ColorMatrix = colorMatrix,
                Source      = new CompositionEffectSourceParameter("Background")
            };

            var effectFactory = _compositor.CreateEffectFactory(graphicsEffect, null);
            var brush         = effectFactory.CreateBrush();

            brush.SetSourceParameter("Background", _compositor.CreateHostBackdropBrush());
            CompositionBrush = brush;
        }
Ejemplo n.º 18
0
        ICanvasImage GetSelectionBorder(ICanvasImage mask, float zoomFactor)
        {
            // Scale so our border will always be the same width no matter how the image is zoomed.
            var scaleToCurrentZoom = new ScaleEffect
            {
                Source = mask,
                Scale  = new Vector2(zoomFactor)
            };

            // Find edges of the selection.
            var detectEdges = new EdgeDetectionEffect
            {
                Source = scaleToCurrentZoom,
                Amount = 0.1f
            };

            // Colorize.
            var colorItMagenta = new ColorMatrixEffect
            {
                Source = detectEdges,

                ColorMatrix = new Matrix5x4
                {
                    M11 = 1,
                    M13 = 1,
                    M14 = 1,
                }
            };

            // Scale back to the original size.
            return(new ScaleEffect
            {
                Source = colorItMagenta,
                Scale = new Vector2(1 / zoomFactor)
            });
        }
Ejemplo n.º 19
0
        private ICanvasImage CreateRgbToHue()
        {
            textLabel = requiresWin10;

            // Convert the input image from RGB to HSV color space.
            var rgbToHueEffect = new RgbToHueEffect
            {
                Source = bitmapTiger
            };

            // This color matrix will operate on HSV values.
            var colorMatrixEffect = new ColorMatrixEffect
            {
                Source = rgbToHueEffect
            };

            // Convert the result back to RGB format.
            var hueToRgbEffect = new HueToRgbEffect
            {
                Source = colorMatrixEffect
            };

            // Animation changes the hue, saturation, and value (brightness) of the image.
            // In HSV format, the red channel indicates hue, green is saturation, and blue is brightness.
            // Altering these values changes the image in very different ways than if we did the same thing to RGB data!
            animationFunction = elapsedTime =>
            {
                colorMatrixEffect.ColorMatrix = new Matrix5x4
                {
                    M11 = 1,
                    M22 = 1,
                    M33 = 1,
                    M44 = 1,

                    M51 = (float)Math.Sin(elapsedTime / 17) * 0.2f,
                    M52 = (float)Math.Sin(elapsedTime * 1.3) * 0.5f,
                    M53 = (float)Math.Sin(elapsedTime / 2) * 0.5f,
                };
            };

            return hueToRgbEffect;
        }
Ejemplo n.º 20
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.
            };
        }
 void UpdateShadowEffect()   //This calls UpdateShadowVisualProperties, UpdateShadowMask and UpdateShadowSizeAndOffset.
 {
     if (compositor == null || shadowVisual == null)
     {
         return;
     }
     if (ShouldUseMask)
     {
         isUsingDropShadow = false;
         if (shadowVisual.Shadow != null)
         {
             var oldShadow = shadowVisual.Shadow;
             shadowVisual.Shadow = null;
             oldShadow.Dispose();
         }
         IGraphicsEffectSource alphaMaskSource = new Transform2DEffect()
         {
             Name = transformEffectName, TransformMatrix = Matrix3x2.Identity, Source = new CompositionEffectSourceParameter(effectSourceName)
         };
         if (SpreadRadius > 0)
         {
             var spreadEffectBlur = new GaussianBlurEffect()
             {
                 BlurAmount = (float)SpreadRadius / 3.0f, Source = alphaMaskSource
             };
             alphaMaskSource = new ColorMatrixEffect()
             {
                 ClampOutput = true, ColorMatrix = new Matrix5x4()
                 {
                     M44 = 10.0f
                 }, Source = spreadEffectBlur
             };                                                                                                                                          //The number 10 seems about right
         }
         if (BlurRadius > 0)
         {
             alphaMaskSource = new GaussianBlurEffect()
             {
                 BlurAmount = (float)BlurRadius / 3.0f, Source = alphaMaskSource
             };
         }
         var colorSourceEffect = new ColorSourceEffect()
         {
             Color = Color
         };
         var finalEffect = new AlphaMaskEffect {
             AlphaMask = alphaMaskSource, Source = colorSourceEffect
         };
         CompositionEffectFactory effectFactory;
         try {
             effectFactory = compositor.CreateEffectFactory(finalEffect, new string[] { transformEffectMatrixName });
         } catch (Exception) {
             return;
         }
         var shadowEffectBrush = effectFactory.CreateBrush();
         var oldBrush          = shadowVisual.Brush;
         shadowVisual.Brush = shadowEffectBrush;
         oldBrush?.Dispose();
         UpdateShadowMask();
     }
     else
     {
         isUsingDropShadow = true;
         if (shadowVisual.Brush != null)
         {
             var oldBrush = shadowVisual.Brush;
             shadowVisual.Brush = null;
             oldBrush.Dispose();
         }
         var dropShadow = shadowVisual.Shadow as DropShadow;
         if (dropShadow == null)
         {
             dropShadow = compositor.CreateDropShadow();
             var oldShadow = shadowVisual.Shadow;
             shadowVisual.Shadow = dropShadow;
             oldShadow?.Dispose();
         }
         dropShadow.BlurRadius = (float)Math.Max(BlurRadius, 0.0);
         dropShadow.Color      = Color;
     }
     UpdateShadowVisualProperties();
     UpdateShadowSizeAndOffset();
 }
Ejemplo n.º 22
0
        public MainPage()
        {
            this.InitializeComponent();

            // 1. Win2D のビットマップ (ここに画像を読み込ませる)
            CanvasBitmap bitmap = null;

            // 2. Win2D Canvas の CreateResources イベントで画像を読み込む
            win2DCanvas.CreateResources += (s, e) =>
            {
                // s is CanvasControl
                // e is CanvasCreateResourcesEventArgs
                e.TrackAsyncAction(LoadImageAsync(s).AsAsyncAction());

                async Task LoadImageAsync(CanvasControl canvas)
                {
                    bitmap = await CanvasBitmap.LoadAsync(canvas, "Assets/ClockPanel.png");

                    // ここでは 1 個だけだが、必要なだけ何個でも!
                }
            };

            // 3. Win2D Canvas の Draw イベントで bitmap を表示する
            win2DCanvas.Draw += (s, e) =>
            {
                // s is CanvasControl
                // e is CanvasDrawEventArgs

                // 単にビットマップをそのまま表示するなら、↓これだけ
                //e.DrawingSession.DrawImage(bitmap, 0, 0);

                // ビットマップにエフェクトを掛ける
                Color c = colorPicker.Color;
                float r = c.R / 255.0f;
                float g = c.G / 255.0f;
                float b = c.B / 255.0f;
                var   colorMatrixEffect = new ColorMatrixEffect
                {
                    Source      = bitmap,
                    ColorMatrix = new Matrix5x4
                    {
                        M11 = r, M12 = 0, M13 = 0, M14 = 0,
                        M21 = 0, M22 = g, M23 = 0, M24 = 0,
                        M31 = 0, M32 = 0, M33 = b, M34 = 0,
                        M41 = 0, M42 = 0, M43 = 0, M44 = 1,
                        M51 = 0, M52 = 0, M53 = 0, M54 = 0
                    },
                };

                // エフェクトを掛けた結果を表示する
                e.DrawingSession.DrawImage(colorMatrixEffect, 0, 0);


                // ※ ここでは、Win2D Canvas を ViewBox の中に入れているため、表示サイズの調整が必要。
                // (Win2D Canvas を固定スケールで表示しているなら、つまり、普通に使っているなら、不要)
                canvasGrid.Width  = bitmap.Size.Width * 2;
                canvasGrid.Height = bitmap.Size.Height;
            };

            // 4. 必要に応じて Win2D Canvas を再描画
            colorPicker.ColorChanged += (s, e) =>
            {
                win2DCanvas.Invalidate();
            };


            SizeChanged += (s, e) =>
            {
                double edgeLength = Math.Min(ActualWidth / 2.0, ActualHeight);
                viewBox1.Width  = edgeLength * 2;
                viewBox1.Height = edgeLength;
            };


            const string ClockPath1 = "Assets/ClockPanel.png";
            const string ClockPath2 = "Assets/ClockPanel1.png";

            image1.Source  = ClockPath1;
            image1.Tapped += (s, e) =>
            {
                if (image1.Source == ClockPath1)
                {
                    image1.Source = ClockPath2;
                }
                else
                {
                    image1.Source = ClockPath1;
                }
            };
        }
    }
Ejemplo n.º 23
0
        private void UpdateEffect()
        {
            ComboBoxItem item = EffectSelection.SelectedValue as ComboBoxItem;

            switch ((EffectTypes)item.Tag)
            {
            case EffectTypes.ColorSwap:
            {
                Matrix5x4 mat = new Matrix5x4()
                {
                    M11 = 0, M12 = 0f, M13 = 1f, M14 = 0,
                    M21 = 0f, M22 = 1f, M23 = 0f, M24 = 0,
                    M31 = 1f, M32 = 0f, M33 = 0f, M34 = 0,
                    M41 = 0f, M42 = 0f, M43 = 0f, M44 = 1,
                    M51 = 0, M52 = 0, M53 = 0, M54 = 0
                };

                IGraphicsEffect graphicsEffect = new ColorMatrixEffect()
                {
                    ColorMatrix = mat,
                    Source      = new CompositionEffectSourceParameter("ImageSource")
                };

                // Create the effect factory and instantiate a brush
                CompositionEffectFactory _effectFactory = _compositor.CreateEffectFactory(graphicsEffect, null);
                CompositionEffectBrush   brush          = _effectFactory.CreateBrush();

                // Set the destination brush as the source of the image content
                brush.SetSourceParameter("ImageSource", _compositor.CreateHostBackdropBrush());

                _hostSprite.Brush = brush;
            }
            break;

            case EffectTypes.ColorMask:
            {
                Matrix5x4 mat = new Matrix5x4()
                {
                    M11 = 1, M12 = 0f, M13 = 0f, M14 = 2,
                    M21 = 0f, M22 = 1f, M23 = 0f, M24 = -1,
                    M31 = 0f, M32 = 0f, M33 = 1f, M34 = -1,
                    M41 = 0f, M42 = 0f, M43 = 0f, M44 = 0,
                    M51 = 0, M52 = 0, M53 = 0, M54 = 0
                };

                IGraphicsEffect graphicsEffect = new ColorMatrixEffect()
                {
                    ColorMatrix = mat,
                    Source      = new CompositionEffectSourceParameter("ImageSource")
                };


                // Create the effect factory and instantiate a brush
                CompositionEffectFactory _effectFactory = _compositor.CreateEffectFactory(graphicsEffect, null);
                CompositionEffectBrush   brush          = _effectFactory.CreateBrush();

                // Set the destination brush as the source of the image content
                brush.SetSourceParameter("ImageSource", _compositor.CreateHostBackdropBrush());

                _hostSprite.Brush = brush;
            }
            break;

            case EffectTypes.RedFilter:
            {
                Matrix5x4 mat = new Matrix5x4()
                {
                    M11 = 1, M12 = 0f, M13 = 0f, M14 = 0,
                    M21 = 0f, M22 = 0f, M23 = 0f, M24 = 0,
                    M31 = 0f, M32 = 0f, M33 = 0f, M34 = 0,
                    M41 = 0f, M42 = 0f, M43 = 0f, M44 = 1,
                    M51 = 0, M52 = 0, M53 = 0, M54 = 0
                };

                IGraphicsEffect graphicsEffect = new ColorMatrixEffect()
                {
                    ColorMatrix = mat,
                    Source      = new CompositionEffectSourceParameter("ImageSource")
                };

                // Create the effect factory and instantiate a brush
                CompositionEffectFactory _effectFactory = _compositor.CreateEffectFactory(graphicsEffect, null);
                CompositionEffectBrush   brush          = _effectFactory.CreateBrush();

                // Set the destination brush as the source of the image content
                brush.SetSourceParameter("ImageSource", _compositor.CreateHostBackdropBrush());

                _hostSprite.Brush = brush;
            }
            break;

            case EffectTypes.ColorHighlight:
            {
                IGraphicsEffect graphicsEffect = new ArithmeticCompositeEffect()
                {
                    MultiplyAmount = 0,
                    Source1Amount  = 1,
                    Source2Amount  = 1,
                    Source1        = new GammaTransferEffect()
                    {
                        RedExponent    = 7,
                        BlueExponent   = 7,
                        GreenExponent  = 7,
                        RedAmplitude   = 3,
                        GreenAmplitude = 3,
                        BlueAmplitude  = 3,
                        Source         = new CompositionEffectSourceParameter("ImageSource")
                    },
                    Source2 = new SaturationEffect()
                    {
                        Saturation = 0,
                        Source     = new CompositionEffectSourceParameter("ImageSource")
                    }
                };

                // Create the effect factory and instantiate a brush
                CompositionEffectFactory _effectFactory = _compositor.CreateEffectFactory(graphicsEffect, null);
                CompositionEffectBrush   brush          = _effectFactory.CreateBrush();

                // Set the destination brush as the source of the image content
                brush.SetSourceParameter("ImageSource", _compositor.CreateHostBackdropBrush());

                _hostSprite.Brush = brush;
            }
            break;

            case EffectTypes.Bloom:
            {
                var bloomEffectDesc = new ArithmeticCompositeEffect
                {
                    Name           = "Bloom",
                    Source1Amount  = 1,
                    Source2Amount  = 2,
                    MultiplyAmount = 0,

                    Source1 = new CompositionEffectSourceParameter("source"),
                    Source2 = new GaussianBlurEffect
                    {
                        Name       = "Blur",
                        BorderMode = EffectBorderMode.Hard,
                        BlurAmount = 40,

                        Source = new BlendEffect
                        {
                            Mode = BlendEffectMode.Multiply,

                            Background = new CompositionEffectSourceParameter("source2"),
                            Foreground = new CompositionEffectSourceParameter("source2"),
                        },
                    },
                };

                var bloomEffectFactory = _compositor.CreateEffectFactory(bloomEffectDesc,
                                                                         new[] { "Bloom.Source2Amount", "Blur.BlurAmount" });
                var brush = bloomEffectFactory.CreateBrush();

                var backdropBrush = _compositor.CreateHostBackdropBrush();
                brush.SetSourceParameter("source", backdropBrush);
                brush.SetSourceParameter("source2", backdropBrush);

                // Setup some animations for the bloom effect
                ScalarKeyFrameAnimation blurAnimation = _compositor.CreateScalarKeyFrameAnimation();
                blurAnimation.InsertKeyFrame(0, 0);
                blurAnimation.InsertKeyFrame(.5f, 2);
                blurAnimation.InsertKeyFrame(1, 0);
                blurAnimation.Duration          = TimeSpan.FromMilliseconds(5000);
                blurAnimation.IterationBehavior = AnimationIterationBehavior.Forever;

                ScalarKeyFrameAnimation bloomAnimation = _compositor.CreateScalarKeyFrameAnimation();
                bloomAnimation.InsertKeyFrame(0, 0);
                bloomAnimation.InsertKeyFrame(.5f, 40);
                bloomAnimation.InsertKeyFrame(1, 0);
                bloomAnimation.Duration          = TimeSpan.FromMilliseconds(5000);
                bloomAnimation.IterationBehavior = AnimationIterationBehavior.Forever;

                brush.StartAnimation("Bloom.Source2Amount", blurAnimation);
                brush.StartAnimation("Blur.BlurAmount", bloomAnimation);

                _hostSprite.Brush = brush;
            }
            break;

            case EffectTypes.None:
            default:
                _hostSprite.Brush = _compositor.CreateHostBackdropBrush();
                break;
            }
        }
Ejemplo n.º 24
0
        protected override void OnConnected()
        {
            Compositor compositor = Window.Current.Compositor;

            // CompositionCapabilities: Are Effects supported?
            bool usingFallback = !CompositionCapabilities.GetForCurrentView().AreEffectsSupported();

            FallbackColor = Color.FromArgb(100, 100, 100, 100);

            if (usingFallback)
            {
                // If Effects are not supported, use Fallback Solid Color
                CompositionBrush = compositor.CreateColorBrush(FallbackColor);
                return;
            }

            // Define Effect graph
            // COLOR SWAP
            Matrix5x4 mat = new Matrix5x4()
            {
                M11 = 0, M12 = 0f, M13 = 1f, M14 = 0,
                M21 = 0f, M22 = 1f, M23 = 0f, M24 = 0,
                M31 = 1f, M32 = 0f, M33 = 0f, M34 = 0,
                M41 = 0f, M42 = 0f, M43 = 0f, M44 = 1,
                M51 = 0, M52 = 0, M53 = 0, M54 = 0
            };

            //// COLOR MASK (DOESNT WORK ???)
            // Matrix5x4 mat = new Matrix5x4()
            //            {
            //                M11 = 1,  M12 = 0f, M13 = 0f, M14 = 2,
            //                M21 = 0f, M22 = 1f, M23 = 0f, M24 = -1,
            //                M31 = 0f, M32 = 0f, M33 = 1f, M34 = -1,
            //                M41 = 0f, M42 = 0f, M43 = 0f, M44 = 0,
            //                M51 = 0,  M52 = 0,  M53 = 0,  M54 = 0
            //            };

            //// REDFILTER
            //Matrix5x4 mat = new Matrix5x4()
            //            {
            //                M11 = 1,  M12 = 0f, M13 = 0f, M14 = 0,
            //                M21 = 0f, M22 = 0f, M23 = 0f, M24 = 0,
            //                M31 = 0f, M32 = 0f, M33 = 0f, M34 = 0,
            //                M41 = 0f, M42 = 0f, M43 = 0f, M44 = 1,
            //                M51 = 0,  M52 = 0,  M53 = 0,  M54 = 0
            //            };

            IGraphicsEffect graphicsEffect = new ColorMatrixEffect()
            {
                ColorMatrix = mat,
                Source      = new CompositionEffectSourceParameter("ImageSource")
            };


            //// COLORHIGHLIGHT
            //IGraphicsEffect graphicsEffect = new ArithmeticCompositeEffect()
            //{
            //    MultiplyAmount = 0,
            //    Source1Amount = 1,
            //    Source2Amount = 1,
            //    Source1 = new GammaTransferEffect()
            //    {
            //        RedExponent = 7,
            //        BlueExponent = 7,
            //        GreenExponent = 7,
            //        RedAmplitude = 3,
            //        GreenAmplitude = 3,
            //        BlueAmplitude = 3,
            //        Source = new CompositionEffectSourceParameter("ImageSource")
            //    },
            //    Source2 = new SaturationEffect()
            //    {
            //        Saturation = 0,
            //        Source = new CompositionEffectSourceParameter("ImageSource")
            //    }
            //};



            // Create the effect factory and instantiate a brush
            CompositionEffectFactory _effectFactory = compositor.CreateEffectFactory(graphicsEffect, null);
            CompositionEffectBrush   effectBrush    = _effectFactory.CreateBrush();

            // Create BackdropBrush
            CompositionBackdropBrush backdrop = compositor.CreateHostBackdropBrush();

            effectBrush.SetSourceParameter("ImageSource", backdrop);

            // Set EffectBrush as the brush that XamlCompBrushBase paints onto Xaml UIElement
            CompositionBrush = effectBrush;
        }
Ejemplo n.º 25
0
        ICanvasImage GetSelectionBorder(ICanvasImage mask, float zoomFactor)
        {
            // Scale so our border will always be the same width no matter how the image is zoomed.
            var scaleToCurrentZoom = new ScaleEffect
            {
                Source = mask,
                Scale = new Vector2(zoomFactor)
            };

            // Find edges of the selection.
            var detectEdges = new EdgeDetectionEffect
            {
                Source = scaleToCurrentZoom,
                Amount = 0.1f
            };

            // Colorize.
            var colorItMagenta = new ColorMatrixEffect
            {
                Source = detectEdges,

                ColorMatrix = new Matrix5x4
                {
                    M11 = 1,
                    M13 = 1,
                    M14 = 1,
                }
            };

            // Scale back to the original size.
            return new ScaleEffect
            {
                Source = colorItMagenta,
                Scale = new Vector2(1 / zoomFactor)
            };
        }
 public ColorMatrixConfigurationViewModel(ColorMatrixEffect layerEffect) : base(layerEffect)
 {
     Properties = layerEffect.Properties;
 }
Ejemplo n.º 27
0
        private ICanvasImage CreateColorMatrix()
        {
            var colorMatrixEffect = new ColorMatrixEffect
            {
                Source = bitmapTiger
            };

            // Animation cycles through different color settings.
            animationFunction = elapsedTime =>
            {
                var matrix = new Matrix5x4();

                matrix.M11 = (float)Math.Sin(elapsedTime * 1.5);
                matrix.M21 = (float)Math.Sin(elapsedTime * 1.4);
                matrix.M31 = (float)Math.Sin(elapsedTime * 1.3);
                matrix.M51 = (1 - matrix.M11 - matrix.M21 - matrix.M31) / 2;

                matrix.M12 = (float)Math.Sin(elapsedTime * 1.2);
                matrix.M22 = (float)Math.Sin(elapsedTime * 1.1);
                matrix.M32 = (float)Math.Sin(elapsedTime * 1.0);
                matrix.M52 = (1 - matrix.M12 - matrix.M22 - matrix.M32) / 2;

                matrix.M13 = (float)Math.Sin(elapsedTime * 0.9);
                matrix.M23 = (float)Math.Sin(elapsedTime * 0.8);
                matrix.M33 = (float)Math.Sin(elapsedTime * 0.7);
                matrix.M53 = (1 - matrix.M13 - matrix.M23 - matrix.M33) / 2;

                matrix.M44 = 1;

                colorMatrixEffect.ColorMatrix = matrix;
            };

            return colorMatrixEffect;
        }
Ejemplo n.º 28
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.
            };
        }
Ejemplo n.º 29
0
        public bool DisplayRegionMask(CanvasDrawingSession drawingSession, float zoomFactor, bool editInProgress)
        {
            if (!IsEnabled || !IsEditingRegion || !ShowRegion || regionMask == null)
                return false;

            if (editInProgress && RegionSelectionOperation == SelectionOperation.Replace)
                return false;

            drawingSession.Blend = CanvasBlend.SourceOver;

            if (!editInProgress)
            {
                // Gray out everything outside the region.
                var mask = new ColorMatrixEffect
                {
                    Source = GetRegionMask(),

                    ColorMatrix = new Matrix5x4
                    {
                        // Set RGB = gray.
                        M51 = 0.5f,
                        M52 = 0.5f,
                        M53 = 0.5f,

                        // Invert and scale the mask alpha.
                        M44 = -0.75f,
                        M54 = 0.75f,
                    }
                };

                drawingSession.DrawImage(mask);
            }

            // Magenta region border.
            var border = GetSelectionBorder(regionMask, zoomFactor);

            drawingSession.DrawImage(border);

            return true;
        }