// -------------------------------------------------------------------------------------------------------------------- // // 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 System; using System.Runtime.InteropServices; using HandBrake.Interop.HbLib; using HandBrake.Interop.Model; using HandBrake.Interop.Model.Encoding; /// /// 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 hb_set_anamorphic_size_native. /// /// /// The job. /// /// /// The title. /// /// /// The object. /// public static AnamorphicResult hb_set_anamorphic_size(PictureSettingsJob job, PictureSettingsTitle title) { int outputHeight = 0; int outputParHeight = 0; int outputParWidth = 0; int outputWidth = 0; hb_job_s nativeJob = new hb_job_s { modulus = job.Modulus.HasValue ? job.Modulus.Value : 16, anamorphic = new hb_anamorphic_substruct { par_width = job.ParW, par_height = job.ParH, itu_par = 0, mode = (int)job.AnamorphicMode, dar_width = 0, dar_height = 0, keep_display_aspect = job.KeepDisplayAspect ? 1 : 0 }, maxWidth = title.Width, maxHeight = title.Height, keep_ratio = job.KeepDisplayAspect ? 1 : 0, width = job.Width, height = job.Height, crop = new[] { job.Crop.Top, job.Crop.Bottom, job.Crop.Left, job.Crop.Right } }; hb_title_s title_s = new hb_title_s { crop = new[] { job.Crop.Top, job.Crop.Bottom, job.Crop.Left, job.Crop.Right }, width = title.Width, height = title.Height, pixel_aspect_width = title.ParW, pixel_aspect_height = title.ParH, aspect = 0 }; IntPtr pointer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(hb_title_s))); Marshal.StructureToPtr(title_s, pointer, false); nativeJob.title = pointer; HBFunctions.hb_set_anamorphic_size( ref nativeJob, ref outputWidth, ref outputHeight, ref outputParWidth, ref outputParHeight); return new AnamorphicResult { OutputWidth = outputWidth, OutputHeight = outputHeight, OutputParWidth = outputParWidth, OutputParHeight = outputParHeight }; } } }