// --------------------------------------------------------------------------------------------------------------------
//
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
//
//
// Defines the PictureSize type.
//
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrakeWPF.Helpers
{
using Caliburn.Micro;
using HandBrake.Interop.Interop.HbLib;
using HandBrake.Interop.Interop.HbLib.Wrappers.Interfaces;
using HandBrake.Interop.Interop.Model;
using HandBrake.Interop.Interop.Model.Encoding;
using HandBrake.Interop.Interop.Providers.Interfaces;
using HandBrakeWPF.Services.Interfaces;
///
/// The picture size Helpers
///
public class PictureSize
{
///
/// The picture settings job.
///
public class PictureSettingsJob
{
///
/// Gets or sets the crop.
///
public Cropping Crop { get; set; }
///
/// Gets or sets the modulus.
///
public int? Modulus { get; set; }
///
/// Gets or sets the par w.
///
public int ParW { get; set; }
///
/// Gets or sets the par h.
///
public int ParH { get; set; }
///
/// Gets or sets a value indicating whether itu par.
///
public bool ItuPar { get; set; }
///
/// Gets or sets the width.
///
public int Width { get; set; }
///
/// Gets or sets the height.
///
public int Height { get; set; }
///
/// Gets or sets the anamorphic mode.
///
public Anamorphic AnamorphicMode { get; set; }
///
/// Gets or sets the max width.
///
public int MaxWidth { get; set; }
///
/// Gets or sets the max height.
///
public int MaxHeight { get; set; }
///
/// Gets or sets a value indicating whether keep display aspect.
///
public bool KeepDisplayAspect { get; set; }
///
/// Gets or sets the dar width.
///
public int DarWidth { get; set; }
///
/// Gets or sets the dar height.
///
public int DarHeight { get; set; }
}
///
/// The picture settings title.
///
public class PictureSettingsTitle
{
///
/// Gets or sets the width.
///
public int Width { get; set; }
///
/// Gets or sets the height.
///
public int Height { get; set; }
///
/// Gets or sets the par w.
///
public int ParW { get; set; }
///
/// Gets or sets the par h.
///
public int ParH { get; set; }
///
/// Gets or sets the aspect.
///
public double Aspect { get; set; }
}
///
/// The anamorphic result.
///
public class AnamorphicResult
{
///
/// Gets or sets the output width.
///
public int OutputWidth { get; set; }
///
/// Gets or sets the output height.
///
public int OutputHeight { get; set; }
///
/// Gets or sets the output par width.
///
public double OutputParWidth { get; set; }
///
/// Gets or sets the output par height.
///
public double OutputParHeight { get; set; }
}
///
/// The keep setting.
///
public enum KeepSetting
{
HB_KEEP_WIDTH = 0x01,
HB_KEEP_HEIGHT = 0x02,
HB_KEEP_DISPLAY_ASPECT = 0x04
}
///
/// The hb_set_anamorphic_size 2.
///
///
/// The job.
///
///
/// The title.
///
///
/// The setting.
///
///
/// The .
///
public static AnamorphicResult hb_set_anamorphic_size2(PictureSettingsJob job, PictureSettingsTitle title, KeepSetting setting)
{
int settingMode = (int)setting + (job.KeepDisplayAspect ? 0x04 : 0);
hb_rational_t computed_par = new hb_rational_t();
switch (job.AnamorphicMode)
{
case Anamorphic.None:
computed_par = new hb_rational_t { den = 1, num = 1 };
break;
case Anamorphic.Custom:
computed_par = new hb_rational_t { den = job.ParH, num = job.ParW };
break;
default:
computed_par = new hb_rational_t { den = title.ParH, num = title.ParW };
break;
}
hb_geometry_settings_s uiGeometry = new hb_geometry_settings_s
{
crop = new[] { job.Crop.Top, job.Crop.Bottom, job.Crop.Left, job.Crop.Right },
itu_par = 0,
keep = settingMode,
maxWidth = job.MaxWidth,
maxHeight = job.MaxHeight,
mode = (int)job.AnamorphicMode,
modulus = job.Modulus.HasValue ? job.Modulus.Value : 16,
geometry = new hb_geometry_s { height = job.Height, width = job.Width, par = computed_par }
};
hb_geometry_s sourceGeometry = new hb_geometry_s
{
width = title.Width,
height = title.Height,
par = new hb_rational_t { den = title.ParH, num = title.ParW }
};
hb_geometry_s result = new hb_geometry_s();
IHbFunctionsProvider provider = IoC.Get(); // TODO make this method non static and remove IoC call.
IHbFunctions hbFunctions = provider.GetHbFunctionsWrapper();
hbFunctions.hb_set_anamorphic_size2(ref sourceGeometry, ref uiGeometry, ref result);
int outputWidth = result.width;
int outputHeight = result.height;
int outputParWidth = result.par.num;
int outputParHeight = result.par.den;
return new AnamorphicResult { OutputWidth = outputWidth, OutputHeight = outputHeight, OutputParWidth = outputParWidth, OutputParHeight = outputParHeight };
}
}
}