diff options
-rw-r--r-- | win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 2 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Helpers/PictureSize.cs | 373 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs | 309 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Views/PictureSettingsView.xaml | 3 |
4 files changed, 161 insertions, 526 deletions
diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index ce90d914a..cb4f87a9b 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -159,6 +159,8 @@ <Compile Include="Helpers\GrayscaleImage.cs" />
<Compile Include="Helpers\GrowlCommunicator.cs" />
<Compile Include="Helpers\AppStyleHelper.cs" />
+ <Compile Include="Helpers\Macros.cs" />
+ <Compile Include="Helpers\PictureSize.cs" />
<Compile Include="Model\OptionsTab.cs" />
<Compile Include="Model\SelectionTitle.cs" />
<Compile Include="Services\EncodeServiceWrapper.cs" />
diff --git a/win/CS/HandBrakeWPF/Helpers/PictureSize.cs b/win/CS/HandBrakeWPF/Helpers/PictureSize.cs index d4cbd2ecf..8adfa909e 100644 --- a/win/CS/HandBrakeWPF/Helpers/PictureSize.cs +++ b/win/CS/HandBrakeWPF/Helpers/PictureSize.cs @@ -136,7 +136,7 @@ namespace HandBrakeWPF.Helpers /// <summary>
/// Gets or sets the output height.
/// </summary>
- public double OutputHeight { get; set; }
+ public int OutputHeight { get; set; }
/// <summary>
/// Gets or sets the output par width.
@@ -150,250 +150,6 @@ namespace HandBrakeWPF.Helpers }
/// <summary>
- /// Calculates job width and height for anamorphic content,
- /// * @param output_width Pointer to returned storage width
- /// * @param output_height Pointer to returned storage height
- /// * @param output_par_width Pointer to returned pixel width
- /// * @param output_par_height Pointer to returned pixel height
- /// </summary>
- /// <param name="job">
- /// The job.
- /// </param>
- /// <param name="title">
- /// The title.
- /// </param>
- /// <param name="output_width">
- /// The output_width.
- /// </param>
- /// <param name="output_height">
- /// The output_height.
- /// </param>
- /// <param name="output_par_width">
- /// The output_par_width.
- /// </param>
- /// <param name="output_par_height">
- /// The output_par_height.
- /// </param>
- public static void hb_set_anamorphic_size(PictureSettingsJob job, PictureSettingsTitle title,
- out int output_width, out int output_height,
- out int output_par_width, out int output_par_height)
- {
- /* Initialise the Output Width / Height */
- output_width = 0;
- output_height = 0;
-
- /* Set up some variables to make the math easier to follow. */
- int cropped_width = title.Width - job.Crop.Left - job.Crop.Right;
- int cropped_height = title.Height - job.Crop.Top - job.Crop.Bottom;
- double storage_aspect = cropped_width / (double)cropped_height;
- int mod = job.Modulus.HasValue ? job.Modulus.Value : 16;
- double aspect = title.Aspect;
-
- long pixel_aspect_width = job.ParW;
- long pixel_aspect_height = job.ParH;
-
- /* If a source was really NTSC or PAL and the user specified ITU PAR - values, replace the standard PAR values with the ITU broadcast ones. */
- if (title.Width == 720 && job.ItuPar)
- {
- // convert aspect to a scaled integer so we can test for 16:9 & 4:3
- // aspect ratios ignoring insignificant differences in the LSBs of
- // the floating point representation.
- int iaspect = (int)Math.Round(aspect * 9.0, 0); // int iaspect = aspect * 9.; TODO CHECK THIS
-
- /* Handle ITU PARs */
- if (title.Height == 480)
- {
- /* It's NTSC */
- if (iaspect == 16)
- {
- /* It's widescreen */
- pixel_aspect_width = 40;
- pixel_aspect_height = 33;
- }
- else if (iaspect == 12)
- {
- /* It's 4:3 */
- pixel_aspect_width = 10;
- pixel_aspect_height = 11;
- }
- }
- else if (title.Height == 576)
- {
- /* It's PAL */
- if (iaspect == 16)
- {
- /* It's widescreen */
- pixel_aspect_width = 16;
- pixel_aspect_height = 11;
- }
- else if (iaspect == 12)
- {
- /* It's 4:3 */
- pixel_aspect_width = 12;
- pixel_aspect_height = 11;
- }
- }
- }
-
- /* Figure out what width the source would display at. */
- int source_display_width = (int)(cropped_width * (double)pixel_aspect_width / (double)pixel_aspect_height); // TODO Check casting
-
- /* - 3 different ways of deciding output dimensions: - - 1: Strict anamorphic, preserve source dimensions - - 2: Loose anamorphic, round to mod16 and preserve storage aspect ratio - - 3: Power user anamorphic, specify everything - */
- int width, height;
- int maxWidth, maxHeight;
-
- maxWidth = Macros.MultipleModDown(job.MaxWidth, mod);
- maxHeight = Macros.MultipleModDown(job.MaxHeight, mod);
-
- switch (job.AnamorphicMode)
- {
- case Anamorphic.Strict:
- /* Strict anamorphic */
- output_width = Macros.MultipleMod(cropped_width, 2);
- output_height = Macros.MultipleMod(cropped_height, 2);
- // adjust the source PAR for new width/height
- // new PAR = source PAR * ( old width / new_width ) * ( new_height / old_height )
- pixel_aspect_width = (long)title.ParW * cropped_width * (output_height);
- pixel_aspect_height = (long)title.ParH * (output_width) * cropped_height;
- break;
-
- case Anamorphic.Loose:
- /* "Loose" anamorphic. - - Uses mod16-compliant dimensions, - - Allows users to set the width - */
- width = job.Width;
- // height: Gets set later, ignore user job->height value
-
- /* Gotta handle bounding dimensions. - If the width is too big, just reset it with no rescaling. - Instead of using the aspect-scaled job height, - we need to see if the job width divided by the storage aspect - is bigger than the max. If so, set it to the max (this is sloppy). - If not, set job height to job width divided by storage aspect. - */
-
- /* Time to get picture width that divide cleanly.*/
- width = Macros.MultipleMod(width, mod);
-
- if (maxWidth != 0 && (maxWidth < job.Width))
- width = maxWidth;
-
- /* Verify these new dimensions don't violate max height and width settings */
- height = (int)Math.Round(((double)width / storage_aspect) + 0.5, 0); // TODO Check Casting and rounding
-
- /* Time to get picture height that divide cleanly.*/
- height = Macros.MultipleMod(height, mod);
-
- if (maxHeight != 0 && (maxHeight < height))
- {
- height = maxHeight;
- width = (int)Math.Round(((double)height * storage_aspect) + 0.5, 0); // TODO Check asting and arounding.
- width = Macros.MultipleMod(width, mod);
- }
-
- /* The film AR is the source's display width / cropped source height. - The output display width is the output height * film AR. - The output PAR is the output display width / output storage width. */
- pixel_aspect_width = (long)height * cropped_width * pixel_aspect_width;
- pixel_aspect_height = (long)width * cropped_height * pixel_aspect_height;
-
- /* Pass the results back to the caller */
- output_width = width;
- output_height = height;
- break;
-
- case Anamorphic.Custom:
- /* Anamorphic 3: Power User Jamboree - - Set everything based on specified values */
-
- /* Use specified storage dimensions */
- storage_aspect = job.Width / (double)job.Height;
- width = job.Width;
- height = job.Height;
-
- /* Time to get picture dimensions that divide cleanly.*/
- width = Macros.MultipleMod(width, mod);
- height = Macros.MultipleMod(height, mod);
-
- /* Bind to max dimensions */
- if (maxWidth != 0 && width > maxWidth)
- {
- width = maxWidth;
- // If we are keeping the display aspect, then we are going
- // to be modifying the PAR anyway. So it's preferred
- // to let the width/height stray some from the original
- // requested storage aspect.
- //
- // But otherwise, PAR and DAR will change the least
- // if we stay as close as possible to the requested
- // storage aspect.
- if (!job.KeepDisplayAspect)
- {
- height = (int)Math.Round(((double)width / storage_aspect) + 0.5, 0); // TODO Check rounding and casting
- height = Macros.MultipleMod(height, mod);
- }
- }
- if (maxHeight != 0 && height > maxHeight)
- {
- height = maxHeight;
- // Ditto, see comment above
- if (!job.KeepDisplayAspect)
- {
- width = (int)Math.Round(((double)height * storage_aspect) + 0.5, 0); // TODO check Rounding and casting
- width = Macros.MultipleMod(width, mod);
- }
- }
-
- /* That finishes the storage dimensions. On to display. */
- if (job.DarWidth != 0 && job.DarHeight != 0)
- {
- /* We need to adjust the PAR to produce this aspect. */
- pixel_aspect_width = (long)height * job.DarWidth / job.DarHeight;
- pixel_aspect_height = width;
- }
- else
- {
- /* If we're doing ana 3 and not specifying a DAR, care needs to be taken. - This indicates a PAR is potentially being set by the interface. But - this is an output PAR, to correct a source, and it should not be assumed - that it properly creates a display aspect ratio when applied to the source, - which could easily be stored in a different resolution. */
- if (job.KeepDisplayAspect)
- {
- /* We can ignore the possibility of a PAR change */
- pixel_aspect_width = (int)Math.Round((long)height * ((double)source_display_width / (double)cropped_height), 0); // TODO Check rounding and casting
- pixel_aspect_height = width;
- }
- else
- {
- int output_display_width = (int)Math.Round(width * (double)pixel_aspect_width / (double)pixel_aspect_height, 0); // TODO Check rounding and casting.
- pixel_aspect_width = output_display_width;
- pixel_aspect_height = width;
- }
- }
-
- /* Back to caller */
- output_width = width;
- output_height = height;
- break;
- }
-
- /* While x264 is smart enough to reduce fractions on its own, libavcodec - * needs some help with the math, so lose superfluous factors. */
- hb_limit_rational64(out pixel_aspect_width, out pixel_aspect_height,
- pixel_aspect_width, pixel_aspect_height, 65535);
- hb_reduce(out output_par_width, out output_par_height,
- (int)pixel_aspect_width, (int)pixel_aspect_height);
- }
-
- /// <summary>
/// The hb_set_anamorphic_size_native.
/// </summary>
/// <param name="job">
@@ -405,7 +161,7 @@ namespace HandBrakeWPF.Helpers /// <returns>
/// The <see cref="AnamorphicResult"/> object.
/// </returns>
- public static AnamorphicResult hb_set_anamorphic_size_native(PictureSettingsJob job, PictureSettingsTitle title)
+ public static AnamorphicResult hb_set_anamorphic_size(PictureSettingsJob job, PictureSettingsTitle title)
{
int outputHeight = 0;
int outputParHeight = 0;
@@ -453,130 +209,5 @@ namespace HandBrakeWPF.Helpers return new AnamorphicResult { OutputWidth = outputWidth, OutputHeight = outputHeight, OutputParWidth = outputParWidth, OutputParHeight = outputParHeight };
}
-
- /// <summary>
- /// The hb_limit_rational 64.
- /// </summary>
- /// <param name="x">
- /// The x.
- /// </param>
- /// <param name="y">
- /// The y.
- /// </param>
- /// <param name="num">
- /// The num.
- /// </param>
- /// <param name="den">
- /// The den.
- /// </param>
- /// <param name="limit">
- /// The limit.
- /// </param>
- private static void hb_limit_rational64(out long x, out long y, long num, long den, long limit)
- {
- hb_reduce64(out num, out den, num, den);
- if (num < limit && den < limit)
- {
- x = num;
- y = den;
- return;
- }
-
- if (num > den)
- {
- double div = (double)limit / num;
- num = limit;
- den *= (int)Math.Round(div, 0); // TODO Check cast and rounding.
- }
- else
- {
- double div = (double)limit / den;
- den = limit;
- num *= (int)Math.Round(div, 0); // TODO Check cast and rounding.
- }
-
- x = num;
- y = den;
- }
-
- /// <summary>
- /// Given a numerator (num) and a denominator (den), reduce them to an
- /// equivalent fraction and store the result in x and y.
- /// </summary>
- /// <param name="x">
- /// The x.
- /// </param>
- /// <param name="y">
- /// The y.
- /// </param>
- /// <param name="num">
- /// The num.
- /// </param>
- /// <param name="den">
- /// The den.
- /// </param>
- private static void hb_reduce64(out long x, out long y, long num, long den)
- {
- // 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>
- /// Given a numerator (num) and a denominator (den), reduce them to an
- /// equivalent fraction and store the result in x and y.
- /// </summary>
- /// <param name="x">
- /// The x.
- /// </param>
- /// <param name="y">
- /// The y.
- /// </param>
- /// <param name="num">
- /// The num.
- /// </param>
- /// <param name="den">
- /// The den.
- /// </param>
- private static void hb_reduce(out int x, out int y, int num, int den)
- {
- // find the greatest common divisor of num & den by Euclid's algorithm
- int n = num, d = den;
- while (d != 0)
- {
- int 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)
- {
- x = num / n;
- y = den / n;
- }
- else
- {
- x = num;
- y = den;
- }
- }
}
}
diff --git a/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs index 87d0bb0c9..a91dc4d3d 100644 --- a/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs @@ -11,7 +11,6 @@ namespace HandBrakeWPF.ViewModels {
using System;
using System.Collections.Generic;
- using System.Drawing;
using System.Globalization;
using Caliburn.Micro;
@@ -19,10 +18,14 @@ namespace HandBrakeWPF.ViewModels using HandBrake.ApplicationServices.Model;
using HandBrake.ApplicationServices.Parsing;
using HandBrake.ApplicationServices.Services.Interfaces;
+ using HandBrake.Interop.Model;
using HandBrake.Interop.Model.Encoding;
+ using HandBrakeWPF.Helpers;
using HandBrakeWPF.ViewModels.Interfaces;
+ using Size = System.Drawing.Size;
+
/// <summary>
/// The Picture Settings View Model
/// </summary>
@@ -151,6 +154,7 @@ namespace HandBrakeWPF.ViewModels {
this.Task.Cropping.Bottom = value;
this.NotifyOfPropertyChange(() => this.CropBottom);
+ this.CropAdjust();
this.SetDisplaySize();
}
}
@@ -169,6 +173,7 @@ namespace HandBrakeWPF.ViewModels {
this.Task.Cropping.Left = value;
this.NotifyOfPropertyChange(() => this.CropLeft);
+ this.CropAdjust();
this.SetDisplaySize();
}
}
@@ -187,6 +192,7 @@ namespace HandBrakeWPF.ViewModels {
this.Task.Cropping.Right = value;
this.NotifyOfPropertyChange(() => this.CropRight);
+ this.CropAdjust();
this.SetDisplaySize();
}
}
@@ -205,6 +211,7 @@ namespace HandBrakeWPF.ViewModels {
this.Task.Cropping.Top = value;
this.NotifyOfPropertyChange(() => this.CropTop);
+ this.CropAdjust();
this.SetDisplaySize();
}
}
@@ -387,9 +394,12 @@ namespace HandBrakeWPF.ViewModels set
{
- this.Task.Anamorphic = value;
- this.AnamorphicAdjust();
- this.NotifyOfPropertyChange(() => this.SelectedAnamorphicMode);
+ if (!object.Equals(this.SelectedAnamorphicMode, value))
+ {
+ this.Task.Anamorphic = value;
+ this.AnamorphicAdjust();
+ this.NotifyOfPropertyChange(() => this.SelectedAnamorphicMode);
+ }
}
}
@@ -709,6 +719,24 @@ namespace HandBrakeWPF.ViewModels this.sourceParValues = title.ParVal;
this.sourceResolution = title.Resolution;
+ // Update the cropping values, preffering those in the presets.
+ if (!preset.Task.HasCropping)
+ {
+ this.CropTop = title.AutoCropDimensions.Top;
+ this.CropBottom = title.AutoCropDimensions.Bottom;
+ this.CropLeft = title.AutoCropDimensions.Left;
+ this.CropRight = title.AutoCropDimensions.Right;
+ this.IsCustomCrop = false;
+ }
+ else
+ {
+ this.CropLeft = preset.Task.Cropping.Left;
+ this.CropRight = preset.Task.Cropping.Right;
+ this.CropTop = preset.Task.Cropping.Top;
+ this.CropBottom = preset.Task.Cropping.Bottom;
+ this.IsCustomCrop = true;
+ }
+
if (preset.PictureSettingsMode == PresetPictureSettingsMode.None)
{
// We have no instructions, so simply set it to the source.
@@ -737,7 +765,15 @@ namespace HandBrakeWPF.ViewModels }
// Set the Width, and Maintain Aspect ratio. That should calc the Height for us.
- this.Width = preset.Task.Width ?? this.MaxWidth; // Note: This will be auto-corrected in the property if it's too large.
+ if (this.SelectedAnamorphicMode == Anamorphic.None)
+ {
+ this.Width = preset.Task.Width ?? (this.MaxWidth - this.CropLeft - this.CropRight);
+ // Note: This will be auto-corrected in the property if it's too large.
+ }
+ else
+ {
+ this.Width = preset.Task.Width ?? this.MaxWidth;
+ }
// If our height is too large, let it downscale the width for us by setting the height to the lower value.
if (!this.MaintainAspectRatio && this.Height > this.MaxHeight)
@@ -751,30 +787,14 @@ namespace HandBrakeWPF.ViewModels }
}
- // Update the cropping values, preffering those in the presets.
- if (!preset.Task.HasCropping)
- {
- this.CropTop = title.AutoCropDimensions.Top;
- this.CropBottom = title.AutoCropDimensions.Bottom;
- this.CropLeft = title.AutoCropDimensions.Left;
- this.CropRight = title.AutoCropDimensions.Right;
- this.IsCustomCrop = false;
- }
- else
- {
- this.CropLeft = preset.Task.Cropping.Left;
- this.CropRight = preset.Task.Cropping.Right;
- this.CropTop = preset.Task.Cropping.Top;
- this.CropBottom = preset.Task.Cropping.Bottom;
- this.IsCustomCrop = true;
- }
-
// Set Screen Controls
this.SourceInfo = string.Format(
- "{0}x{1}, Aspect Ratio: {2:0.00}",
+ "{0}x{1}, Aspect Ratio: {2:0.00}, PAR: {3}/{4}",
title.Resolution.Width,
title.Resolution.Height,
- title.AspectRatio);
+ title.AspectRatio,
+ title.ParVal.Width,
+ title.ParVal.Height);
}
this.NotifyOfPropertyChange(() => this.Task);
@@ -787,17 +807,33 @@ namespace HandBrakeWPF.ViewModels #region Methods
/// <summary>
- /// Adjust other values after the user has altered the anamorphic.
+ /// The crop adjust.
/// </summary>
- private void AnamorphicAdjust()
+ private void CropAdjust()
{
- this.DisplaySize = this.sourceResolution.IsEmpty
+ PictureSize.AnamorphicResult result = PictureSize.hb_set_anamorphic_size(this.GetPictureSettings(), this.GetPictureTitleInfo());
+ switch (this.SelectedAnamorphicMode)
+ {
+ case Anamorphic.None:
+ //this.Width = result.OutputWidth;
+ //this.Height = result.OutputHeight;
+ break;
+ case Anamorphic.Strict:
+ case Anamorphic.Loose:
+ case Anamorphic.Custom:
+ double dispWidth = Math.Round((result.OutputWidth * result.OutputParWidth / result.OutputParHeight), 0);
+ this.DisplaySize = this.sourceResolution.IsEmpty
? "No Title Selected"
- : string.Format(
- "{0}x{1}",
- this.CalculateAnamorphicSizes().Width,
- this.CalculateAnamorphicSizes().Height);
+ : string.Format("Storage: {0}x{1}, Display: {2}x{3}", result.OutputWidth, result.OutputHeight, dispWidth, result.OutputHeight);
+ break;
+ }
+ }
+ /// <summary>
+ /// Adjust other values after the user has altered the anamorphic.
+ /// </summary>
+ private void AnamorphicAdjust()
+ {
this.ShowDisplaySize = true;
this.ShowKeepAR = true;
switch (this.SelectedAnamorphicMode)
@@ -807,7 +843,7 @@ namespace HandBrakeWPF.ViewModels this.HeightControlEnabled = true;
this.ShowCustomAnamorphicControls = false;
this.ShowModulus = true;
- this.ShowDisplaySize = false;
+ this.ShowDisplaySize = true;
this.ShowKeepAR = true;
this.SelectedModulus = 16; // Reset
if (this.Width == 0)
@@ -820,6 +856,8 @@ namespace HandBrakeWPF.ViewModels this.Height = this.GetModulusValue(this.sourceResolution.Height - this.CropTop - this.CropBottom);
}
+ this.MaintainAspectRatio = true;
+
this.SetDisplaySize();
break;
case Anamorphic.Strict:
@@ -830,6 +868,8 @@ namespace HandBrakeWPF.ViewModels this.SelectedModulus = 16; // Reset
this.ShowKeepAR = false;
+
+
this.Width = 0;
this.Height = 0;
this.SetDisplaySize();
@@ -840,11 +880,10 @@ namespace HandBrakeWPF.ViewModels this.HeightControlEnabled = false;
this.ShowCustomAnamorphicControls = false;
this.ShowModulus = true;
- if (this.Width == 0)
- {
- this.Width = this.sourceResolution.Width;
- }
- this.Height = 0;
+
+ // Reset to the source size.
+ this.Width = this.sourceResolution.Width;
+ this.Height = 0; //this.sourceResolution.Height - this.CropTop - this.CropBottom;
this.ShowKeepAR = false;
this.SetDisplaySize();
@@ -877,120 +916,20 @@ namespace HandBrakeWPF.ViewModels }
/// <summary>
- /// Calculate the Anamorphic Resolution for the selected title.
- /// </summary>
- /// <returns>
- /// A Size With Width/Height for this title.
- /// </returns>
- private Size CalculateAnamorphicSizes()
- {
- if (this.sourceResolution.IsEmpty)
- {
- return new Size(0, 0);
- }
-
- /* Set up some variables to make the math easier to follow. */
- int croppedWidth = this.sourceResolution.Width - this.CropLeft - this.CropRight;
- int croppedHeight = this.sourceResolution.Height - this.CropTop - this.CropBottom;
- double storageAspect = (double)croppedWidth / croppedHeight;
-
- /* Figure out what width the source would display at. */
- double sourceDisplayWidth = (double)croppedWidth * this.sourceParValues.Width / this.sourceParValues.Height;
-
- /*
- 3 different ways of deciding output dimensions:
- - 1: Strict anamorphic, preserve source dimensions
- - 2: Loose anamorphic, round to mod16 and preserve storage aspect ratio
- - 3: Power user anamorphic, specify everything
- */
- double calcHeight;
- switch (this.SelectedAnamorphicMode)
- {
- default:
- case Anamorphic.Strict:
-
- /* Strict anamorphic */
- double dispWidth = ((double)croppedWidth * this.sourceParValues.Width / this.sourceParValues.Height);
- dispWidth = Math.Round(dispWidth, 0);
- Size output = new Size((int)dispWidth, croppedHeight);
- return output;
-
- case Anamorphic.Loose:
-
- /* "Loose" anamorphic.
- - Uses mod16-compliant dimensions,
- - Allows users to set the width
- */
- double calcWidth = this.GetModulusValue(this.Width);
- calcHeight = (calcWidth / storageAspect) + 0.5;
- calcHeight = this.GetModulusValue(calcHeight); /* Time to get picture height that divide cleanly.*/
-
- /* The film AR is the source's display width / cropped source height.
- The output display width is the output height * film AR.
- The output PAR is the output display width / output storage width. */
- double pixelAspectWidth = calcHeight * sourceDisplayWidth / croppedHeight;
- double pixelAspectHeight = calcWidth;
-
- double disWidthLoose = (calcWidth * pixelAspectWidth / pixelAspectHeight);
- if (double.IsNaN(disWidthLoose))
- {
- disWidthLoose = 0;
- }
-
- return new Size((int)disWidthLoose, (int)calcHeight);
-
- case Anamorphic.Custom:
- // Get the User Interface Values
- double uIdisplayWidth;
- double.TryParse(this.DisplayWidth.ToString(CultureInfo.InvariantCulture), NumberStyles.Any, CultureInfo.InvariantCulture, out uIdisplayWidth);
-
- /* Anamorphic 3: Power User Jamboree - Set everything based on specified values */
- calcHeight = this.GetModulusValue(this.Height);
-
- if (this.MaintainAspectRatio)
- {
- return new Size((int)Math.Truncate(uIdisplayWidth), (int)calcHeight);
- }
-
- return new Size((int)Math.Truncate(uIdisplayWidth), (int)calcHeight);
- }
- }
-
- /// <summary>
- /// Correct the new value so that the result of the modulus of that value is 0
- /// </summary>
- /// <param name="oldValue">
- /// The old value.
- /// </param>
- /// <param name="newValue">
- /// The new value.
- /// </param>
- /// <returns>
- /// The Value corrected so that for a given modulus the result is 0
- /// </returns>
- private int CorrectForModulus(int oldValue, int newValue)
- {
- int remainder = newValue % 2;
- if (remainder == 0)
- {
- return newValue;
- }
-
- return newValue > oldValue ? newValue + remainder : newValue - remainder;
- }
-
- /// <summary>
/// Adjust other values after the user has altered one of the custom anamorphic settings
/// </summary>
private void CustomAnamorphicAdjust()
{
- if (this.MaintainAspectRatio && this.DisplayWidth != 0)
+ if (this.SelectedAnamorphicMode == Anamorphic.Custom)
{
- this.ParWidth = this.DisplayWidth;
- this.ParHeight = this.Width;
- }
+ if (this.MaintainAspectRatio && this.DisplayWidth != 0)
+ {
+ this.ParWidth = this.DisplayWidth;
+ this.ParHeight = this.Width;
+ }
- this.SetDisplaySize();
+ this.SetDisplaySize();
+ }
}
/// <summary>
@@ -1075,12 +1014,24 @@ namespace HandBrakeWPF.ViewModels /// </summary>
private void SetDisplaySize()
{
- this.DisplaySize = this.sourceResolution.IsEmpty
- ? "No Title Selected"
- : string.Format(
- "{0}x{1}",
- this.CalculateAnamorphicSizes().Width,
- this.CalculateAnamorphicSizes().Height);
+ /*
+ * Handle Anamorphic Display
+ */
+ if (this.SelectedAnamorphicMode != Anamorphic.None)
+ {
+ PictureSize.AnamorphicResult result = PictureSize.hb_set_anamorphic_size(this.GetPictureSettings(), this.GetPictureTitleInfo());
+ double dispWidth = Math.Round((result.OutputWidth * result.OutputParWidth / result.OutputParHeight), 0);
+
+ this.DisplaySize = this.sourceResolution.IsEmpty
+ ? "No Title Selected"
+ : string.Format("Output: {0}x{1}, Anamorphic: {2}x{3}", result.OutputWidth, result.OutputHeight, dispWidth, result.OutputHeight);
+ }
+ else
+ {
+ this.DisplaySize = this.sourceResolution.IsEmpty
+ ? "No Title Selected"
+ : string.Format("Output: {0}x{1}, Anamorphic: {2}x{3}", this.Width, this.Height, this.Width, this.Height);
+ }
}
/// <summary>
@@ -1159,6 +1110,60 @@ namespace HandBrakeWPF.ViewModels return max.HasValue ? (value > max.Value ? max.Value : value) : value;
}
+ /// <summary>
+ /// The get picture title info.
+ /// </summary>
+ /// <returns>
+ /// The <see cref="PictureSize.PictureSettingsTitle"/>.
+ /// </returns>
+ private PictureSize.PictureSettingsTitle GetPictureTitleInfo()
+ {
+ PictureSize.PictureSettingsTitle title = new PictureSize.PictureSettingsTitle
+ {
+ Width = this.sourceResolution.Width,
+ Height = this.sourceResolution.Height,
+ ParW = this.sourceParValues.Width,
+ ParH = this.sourceParValues.Height,
+ Aspect = 0 // TODO
+ };
+
+ return title;
+ }
+
+ /// <summary>
+ /// The get picture settings.
+ /// </summary>
+ /// <returns>
+ /// The <see cref="PictureSize.PictureSettingsJob"/>.
+ /// </returns>
+ private PictureSize.PictureSettingsJob GetPictureSettings()
+ {
+ PictureSize.PictureSettingsJob job = new PictureSize.PictureSettingsJob
+ {
+ Width = this.Width,
+ Height = this.Height,
+ ItuPar = false,
+ Modulus = this.SelectedModulus,
+ ParW = this.ParWidth,
+ ParH = this.ParHeight,
+ MaxWidth = this.MaxWidth,
+ MaxHeight = this.MaxHeight,
+ KeepDisplayAspect = this.MaintainAspectRatio,
+ AnamorphicMode = this.SelectedAnamorphicMode,
+ DarWidth = 0,
+ DarHeight = 0,
+ Crop = new Cropping(this.CropTop, this.CropBottom, this.CropLeft, this.CropRight),
+ };
+
+ if (this.SelectedAnamorphicMode == Anamorphic.Loose)
+ {
+ job.ParW = sourceParValues.Width;
+ job.ParH = sourceParValues.Height;
+ }
+
+ return job;
+ }
+
#endregion
}
}
\ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Views/PictureSettingsView.xaml b/win/CS/HandBrakeWPF/Views/PictureSettingsView.xaml index c9aa0d69b..7701b7272 100644 --- a/win/CS/HandBrakeWPF/Views/PictureSettingsView.xaml +++ b/win/CS/HandBrakeWPF/Views/PictureSettingsView.xaml @@ -93,11 +93,8 @@ <Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
- <ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
- <Label Content="Display Size:" Grid.Row="0" Grid.Column="0"
- Visibility="{Binding ShowDisplaySize, Converter={StaticResource boolToVisConverter}}" />
<Label Content="{Binding DisplaySize}" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" Margin="0,0,0,5"
Visibility="{Binding ShowDisplaySize, Converter={StaticResource boolToVisConverter}}" />
|