--- /dev/null
+// --------------------------------------------------------------------------------------------------------------------\r
+// <copyright file="GrayscaleImage.cs" company="HandBrake Project (http://handbrake.fr)">\r
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.\r
+// </copyright>\r
+// <summary>\r
+// Extend the Image Class to support a grayscale mode.\r
+// Usage: local:AutoGreyableImage Source="Image.png"\r
+// </summary>\r
+// --------------------------------------------------------------------------------------------------------------------\r
+\r
+namespace HandBrakeWPF.Helpers\r
+{\r
+ using System;\r
+ using System.Windows;\r
+ using System.Windows.Controls;\r
+ using System.Windows.Media;\r
+ using System.Windows.Media.Imaging;\r
+\r
+ /// <summary>\r
+ /// Extend the Image Class to support a grayscale mode.\r
+ /// </summary>\r
+ public class GrayscaleImage : Image\r
+ {\r
+ /// <summary>\r
+ /// Initializes static members of the <see cref="GrayscaleImage"/> class. \r
+ /// Usage: local:AutoGreyableImage Source="Image.png"\r
+ /// </summary>\r
+ static GrayscaleImage()\r
+ {\r
+ // Override the metadata of the IsEnabled property.\r
+ IsEnabledProperty.OverrideMetadata(typeof(GrayscaleImage), new FrameworkPropertyMetadata(true, IsEnabledPropertyChanged));\r
+ }\r
+\r
+ /// <summary>\r
+ /// The is enabled property changed.\r
+ /// When this changes, grayscale the image when false, leave with colour when true.\r
+ /// </summary>\r
+ /// <param name="source">\r
+ /// The source.\r
+ /// </param>\r
+ /// <param name="args">\r
+ /// The args.\r
+ /// </param>\r
+ private static void IsEnabledPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs args)\r
+ {\r
+ var sourceImage = source as GrayscaleImage;\r
+ if (sourceImage != null)\r
+ {\r
+ if (!Convert.ToBoolean(args.NewValue))\r
+ {\r
+ var bitmapImage = new BitmapImage(new Uri(sourceImage.Source.ToString()));\r
+ sourceImage.Source = new FormatConvertedBitmap(bitmapImage, PixelFormats.Gray32Float, null, 0);\r
+ sourceImage.OpacityMask = new ImageBrush(bitmapImage);\r
+ }\r
+ else\r
+ {\r
+ sourceImage.Source = ((FormatConvertedBitmap)sourceImage.Source).Source;\r
+ sourceImage.OpacityMask = null;\r
+ }\r
+ }\r
+ }\r
+ }\r
+}\r
\r
set\r
{\r
- this.Task.DisplayWidth = value;\r
- this.CustomAnamorphicAdjust();\r
- this.NotifyOfPropertyChange(() => this.DisplayWidth);\r
+ if (!object.Equals(this.Task.DisplayWidth, value))\r
+ {\r
+ this.Task.DisplayWidth = value;\r
+ this.CustomAnamorphicAdjust();\r
+ this.NotifyOfPropertyChange(() => this.DisplayWidth);\r
+ }\r
}\r
}\r
\r
\r
set\r
{\r
- this.Task.Height = value;\r
- this.HeightAdjust();\r
- this.NotifyOfPropertyChange(() => this.Height);\r
+ if (!object.Equals(this.Task.Height, value))\r
+ {\r
+ this.Task.Height = value;\r
+ this.HeightAdjust();\r
+ this.NotifyOfPropertyChange(() => this.Height);\r
+ }\r
}\r
}\r
\r
\r
set\r
{\r
- this.Task.PixelAspectY = value;\r
- this.CustomAnamorphicAdjust();\r
- this.NotifyOfPropertyChange(() => this.ParHeight);\r
+ if (!object.Equals(this.Task.PixelAspectY, value))\r
+ {\r
+ this.Task.PixelAspectY = value;\r
+ this.CustomAnamorphicAdjust();\r
+ this.NotifyOfPropertyChange(() => this.ParHeight);\r
+ }\r
}\r
}\r
\r
\r
set\r
{\r
- this.Task.PixelAspectX = value;\r
- this.CustomAnamorphicAdjust();\r
- this.NotifyOfPropertyChange(() => this.ParWidth);\r
+ if (!object.Equals(this.Task.PixelAspectX, value))\r
+ {\r
+ this.Task.PixelAspectX = value;\r
+ this.CustomAnamorphicAdjust();\r
+ this.NotifyOfPropertyChange(() => this.ParWidth);\r
+ }\r
}\r
}\r
\r
\r
set\r
{\r
- this.Task.Width = value;\r
- this.WidthAdjust();\r
- this.NotifyOfPropertyChange(() => this.Width);\r
+ if (!object.Equals(this.Task.Width, value))\r
+ {\r
+ this.Task.Width = value;\r
+ this.WidthAdjust();\r
+ this.NotifyOfPropertyChange(() => this.Width);\r
+ }\r
}\r
}\r
\r
this.NotifyOfPropertyChange(() => this.Height);\r
this.NotifyOfPropertyChange(() => this.SelectedAnamorphicMode);\r
this.NotifyOfPropertyChange(() => this.SelectedModulus);\r
- this.NotifyOfPropertyChange(() => this.DisplayWidth);\r
- this.NotifyOfPropertyChange(() => this.ParHeight);\r
- this.NotifyOfPropertyChange(() => this.ParWidth);\r
}\r
\r
/// <summary>\r
\r
this.Width = 0;\r
this.Height = 0;\r
- this.NotifyOfPropertyChange(() => this.Width);\r
- this.NotifyOfPropertyChange(() => this.Height);\r
this.SetDisplaySize();\r
break;\r
\r
this.HeightControlEnabled = false;\r
this.ShowCustomAnamorphicControls = false;\r
this.ShowModulus = true;\r
-\r
this.Width = this.sourceResolution.Width;\r
this.Height = 0;\r
- this.NotifyOfPropertyChange(() => this.Width);\r
- this.NotifyOfPropertyChange(() => this.Height);\r
+\r
this.SetDisplaySize();\r
break;\r
\r
this.MaintainAspectRatio = true;\r
this.ShowModulus = true;\r
\r
+ // Ignore any of the users current settings and reset to source to make things easier.\r
this.Width = this.sourceResolution.Width;\r
- this.NotifyOfPropertyChange(() => this.Width);\r
- this.NotifyOfPropertyChange(() => this.Height);\r
+ this.Height = this.sourceResolution.Height - this.CropTop - this.CropBottom;\r
\r
- this.DisplayWidth = this.CalculateAnamorphicSizes().Width;\r
+ // Set the Display Width and set the Par X/Y to the source values initially. \r
this.ParWidth = this.sourceParValues.Width;\r
this.ParHeight = this.sourceParValues.Height;\r
- this.NotifyOfPropertyChange(() => this.ParHeight);\r
- this.NotifyOfPropertyChange(() => this.ParWidth);\r
- this.NotifyOfPropertyChange(() => this.DisplayWidth);\r
+ if (this.ParHeight != 0)\r
+ {\r
+ this.DisplayWidth = (this.Width * this.ParWidth / this.ParHeight);\r
+ }\r
\r
this.SetDisplaySize();\r
break;\r
return new Size((int)disWidthLoose, (int)calcHeight);\r
\r
case Anamorphic.Custom:\r
-\r
// Get the User Interface Values\r
double uIdisplayWidth;\r
double.TryParse(this.DisplayWidth.ToString(CultureInfo.InvariantCulture), out uIdisplayWidth);\r