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