Example #1
0
 static GrayscaleDef()
 {
     if (grayscaleEffect == null)
     {
         grayscaleEffect = Util.GetComponentVar <GrayscaleEffect, GrayscaleEffect>(grayscaleEffect);
     }
 }
Example #2
0
        protected override void OnConnected()
        {
            // Delay creating composition resources until they're required.
            if (CompositionBrush == null)
            {
                var backdrop = Window.Current.Compositor.CreateBackdropBrush();

                // Use a Win2D effect applied to a CompositionBackdropBrush.
                var effect = new GrayscaleEffect
                {
                    Name   = "Grayscale",
                    Source = new OpacityEffect
                    {
                        Name    = "GrayscaleOpacity",
                        Opacity = 1.0f,
                        Source  = new CompositionEffectSourceParameter("backdrop")
                    }
                };

                var effectFactory = Window.Current.Compositor.CreateEffectFactory(effect);
                var effectBrush   = effectFactory.CreateBrush();
                effectBrush.SetSourceParameter("backdrop", backdrop);

                CompositionBrush = effectBrush;
            }
        }
Example #3
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Z))
        {
            foreach (GameObject go in gameObjectsToToggle)
            {
                SetMaterialToBlack(go);
            }
        }

        if (Input.GetKeyDown(KeyCode.X))
        {
            foreach (GameObject go in gameObjectsToToggle)
            {
                SetMaterialToDefault(go);
            }
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            if (mainCamera != null)
            {
                GrayscaleEffect gs = mainCamera.GetComponent <GrayscaleEffect>();
                gs.enabled = !gs.enabled;
            }
        }
    }
Example #4
0
        private void InitializeBrushes()
        {
            if (this.DataContext is ViewImageEditorMetadata)
            {
                var viewImageEditorMetadata = (ViewImageEditorMetadata)this.DataContext;

                // noeffect brush
                Size imageSize;
                //m_noEffectBrush = CreateBrushFromAsset("xxxxx.jpg", out imageSize);
                m_noEffectBrush    = CreateBrushFromAsset(viewImageEditorMetadata.Bitmap, out imageSize);
                m_imageAspectRatio = (imageSize.Width == 0 && imageSize.Height == 0) ? 1 : imageSize.Width / imageSize.Height;

                renderSurface.UpdateLayout();
                ResizeImage(new Size(renderSurface.ActualWidth, renderSurface.ActualHeight));

                // Exposure
                var exposureEffectDesc = new ExposureEffect
                {
                    Name   = "effect",
                    Source = new CompositionEffectSourceParameter("Image")
                };
                m_exposureEffectBrush = m_compositor.CreateEffectFactory(exposureEffectDesc, new[] { "effect.Exposure" }).CreateBrush();
                ChangeExposureValue(0.5f);
                m_exposureEffectBrush.SetSourceParameter("Image", m_noEffectBrush);

                // monochromatic gray
                var grayscaleEffectDesc = new GrayscaleEffect
                {
                    Name   = "effect",
                    Source = new CompositionEffectSourceParameter("Image")
                };
                m_grayscaleEffectBrush = m_compositor.CreateEffectFactory(grayscaleEffectDesc).CreateBrush();
                m_grayscaleEffectBrush.SetSourceParameter("Image", m_noEffectBrush);
            }
        }
Example #5
0
        public static string GetConvertedImage(byte[] stream)
        {
            using (var bmp = new GcBitmap())
            {
                bmp.Load(stream);
                // Add watermark
                var newImg = new GcBitmap();
                newImg.Load(stream);
                using (var g = bmp.CreateGraphics(Color.White))
                {
                    g.DrawImage(
                        Image.FromGcBitmap(newImg, true),
                        new RectangleF(0, 0, bmp.Width, bmp.Height),
                        null,
                        ImageAlign.Default
                        );

                    g.DrawString("DOCUMENT", new TextFormat
                    {
                        FontSize  = 96,
                        ForeColor = Color.FromArgb(128, Color.Yellow),
                        Font      = FontCollection.SystemFonts.DefaultFont
                    },
                                 new RectangleF(0, 0, bmp.Width, bmp.Height),
                                 TextAlignment.Center, ParagraphAlignment.Center, false);
                }
                // Convert to grayscale
                bmp.ApplyEffect(GrayscaleEffect.Get(GrayscaleStandard.BT601));
                // Resize to thumbnail
                var resizedImage = bmp.Resize(100, 100, InterpolationMode.NearestNeighbor);
                return(GetBase64(resizedImage));
            }
        }
Example #6
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(silhouetteMode))
        {
            foreach (GameObject go in gameObjectsToToggle)
            {
                SetMaterialToBlack(go);
            }
        }

        if (Input.GetKeyDown(defaultMaterialMode))
        {
            foreach (GameObject go in gameObjectsToToggle)
            {
                SetMaterialToDefault(go);
            }
        }

        if (Input.GetKeyDown(grayscaleMode))
        {
            if (mainCamera != null)
            {
                GrayscaleEffect gs = mainCamera.GetComponent <GrayscaleEffect>();
                gs.enabled = !gs.enabled;

                GrayscaleEffect gsp = perspectiveCamera.GetComponent <GrayscaleEffect>();
                gsp.enabled = !gsp.enabled;
            }
        }
    }
        private static ICanvasImage CreateGrayscaleEffect(ICanvasImage canvasImage)
        {
            var ef = new GrayscaleEffect();

            ef.Source = canvasImage;
            return(ef);
        }
 async Task <Uri> Grayscale()
 {
     using (var source = new StorageFileImageSource(imageStorageFile))
         using (var sharpnessEffect = new GrayscaleEffect(source))
         {
             LastEffect = sharpnessEffect;
             return(await SaveToImage());
         }
 }
Example #9
0
    void Awake()
    {
        m_Material = new Material(Shader.Find(SHADER_NAME));

        //singleton
        if (Instance == null)
        {
            Instance = this;
        }
    }
Example #10
0
 void Awake()
 {
     if (levelController == null)
     {
         levelController = this;
     }
     anim      = transition.GetComponent <Animation>();
     grayscale = Camera.main.GetComponent <GrayscaleEffect>();
     levelId   = levelSet.levelToLoad;
     LevelTransition(false);
 }
Example #11
0
        public override void Start()
        {
            base.Start();
            m_spellID         = SpellID.SlowDownTime;
            m_music           = (Music)GameObject.FindObjectOfType(typeof(Music));
            m_grayscaleEffect = (GrayscaleEffect)GameObject.FindObjectOfType(typeof(GrayscaleEffect));
            if (m_grayscaleEffect)
            {
                m_grayscaleEffect.enabled = false;
            }

            SlowDownTime.SLOW_DOWN_TIME_SCALAR = 1f;
        }
Example #12
0
        public static string GetConvertedImage(byte[] stream)
        {
            using (var bmp = new GcBitmap())
            {
                bmp.Load(stream);

                //  Convert to grayscale
                bmp.ApplyEffect(GrayscaleEffect.Get(GrayscaleStandard.BT601));
                //  Resize to thumbnail
                var resizedImage = bmp.Resize(100, 100, InterpolationMode.NearestNeighbor);
                return(GetBase64(resizedImage));
            }
        }
Example #13
0
    public void MainCameraSetGray(bool _state)
    {
        GrayscaleEffect effect = mainCamera.GetComponent <GrayscaleEffect>();

        if (effect.shader == null)
        {
            effect.shader = Shader.Find("Shader/GrayscaleEffect");
        }
        if (effect != null)
        {
            effect.enabled = _state;
        }
    }
        public MainPage()
        {
            InitializeComponent();

            double scaleFactor = 1.0;
            scaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;

            _writeableBitmap = new WriteableBitmap((int)(Window.Current.Bounds.Width * scaleFactor), (int)(Window.Current.Bounds.Height * scaleFactor));
            _thumbnailImageBitmap = new WriteableBitmap((int)OriginalImage.Width, (int)OriginalImage.Height);
            _grayscaleEffect = new GrayscaleEffect();
            _brightnessEffect = new BrightnessEffect(_grayscaleEffect);
            SwapChainPanelTarget.Loaded += SwapChainPanelTarget_Loaded;

        }
        public MainPage()
        {
            InitializeComponent();

            double scaleFactor = 1.0;

            scaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;

            _writeableBitmap             = new WriteableBitmap((int)(Window.Current.Bounds.Width * scaleFactor), (int)(Window.Current.Bounds.Height * scaleFactor));
            _thumbnailImageBitmap        = new WriteableBitmap((int)OriginalImage.Width, (int)OriginalImage.Height);
            _grayscaleEffect             = new GrayscaleEffect();
            _brightnessEffect            = new BrightnessEffect(_grayscaleEffect);
            SwapChainPanelTarget.Loaded += SwapChainPanelTarget_Loaded;
        }
Example #16
0
        private ObservableCollection <VideoEffectsViewModel> CreateNonEditableEffects()
        {
            var effects = new ObservableCollection <VideoEffectsViewModel>();

            m_antiqueEffect = new AntiqueEffect();
            effects.Add(new VideoEffectsViewModel(m_antiqueEffect, "antique_thumbnail.jpg")
            {
                Name = "Antique"
            });

            m_sepiaEffect = new SepiaEffect();
            effects.Add(new VideoEffectsViewModel(m_sepiaEffect, "sepia_thumbnail.jpg")
            {
                Name = "Sepia"
            });

            m_blendEffect = new BlendEffect()
            {
                GlobalAlpha = 0.5
            };

            effects.Add(new VideoEffectsViewModel(m_blendEffect, "blend_brokenglass_thumbnail.jpg", "BrokenGlas.png")
            {
                Name = "Blend 1"
            });

            var effect = new BlendEffect()
            {
                BlendFunction = BlendFunction.Overlay, GlobalAlpha = 0.5
            };

            effects.Add(new VideoEffectsViewModel(effect, "blend_raindrops_thumbnail.jpg", "raindrops.jpg")
            {
                Name = "Blend 2"
            });

            m_mirrorEffect = new MirrorEffect();
            effects.Add(new VideoEffectsViewModel(m_mirrorEffect, "mirror_thumbnail.jpg")
            {
                Name = "Mirror"
            });

            m_grayscaleEffect = new GrayscaleEffect();
            effects.Add(new VideoEffectsViewModel(m_grayscaleEffect, "grayscale_thumbnail.jpg")
            {
                Name = "Grayscale"
            });

            return(effects);
        }
Example #17
0
 public MainPage()
 {
     this.InitializeComponent();
     bitmap          = new WriteableBitmap(10, 10);
     grayscaleEffect = new GrayscaleEffect();
     //renderer = new SwapChainPanelRenderer(grayscaleEffect, SwapChainPanelTarget);
     if (SwapChainPanelTarget.ActualHeight > 0 && SwapChainPanelTarget.ActualWidth > 0)
     {
         if (renderer == null)
         {
             renderer = new SwapChainPanelRenderer(grayscaleEffect, SwapChainPanelTarget);
         }
     }
 }
Example #18
0
        public override bool Enter(CameraControll owner)
        {
            base.Enter(owner);
            if (!Grayscale)
            {
                Grayscale = owner.gameObject.AddComponent <GrayscaleEffect>();
            }
            Grayscale.enabled = true;
            Shader shader = Shader.Find("MOYU/Grayscale");

            Grayscale.shader = shader;
            isdone           = true;
            return(true);
        }
        public static byte[] GetConvertedImage(byte[] str)
        {
            GcBitmap.SetLicenseKey(System.Environment.GetEnvironmentVariable("GcImagingLicenseKey", EnvironmentVariableTarget.Process));

            using (var bmp = new GcBitmap())
            {
                bmp.Load(str);
                // Add watermark
                var newImg = new GcBitmap();
                newImg.Load(str);
                using (var g = bmp.CreateGraphics(Color.White))
                {
                    g.DrawImage(
                        Image.FromGcBitmap(newImg, true),
                        new RectangleF(0, 0, bmp.Width, bmp.Height),
                        null,
                        ImageAlign.Default
                        );
                    g.DrawString("DOCUMENT", new TextFormat
                    {
                        FontSize  = 22,
                        ForeColor = Color.FromArgb(128, Color.Yellow),
                        Font      = FontCollection.SystemFonts.DefaultFont
                    },
                                 new RectangleF(0, 0, bmp.Width, bmp.Height),
                                 TextAlignment.Center, ParagraphAlignment.Center, false);
                }
                // GcBitmap.SetLicenseKey("");
                //  Convert to grayscale
                bmp.ApplyEffect(GrayscaleEffect.Get(GrayscaleStandard.BT601));
                //  Resize to thumbnail
                var resizedImage = bmp.Resize(100, 100, InterpolationMode.NearestNeighbor);
                using (MemoryStream m = new MemoryStream())
                {
                    resizedImage.SaveAsPng(m);
                    m.Position = 0;

                    byte[] _buffer = new byte[16 * 1024];
                    using (MemoryStream _ms = new MemoryStream())
                    {
                        int _read;
                        while ((_read = m.Read(_buffer, 0, _buffer.Length)) > 0)
                        {
                            _ms.Write(_buffer, 0, _read);
                        }
                        return(_ms.ToArray());
                    }
                }
            }
        }
Example #20
0
        static public CompositionEffectBrush CreateGrayscaleEffectBrush()
        {
            var effect = new GrayscaleEffect
            {
                Name   = "Grayscale",
                Source = new CompositionEffectSourceParameter("source")
            };

            var compositor = Window.Current.Compositor;
            var factory    = compositor.CreateEffectFactory(effect);
            var brush      = factory.CreateBrush();

            brush.SetSourceParameter("source", compositor.CreateBackdropBrush());
            return(brush);
        }
Example #21
0
    void Start()
    {
        pausedLogo       = GameObject.FindGameObjectWithTag("Pause");
        pausedLogoSprite = GameObject.FindGameObjectWithTag("Pause").GetComponent <UISprite>();
        enablePauseLogo(false);

        _originalTimeScale      = Time.timeScale;
        _originalFixedDeltaTime = Time.fixedDeltaTime;

        _AnimationCompleted = playerSprite.AnimationCompleted;
        _status             = (Status)GetComponent <Status> ();
        _camera             = GameObject.FindGameObjectWithTag("MainCamera");
        _grayscaleEffect    = (GrayscaleEffect)_camera.gameObject.GetComponent <GrayscaleEffect> ();
        _rcc = (RaycastCharacterController)GetComponent("RaycastCharacterController");
        _insufficientManaCFX = transform.FindChild("CFX_Text_Insufficient_Mana").particleSystem;
    }
        /// <summary>
        /// Constructs a high pass effect with the specified parameters.
        /// </summary>
        /// <param name="kernelSize">The size of the filter kernel. A larger size preserves more of lower frequencies.</param>
        /// <param name="isGrayscale">True if the highpass effect should give a grayscale result. Otherwise the individual R, G, B channels are treated separately.</param>
        /// <param name="downscaleDivisor">How much to downscale the image to reduce the cost of the internal blur operation, trading speed for some fidelity. Suitable value depends on the kernelSize.</param>
        public HighpassEffect(uint kernelSize, bool isGrayscale = false, uint downscaleDivisor = 1)
        {
            m_kernelSize       = kernelSize;
            m_downscaleDivisor = downscaleDivisor;
            m_isGrayscale      = isGrayscale;

            if (m_downscaleDivisor > 1)
            {
                m_downscaleEffect        = new ScaleEffect(/*source*/ 1.0 / m_downscaleDivisor);
                m_downscaleCachingEffect = new CachingEffect(m_downscaleEffect);

                int blurKernelSize = Math.Max(1, (int)(3.0 * m_kernelSize / m_downscaleDivisor));

                m_blurEffect = new BlurEffect(m_downscaleCachingEffect)
                {
                    KernelSize = blurKernelSize
                };

                m_highPassBlendEffect = new BlendEffect(/*source*/)
                {
                    ForegroundSource = m_blurEffect,
                    BlendFunction    = BlendFunction.SignedDifference
                };
            }
            else
            {
                int blurKernelSize = Math.Max(1, (int)(3.0 * m_kernelSize));

                m_blurEffect = new BlurEffect()
                {
                    KernelSize = blurKernelSize
                };

                m_highPassBlendEffect = new BlendEffect(/*source*/)
                {
                    ForegroundSource = m_blurEffect,
                    BlendFunction    = BlendFunction.SignedDifference
                };
            }

            if (m_isGrayscale)
            {
                m_highPassGrayscaleEffect = new GrayscaleEffect(m_highPassBlendEffect);
            }
        }
Example #23
0
        private void DrawLocal(CanvasDrawingSession ds, Size size)
        {
            var rect = new Rect(size.Width / 2,
                                0,
                                size.Width / 2,
                                size.Height / 2);

            if (localBitmap != null)
            {
                var effect = new GrayscaleEffect
                {
                    Source = localBitmap
                };

                var sourceRect = new Rect(0, 0, localBitmap.SizeInPixels.Width, localBitmap.SizeInPixels.Height);

                ds.DrawImage(effect, rect, sourceRect);
            }
        }
    void Awake()
    {
        //get a reference to the vehicle
        vehicle = this.GetComponentInParent <Vehicle> ();
        //get a reference to the vehicle spotlight
        GameObject lightObj = vehicle.gameObject.GetChildObjectByName("Vehicle Spotlight");

        //get a reference to the light component of the vehicle spotlight
        this.vehicleSpotLight = lightObj.GetComponent <Light> ();
        //get a reference to the main directional light
        directionalLight = GameObject.FindGameObjectWithTag(TagManager.DirectionalLight).GetComponent <Light>();
        //get a reference to the GrayScaleEffect component
        grayScaleEffect = GetComponent <GrayscaleEffect>();
        //get a reference to the camera component
        _camera = GetComponent <Camera> ();
        //get a reference to the eye that contains the retina.
        if (this.eyeType == null)
        {
            Debug.LogError("Null reference for retina eye type.");
            return;
        }
        foreach (Eye e in this.GetComponentsInParent <Eye>(true))
        {
            if (e.eyeType == this.eyeType)
            {
                this.eye = e;
                break;
            }
        }
        //log error if eye with the appropriate type cannot be found
        if (this.eye == null)
        {
            Debug.LogError("Could not find eye for retina. Are you missing an EyeType reference?");
        }
        this.ambientLighting = RenderSettings.ambientLight;
        this.vehicleSpotLightOriginalSetting = this.vehicle.vehicleSpotlight;
        complexRetinaMaterial = new Material(Shader.Find("Custom/ComplexEye"));
        simpleRetinaMaterial  = new Material(Shader.Find("Custom/AverageBrightness"));
    }
        private void MainGridLoaded(object sender, RoutedEventArgs e)
        {
            m_compositor = ElementCompositionPreview.GetElementVisual(MainGrid).Compositor;
            m_root       = m_compositor.CreateContainerVisual();
            ElementCompositionPreview.SetElementChildVisual(MainGrid, m_root);

            Size imageSize;

            m_noEffectBrush = CreateBrushFromAsset(
                "Bruno'sFamily2015 (13)-X2.jpg",
                out imageSize);
            m_imageAspectRatio = (imageSize.Width == 0 && imageSize.Height == 0) ? 1 : imageSize.Width / imageSize.Height;

            m_sprite = m_compositor.CreateSpriteVisual();
            ResizeImage(new Size(MainGrid.ActualWidth, MainGrid.ActualHeight));
            m_root.Children.InsertAtTop(m_sprite);

            // Image with alpha channel as an mask.
            var alphaMaskEffectDesc = new CompositeEffect
            {
                Mode    = CanvasComposite.DestinationIn,
                Sources =
                {
                    new CompositionEffectSourceParameter("Image"),
                    new Transform2DEffect
                    {
                        Name   = "MaskTransform",
                        Source = new CompositionEffectSourceParameter("Mask")
                    }
                }
            };

            m_alphaMaskEffectBrush = m_compositor.CreateEffectFactory(
                alphaMaskEffectDesc,
                new[] { "MaskTransform.TransformMatrix" }
                ).CreateBrush();
            m_alphaMaskEffectBrush.SetSourceParameter(
                "Image",
                m_noEffectBrush);
            m_alphaMaskEffectBrush.SetSourceParameter(
                "Mask",
                CreateBrushFromAsset("CircleMask.png"));

            // Arithmetic operations between two images.
            var arithmeticEffectDesc = new ArithmeticCompositeEffect
            {
                Name        = "effect",
                ClampOutput = false,
                Source1     = new CompositionEffectSourceParameter("Source1"),
                Source2     = new CompositionEffectSourceParameter("Source2")
            };

            m_arithmeticEffectBrush = m_compositor.CreateEffectFactory(
                arithmeticEffectDesc,
                new[]
            {
                "effect.MultiplyAmount",
                "effect.Source1Amount",
                "effect.Source2Amount",
                "effect.Offset"
            }
                ).CreateBrush();
            m_arithmeticEffectBrush.SetSourceParameter(
                "Source1",
                m_noEffectBrush);
            m_arithmeticEffectBrush.SetSourceParameter(
                "Source2",
                CreateBrushFromAsset("_P2A8041.jpg"));

            // Creates a blend effect that combines two images.
            var foregroundBrush = CreateBrushFromAsset("Checkerboard_100x100.png");

            m_blendEffectBrushes = new CompositionEffectBrush[m_supportedBlendModes.Length];
            for (int i = 0; i < m_supportedBlendModes.Length; i++)
            {
                var blendEffectDesc = new BlendEffect
                {
                    Mode       = m_supportedBlendModes[i],
                    Background = new CompositionEffectSourceParameter("Background"),
                    Foreground = new CompositionEffectSourceParameter("Foreground")
                };
                m_blendEffectBrushes[i] = m_compositor.CreateEffectFactory(
                    blendEffectDesc
                    ).CreateBrush();
                m_blendEffectBrushes[i].SetSourceParameter(
                    "Background",
                    m_noEffectBrush);
                m_blendEffectBrushes[i].SetSourceParameter(
                    "Foreground",
                    foregroundBrush);
            }

            // Generates an image containing a solid color.
            var colorSourceEffectDesc = new ColorSourceEffect // FloodEffect
            {
                Name = "effect"
            };

            m_colorSourceEffectBrush = m_compositor.CreateEffectFactory(
                colorSourceEffectDesc,
                new[] { "effect.Color" }
                ).CreateBrush();

            // Changes the contrast of an image.
            var contrastEffectDesc = new ContrastEffect
            {
                Name   = "effect",
                Source = new CompositionEffectSourceParameter("Image")
            };

            m_contrastEffectBrush = m_compositor.CreateEffectFactory(
                contrastEffectDesc,
                new[] { "effect.Contrast" }
                ).CreateBrush();
            m_contrastEffectBrush.SetSourceParameter(
                "Image",
                m_noEffectBrush);

            // Changes the exposure of an image.
            var exposureEffectDesc = new ExposureEffect
            {
                Name   = "effect",
                Source = new CompositionEffectSourceParameter("Image")
            };

            m_exposureEffectBrush = m_compositor.CreateEffectFactory(
                exposureEffectDesc,
                new[] { "effect.Exposure" }
                ).CreateBrush();
            m_exposureEffectBrush.SetSourceParameter(
                "Image",
                m_noEffectBrush);

            // Alters the colors of an image by applying a per-channel gamma transfer function.
            var gammaTransferEffectDesc = new GammaTransferEffect
            {
                Name         = "effect",
                RedDisable   = false,
                GreenDisable = false,
                BlueDisable  = false,
                AlphaDisable = false,
                Source       = new CompositionEffectSourceParameter("Image")
            };

            m_gammaTransferEffectBrush = m_compositor.CreateEffectFactory(
                gammaTransferEffectDesc,
                new[]
            {
                "effect.RedAmplitude",
                "effect.RedExponent",
                "effect.RedOffset",
                "effect.GreenAmplitude",
                "effect.GreenExponent",
                "effect.GreenOffset",
                "effect.BlueAmplitude",
                "effect.BlueExponent",
                "effect.BlueOffset"
            }
                ).CreateBrush();
            m_gammaTransferEffectBrush.SetSourceParameter(
                "Image",
                m_noEffectBrush);

            // Converts an image to monochromatic gray.
            var grayscaleEffectDesc = new GrayscaleEffect
            {
                Name   = "effect",
                Source = new CompositionEffectSourceParameter("Image")
            };

            m_grayscaleEffectBrush = m_compositor.CreateEffectFactory(
                grayscaleEffectDesc
                ).CreateBrush();
            m_grayscaleEffectBrush.SetSourceParameter(
                "Image",
                m_noEffectBrush);

            // Alters the color of an image by rotating its hue values.
            var hueRotationEffectDesc = new HueRotationEffect
            {
                Name   = "effect",
                Source = new CompositionEffectSourceParameter("Image")
            };

            m_hueRotationEffectBrush = m_compositor.CreateEffectFactory(
                hueRotationEffectDesc,
                new[] { "effect.Angle" }
                ).CreateBrush();
            m_hueRotationEffectBrush.SetSourceParameter(
                "Image",
                m_noEffectBrush);

            // Inverts the colors of an image.
            var invertEffectDesc = new InvertEffect
            {
                Name   = "effect",
                Source = new CompositionEffectSourceParameter("Image")
            };

            m_invertEffectBrush = m_compositor.CreateEffectFactory(
                invertEffectDesc
                ).CreateBrush();
            m_invertEffectBrush.SetSourceParameter(
                "Image",
                m_noEffectBrush);

            // Alters the saturation of an image.
            var saturationEffectDesc = new SaturationEffect
            {
                Name   = "effect",
                Source = new CompositionEffectSourceParameter("Image")
            };

            m_saturateEffectBrush = m_compositor.CreateEffectFactory(
                saturationEffectDesc,
                new[] { "effect.Saturation" }
                ).CreateBrush();
            m_saturateEffectBrush.SetSourceParameter(
                "Image",
                m_noEffectBrush);

            // Converts an image to sepia tones.
            var supportedAlphaModes = new[]
            {
                CanvasAlphaMode.Premultiplied,
                CanvasAlphaMode.Straight
            };

            m_sepiaEffectBrushes = new CompositionEffectBrush[supportedAlphaModes.Length];
            for (int i = 0; i < supportedAlphaModes.Length; i++)
            {
                var sepiaEffectDesc = new SepiaEffect
                {
                    Name      = "effect",
                    AlphaMode = supportedAlphaModes[i],
                    Source    = new CompositionEffectSourceParameter("Image")
                };
                m_sepiaEffectBrushes[i] = m_compositor.CreateEffectFactory(
                    sepiaEffectDesc,
                    new[] { "effect.Intensity" }
                    ).CreateBrush();
                m_sepiaEffectBrushes[i].SetSourceParameter(
                    "Image",
                    m_noEffectBrush);
            }

            // Adjusts the temperature and/or tint of an image.
            var temperatureAndTintEffectDesc = new TemperatureAndTintEffect
            {
                Name   = "effect",
                Source = new CompositionEffectSourceParameter("Image")
            };

            m_temperatureAndTintEffectBrush = m_compositor.CreateEffectFactory(
                temperatureAndTintEffectDesc,
                new[]
            {
                "effect.Temperature",
                "effect.Tint"
            }
                ).CreateBrush();
            m_temperatureAndTintEffectBrush.SetSourceParameter(
                "Image",
                m_noEffectBrush);

            // Applies a 2D affine transform matrix to an image.
            var transform2DEffectDesc = new Transform2DEffect
            {
                TransformMatrix = new Matrix3x2(
                    -1, 0,
                    0, 1,
                    m_sprite.Size.X, 0),
                Source = new CompositionEffectSourceParameter("Image")
            };

            m_transform2DEffectBrush = m_compositor.CreateEffectFactory(
                transform2DEffectDesc
                ).CreateBrush();
            m_transform2DEffectBrush.SetSourceParameter(
                "Image",
                m_noEffectBrush);

            // For simplying UI states switch, put effect parameter grids in an array
            m_effectParamsGrids = new Grid[(int)EffectType.NumEffectTypes];
            m_effectParamsGrids[(int)EffectType.NoEffect]           = null;
            m_effectParamsGrids[(int)EffectType.AlphaMask]          = AlphaMaskParams;
            m_effectParamsGrids[(int)EffectType.Arithmetic]         = ArithmeticParams;
            m_effectParamsGrids[(int)EffectType.Blend]              = BlendParams;
            m_effectParamsGrids[(int)EffectType.ColorSource]        = ColorSourceParams;
            m_effectParamsGrids[(int)EffectType.Contrast]           = ContrastParams;
            m_effectParamsGrids[(int)EffectType.Exposure]           = ExposureParams;
            m_effectParamsGrids[(int)EffectType.GammaTransfer]      = GammaTransferParams;
            m_effectParamsGrids[(int)EffectType.Grayscale]          = null;
            m_effectParamsGrids[(int)EffectType.HueRotation]        = HueRotationParams;
            m_effectParamsGrids[(int)EffectType.Invert]             = null;
            m_effectParamsGrids[(int)EffectType.Saturation]         = SaturationParams;
            m_effectParamsGrids[(int)EffectType.Sepia]              = SepiaParams;
            m_effectParamsGrids[(int)EffectType.TemperatureAndTint] = TemperatureAndTintParams;
            m_effectParamsGrids[(int)EffectType.Transform2D]        = null;

            // Same as grids
            m_effectBrushes = new CompositionBrush[(int)EffectType.NumEffectTypes];
            m_effectBrushes[(int)EffectType.NoEffect]           = m_noEffectBrush;
            m_effectBrushes[(int)EffectType.AlphaMask]          = m_alphaMaskEffectBrush;
            m_effectBrushes[(int)EffectType.Arithmetic]         = m_arithmeticEffectBrush;
            m_effectBrushes[(int)EffectType.Blend]              = m_blendEffectBrushes[m_activeBlendMode];
            m_effectBrushes[(int)EffectType.ColorSource]        = m_colorSourceEffectBrush;
            m_effectBrushes[(int)EffectType.Contrast]           = m_contrastEffectBrush;
            m_effectBrushes[(int)EffectType.Exposure]           = m_exposureEffectBrush;
            m_effectBrushes[(int)EffectType.GammaTransfer]      = m_gammaTransferEffectBrush;
            m_effectBrushes[(int)EffectType.Grayscale]          = m_grayscaleEffectBrush;
            m_effectBrushes[(int)EffectType.HueRotation]        = m_hueRotationEffectBrush;
            m_effectBrushes[(int)EffectType.Invert]             = m_invertEffectBrush;
            m_effectBrushes[(int)EffectType.Saturation]         = m_saturateEffectBrush;
            m_effectBrushes[(int)EffectType.Sepia]              = m_sepiaEffectBrushes[m_activeSepiaAlphaMode];
            m_effectBrushes[(int)EffectType.TemperatureAndTint] = m_temperatureAndTintEffectBrush;
            m_effectBrushes[(int)EffectType.Transform2D]        = m_transform2DEffectBrush;

            this.InitializeValues();
        }
        public CanvasRenderTarget applyEdgeDetectionEffects(CanvasBitmap workingBitmap)
        {
            //CanvasBitmap workingBitmap = SelectWorkingBitmap(useOriginalBitmap);


            if (workingBitmap != null)
            {
                int ww = (int)workingBitmap.SizeInPixels.Width;
                int hh = (int)workingBitmap.SizeInPixels.Height;

                //GrayscaleEffect grayscaleEffect = new GrayscaleEffect();
                //grayscaleEffect.Source=canvasBitmap;

                ContrastEffect contrastEffect = new ContrastEffect();
                contrastEffect.Contrast = (float)edgeDetectionContrast;
                contrastEffect.Source   = workingBitmap;

                ExposureEffect exposureEffect = new ExposureEffect();
                exposureEffect.Source   = contrastEffect;
                exposureEffect.Exposure = (float)edgeDetectionExposure;


                EdgeDetectionEffect edgeDetectionEffect = new EdgeDetectionEffect();
                edgeDetectionEffect.Source     = exposureEffect;
                edgeDetectionEffect.Amount     = (float)edgeDetectionAmount;
                edgeDetectionEffect.BlurAmount = (float)edgeDetectionBlurAmount;
                //edgeDetectionEffect.OverlayEdges = true;
                //edgeDetectionEffect.Mode = EdgeDetectionEffectMode.Prewitt;

                GrayscaleEffect grayscaleEffect = null;
                if (edgeDetectionGrayscale)
                {
                    grayscaleEffect            = new GrayscaleEffect();
                    grayscaleEffect.Source     = exposureEffect;
                    edgeDetectionEffect.Source = grayscaleEffect;
                }

                InvertEffect invertEdgeEffect = null;
                if (edgeDetectionMaskInvert)
                {
                    invertEdgeEffect        = new InvertEffect();
                    invertEdgeEffect.Source = edgeDetectionEffect;
                }



                BlendEffect blendEffect = null;
                if (edgeDetectionOverlayImage)
                {
                    OpacityEffect opacityEffect = new OpacityEffect();
                    opacityEffect.Opacity = (float)edgeDetectionOverlayOpacity;
                    opacityEffect.Source  = workingBitmap;

                    blendEffect            = new BlendEffect();
                    blendEffect.Foreground = edgeDetectionEffect;
                    blendEffect.Background = opacityEffect;
                    if (edgeDetectionMaskInvert)
                    {
                        //blendEffect.Background = invertEdgeEffect;
                        //blendEffect.Foreground = opacityEffect;

                        InvertEffect invertOrgEffect = new InvertEffect();
                        invertOrgEffect.Source = opacityEffect;
                        blendEffect.Background = invertOrgEffect;
                    }

                    blendEffect.Mode = edgeDetectionBlendEffectMode;
                }


                //if (canvasRenderTarget != null)
                //    canvasRenderTarget.Dispose();
                CanvasRenderTarget canvasRenderTarget = new CanvasRenderTarget(CanvasDevice.GetSharedDevice(), ww, hh, canvasBitmap.Dpi);
                using (var session = canvasRenderTarget.CreateDrawingSession())
                {
                    if (edgeDetectionOverlayImage)
                    {
                        session.DrawImage(blendEffect);
                    }
                    else
                    {
                        if (edgeDetectionMaskInvert)
                        {
                            session.DrawImage(invertEdgeEffect);
                        }
                        else
                        {
                            session.DrawImage(edgeDetectionEffect);
                        }
                    }
                }

                return(canvasRenderTarget);
            }

            return(null);
        }
Example #27
0
        private async void btnUpload_Clicked(object sender, RoutedEventArgs e)
        {
            FileOpenPicker openPicker = new FileOpenPicker();

            openPicker.ViewMode = PickerViewMode.Thumbnail;
            openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            openPicker.FileTypeFilter.Add(".jpg");
            openPicker.FileTypeFilter.Add(".jpeg");
            openPicker.FileTypeFilter.Add(".png");

            // Pick only one file once a time
            StorageFile file = await openPicker.PickSingleFileAsync();

            if (file == null)
            {
                return;
            }

            using (IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read))
            {
                cl = new CanvasCommandList(canvas);

                using (CanvasDrawingSession clds = cl.CreateDrawingSession())
                {
                    BitmapDecoder decoder = await BitmapDecoder.CreateAsync(fileStream);

                    clds.DrawImage(
                        CanvasBitmap.CreateFromSoftwareBitmap(canvas,
                                                              await decoder.GetSoftwareBitmapAsync(BitmapPixelFormat.Rgba16, BitmapAlphaMode.Premultiplied)));
                }

                blur = new GaussianBlurEffect
                {
                    Source     = cl,
                    BlurAmount = (float)gaussianBlurAmountSlider.Value
                };

                hueRotation = new HueRotationEffect
                {
                    Source = blur,
                    Angle  = (float)hueRotationAmountSlider.Value / 100f * 360f
                };

                contrast = new ContrastEffect
                {
                    Source   = hueRotation,
                    Contrast = (float)(contrastAmountSlider.Value - 50f) / 50f
                };

                saturation = new SaturationEffect
                {
                    Source     = contrast,
                    Saturation = (float)saturationAmountSlider.Value / 100f
                };

                temperatureAndTint = new TemperatureAndTintEffect
                {
                    Source      = saturation,
                    Temperature = (float)(temperatureAmountSlider.Value - 50f) / 50f,
                    Tint        = (float)(tintAmountSlider.Value - 50f) / 50f
                };

                grayscale = new GrayscaleEffect
                {
                    Source = temperatureAndTint
                };

                canvasEffect = saturation;

                // CanvasControl.Invalidate Method iIndicates that the contents of the CanvasControl need to be redrawn.
                // Calling Invalidate results in the Draw event being raised shortly afterward.
                //
                // Reference: https://microsoft.github.io/Win2D/html/M_Microsoft_Graphics_Canvas_UI_Xaml_CanvasControl_Invalidate.htm
                canvas.Invalidate();

                gaussianBlurAmountSlider.IsEnabled = true;
                hueRotationAmountSlider.IsEnabled  = true;
                contrastAmountSlider.IsEnabled     = true;
                saturationAmountSlider.IsEnabled   = true;
                temperatureAmountSlider.IsEnabled  = true;
                tintAmountSlider.IsEnabled         = true;
                grayscaleBufferPrevision.IsEnabled = true;

                var image = new BitmapImage();
                await image.SetSourceAsync(fileStream);
            }
        }
        //private bool correctionFlag = false;

        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())
                        using (var scaleEffect = new ScaleEffect())
                            using (CanvasSolidColorBrush solidColorBrush = new CanvasSolidColorBrush(_canvasDevice, _backgroundColor))
                            {
                                solidColorBrush.Opacity = _backgroundOpacity;
                                double rel = context.InputFrame.RelativeTime.Value.Ticks / (double)TimeSpan.TicksPerMillisecond;

                                //context.OutputFrame.Duration = new TimeSpan( (long)(frameLength * TimeSpan.TicksPerMillisecond));



                                int frameTimeCounter = (int)Math.Round(rel / _frameLength, 0);

                                int[] pitch = new int[_count];
                                int[] yaw   = new int[_count];
                                int[] fov   = new int[_count];

                                for (int i = 0; i < _count; i++)
                                {
                                    try
                                    {
                                        //pitch[i] = this.pitch[ (frameTimeCounter + (int)Math.Round(offset, 0)) * (count) + i];
                                        //fov[i] = this.fov[ (frameTimeCounter + (int)Math.Round(offset, 0)) * (count) + i];
                                        //yaw[i] = this.yaw[ (frameTimeCounter + (int)Math.Round(offset, 0)) * (count) + i];

                                        pitch[i] = this._pitch[(frameTimeCounter + (int)_offset) * (_count) + i];
                                        fov[i]   = this._fov[(frameTimeCounter + (int)_offset) * (_count) + i];
                                        yaw[i]   = this._yaw[(frameTimeCounter + (int)_offset) * (_count) + i];
                                    }
                                    catch (ArgumentOutOfRangeException ex)
                                    {
                                        Debug.WriteLine(ex.Message);
                                        pitch[i] = 0;
                                        fov[i]   = 0;
                                        yaw[i]   = 0;
                                    }
                                }

                                byte[]       tab = Heatmap.GenerateHeatmap(pitch, yaw, fov);
                                CanvasBitmap cb  = CanvasBitmap.CreateFromBytes(_canvasDevice, tab, 64, 64, Windows.Graphics.DirectX.DirectXPixelFormat.B8G8R8A8UIntNormalized, 96, CanvasAlphaMode.Premultiplied);
                                scaleEffect.Source            = cb;
                                scaleEffect.Scale             = new System.Numerics.Vector2((float)_width / 64, (float)_height / 64);
                                scaleEffect.InterpolationMode = CanvasImageInterpolation.Cubic;
                                scaleEffect.BorderMode        = EffectBorderMode.Hard;


                                if (_graysclaleVideoFlag)
                                {
                                    var grayScaleEffect = new GrayscaleEffect
                                    {
                                        BufferPrecision = CanvasBufferPrecision.Precision8UIntNormalized,
                                        CacheOutput     = false,
                                        Source          = inputBitmap
                                    };
                                    ds.DrawImage(grayScaleEffect);
                                }
                                else
                                {
                                    ds.DrawImage(inputBitmap);
                                }

                                ds.DrawImage(scaleEffect, 0, 0, new Windows.Foundation.Rect {
                                    Height = _height, Width = _width
                                }, _heatmapOpacity);



                                if (_generateDots)
                                {
                                    for (int i = 0; i < _count; i++)
                                    {
                                        ds.FillCircle(yaw[i] * _width / 64, pitch[i] * _height / 64, _dotsRadius, _colors[i % 5]);
                                    }
                                }



                                ds.FillRectangle(new Windows.Foundation.Rect {
                                    Height = _height, Width = _width
                                }, solidColorBrush);

                                ds.Flush();
                            }
        }
Example #29
0
        /// <summary>
        /// TODO: Apply filter to image
        /// </summary>
        /// <param name="fileStream"></param>
        private async void ApplyEffectAsync(IRandomAccessStream fileStream)
        {
            double scaleFactor = 1.0;
            scaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;

            _writeableBitmap = new WriteableBitmap((int)(Window.Current.Bounds.Width * scaleFactor), (int)(Window.Current.Bounds.Height * scaleFactor));
            _grayscaleEffect = new GrayscaleEffect();
            _brightnessEffect = new BrightnessEffect(_grayscaleEffect);
            //            m_renderer = new SwapChainPanelRenderer(_brightnessEffect, SwapChainPanelTarget);

            string errorMessage = null;

            try
            {
                // Rewind the stream to start.
                fileStream.Seek(0);

                // Set the imageSource on the effect and render.
                ((IImageConsumer)_grayscaleEffect).Source = new Lumia.Imaging.RandomAccessStreamImageSource(fileStream);
                await m_renderer.RenderAsync();

            }
            catch (Exception exception)
            {
                errorMessage = exception.Message;
            }
        }
        /// <summary>
        /// Constructs a high pass effect with the specified parameters.
        /// </summary>
        /// <param name="kernelSize">The size of the filter kernel. A larger size preserves more of lower frequencies.</param>
        /// <param name="isGrayscale">True if the highpass effect should give a grayscale result. Otherwise the individual R, G, B channels are treated separately.</param>
        /// <param name="downscaleDivisor">How much to downscale the image to reduce the cost of the internal blur operation, trading speed for some fidelity. Suitable value depends on the kernelSize.</param>
        public HighpassEffect(uint kernelSize, bool isGrayscale = false, uint downscaleDivisor = 1)
        {
            m_kernelSize = kernelSize;
            m_downscaleDivisor = downscaleDivisor;
            m_isGrayscale = isGrayscale;
            
            if (m_downscaleDivisor > 1)
            {
                m_downscaleEffect = new ScaleEffect(/*source*/ 1.0 / m_downscaleDivisor);
                m_downscaleCachingEffect = new CachingEffect(m_downscaleEffect);

                int blurKernelSize = Math.Max(1, (int)(3.0 * m_kernelSize / m_downscaleDivisor));

                m_blurEffect = new BlurEffect(m_downscaleCachingEffect) { KernelSize = blurKernelSize };

                m_highPassBlendEffect = new BlendEffect( /*source*/)
                {
                    ForegroundSource = m_blurEffect,
                    BlendFunction = BlendFunction.SignedDifference
                };
            }
            else
            {
                int blurKernelSize = Math.Max(1, (int)(3.0 * m_kernelSize));

                m_blurEffect = new BlurEffect() { KernelSize = blurKernelSize };

                m_highPassBlendEffect = new BlendEffect( /*source*/)
                {
                    ForegroundSource = m_blurEffect,
                    BlendFunction = BlendFunction.SignedDifference
                };
            }
                 
            if (m_isGrayscale)
            {
                m_highPassGrayscaleEffect = new GrayscaleEffect(m_highPassBlendEffect);
            }
        }
Example #31
0
	public virtual void Start()
	{
		m_grayScale = (GrayscaleEffect)Object.FindObjectOfType(typeof(GrayscaleEffect));

		if(m_grayScale==null){
			m_grayScale = Camera.main.gameObject.AddComponent<GrayscaleEffect>();
			m_grayScale.shader = Shader.Find("Hidden/Grayscale Effect");			
		}

		
		myStart();
		
	}
        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())
            //{

            //    var grayscale = new GrayscaleEffect()
            //    {
            //        Source = inputBitmap
            //    };

            //    ds.DrawImage(grayscale);
            //}

            // When using SupportedMemoryTypes => MediaMemoryTypes.GpuAndCpu we need to check if we're using GPU or CPU for the frame

            // If we're on GPU, use InputFrame.Direct3DSurface
            if (context.InputFrame.SoftwareBitmap == null)
            {
                using (var inputBitmap = CanvasBitmap.CreateFromDirect3D11Surface(_canvasDevice, context.InputFrame.Direct3DSurface))
                    using (var renderTarget = CanvasRenderTarget.CreateFromDirect3D11Surface(_canvasDevice, context.OutputFrame.Direct3DSurface))
                        using (var ds = renderTarget.CreateDrawingSession())
                        {
                            var grayscale = new GrayscaleEffect()
                            {
                                Source = inputBitmap
                            };

                            ds.DrawImage(grayscale);
                        }

                return;
            }

            // If we're on CPU, use InputFrame.SoftwareBitmap
            if (context.InputFrame.Direct3DSurface == null)
            {
                // InputFrame's raw pixels
                byte[] inputFrameBytes = new byte[4 * context.InputFrame.SoftwareBitmap.PixelWidth * context.InputFrame.SoftwareBitmap.PixelHeight];
                context.InputFrame.SoftwareBitmap.CopyToBuffer(inputFrameBytes.AsBuffer());

                using (var inputBitmap = CanvasBitmap.CreateFromBytes(
                           _canvasDevice,
                           inputFrameBytes,
                           context.InputFrame.SoftwareBitmap.PixelWidth,
                           context.InputFrame.SoftwareBitmap.PixelHeight,
                           context.InputFrame.SoftwareBitmap.BitmapPixelFormat.ToDirectXPixelFormat()))

                    using (var renderTarget = new CanvasRenderTarget(
                               _canvasDevice,
                               context.OutputFrame.SoftwareBitmap.PixelWidth,
                               context.OutputFrame.SoftwareBitmap.PixelHeight,
                               (float)context.OutputFrame.SoftwareBitmap.DpiX,
                               context.OutputFrame.SoftwareBitmap.BitmapPixelFormat.ToDirectXPixelFormat(),
                               CanvasAlphaMode.Premultiplied))
                    {
                        using (var ds = renderTarget.CreateDrawingSession())
                        {
                            var grayscale = new GrayscaleEffect()
                            {
                                Source = inputBitmap
                            };

                            ds.DrawImage(grayscale);
                        }
                    }
            }
        }
Example #33
0
        void UpdateCamera(bool allowSmoothing)
        {
            if (_target)
            {
                GrayscaleEffect ge = GetComponentInChildren <GrayscaleEffect> ();

                var h = getHealth != null?getHealth() : 100;

                var a = getAiming != null?getAiming() : false;

                var p = getPitch != null?getPitch() : 0f;

                if (h >= 85)
                {
                    ge.ramp = 0f;
                }
                else
                {
                    ge.ramp = 1f - ((h / 85f));
                }

                Cursor.lockState = CursorLockMode.Locked;
                Cursor.visible   = false;

                if (_aiming)
                {
                    if (a == false)
                    {
                        _aiming    = false;
                        _aimingAcc = 0f;
                    }
                }
                else
                {
                    if (a)
                    {
                        _aiming    = true;
                        _aimingAcc = 0f;
                    }
                }

                _aimingAcc += Time.deltaTime;

                if (_aiming)
                {
                    _distance = Mathf.Lerp(_distance, aimingDistance, _aimingAcc / 0.4f);
                }
                else
                {
                    _distance = Mathf.Lerp(_distance, runningDistance, _aimingAcc / 0.4f);
                }

                Vector3    pos;
                Quaternion rot;

                CalculateCameraTransform(_target, p, _distance, out pos, out rot);

                if (!_aiming || allowSmoothing)
                {
                    pos = Vector3.SmoothDamp(transform.position, pos, ref _velocity, runningSmoothTime);
                }

                transform.position = pos;
                transform.rotation = rot;

                cam.transform.localRotation = Quaternion.identity;
                cam.transform.localPosition = Vector3.zero;
            }
        }
Example #34
0
        public System.Windows.Media.Imaging.BitmapSource DoEffect(System.Windows.Media.Imaging.BitmapSource img, int?def)
        {
            GrayscaleEffect eff = new GrayscaleEffect();

            if (!def.HasValue)
            {
                eff.ChannelR = contr.SelectedColor.ScR;
                eff.ChannelG = contr.SelectedColor.ScG;
                eff.ChannelB = contr.SelectedColor.ScB;
            }
            else
            {
                switch (def)
                {
                case 0:
                    //Use default
                    break;

                case 1:
                    eff.ChannelR = 1;
                    eff.ChannelG = 0;
                    eff.ChannelB = 0;
                    break;

                case 2:
                    eff.ChannelR = 0;
                    eff.ChannelG = 1;
                    eff.ChannelB = 0;
                    break;

                case 3:
                    eff.ChannelR = 0;
                    eff.ChannelG = 0;
                    eff.ChannelB = 1;
                    break;

                case 4:
                    eff.ChannelR = 1;
                    eff.ChannelG = 1;
                    eff.ChannelB = 0;
                    break;

                case 5:
                    eff.ChannelR = 1;
                    eff.ChannelG = 0;
                    eff.ChannelB = 1;
                    break;

                case 6:
                    eff.ChannelR = 0;
                    eff.ChannelG = 1;
                    eff.ChannelB = 1;
                    break;

                default:
                    throw new NotImplementedException();
                }
            }

            return(img.UseEffect(eff));
        }
Example #35
0
        private ObservableCollection<VideoEffectsViewModel> CreateNonEditableEffects()
        {
            var effects = new ObservableCollection<VideoEffectsViewModel>();

            m_antiqueEffect = new AntiqueEffect();
            effects.Add(new VideoEffectsViewModel(m_antiqueEffect, "antique_thumbnail.jpg") { Name = "Antique" });

            m_sepiaEffect = new SepiaEffect();
            effects.Add(new VideoEffectsViewModel(m_sepiaEffect, "sepia_thumbnail.jpg") { Name = "Sepia" });

            m_blendEffect = new BlendEffect() { GlobalAlpha = 0.5 };

            effects.Add(new VideoEffectsViewModel(m_blendEffect, "blend_brokenglass_thumbnail.jpg", "BrokenGlas.png") { Name = "Blend 1" });

            var effect = new BlendEffect() { BlendFunction = BlendFunction.Overlay, GlobalAlpha = 0.5 };

            effects.Add(new VideoEffectsViewModel(effect, "blend_raindrops_thumbnail.jpg", "raindrops.jpg") { Name = "Blend 2" });

            m_mirrorEffect = new MirrorEffect();
            effects.Add(new VideoEffectsViewModel(m_mirrorEffect, "mirror_thumbnail.jpg") { Name = "Mirror" });

            m_grayscaleEffect = new GrayscaleEffect();
            effects.Add(new VideoEffectsViewModel(m_grayscaleEffect, "grayscale_thumbnail.jpg") { Name = "Grayscale" });

            m_binaryEffect = new BinaryEffect();
            effects.Add(new VideoEffectsViewModel(m_binaryEffect, "grayscale_thumbnail.jpg") { Name = "Binary" });

            m_medianFilter = new MedianFilter();
            effects.Add(new VideoEffectsViewModel(m_medianFilter, "grayscale_thumbnail.jpg") { Name = "Median" });
            return effects;
        }
Example #36
0
        private async void OnTap(object sender, TappedRoutedEventArgs e)
        {
            

            ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();

            mediaCapture.CapturePhotoToStreamAsync(imageProperties, fPhotoStream).AsTask().Wait();

            fPhotoStream.FlushAsync().AsTask().Wait();
            fPhotoStream.Seek(0);
            WriteableBitmap bitter = new WriteableBitmap(100, 100);
            bitter.SetSource(fPhotoStream);

            await mediaCapture.StopPreviewAsync();
            captureElement.Visibility = Visibility.Collapsed;
            PreviewImage.Visibility = Visibility.Visible;

            PreviewImage.Source = bitter;
            NormalThumb.Source = bitter;

            using (_grayscaleEffect = new GrayscaleEffect())
                await ApplyEffectAsync(fPhotoStream, _grayscaleEffect, GreyScaleThumb);

            using (_colorboostEffect = new ColorBoostEffect())
            {
                _colorboostEffect.Gain = 0.75;
                await ApplyEffectAsync(fPhotoStream, _colorboostEffect, ColorBoostThumb);
            }

            using (_hueSaturationEffect = new HueSaturationEffect())
                await ApplyEffectAsync(fPhotoStream, _hueSaturationEffect, HueSaturationThumb);

            using (_lensblurEffect = new LensBlurEffect())
                await ApplyEffectAsync(fPhotoStream, _lensblurEffect, LensBlurThumb);

            using (_antiqueEffect = new AntiqueEffect())
                await ApplyEffectAsync(fPhotoStream, _antiqueEffect, SepiaThumb);


            
            

            inking_initialization();
            myInkCanvas.Visibility = Visibility.Visible;
        }
Example #37
0
        private async void GreyScaleThumb_Tapped(object sender, TappedRoutedEventArgs e)
        {
            FilteredImage.Width = PreviewImage.ActualWidth;
            FilteredImage.Height = PreviewImage.ActualHeight;

            PreviewImage.Visibility = Visibility.Collapsed;
            FilteredImage.Visibility = Visibility.Visible;
            using (_grayscaleEffect = new GrayscaleEffect())
                await ApplyEffectAsync(fPhotoStream, _grayscaleEffect, FilteredImage);

        }