PageRenderTime 55ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/Win7oob/Projects/TheOliver.Controls.Effects/ShaderEffects/ChromaKeyAlphaEffect.cs

#
C# | 119 lines | 65 code | 17 blank | 37 comment | 2 complexity | fdd270ef5186a5fa6ede8f5a27d75b41 MD5 | raw file
  1. // <copyright file="ChromaKeyAlphaEffect.cs" company="Microsoft Corporation">
  2. // Copyright (c) 2009 Microsoft Corporation All Rights Reserved
  3. // </copyright>
  4. // <author>Michael S. Scherotter</author>
  5. // <email>mischero@microsoft.com</email>
  6. // <date>2009-05-10</date>
  7. // <summary>Color Key Alpha Pixel Effect for Silverlight 3</summary>
  8. namespace TheOliver.Controls.ShaderEffects
  9. {
  10. using System.ComponentModel;
  11. using System.Windows;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Effects;
  14. using TheOliver.Controls;
  15. /// <summary>
  16. /// Color Key alpha effect for Silverlight 3
  17. /// </summary>
  18. [Description("Chroma Key Alpha effect with tolerance")]
  19. public class ChromaKeyAlphaEffect : ShaderEffect
  20. {
  21. #region Fields
  22. /// <summary>
  23. /// This property is mapped to the InputColor variable within the pixel shader.
  24. /// </summary>
  25. public static readonly DependencyProperty ColorKeyProperty = DependencyProperty.Register("ColorKey", typeof(Color), typeof(ChromaKeyAlphaEffect), new PropertyMetadata(Colors.Green, PixelShaderConstantCallback(0)));
  26. /// <summary>
  27. /// This is the tolerance 0=exact 1=full
  28. /// </summary>
  29. public static readonly DependencyProperty ToleranceProperty = DependencyProperty.Register("Tolerance", typeof(double), typeof(ChromaKeyAlphaEffect), new PropertyMetadata(0.1, PixelShaderConstantCallback(1)));
  30. /// <summary>
  31. /// The explict input for this pixel shader.
  32. /// </summary>
  33. public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(ChromaKeyAlphaEffect), 0);
  34. /// <summary>
  35. /// A reference to the pixel shader used.
  36. /// </summary>
  37. private static PixelShader pixelShader;
  38. #endregion
  39. #region Constructors
  40. /// <summary>
  41. /// Initializes static members of the ChromaKeyAlphaEffect class.
  42. /// </summary>
  43. static ChromaKeyAlphaEffect()
  44. {
  45. pixelShader = new PixelShader();
  46. pixelShader.UriSource = Global.MakePackUri("ShaderSource/ChromaKeyAlpha.fx.ps");
  47. }
  48. /// <summary>
  49. /// Initializes a new instance of the ChromaKeyAlphaEffect class.
  50. /// </summary>
  51. public ChromaKeyAlphaEffect()
  52. {
  53. this.PixelShader = pixelShader;
  54. UpdateShaderValue(ColorKeyProperty);
  55. UpdateShaderValue(ToleranceProperty);
  56. UpdateShaderValue(InputProperty);
  57. }
  58. #endregion
  59. #region Properties
  60. /// <summary>
  61. /// Gets or sets the InputColor variable within the shader.
  62. /// </summary>
  63. public Color ColorKey
  64. {
  65. get
  66. {
  67. return (Color)GetValue(ColorKeyProperty);
  68. }
  69. set
  70. {
  71. SetValue(ColorKeyProperty, value);
  72. }
  73. }
  74. /// <summary>
  75. /// Gets or sets the exactness by which the color must match (0=exact, 1=all colors)
  76. /// </summary>
  77. public double Tolerance
  78. {
  79. get
  80. {
  81. return (double)GetValue(ToleranceProperty);
  82. }
  83. set
  84. {
  85. if (value >= 0.0 && value <= 1.0)
  86. {
  87. SetValue(ToleranceProperty, value);
  88. }
  89. }
  90. }
  91. /// <summary>
  92. /// Gets or sets the Input of shader.
  93. /// </summary>
  94. [Description("Gets or sets the input of the shader")]
  95. public Brush Input
  96. {
  97. get { return (Brush)GetValue(InputProperty); }
  98. set { SetValue(InputProperty, value); }
  99. }
  100. #endregion
  101. }
  102. }