]> granicus.if.org Git - handbrake/commitdiff
WinGui: Don't enable the Display Width control for Custom Anamorphic when KeepAR...
authorsr55 <sr55.hb@outlook.com>
Tue, 4 Jul 2017 21:08:26 +0000 (22:08 +0100)
committersr55 <sr55.hb@outlook.com>
Tue, 4 Jul 2017 21:08:44 +0000 (22:08 +0100)
win/CS/HandBrake.ApplicationServices/Interop/HandBrakeUtils.cs
win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs
win/CS/HandBrakeWPF/Views/PictureSettingsView.xaml

index 1acb411b028a64f2764ce58310fa30a3f7aeafeb..b8fb24778a4f8980e8e8c00e3f7e34fa3722a37d 100644 (file)
@@ -304,6 +304,29 @@ namespace HandBrake.ApplicationServices.Interop
             return JsonConvert.DeserializeObject<Geometry>(result);\r
         }\r
 \r
+        public static void Reduce(long den, long num, out long x, out long y)\r
+        {\r
+            // find the greatest common divisor of num & den by Euclid's algorithm\r
+            long n = num, d = den;\r
+            while (d > 0)\r
+            {\r
+                long t = d;\r
+                d = n % d;\r
+                n = t;\r
+            }\r
+\r
+            // at this point n is the gcd. if it's non-zero remove it from num\r
+            // and den. Otherwise just return the original values.\r
+            if (n > 0)\r
+            {\r
+                num /= n;\r
+                den /= n;\r
+            }\r
+\r
+            x = num;\r
+            y = den;\r
+        }\r
+\r
         /// <summary>\r
         /// Sends the message logged event to any registered listeners.\r
         /// </summary>\r
index 42cbf094329bd26e0e678daa08b187f08106318f..f4afb51095a0572d354ae432d452c9fd02e7b8a0 100644 (file)
@@ -13,6 +13,7 @@ namespace HandBrakeWPF.ViewModels
     using System.Collections.Generic;\r
     using System.Globalization;\r
 \r
+    using HandBrake.ApplicationServices.Interop;\r
     using HandBrake.ApplicationServices.Interop.Model;\r
     using HandBrake.ApplicationServices.Interop.Model.Encoding;\r
 \r
@@ -428,7 +429,7 @@ namespace HandBrakeWPF.ViewModels
         /// <summary>\r
         /// Gets or sets DisplayWidth.\r
         /// </summary>\r
-        public int DisplayWidth\r
+        public long DisplayWidth\r
         {\r
             get\r
             {\r
@@ -866,7 +867,7 @@ namespace HandBrakeWPF.ViewModels
         /// <returns>\r
         /// The <see cref="PictureSize.PictureSettingsJob"/>.\r
         /// </returns>\r
-        private PictureSize.PictureSettingsJob GetPictureSettings()\r
+        private PictureSize.PictureSettingsJob GetPictureSettings(ChangedPictureField changedField)\r
         {\r
             PictureSize.PictureSettingsJob job = new PictureSize.PictureSettingsJob\r
             {\r
@@ -883,16 +884,23 @@ namespace HandBrakeWPF.ViewModels
                 Crop = new Cropping(this.CropTop, this.CropBottom, this.CropLeft, this.CropRight),\r
             };\r
 \r
-            if (this.SelectedAnamorphicMode == Anamorphic.Loose)\r
+            if (this.SelectedAnamorphicMode == Anamorphic.Custom)\r
             {\r
-                job.ParW = sourceParValues.Width;\r
-                job.ParH = sourceParValues.Height;\r
+                if (changedField == ChangedPictureField.DisplayWidth)\r
+                {\r
+                    var displayWidth = this.DisplayWidth;\r
+                    job.ParW = (int)displayWidth;  // num\r
+                    job.ParH = job.Width; // den\r
+                }\r
             }\r
 \r
-            if (SelectedAnamorphicMode == Anamorphic.Custom)\r
+            // Reduce the Par W/H if we can. Don't do it while the user is altering the PAR controls through as it will mess with the result.\r
+            if (changedField != ChangedPictureField.ParH && changedField != ChangedPictureField.ParW)\r
             {\r
-                job.ParW = this.DisplayWidth;  // num\r
-                job.ParH = this.Width; // den\r
+                long x, y;\r
+                HandBrakeUtils.Reduce(job.ParW, job.ParH, out x, out y);\r
+                job.ParW = (int)y;\r
+                job.ParH = (int)x;\r
             }\r
 \r
             return job;\r
@@ -939,23 +947,22 @@ namespace HandBrakeWPF.ViewModels
             }\r
 \r
             // Step 2, For the changed field, call hb_set_anamorphic_size and process the results.\r
-            PictureSize.AnamorphicResult result = PictureSize.hb_set_anamorphic_size2(this.GetPictureSettings(), this.GetPictureTitleInfo(), setting);\r
+            PictureSize.AnamorphicResult result = PictureSize.hb_set_anamorphic_size2(this.GetPictureSettings(changedField), this.GetPictureTitleInfo(), setting);\r
+            double dispWidth = Math.Round((result.OutputWidth * result.OutputParWidth / result.OutputParHeight), 0);\r
+\r
             this.Task.Width = result.OutputWidth;\r
             this.Task.Height = result.OutputHeight;\r
+            long x, y;\r
+            HandBrakeUtils.Reduce((int)Math.Round(result.OutputParWidth, 0), (int)Math.Round(result.OutputParHeight, 0), out x, out y);\r
             this.Task.PixelAspectX = (int)Math.Round(result.OutputParWidth, 0);\r
             this.Task.PixelAspectY = (int)Math.Round(result.OutputParHeight, 0);\r
+            this.Task.DisplayWidth = dispWidth;\r
 \r
             // Step 3, Set the display width label to indicate the output.\r
-            double dispWidth = Math.Round((result.OutputWidth * result.OutputParWidth / result.OutputParHeight), 0);\r
             this.DisplaySize = this.sourceResolution == null || this.sourceResolution.IsEmpty\r
                            ? string.Empty\r
                            : string.Format(Resources.PictureSettingsViewModel_StorageDisplayLabel, dispWidth, result.OutputHeight, this.ParWidth, this.ParHeight);\r
 \r
-            if (changedField != ChangedPictureField.DisplayWidth)\r
-            {\r
-                this.Task.DisplayWidth = (int)dispWidth;\r
-            }\r
-\r
             // Step 4, Force an update on all the UI elements.\r
             this.NotifyOfPropertyChange(() => this.Width);\r
             this.NotifyOfPropertyChange(() => this.Height);\r
index c6e19a89b5a61a1bf5ea7d5ac5df5b712d2b7b85..83540d253cfbd13b076db4f105295d1da43c452a 100644 (file)
@@ -93,7 +93,7 @@
                     <Label Content="{x:Static Properties:ResourcesUI.PictureSettingsView_PAR}" Grid.Row="1" Grid.Column="0" />\r
 \r
                     <controls:NumberBox Width="60" Number="{Binding DisplayWidth, Mode=TwoWay}" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" Margin="0,0,0,5" \r
-                                    AllowEmpty="False" />\r
+                                    AllowEmpty="False" IsEnabled="{Binding MaintainAspectRatio, Converter={StaticResource boolConverter}, ConverterParameter=true}" />\r
                     <StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="1">\r
                         <controls:NumberBox Width="60" Number="{Binding ParWidth, Mode=TwoWay}" HorizontalAlignment="Left" AllowEmpty="False"\r
                                                  IsEnabled="{Binding MaintainAspectRatio, Converter={StaticResource boolConverter}, ConverterParameter=true}" Margin="0,0,0,5"\r