Ejemplo n.º 1
0
        /// <summary>
        /// Implementation of <see cref="System.Windows.Freezable.CloneCurrentValueCore(Freezable)">Freezable.CloneCurrentValueCore</see>.
        /// </summary>
        /// <param name="sourceFreezable"></param>
        protected override void CloneCurrentValueCore(Freezable sourceFreezable)
        {
            ShaderEffect effect = (ShaderEffect)sourceFreezable;

            base.CloneCurrentValueCore(sourceFreezable);
            CopyCommon(effect);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Implementation of <see cref="System.Windows.Freezable.GetCurrentValueAsFrozenCore(Freezable)">Freezable.GetCurrentValueAsFrozenCore</see>.
        /// </summary>
        /// <param name="sourceFreezable"></param>
        protected override void GetCurrentValueAsFrozenCore(Freezable sourceFreezable)
        {
            ShaderEffect effect = (ShaderEffect)sourceFreezable;

            base.GetCurrentValueAsFrozenCore(sourceFreezable);
            CopyCommon(effect);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Renders the Xray image on the CPU.
        /// </summary>
        /// <param name="bsource"></param>
        /// <param name="sourceObject"></param>
        /// <param name="viewObject"></param>
        /// <param name="xrayImageEffect"></param>
        /// <param name="trimatEffect"></param>
        /// <param name="effects"></param>
        /// <param name="displayWidth"></param>
        /// <param name="displayHeight"></param>
        /// <param name="adornerLayerManager"></param>
        /// <param name="displayAnnotations"></param>
        /// <param name="displayMeasurements"></param>
        /// <returns>The newly rendered bitmap.</returns>
        public static BitmapSource GetRenderedXrayImage(BitmapSource bsource,
                                                        SourceObject sourceObject,
                                                        ViewObject viewObject,
                                                        ShaderEffect xrayOrTrimateImageEffect,
                                                        List<Effect> effects,
                                                        double displayWidth,
                                                        double displayHeight,
                                                        AdornerLayerManager adornerLayerManager,
                                                        bool displayAnnotations,
                                                        bool displayMeasurements)
        {
            if (xrayOrTrimateImageEffect != null && xrayOrTrimateImageEffect.GetType() == typeof(XrayImageEffect))
            {
                RenderXrayImage_XRayImageEffect(ref bsource, (XrayImageEffect)xrayOrTrimateImageEffect, sourceObject);
            }
            //else if (xrayOrTrimateImageEffect.GetType() == typeof(TrimatEffect))
            //{
            //    RenderXrayImage_TrimatEffect(ref bsource, (TrimatEffect)xrayOrTrimateImageEffect, sourceObject, viewObject);
            //}
            foreach (Effect effect in effects)
            {
                ApplyEffectToBitmap(ref bsource, effect);
            }
            if (displayAnnotations)
            {
                RenderAnnotations(ref bsource, displayWidth, displayHeight, adornerLayerManager);
            }
            if (displayMeasurements)
            {
                RenderMeasurements(ref bsource, displayWidth, displayHeight, adornerLayerManager);
            }

            return bsource;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Construct a PropertyChangedCallback which, when invoked, will result in the DP being
 /// associated with the specified shader constant register index.
 /// </summary>
 protected static PropertyChangedCallback PixelShaderConstantCallback(int floatRegisterIndex)
 {
     return
         ((obj, args) =>
     {
         ShaderEffect eff = obj as ShaderEffect;
         if (eff != null)
         {
             eff.UpdateShaderConstant(args.Property, args.NewValue, floatRegisterIndex);
         }
     });
 }
Ejemplo n.º 5
0
        //------------------------------------------------------
        //
        //  Public Properties
        //
        //------------------------------------------------------

        private static void PixelShaderPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ShaderEffect target = ((ShaderEffect)d);


            target.PixelShaderPropertyChangedHook(e);



            // The first change to the default value of a mutable collection property (e.g. GeometryGroup.Children)
            // will promote the property value from a default value to a local value. This is technically a sub-property
            // change because the collection was changed and not a new collection set (GeometryGroup.Children.
            // Add versus GeometryGroup.Children = myNewChildrenCollection). However, we never marshalled
            // the default value to the compositor. If the property changes from a default value, the new local value
            // needs to be marshalled to the compositor. We detect this scenario with the second condition
            // e.OldValueSource != e.NewValueSource. Specifically in this scenario the OldValueSource will be
            // Default and the NewValueSource will be Local.
            if (e.IsASubPropertyChange &&
                (e.OldValueSource == e.NewValueSource))
            {
                return;
            }



            PixelShader oldV = (PixelShader)e.OldValue;
            PixelShader newV = (PixelShader)e.NewValue;

            System.Windows.Threading.Dispatcher dispatcher = target.Dispatcher;

            if (dispatcher != null)
            {
                DUCE.IResource targetResource = (DUCE.IResource)target;
                using (CompositionEngineLock.Acquire())
                {
                    int channelCount = targetResource.GetChannelCount();

                    for (int channelIndex = 0; channelIndex < channelCount; channelIndex++)
                    {
                        DUCE.Channel channel = targetResource.GetChannel(channelIndex);
                        Debug.Assert(!channel.IsOutOfBandChannel);
                        Debug.Assert(!targetResource.GetHandle(channel).IsNull);
                        target.ReleaseResource(oldV, channel);
                        target.AddRefResource(newV, channel);
                    }
                }
            }

            target.PropertyChanged(PixelShaderProperty);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Construct a PropertyChangedCallback which, when invoked, will result
 /// in the DP being associated with the specified shader sampler
 /// register index. Expected to be called on a Brush-valued
 /// DependencyProperty.
 /// </summary>
 protected static PropertyChangedCallback PixelShaderSamplerCallback(int samplerRegisterIndex, SamplingMode samplingMode)
 {
     return
         ((obj, args) =>
     {
         ShaderEffect eff = obj as ShaderEffect;
         if (eff != null)
         {
             if (args.IsAValueChange)
             {
                 eff.UpdateShaderSampler(args.Property, args.NewValue, samplerRegisterIndex, samplingMode);
             }
         }
     });
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Clones values that do not have corresponding DPs.
 /// </summary>
 /// <param name="transform"></param>
 private void CopyCommon(ShaderEffect effect)
 {
     _topPadding    = effect._topPadding;
     _bottomPadding = effect._bottomPadding;
     _leftPadding   = effect._leftPadding;
     _rightPadding  = effect._rightPadding;
     if (_floatRegisters != null)
     {
         _floatRegisters = new List <MilColorF?>(effect._floatRegisters);
     }
     if (_samplerData != null)
     {
         _samplerData = new List <SamplerData?>(effect._samplerData);
     }
     _floatCount              = effect._floatCount;
     _samplerCount            = effect._samplerCount;
     _ddxUvDdyUvRegisterIndex = effect._ddxUvDdyUvRegisterIndex;
 }
        public string GetEffectName(ShaderEffect shaderEffect)
        {
            string effectName = "no effect";
            if (shaderEffect != null)
            {
                var descriptionAttribute = (DescriptionAttribute)Attribute.GetCustomAttribute(shaderEffect.GetType(), typeof(DescriptionAttribute));
                if (descriptionAttribute == null)
                {
                    effectName = shaderEffect.GetType().Name;
                }
                else
                {
                    effectName = descriptionAttribute.Description;
                }
            }

            return effectName;
        }
Ejemplo n.º 9
0
 public void Draw(Texture2D texture, Vector2 position, DoubleRectangle? sourceRectangle, ShaderEffect shaderEffect, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth)
 {
     DrawCommand cmd = GetRenderer().GetAvailableCommand();
     cmd.CommandType = DrawCommand.DrawCommandType.Texture;
     cmd.Texture = texture;
     cmd.Position = position;
     cmd.ShaderEffect = shaderEffect;
     cmd.Rotation = rotation;
     cmd.Origin = origin;
     if (sourceRectangle != null)
     {
         cmd.SourceRectangle = sourceRectangle.Value;
     }
     else
     {
         cmd.SourceRectangle = DoubleRectangle.FromRectangle(texture.SourceRect);
     }
     cmd.Scale = scale;
     cmd.Effects = effects;
     cmd.LayerDepth = layerDepth;
 }
Ejemplo n.º 10
0
 protected virtual void Draw(Texture2D texture, Vector2 position, ref DoubleRectangle sourceRectangle, ShaderEffect shaderEffect, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth)
 {
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Shows screen saver by creating one instance of ScreenSaverWindow for each monitor.
        /// 
        /// Note: uses WinForms's Screen class to get monitor info.
        /// </summary>
        internal void ShowScreensaver()
        {
            System.Windows.Point scale = Interop.GetVisualScale();
            Debug.WriteLine(scale);

            fx = new GrayscaleEffect
            {
                Chrominance = App.Config.Chrominance,
                Negative = App.Config.Negative,
                LeaveBlack = App.Config.LeaveBlack
            };

            //System.Windows.Forms.Screen primary = System.Windows.Forms.Screen.PrimaryScreen;

            //set volume and stretch method
            this.VideoElement             = new MediaElement();
            VideoElement.UnloadedBehavior = MediaState.Manual;
            VideoElement.Source           = App.Config.Video;
            VideoElement.IsMuted          = false;
            VideoElement.Volume           = App.Config.Volume;
            VideoElement.Stretch          = App.Config.Stretch;
            VideoElement.MediaEnded  += new RoutedEventHandler(VideoElement_MediaEnded);
            VideoElement.MediaOpened += new RoutedEventHandler(VideoElement_MediaOpened);

            //creates window on every screens
            foreach (System.Windows.Forms.Screen screen in System.Windows.Forms.Screen.AllScreens)
            {
                ScreenSaverWindow window     = new ScreenSaverWindow(new VisualBrush(VideoElement));
                window.WindowStartupLocation = WindowStartupLocation.Manual;

                //covers entire monitor
                Debug.WriteLine(screen.Bounds);
                window.Left              = screen.Bounds.Left / scale.X;
                window.Top               = screen.Bounds.Top / scale.Y;
                window.Width             = (screen.Bounds.Right  - screen.Bounds.Left) / scale.X;
                window.Height            = (screen.Bounds.Bottom - screen.Bounds.Top)  / scale.Y;
                window.VideoBlock.Width  = window.Width;
                window.VideoBlock.Height = window.Height;
                window.Show();
            }

            VideoElement.Play();
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Shows screen saver preview by creating one instance of ScreenSaverWindow.
        /// 
        /// Note: uses WinForms's Screen class to get monitor info.
        /// </summary>
        internal void ShowPreview(String arg)
        {
            System.Windows.Point scale = Interop.GetVisualScale();
            Debug.WriteLine(scale);

            fx = new GrayscaleEffect
            {
                Chrominance = App.Config.Chrominance,
                Negative = App.Config.Negative,
                LeaveBlack = App.Config.LeaveBlack
            };

            //set volume and stretch method
            this.VideoElement             = new MediaElement();
            VideoElement.UnloadedBehavior = MediaState.Manual;
            VideoElement.Source           = App.Config.Video;
            VideoElement.IsMuted          = false;
            VideoElement.Volume           = App.Config.Volume;
            VideoElement.Stretch          = App.Config.Stretch;
            VideoElement.MediaEnded  += new RoutedEventHandler(VideoElement_MediaEnded);
            VideoElement.MediaOpened += new RoutedEventHandler(VideoElement_MediaOpened);

            Int32  previewHandle = Convert.ToInt32(arg);
            IntPtr pPreviewHnd   = new IntPtr(previewHandle);
            RECT lpRect          = new RECT();
            bool bGetRect        = GetClientRect(pPreviewHnd, ref lpRect);

            this.winSaver = new ScreenSaverWindow(new VisualBrush(VideoElement));
            HwndSourceParameters sourceParams = new HwndSourceParameters("sourceParams");

            //set window properties
            sourceParams.Height = lpRect.Bottom - lpRect.Top;
            sourceParams.Width = lpRect.Right - lpRect.Left;
            sourceParams.ParentWindow = pPreviewHnd;
            sourceParams.WindowStyle = (int)(0x10000000 | 0x40000000 | 0x02000000);

            //set up preview
            winWPFContent = new HwndSource(sourceParams);
            winWPFContent.Disposed += new EventHandler(winWPFContent_Disposed);
            winWPFContent.RootVisual   = winSaver.grid1;
            winSaver.Width             = (lpRect.Right  - lpRect.Left) / scale.X;
            winSaver.Height            = (lpRect.Bottom - lpRect.Top)  / scale.Y;
            winSaver.VideoBlock.Width  = (lpRect.Right  - lpRect.Left) / scale.X;
            winSaver.VideoBlock.Height = (lpRect.Right  - lpRect.Left) / scale.X;

            //set a background
            //Note: Uses an arbitrary screen size to determine when to do this
            if (winSaver.Width <= 320 && winSaver.Height <= 240)
            {
                winSaver.DesktopBackground.Source = new BitmapImage(new Uri(Interop.GetDesktopWallpaper(), UriKind.Absolute));
                winSaver.DesktopBackground.Stretch = Interop.GetWallpaperStretch();
            }

            winSaver.isPreview = true;
            winSaver.Show();
            VideoElement.Play();
        }
		private void LoadEffect(ShaderEffect shaderEffect)
		{
			imageViewbox.Effect = shaderEffect;
			DisplayMessage(_effectManager.GetEffectName(shaderEffect));
			UpdateInformation();
		}