From f5108ef3ae828197e68cb2f03f37ef90679f02c5 Mon Sep 17 00:00:00 2001 From: sr55 Date: Tue, 14 Jul 2009 23:11:09 +0000 Subject: WinGui: - Updates Picture Settings code. A mix/match of old/new/libhb code. - Custom anamorphic mode widgets are not hooked up yet, but if the user sets them manually, they will work just fine. - Some of the logic has been simplified so that it works better however it's not bullet proof in terms of allowing users to misbehave. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@2692 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- win/C#/Controls/PictureSettings.Designer.cs | 563 +++++++++++++++------------ win/C#/Controls/PictureSettings.cs | 575 ++++++++++++---------------- win/C#/Functions/PresetLoader.cs | 13 +- win/C#/Functions/QueryGenerator.cs | 12 +- win/C#/frmMain.Designer.cs | 11 - win/C#/frmMain.cs | 6 +- 6 files changed, 584 insertions(+), 596 deletions(-) diff --git a/win/C#/Controls/PictureSettings.Designer.cs b/win/C#/Controls/PictureSettings.Designer.cs index 9036eb5c2..51dd32c32 100644 --- a/win/C#/Controls/PictureSettings.Designer.cs +++ b/win/C#/Controls/PictureSettings.Designer.cs @@ -28,28 +28,28 @@ namespace Handbrake.Controls /// private void InitializeComponent() { - this.check_customCrop = new System.Windows.Forms.RadioButton(); - this.check_autoCrop = new System.Windows.Forms.RadioButton(); - this.crop_bottom = new System.Windows.Forms.NumericUpDown(); - this.crop_top = new System.Windows.Forms.NumericUpDown(); + this.tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel(); + this.Label15 = new System.Windows.Forms.Label(); this.crop_left = new System.Windows.Forms.NumericUpDown(); this.crop_right = new System.Windows.Forms.NumericUpDown(); - this.label8 = new System.Windows.Forms.Label(); + this.check_autoCrop = new System.Windows.Forms.RadioButton(); + this.Label51 = new System.Windows.Forms.Label(); + this.crop_top = new System.Windows.Forms.NumericUpDown(); this.Label53 = new System.Windows.Forms.Label(); this.Label52 = new System.Windows.Forms.Label(); - this.Label51 = new System.Windows.Forms.Label(); - this.Label15 = new System.Windows.Forms.Label(); - this.check_KeepAR = new System.Windows.Forms.CheckBox(); - this.text_height = new System.Windows.Forms.NumericUpDown(); - this.text_width = new System.Windows.Forms.NumericUpDown(); - this.label4 = new System.Windows.Forms.Label(); - this.lbl_max = new System.Windows.Forms.Label(); - this.lbl_src_res = new System.Windows.Forms.Label(); + this.crop_bottom = new System.Windows.Forms.NumericUpDown(); + this.check_customCrop = new System.Windows.Forms.RadioButton(); + this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); this.label7 = new System.Windows.Forms.Label(); - this.label26 = new System.Windows.Forms.Label(); - this.lbl_Aspect = new System.Windows.Forms.Label(); + this.lbl_src_res = new System.Windows.Forms.Label(); this.Label91 = new System.Windows.Forms.Label(); + this.lbl_Aspect = new System.Windows.Forms.Label(); this.Label55 = new System.Windows.Forms.Label(); + this.text_width = new System.Windows.Forms.NumericUpDown(); + this.lbl_max = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.text_height = new System.Windows.Forms.NumericUpDown(); + this.check_KeepAR = new System.Windows.Forms.CheckBox(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.updownParHeight = new System.Windows.Forms.NumericUpDown(); this.label6 = new System.Windows.Forms.Label(); @@ -63,80 +63,66 @@ namespace Handbrake.Controls this.lbl_modulus = new System.Windows.Forms.Label(); this.lbl_displayWidth = new System.Windows.Forms.Label(); this.drp_modulus = new System.Windows.Forms.ComboBox(); - ((System.ComponentModel.ISupportInitialize)(this.crop_bottom)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.crop_top)).BeginInit(); + this.label8 = new System.Windows.Forms.Label(); + this.label26 = new System.Windows.Forms.Label(); + this.tableLayoutPanel3.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.crop_left)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.crop_right)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.text_height)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.crop_top)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.crop_bottom)).BeginInit(); + this.tableLayoutPanel2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.text_width)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.text_height)).BeginInit(); this.tableLayoutPanel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.updownParHeight)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.updownParWidth)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.updownDisplayWidth)).BeginInit(); this.SuspendLayout(); // - // check_customCrop - // - this.check_customCrop.AutoSize = true; - this.check_customCrop.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.check_customCrop.Location = new System.Drawing.Point(399, 57); - this.check_customCrop.Name = "check_customCrop"; - this.check_customCrop.Size = new System.Drawing.Size(65, 17); - this.check_customCrop.TabIndex = 106; - this.check_customCrop.Text = "Custom:"; - this.check_customCrop.UseVisualStyleBackColor = true; - // - // check_autoCrop - // - this.check_autoCrop.AutoSize = true; - this.check_autoCrop.Checked = true; - this.check_autoCrop.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.check_autoCrop.Location = new System.Drawing.Point(399, 33); - this.check_autoCrop.Name = "check_autoCrop"; - this.check_autoCrop.Size = new System.Drawing.Size(73, 17); - this.check_autoCrop.TabIndex = 105; - this.check_autoCrop.TabStop = true; - this.check_autoCrop.Text = "Automatic"; - this.check_autoCrop.UseVisualStyleBackColor = true; - this.check_autoCrop.CheckedChanged += new System.EventHandler(this.check_autoCrop_CheckedChanged); - // - // crop_bottom - // - this.crop_bottom.Enabled = false; - this.crop_bottom.Increment = new decimal(new int[] { - 2, - 0, - 0, - 0}); - this.crop_bottom.Location = new System.Drawing.Point(479, 146); - this.crop_bottom.Maximum = new decimal(new int[] { - 1080, - 0, - 0, - 0}); - this.crop_bottom.Name = "crop_bottom"; - this.crop_bottom.Size = new System.Drawing.Size(44, 21); - this.crop_bottom.TabIndex = 103; - this.crop_bottom.ValueChanged += new System.EventHandler(this.crop_ValueChanged); + // tableLayoutPanel3 + // + this.tableLayoutPanel3.AutoSize = true; + this.tableLayoutPanel3.ColumnCount = 5; + this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.tableLayoutPanel3.Controls.Add(this.Label15, 0, 4); + this.tableLayoutPanel3.Controls.Add(this.crop_left, 1, 4); + this.tableLayoutPanel3.Controls.Add(this.crop_right, 3, 4); + this.tableLayoutPanel3.Controls.Add(this.check_autoCrop, 0, 0); + this.tableLayoutPanel3.Controls.Add(this.Label51, 4, 4); + this.tableLayoutPanel3.Controls.Add(this.crop_top, 2, 3); + this.tableLayoutPanel3.Controls.Add(this.Label53, 2, 6); + this.tableLayoutPanel3.Controls.Add(this.Label52, 2, 2); + this.tableLayoutPanel3.Controls.Add(this.crop_bottom, 2, 5); + this.tableLayoutPanel3.Controls.Add(this.check_customCrop, 0, 1); + this.tableLayoutPanel3.Location = new System.Drawing.Point(419, 35); + this.tableLayoutPanel3.Name = "tableLayoutPanel3"; + this.tableLayoutPanel3.RowCount = 7; + this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel3.Size = new System.Drawing.Size(217, 165); + this.tableLayoutPanel3.TabIndex = 117; // - // crop_top + // Label15 // - this.crop_top.Enabled = false; - this.crop_top.Increment = new decimal(new int[] { - 2, - 0, - 0, - 0}); - this.crop_top.Location = new System.Drawing.Point(479, 100); - this.crop_top.Maximum = new decimal(new int[] { - 1080, - 0, - 0, - 0}); - this.crop_top.Name = "crop_top"; - this.crop_top.Size = new System.Drawing.Size(44, 21); - this.crop_top.TabIndex = 100; - this.crop_top.ValueChanged += new System.EventHandler(this.crop_ValueChanged); + this.Label15.Anchor = System.Windows.Forms.AnchorStyles.Right; + this.Label15.AutoSize = true; + this.Label15.BackColor = System.Drawing.Color.Transparent; + this.Label15.ImeMode = System.Windows.Forms.ImeMode.NoControl; + this.Label15.Location = new System.Drawing.Point(0, 99); + this.Label15.Margin = new System.Windows.Forms.Padding(0, 3, 3, 3); + this.Label15.Name = "Label15"; + this.Label15.Size = new System.Drawing.Size(26, 13); + this.Label15.TabIndex = 97; + this.Label15.Text = "Left"; // // crop_left // @@ -146,7 +132,7 @@ namespace Handbrake.Controls 0, 0, 0}); - this.crop_left.Location = new System.Drawing.Point(428, 122); + this.crop_left.Location = new System.Drawing.Point(32, 95); this.crop_left.Maximum = new decimal(new int[] { 1920, 0, @@ -165,7 +151,7 @@ namespace Handbrake.Controls 0, 0, 0}); - this.crop_right.Location = new System.Drawing.Point(530, 122); + this.crop_right.Location = new System.Drawing.Point(132, 95); this.crop_right.Maximum = new decimal(new int[] { 1920, 0, @@ -176,24 +162,62 @@ namespace Handbrake.Controls this.crop_right.TabIndex = 101; this.crop_right.ValueChanged += new System.EventHandler(this.crop_ValueChanged); // - // label8 + // check_autoCrop // - this.label8.AutoSize = true; - this.label8.BackColor = System.Drawing.Color.Transparent; - this.label8.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label8.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.label8.Location = new System.Drawing.Point(396, 13); - this.label8.Name = "label8"; - this.label8.Size = new System.Drawing.Size(33, 13); - this.label8.TabIndex = 96; - this.label8.Text = "Crop"; + this.check_autoCrop.AutoSize = true; + this.check_autoCrop.Checked = true; + this.tableLayoutPanel3.SetColumnSpan(this.check_autoCrop, 5); + this.check_autoCrop.ImeMode = System.Windows.Forms.ImeMode.NoControl; + this.check_autoCrop.Location = new System.Drawing.Point(0, 3); + this.check_autoCrop.Margin = new System.Windows.Forms.Padding(0, 3, 3, 3); + this.check_autoCrop.Name = "check_autoCrop"; + this.check_autoCrop.Size = new System.Drawing.Size(73, 17); + this.check_autoCrop.TabIndex = 105; + this.check_autoCrop.TabStop = true; + this.check_autoCrop.Text = "Automatic"; + this.check_autoCrop.UseVisualStyleBackColor = true; + this.check_autoCrop.CheckedChanged += new System.EventHandler(this.check_autoCrop_CheckedChanged); + // + // Label51 + // + this.Label51.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.Label51.AutoSize = true; + this.Label51.BackColor = System.Drawing.Color.Transparent; + this.Label51.ImeMode = System.Windows.Forms.ImeMode.NoControl; + this.Label51.Location = new System.Drawing.Point(182, 99); + this.Label51.Margin = new System.Windows.Forms.Padding(3); + this.Label51.Name = "Label51"; + this.Label51.Size = new System.Drawing.Size(32, 13); + this.Label51.TabIndex = 102; + this.Label51.Text = "Right"; + // + // crop_top + // + this.crop_top.Enabled = false; + this.crop_top.Increment = new decimal(new int[] { + 2, + 0, + 0, + 0}); + this.crop_top.Location = new System.Drawing.Point(82, 68); + this.crop_top.Maximum = new decimal(new int[] { + 1080, + 0, + 0, + 0}); + this.crop_top.Name = "crop_top"; + this.crop_top.Size = new System.Drawing.Size(44, 21); + this.crop_top.TabIndex = 100; + this.crop_top.ValueChanged += new System.EventHandler(this.crop_ValueChanged); // // Label53 // + this.Label53.Anchor = System.Windows.Forms.AnchorStyles.Top; this.Label53.AutoSize = true; this.Label53.BackColor = System.Drawing.Color.Transparent; this.Label53.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.Label53.Location = new System.Drawing.Point(477, 170); + this.Label53.Location = new System.Drawing.Point(83, 149); + this.Label53.Margin = new System.Windows.Forms.Padding(3); this.Label53.Name = "Label53"; this.Label53.Size = new System.Drawing.Size(41, 13); this.Label53.TabIndex = 104; @@ -201,165 +225,210 @@ namespace Handbrake.Controls // // Label52 // + this.Label52.Anchor = System.Windows.Forms.AnchorStyles.Bottom; this.Label52.AutoSize = true; this.Label52.BackColor = System.Drawing.Color.Transparent; this.Label52.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.Label52.Location = new System.Drawing.Point(486, 85); + this.Label52.Location = new System.Drawing.Point(91, 49); + this.Label52.Margin = new System.Windows.Forms.Padding(3); this.Label52.Name = "Label52"; this.Label52.Size = new System.Drawing.Size(25, 13); this.Label52.TabIndex = 99; this.Label52.Text = "Top"; // - // Label51 - // - this.Label51.AutoSize = true; - this.Label51.BackColor = System.Drawing.Color.Transparent; - this.Label51.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.Label51.Location = new System.Drawing.Point(580, 124); - this.Label51.Name = "Label51"; - this.Label51.Size = new System.Drawing.Size(32, 13); - this.Label51.TabIndex = 102; - this.Label51.Text = "Right"; - // - // Label15 - // - this.Label15.AutoSize = true; - this.Label15.BackColor = System.Drawing.Color.Transparent; - this.Label15.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.Label15.Location = new System.Drawing.Point(396, 124); - this.Label15.Name = "Label15"; - this.Label15.Size = new System.Drawing.Size(26, 13); - this.Label15.TabIndex = 97; - this.Label15.Text = "Left"; - // - // check_KeepAR - // - this.check_KeepAR.AutoSize = true; - this.check_KeepAR.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.check_KeepAR.Location = new System.Drawing.Point(68, 85); - this.check_KeepAR.Name = "check_KeepAR"; - this.check_KeepAR.Size = new System.Drawing.Size(114, 17); - this.check_KeepAR.TabIndex = 95; - this.check_KeepAR.Text = "Keep Aspect Ratio"; - this.check_KeepAR.UseVisualStyleBackColor = true; - this.check_KeepAR.CheckedChanged += new System.EventHandler(this.check_KeepAR_CheckedChanged); - // - // text_height + // crop_bottom // - this.text_height.Location = new System.Drawing.Point(206, 59); - this.text_height.Maximum = new decimal(new int[] { - 2560, + this.crop_bottom.Enabled = false; + this.crop_bottom.Increment = new decimal(new int[] { + 2, 0, 0, 0}); - this.text_height.Name = "text_height"; - this.text_height.Size = new System.Drawing.Size(64, 21); - this.text_height.TabIndex = 86; - this.text_height.ValueChanged += new System.EventHandler(this.text_height_ValueChanged); - // - // text_width - // - this.text_width.Location = new System.Drawing.Point(68, 59); - this.text_width.Maximum = new decimal(new int[] { - 2560, + this.crop_bottom.Location = new System.Drawing.Point(82, 122); + this.crop_bottom.Maximum = new decimal(new int[] { + 1080, 0, 0, 0}); - this.text_width.Name = "text_width"; - this.text_width.Size = new System.Drawing.Size(64, 21); - this.text_width.TabIndex = 85; - this.text_width.ValueChanged += new System.EventHandler(this.text_width_ValueChanged); - // - // label4 - // - this.label4.AutoSize = true; - this.label4.BackColor = System.Drawing.Color.Transparent; - this.label4.ForeColor = System.Drawing.Color.Black; - this.label4.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.label4.Location = new System.Drawing.Point(152, 63); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(42, 13); - this.label4.TabIndex = 84; - this.label4.Text = "Height:"; - // - // lbl_max + this.crop_bottom.Name = "crop_bottom"; + this.crop_bottom.Size = new System.Drawing.Size(44, 21); + this.crop_bottom.TabIndex = 103; + this.crop_bottom.ValueChanged += new System.EventHandler(this.crop_ValueChanged); // - this.lbl_max.AutoSize = true; - this.lbl_max.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.lbl_max.Location = new System.Drawing.Point(279, 61); - this.lbl_max.Name = "lbl_max"; - this.lbl_max.Size = new System.Drawing.Size(37, 13); - this.lbl_max.TabIndex = 83; - this.lbl_max.Text = "{max}"; + // check_customCrop // - // lbl_src_res + this.check_customCrop.AutoSize = true; + this.tableLayoutPanel3.SetColumnSpan(this.check_customCrop, 5); + this.check_customCrop.ImeMode = System.Windows.Forms.ImeMode.NoControl; + this.check_customCrop.Location = new System.Drawing.Point(0, 26); + this.check_customCrop.Margin = new System.Windows.Forms.Padding(0, 3, 3, 3); + this.check_customCrop.Name = "check_customCrop"; + this.check_customCrop.Size = new System.Drawing.Size(61, 17); + this.check_customCrop.TabIndex = 106; + this.check_customCrop.Text = "Custom"; + this.check_customCrop.UseVisualStyleBackColor = true; // - this.lbl_src_res.AutoSize = true; - this.lbl_src_res.BackColor = System.Drawing.Color.Transparent; - this.lbl_src_res.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.lbl_src_res.Location = new System.Drawing.Point(66, 36); - this.lbl_src_res.Name = "lbl_src_res"; - this.lbl_src_res.Size = new System.Drawing.Size(68, 13); - this.lbl_src_res.TabIndex = 77; - this.lbl_src_res.Text = "Select a Title"; + // tableLayoutPanel2 + // + this.tableLayoutPanel2.AutoSize = true; + this.tableLayoutPanel2.ColumnCount = 5; + this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.tableLayoutPanel2.Controls.Add(this.label7, 0, 0); + this.tableLayoutPanel2.Controls.Add(this.lbl_src_res, 1, 0); + this.tableLayoutPanel2.Controls.Add(this.Label91, 2, 0); + this.tableLayoutPanel2.Controls.Add(this.lbl_Aspect, 3, 0); + this.tableLayoutPanel2.Controls.Add(this.Label55, 0, 1); + this.tableLayoutPanel2.Controls.Add(this.text_width, 1, 1); + this.tableLayoutPanel2.Controls.Add(this.lbl_max, 4, 1); + this.tableLayoutPanel2.Controls.Add(this.label4, 2, 1); + this.tableLayoutPanel2.Controls.Add(this.text_height, 3, 1); + this.tableLayoutPanel2.Controls.Add(this.check_KeepAR, 1, 2); + this.tableLayoutPanel2.Location = new System.Drawing.Point(16, 35); + this.tableLayoutPanel2.Name = "tableLayoutPanel2"; + this.tableLayoutPanel2.RowCount = 3; + this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel2.Size = new System.Drawing.Size(376, 69); + this.tableLayoutPanel2.TabIndex = 116; // // label7 // + this.label7.Anchor = System.Windows.Forms.AnchorStyles.Left; this.label7.AutoSize = true; this.label7.BackColor = System.Drawing.Color.Transparent; this.label7.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.label7.Location = new System.Drawing.Point(13, 35); + this.label7.Location = new System.Drawing.Point(0, 3); + this.label7.Margin = new System.Windows.Forms.Padding(0, 3, 3, 3); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(44, 13); this.label7.TabIndex = 76; this.label7.Text = "Source:"; // - // label26 - // - this.label26.AutoSize = true; - this.label26.BackColor = System.Drawing.Color.Transparent; - this.label26.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label26.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.label26.Location = new System.Drawing.Point(13, 13); - this.label26.Name = "label26"; - this.label26.Size = new System.Drawing.Size(30, 13); - this.label26.TabIndex = 75; - this.label26.Text = "Size"; - // - // lbl_Aspect + // lbl_src_res // - this.lbl_Aspect.AutoSize = true; - this.lbl_Aspect.BackColor = System.Drawing.Color.Transparent; - this.lbl_Aspect.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.lbl_Aspect.Location = new System.Drawing.Point(241, 36); - this.lbl_Aspect.Name = "lbl_Aspect"; - this.lbl_Aspect.Size = new System.Drawing.Size(68, 13); - this.lbl_Aspect.TabIndex = 79; - this.lbl_Aspect.Text = "Select a Title"; + this.lbl_src_res.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.lbl_src_res.AutoSize = true; + this.lbl_src_res.BackColor = System.Drawing.Color.Transparent; + this.lbl_src_res.ImeMode = System.Windows.Forms.ImeMode.NoControl; + this.lbl_src_res.Location = new System.Drawing.Point(50, 3); + this.lbl_src_res.Margin = new System.Windows.Forms.Padding(3); + this.lbl_src_res.Name = "lbl_src_res"; + this.lbl_src_res.Size = new System.Drawing.Size(15, 13); + this.lbl_src_res.TabIndex = 77; + this.lbl_src_res.Text = "--"; // // Label91 // + this.Label91.Anchor = System.Windows.Forms.AnchorStyles.Left; this.Label91.AutoSize = true; this.Label91.BackColor = System.Drawing.Color.Transparent; this.Label91.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.Label91.Location = new System.Drawing.Point(152, 35); + this.Label91.Location = new System.Drawing.Point(120, 3); + this.Label91.Margin = new System.Windows.Forms.Padding(3); this.Label91.Name = "Label91"; this.Label91.Size = new System.Drawing.Size(72, 13); this.Label91.TabIndex = 78; this.Label91.Text = "Aspect Ratio:"; // + // lbl_Aspect + // + this.lbl_Aspect.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.lbl_Aspect.AutoSize = true; + this.lbl_Aspect.BackColor = System.Drawing.Color.Transparent; + this.lbl_Aspect.ImeMode = System.Windows.Forms.ImeMode.NoControl; + this.lbl_Aspect.Location = new System.Drawing.Point(198, 3); + this.lbl_Aspect.Margin = new System.Windows.Forms.Padding(3); + this.lbl_Aspect.Name = "lbl_Aspect"; + this.lbl_Aspect.Size = new System.Drawing.Size(15, 13); + this.lbl_Aspect.TabIndex = 79; + this.lbl_Aspect.Text = "--"; + // // Label55 // + this.Label55.Anchor = System.Windows.Forms.AnchorStyles.Left; this.Label55.AutoSize = true; this.Label55.BackColor = System.Drawing.Color.Transparent; this.Label55.ForeColor = System.Drawing.Color.Black; this.Label55.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.Label55.Location = new System.Drawing.Point(13, 63); + this.Label55.Location = new System.Drawing.Point(0, 26); + this.Label55.Margin = new System.Windows.Forms.Padding(0, 3, 3, 3); this.Label55.Name = "Label55"; this.Label55.Size = new System.Drawing.Size(39, 13); this.Label55.TabIndex = 80; this.Label55.Text = "Width:"; // + // text_width + // + this.text_width.Location = new System.Drawing.Point(50, 22); + this.text_width.Maximum = new decimal(new int[] { + 2560, + 0, + 0, + 0}); + this.text_width.Name = "text_width"; + this.text_width.Size = new System.Drawing.Size(64, 21); + this.text_width.TabIndex = 85; + this.text_width.ValueChanged += new System.EventHandler(this.text_width_ValueChanged); + // + // lbl_max + // + this.lbl_max.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.lbl_max.AutoSize = true; + this.lbl_max.ImeMode = System.Windows.Forms.ImeMode.NoControl; + this.lbl_max.Location = new System.Drawing.Point(268, 26); + this.lbl_max.Margin = new System.Windows.Forms.Padding(3); + this.lbl_max.Name = "lbl_max"; + this.lbl_max.Size = new System.Drawing.Size(15, 13); + this.lbl_max.TabIndex = 83; + this.lbl_max.Text = "--"; + // + // label4 + // + this.label4.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.label4.AutoSize = true; + this.label4.BackColor = System.Drawing.Color.Transparent; + this.label4.ForeColor = System.Drawing.Color.Black; + this.label4.ImeMode = System.Windows.Forms.ImeMode.NoControl; + this.label4.Location = new System.Drawing.Point(120, 26); + this.label4.Margin = new System.Windows.Forms.Padding(3); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(42, 13); + this.label4.TabIndex = 84; + this.label4.Text = "Height:"; + // + // text_height + // + this.text_height.Location = new System.Drawing.Point(198, 22); + this.text_height.Maximum = new decimal(new int[] { + 2560, + 0, + 0, + 0}); + this.text_height.Name = "text_height"; + this.text_height.Size = new System.Drawing.Size(64, 21); + this.text_height.TabIndex = 86; + this.text_height.ValueChanged += new System.EventHandler(this.text_height_ValueChanged); + // + // check_KeepAR + // + this.check_KeepAR.AutoSize = true; + this.check_KeepAR.Checked = true; + this.check_KeepAR.CheckState = System.Windows.Forms.CheckState.Checked; + this.tableLayoutPanel2.SetColumnSpan(this.check_KeepAR, 3); + this.check_KeepAR.ImeMode = System.Windows.Forms.ImeMode.NoControl; + this.check_KeepAR.Location = new System.Drawing.Point(50, 49); + this.check_KeepAR.Name = "check_KeepAR"; + this.check_KeepAR.Size = new System.Drawing.Size(114, 17); + this.check_KeepAR.TabIndex = 95; + this.check_KeepAR.Text = "Keep Aspect Ratio"; + this.check_KeepAR.UseVisualStyleBackColor = true; + this.check_KeepAR.CheckedChanged += new System.EventHandler(this.check_KeepAR_CheckedChanged); + // // tableLayoutPanel1 // this.tableLayoutPanel1.AutoSize = true; @@ -379,7 +448,7 @@ namespace Handbrake.Controls this.tableLayoutPanel1.Controls.Add(this.lbl_modulus, 0, 1); this.tableLayoutPanel1.Controls.Add(this.lbl_displayWidth, 0, 2); this.tableLayoutPanel1.Controls.Add(this.drp_modulus, 1, 1); - this.tableLayoutPanel1.Location = new System.Drawing.Point(16, 108); + this.tableLayoutPanel1.Location = new System.Drawing.Point(16, 110); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; this.tableLayoutPanel1.RowCount = 6; this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); @@ -389,7 +458,7 @@ namespace Handbrake.Controls this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel1.Size = new System.Drawing.Size(195, 154); - this.tableLayoutPanel1.TabIndex = 110; + this.tableLayoutPanel1.TabIndex = 115; // // updownParHeight // @@ -402,7 +471,6 @@ namespace Handbrake.Controls this.updownParHeight.Name = "updownParHeight"; this.updownParHeight.Size = new System.Drawing.Size(53, 21); this.updownParHeight.TabIndex = 112; - this.updownParHeight.ValueChanged += new System.EventHandler(this.text_width_ValueChanged); // // label6 // @@ -425,9 +493,9 @@ namespace Handbrake.Controls this.labelDisplaySize.Location = new System.Drawing.Point(82, 138); this.labelDisplaySize.Margin = new System.Windows.Forms.Padding(3); this.labelDisplaySize.Name = "labelDisplaySize"; - this.labelDisplaySize.Size = new System.Drawing.Size(68, 13); + this.labelDisplaySize.Size = new System.Drawing.Size(15, 13); this.labelDisplaySize.TabIndex = 108; - this.labelDisplaySize.Text = "Select a Title"; + this.labelDisplaySize.Text = "--"; // // lbl_parHeight // @@ -466,7 +534,6 @@ namespace Handbrake.Controls this.updownParWidth.Name = "updownParWidth"; this.updownParWidth.Size = new System.Drawing.Size(53, 21); this.updownParWidth.TabIndex = 111; - this.updownParWidth.ValueChanged += new System.EventHandler(this.text_width_ValueChanged); // // drp_anamorphic // @@ -507,7 +574,6 @@ namespace Handbrake.Controls this.updownDisplayWidth.Name = "updownDisplayWidth"; this.updownDisplayWidth.Size = new System.Drawing.Size(53, 21); this.updownDisplayWidth.TabIndex = 110; - this.updownDisplayWidth.ValueChanged += new System.EventHandler(this.text_width_ValueChanged); // // lbl_modulus // @@ -550,44 +616,54 @@ namespace Handbrake.Controls this.drp_modulus.TabIndex = 88; this.drp_modulus.SelectedIndexChanged += new System.EventHandler(this.drp_modulus_SelectedIndexChanged); // + // label8 + // + this.label8.AutoSize = true; + this.label8.BackColor = System.Drawing.Color.Transparent; + this.label8.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label8.ImeMode = System.Windows.Forms.ImeMode.NoControl; + this.label8.Location = new System.Drawing.Point(416, 13); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(57, 13); + this.label8.TabIndex = 114; + this.label8.Text = "Cropping"; + // + // label26 + // + this.label26.AutoSize = true; + this.label26.BackColor = System.Drawing.Color.Transparent; + this.label26.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label26.ImeMode = System.Windows.Forms.ImeMode.NoControl; + this.label26.Location = new System.Drawing.Point(13, 13); + this.label26.Name = "label26"; + this.label26.Size = new System.Drawing.Size(30, 13); + this.label26.TabIndex = 113; + this.label26.Text = "Size"; + // // PictureSettings // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.Transparent; + this.Controls.Add(this.tableLayoutPanel3); + this.Controls.Add(this.tableLayoutPanel2); this.Controls.Add(this.tableLayoutPanel1); - this.Controls.Add(this.check_customCrop); - this.Controls.Add(this.check_autoCrop); - this.Controls.Add(this.crop_bottom); - this.Controls.Add(this.crop_top); - this.Controls.Add(this.crop_left); - this.Controls.Add(this.crop_right); this.Controls.Add(this.label8); - this.Controls.Add(this.Label53); - this.Controls.Add(this.Label52); - this.Controls.Add(this.Label51); - this.Controls.Add(this.Label15); - this.Controls.Add(this.check_KeepAR); - this.Controls.Add(this.text_height); - this.Controls.Add(this.text_width); - this.Controls.Add(this.label4); - this.Controls.Add(this.lbl_max); - this.Controls.Add(this.lbl_src_res); - this.Controls.Add(this.label7); this.Controls.Add(this.label26); - this.Controls.Add(this.lbl_Aspect); - this.Controls.Add(this.Label91); - this.Controls.Add(this.Label55); this.Enabled = false; this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Name = "PictureSettings"; this.Size = new System.Drawing.Size(666, 279); - ((System.ComponentModel.ISupportInitialize)(this.crop_bottom)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.crop_top)).EndInit(); + this.tableLayoutPanel3.ResumeLayout(false); + this.tableLayoutPanel3.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.crop_left)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.crop_right)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.text_height)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.crop_top)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.crop_bottom)).EndInit(); + this.tableLayoutPanel2.ResumeLayout(false); + this.tableLayoutPanel2.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.text_width)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.text_height)).EndInit(); this.tableLayoutPanel1.ResumeLayout(false); this.tableLayoutPanel1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.updownParHeight)).EndInit(); @@ -600,27 +676,26 @@ namespace Handbrake.Controls #endregion - internal System.Windows.Forms.RadioButton check_customCrop; - internal System.Windows.Forms.RadioButton check_autoCrop; - internal System.Windows.Forms.NumericUpDown crop_bottom; - internal System.Windows.Forms.NumericUpDown crop_top; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel3; + internal System.Windows.Forms.Label Label15; internal System.Windows.Forms.NumericUpDown crop_left; internal System.Windows.Forms.NumericUpDown crop_right; - internal System.Windows.Forms.Label label8; + internal System.Windows.Forms.RadioButton check_autoCrop; + internal System.Windows.Forms.Label Label51; + internal System.Windows.Forms.NumericUpDown crop_top; internal System.Windows.Forms.Label Label53; internal System.Windows.Forms.Label Label52; - internal System.Windows.Forms.Label Label51; - internal System.Windows.Forms.Label Label15; - internal System.Windows.Forms.CheckBox check_KeepAR; - internal System.Windows.Forms.NumericUpDown text_height; - internal System.Windows.Forms.Label label4; - private System.Windows.Forms.Label lbl_max; - internal System.Windows.Forms.Label lbl_src_res; + internal System.Windows.Forms.NumericUpDown crop_bottom; + internal System.Windows.Forms.RadioButton check_customCrop; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2; internal System.Windows.Forms.Label label7; - internal System.Windows.Forms.Label label26; - internal System.Windows.Forms.Label lbl_Aspect; + internal System.Windows.Forms.Label lbl_src_res; internal System.Windows.Forms.Label Label91; + internal System.Windows.Forms.Label lbl_Aspect; internal System.Windows.Forms.Label Label55; + private System.Windows.Forms.Label lbl_max; + internal System.Windows.Forms.Label label4; + internal System.Windows.Forms.CheckBox check_KeepAR; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; internal System.Windows.Forms.NumericUpDown updownParHeight; internal System.Windows.Forms.Label label6; @@ -634,7 +709,11 @@ namespace Handbrake.Controls internal System.Windows.Forms.Label lbl_modulus; internal System.Windows.Forms.Label lbl_displayWidth; internal System.Windows.Forms.ComboBox drp_modulus; + internal System.Windows.Forms.Label label8; + internal System.Windows.Forms.Label label26; internal System.Windows.Forms.NumericUpDown text_width; + internal System.Windows.Forms.NumericUpDown text_height; + } diff --git a/win/C#/Controls/PictureSettings.cs b/win/C#/Controls/PictureSettings.cs index 096ccad4a..d3196aec1 100644 --- a/win/C#/Controls/PictureSettings.cs +++ b/win/C#/Controls/PictureSettings.cs @@ -1,6 +1,7 @@ using System; using System.ComponentModel; using System.Drawing; +using System.Globalization; using System.Windows.Forms; using Handbrake.Parsing; @@ -8,13 +9,13 @@ namespace Handbrake.Controls { public partial class PictureSettings : UserControl { - private bool _preventChangingWidth, _preventChangingHeight; - private int _maxWidth, _maxHeight, _lastEncodeWidth, _lastEncodeHeight; - private double _anamorphicRatio, _displayRatio; - private Title _title; - private double storageAspect; + private readonly CultureInfo Culture = new CultureInfo("en-US", false); public event EventHandler PictureSettingsChanged; + private Boolean preventChangingWidth, preventChangingHeight; + private int _PresetMaximumWidth, _PresetMaximumHeight; + private Title _SourceTitle; + public PictureSettings() { InitializeComponent(); @@ -30,356 +31,161 @@ namespace Handbrake.Controls [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public Title Source { - get { return _title; } + get { return _SourceTitle; } set { - _title = value; - _displayRatio = ((double)_title.Resolution.Width * _title.ParVal.Width / _title.ParVal.Height) / _title.Resolution.Height; - - Enabled = _title != null; - - MaximumWidth = _title.Resolution.Width; - MaximumHeight = _title.Resolution.Height; - - updownParWidth.Value = _title.ParVal.Width; - updownParHeight.Value = _title.ParVal.Height; - - // Set the source resolution - lbl_src_res.Text = Source.Resolution.Width + " x " + Source.Resolution.Height; - - // Set ratios - _anamorphicRatio = (double)Source.Resolution.Width / Source.Resolution.Height; - - // Set the encode width and height - EncodeWidth = _title.Resolution.Width; - EncodeHeight = _title.Resolution.Height; - - _lastEncodeWidth = _title.Resolution.Width; - _lastEncodeHeight = _title.Resolution.Height; - - // Set cropping - CroppingValues = _title.AutoCropDimensions; - - lbl_Aspect.Text = _title.AspectRatio.ToString(); - - UpdateAnamorphicValue(); - } - } + _SourceTitle = value; + Enabled = _SourceTitle != null; - /// - /// Gets or sets the resolution of the displayed video. - /// - public Size DisplayResolution { get; set; } + // Set the Aspect Ratio + lbl_Aspect.Text = _SourceTitle.AspectRatio.ToString(Culture); + lbl_src_res.Text = _SourceTitle.Resolution.Width + " x " + _SourceTitle.Resolution.Height; - public int EncodeWidth { get { return (int)text_width.Value; } set { text_width.Value = value; } } + // Set the Recommended Cropping values + crop_top.Value = GetCropMod2Clean(_SourceTitle.AutoCropDimensions[0]); + crop_bottom.Value = GetCropMod2Clean(_SourceTitle.AutoCropDimensions[1]); + crop_left.Value = GetCropMod2Clean(_SourceTitle.AutoCropDimensions[2]); + crop_right.Value = GetCropMod2Clean(_SourceTitle.AutoCropDimensions[3]); - public int EncodeHeight { get { return (int)text_height.Value; } set { text_height.Value = value; } } + // Set the Resolution Boxes + text_width.Value = _SourceTitle.Resolution.Width; - public int[] CroppingValues - { - get - { - return new int[4] + if (drp_anamorphic.SelectedIndex == 0) { - (int)crop_top.Value, - (int)crop_bottom.Value, - (int)crop_left.Value, - (int)crop_right.Value - }; - } - set - { - if (value.Length != 4) + int width = _SourceTitle.Resolution.Width; + + double crop_width = _SourceTitle.Resolution.Width - (double)crop_left.Value - (double)crop_right.Value; + double crop_height = _SourceTitle.Resolution.Height - (double)crop_top.Value - (double)crop_bottom.Value; + double newHeight = (width * _SourceTitle.Resolution.Width * sourceAspect.Height * crop_height) / (_SourceTitle.Resolution.Height * sourceAspect.Width * crop_width); + text_height.Value = (decimal)GetModulusValue(newHeight); + } + else { - throw new ArgumentException("The cropping values given must have a length of 4."); + text_height.Value = _SourceTitle.Resolution.Height - (int)crop_top.Value - (int)crop_bottom.Value; + labelDisplaySize.Text = calculateAnamorphicSizes().Width + "x" + calculateAnamorphicSizes().Height; } - crop_top.Value = value[0]; - crop_bottom.Value = value[1]; - crop_left.Value = value[2]; - crop_right.Value = value[3]; - } - } + updownParWidth.Value = _SourceTitle.ParVal.Width; + updownParHeight.Value = _SourceTitle.ParVal.Height; + updownDisplayWidth.Value = calculateAnamorphicSizes().Width; - /// - /// Gets or sets the maximum allowable width of the encoded video. - /// - public int MaximumWidth - { - get { return _maxWidth; } - set - { - _maxWidth = value > 0 ? value : (Source != null ? Source.Resolution.Width : 2560); } } /// - /// Gets or sets the maximum allowable height of the encoded video. + /// Gets or sets the maximum allowable size for the encoded resolution. Set a value to + /// "0" if the maximum does not matter. /// - public int MaximumHeight + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public Size PresetMaximumResolution { - get { return _maxHeight; } + get { return new Size(_PresetMaximumWidth, _PresetMaximumHeight); } set { - _maxHeight = value > 0 ? value : (Source != null ? Source.Resolution.Height : 2560); + _PresetMaximumWidth = value.Width; + _PresetMaximumHeight = value.Height; + + if (value.Width != 0 && value.Height != 0) + lbl_max.Text = "Max Width / Height"; + else if (value.Width != 0) + lbl_max.Text = "Max Width"; + else if (value.Height != 0) + lbl_max.Text = "Max Height"; + else + lbl_max.Text = ""; } - } - - public void setMax() - { - } - /// - /// Updates the anamorphic value shown as the display width. - /// - private void UpdateAnamorphicValue() + // Picture Controls + private void text_width_ValueChanged(object sender, EventArgs e) { - if (_title == null || _title.ParVal.IsEmpty) + if (preventChangingWidth) return; - // Set globally useful values - double width; - double par; + // Make sure the new value doesn't exceed the maximum + if (Source != null) + if (text_width.Value > Source.Resolution.Width) + text_width.Value = Source.Resolution.Width; switch (drp_anamorphic.SelectedIndex) { - case 2: - int actualWidth = (int)text_width.Value - (int)crop_left.Value - (int)crop_right.Value; - int source_display_width = Source.Resolution.Width * Source.ParVal.Width / Source.ParVal.Height; - int source_cropped_height = Source.Resolution.Height - (int)crop_top.Value - (int)crop_bottom.Value; - par = ((double) text_height.Value*source_display_width/source_cropped_height)/actualWidth; - width = (actualWidth * par); - width = Math.Truncate(width); - break; - default: + case 0: + if (check_KeepAR.Checked && Source != null) { - if (drp_anamorphic.SelectedIndex == 1) // Strict - par = (double)Source.ParVal.Width / Source.ParVal.Height; - else // Custom - par = (double)updownParWidth.Value / (double)updownParHeight.Value; + preventChangingHeight = true; + + int width = (int)text_width.Value; - // Store the latest DAR - double rawWidth = (double)text_width.Value * par; - _displayRatio = rawWidth / (double)text_height.Value; + double crop_width = Source.Resolution.Width - (double)crop_left.Value - (double)crop_right.Value; + double crop_height = Source.Resolution.Height - (double)crop_top.Value - (double)crop_bottom.Value; + double newHeight = (width * Source.Resolution.Width * sourceAspect.Height * crop_height) / + (Source.Resolution.Height * sourceAspect.Width * crop_width); + text_height.Value = (decimal)GetModulusValue(newHeight); - width = (int)Math.Round(rawWidth); - break; + preventChangingHeight = false; } + break; + default: + labelDisplaySize.Text = calculateAnamorphicSizes().Width + "x" + calculateAnamorphicSizes().Height; + break; } - labelDisplaySize.Text = width + " x " + text_height.Value; - - updownDisplayWidth.Value = (decimal)width; - updownParWidth.Value = (decimal)width; - updownParHeight.Value = text_width.Value; - } - - /// - /// Sets the visibility of the advanced anamorphic options. - /// - /// Whether or not the options should be visible. - private void SetCustomAnamorphicOptionsVisible(bool visible) - { - lbl_modulus.Visible = visible; - lbl_displayWidth.Visible = visible; - lbl_parWidth.Visible = visible; - lbl_parHeight.Visible = visible; - - drp_modulus.Visible = visible; - updownDisplayWidth.Visible = visible; - updownParWidth.Visible = visible; - updownParHeight.Visible = visible; - } - - /// - /// Gets the normalized value from one given by the user that is divisible by the number - /// set in . - /// - /// The value to normalize - /// A number that is divisible by . - /// - /// The way that some video codecs, such as x264, compress video is by creating "macroblocks" - /// that are seperated into defined squares, often 16x16 pixels. Because of this, if the width - /// and height of the encoded video are not each divisible by the modulus defined, video quality - /// will suffer. This method takes the supplied value and normalizes it to the nearest mutliple - /// of . - /// - private int GetModulusValue(int value) - { - int mod = int.Parse(drp_modulus.SelectedItem.ToString()); - int remainder = value % mod; - - if (remainder == 0) - return value; - - return remainder >= mod / 2 ? value + (mod - remainder) : value - remainder; - } - - private void ApplyStrictAnamorphic() - { - if (_anamorphicRatio == 0) - return; - - _preventChangingWidth = true; - _preventChangingHeight = true; - - text_width.Value = _title.Resolution.Width; - text_height.Value = _title.Resolution.Height; - - _preventChangingWidth = false; - _preventChangingHeight = false; - } - - /// - /// Loosely anamorphs encode width and height values. - /// - private void ApplyLooseAnamorphic() - { - // Prevents DivideByZeroExceptions - if (_anamorphicRatio == 0) - return; - - int actualWidth = (int)text_width.Value - (int)crop_left.Value - (int)crop_right.Value; - int source_cropped_height = Source.Resolution.Height - (int)crop_top.Value - (int)crop_bottom.Value; - - if (storageAspect == 0) - storageAspect = (double)actualWidth / source_cropped_height; - double hcalc = (actualWidth / storageAspect) + 0.5; - double newHeight = GetModulusValue((int)hcalc); - - text_width.Value = GetModulusValue((int)text_width.Value); - text_height.Value = (decimal)newHeight; - - UpdateAnamorphicValue(); - } - - /// - /// Anamorphs encode width and height based on the custom options specified. - /// - private void ApplyCustomAnamorphic(Control ctrlUpdated) - { - // Make sure the PAR values are set correctly - if (updownParWidth.Value == 0) - updownParWidth.Value = Source.ParVal.Width; - if (updownParHeight.Value == 0) - updownParHeight.Value = Source.ParVal.Height; - - // Set various values - int parWidth = (int)updownParWidth.Value; - int parHeight = (int)updownParHeight.Value; - - if (!check_KeepAR.Checked) - { - switch (ctrlUpdated.Name) - { - case "text_width": - case "updownParWidth": - case "updownParHeight": - updownDisplayWidth.Value = Math.Round(text_width.Value * parWidth / parHeight); - break; - case "updownDisplayWidth": - updownParWidth.Value = updownDisplayWidth.Value; - updownParHeight.Value = text_width.Value; - break; - } - } - else - { - switch (ctrlUpdated.Name) - { - case "updownDisplayWidth": - _preventChangingHeight = true; - - text_height.Value = GetModulusValue((int)((double)updownDisplayWidth.Value / _displayRatio)); - - _preventChangingHeight = false; - goto case "text_width"; - case "text_height": - updownDisplayWidth.Value = GetModulusValue((int)((double)text_width.Value * _anamorphicRatio * _displayRatio)); - goto case "text_width"; - case "text_width": - updownParWidth.Value = updownDisplayWidth.Value; - updownParHeight.Value = text_width.Value; - break; - } - } + preventChangingWidth = false; } - - - - private void text_width_ValueChanged(object sender, EventArgs e) + private void text_height_ValueChanged(object sender, EventArgs e) { - if (_preventChangingWidth) + if (preventChangingHeight) return; - _preventChangingWidth = true; - - if (text_width.Value > MaximumWidth) - { - text_width.Value = MaximumWidth; - } + if (Source != null) + if (text_height.Value > Source.Resolution.Height) + text_height.Value = Source.Resolution.Height; switch (drp_anamorphic.SelectedIndex) { case 0: - if (check_KeepAR.Checked) + if (check_KeepAR.Checked && Source != null) { - _preventChangingHeight = true; + preventChangingWidth = true; + + double crop_width = Source.Resolution.Width - (double)crop_left.Value - (double)crop_right.Value; + double crop_height = Source.Resolution.Height - (double)crop_top.Value - (double)crop_bottom.Value; - decimal newHeight = text_width.Value / (decimal)_anamorphicRatio; - text_height.Value = newHeight > MaximumHeight ? MaximumHeight : newHeight; + double new_width = ((double)text_height.Value * Source.Resolution.Height * sourceAspect.Width * crop_width) / + (Source.Resolution.Width * sourceAspect.Height * crop_height); - _preventChangingHeight = false; + text_width.Value = (decimal)GetModulusValue(new_width); + + preventChangingWidth = false; } break; - case 1: - ApplyStrictAnamorphic(); - break; - case 2: - ApplyLooseAnamorphic(); - break; - case 3: - ApplyCustomAnamorphic((Control)sender); + default: + labelDisplaySize.Text = calculateAnamorphicSizes().Width + "x" + calculateAnamorphicSizes().Height; break; } - _preventChangingWidth = false; + preventChangingHeight = false; } - - private void text_height_ValueChanged(object sender, EventArgs e) + private void check_KeepAR_CheckedChanged(object sender, EventArgs e) { - if (_preventChangingHeight) - return; - - _preventChangingHeight = true; - - if (text_height.Value > MaximumHeight) - { - text_height.Value = MaximumHeight; - } + //Force TextWidth to recalc height + if (check_KeepAR.Checked) + text_width_ValueChanged(this, new EventArgs()); - switch (drp_anamorphic.SelectedIndex) + // Disable the Custom Anamorphic Par Controls if checked. + if (drp_anamorphic.SelectedIndex == 3) { - case 0: - if (check_KeepAR.Checked) - { - _preventChangingWidth = true; - - decimal newWidth = text_height.Value * (decimal)_anamorphicRatio; - text_width.Value = newWidth > MaximumWidth ? MaximumWidth : newWidth; - - _preventChangingWidth = false; - } - break; - case 3: - ApplyCustomAnamorphic((Control)sender); - break; + updownParWidth.Enabled = !check_KeepAR.Checked; + updownParHeight.Enabled = !check_KeepAR.Checked; } - _preventChangingHeight = false; + // Raise the Picture Settings Changed Event + if (PictureSettingsChanged != null) + PictureSettingsChanged(this, new EventArgs()); } + // Anamorphic Controls private void drp_anamorphic_SelectedIndexChanged(object sender, EventArgs e) { switch (drp_anamorphic.SelectedIndex) @@ -389,20 +195,26 @@ namespace Handbrake.Controls text_height.Enabled = true; check_KeepAR.Enabled = true; - SetCustomAnamorphicOptionsVisible(false); + setCustomAnamorphicOptionsVisible(false); labelStaticDisplaySize.Visible = false; labelDisplaySize.Visible = false; check_KeepAR.Checked = true; - break; + drp_modulus.SelectedIndex = 0; + + if (check_KeepAR.Checked) + text_width_ValueChanged(this, new EventArgs()); + // Don't update display size if we're not using anamorphic + return; case 1: text_width.Enabled = false; text_height.Enabled = false; check_KeepAR.Enabled = false; - SetCustomAnamorphicOptionsVisible(false); + setCustomAnamorphicOptionsVisible(false); labelStaticDisplaySize.Visible = true; labelDisplaySize.Visible = true; + drp_modulus.SelectedIndex = 0; check_KeepAR.Checked = true; break; @@ -411,9 +223,10 @@ namespace Handbrake.Controls text_height.Enabled = false; check_KeepAR.Enabled = false; - SetCustomAnamorphicOptionsVisible(false); + setCustomAnamorphicOptionsVisible(false); labelStaticDisplaySize.Visible = true; labelDisplaySize.Visible = true; + drp_modulus.SelectedIndex = 0; check_KeepAR.Checked = true; break; @@ -422,7 +235,7 @@ namespace Handbrake.Controls text_height.Enabled = true; check_KeepAR.Enabled = true; - SetCustomAnamorphicOptionsVisible(true); + setCustomAnamorphicOptionsVisible(true); labelStaticDisplaySize.Visible = true; labelDisplaySize.Visible = true; @@ -430,30 +243,33 @@ namespace Handbrake.Controls break; } - UpdateAnamorphicValue(); - } + labelDisplaySize.Text = calculateAnamorphicSizes().Width + "x" + calculateAnamorphicSizes().Height; - private void check_KeepAR_CheckedChanged(object sender, EventArgs e) - { - if (drp_anamorphic.SelectedIndex != 3) - { - if (check_KeepAR.Checked) - { - text_width_ValueChanged(this, new EventArgs()); - } - } - else - { - updownParWidth.Enabled = !check_KeepAR.Checked; - updownParHeight.Enabled = !check_KeepAR.Checked; - } - } + if (check_KeepAR.Checked) + text_width_ValueChanged(this, new EventArgs()); - private void crop_ValueChanged(object sender, EventArgs e) + if (PictureSettingsChanged != null) + PictureSettingsChanged(this, new EventArgs()); + } + private void drp_modulus_SelectedIndexChanged(object sender, EventArgs e) { - text_width_ValueChanged(this, new EventArgs()); + preventChangingWidth = true; + preventChangingHeight = true; + + text_width.Value = (decimal)GetModulusValue((double)text_width.Value); + text_height.Value = (decimal)GetModulusValue((double)text_height.Value); + + preventChangingWidth = false; + preventChangingHeight = false; + + text_width.Increment = int.Parse(drp_modulus.SelectedItem.ToString()); + text_height.Increment = int.Parse(drp_modulus.SelectedItem.ToString()); + + if (PictureSettingsChanged != null) + PictureSettingsChanged(this, new EventArgs()); } + // Cropping Controls private void check_autoCrop_CheckedChanged(object sender, EventArgs e) { crop_top.Enabled = check_customCrop.Checked; @@ -461,11 +277,120 @@ namespace Handbrake.Controls crop_left.Enabled = check_customCrop.Checked; crop_right.Enabled = check_customCrop.Checked; } + private void crop_ValueChanged(object sender, EventArgs e) + { + text_width_ValueChanged(this, new EventArgs()); + } - private void drp_modulus_SelectedIndexChanged(object sender, EventArgs e) + // GUI Functions + private void setCustomAnamorphicOptionsVisible(bool visible) { - text_width.Increment = int.Parse(drp_modulus.SelectedItem.ToString()); - text_height.Increment = int.Parse(drp_modulus.SelectedItem.ToString()); + lbl_modulus.Visible = visible; + lbl_displayWidth.Visible = visible; + lbl_parWidth.Visible = visible; + lbl_parHeight.Visible = visible; + + drp_modulus.Visible = visible; + updownDisplayWidth.Visible = visible; + updownParWidth.Visible = visible; + updownParHeight.Visible = visible; + } + + // Calculation Functions + private Size sourceAspect + { + get + { + if (Source != null) + { + if (Source.AspectRatio == 1.78F) + return new Size(16, 9); + if (Source.AspectRatio == 1.33F) + return new Size(4, 3); + } + return new Size(0, 0); + } + } + private Size calculateAnamorphicSizes() + { + if (Source != null) + { + /* Set up some variables to make the math easier to follow. */ + int cropped_width = Source.Resolution.Width - (int)crop_left.Value - (int)crop_right.Value; + int cropped_height = Source.Resolution.Height - (int)crop_top.Value - (int)crop_bottom.Value; + double storage_aspect = (double)cropped_width / cropped_height; + + /* Figure out what width the source would display at. */ + double source_display_width = (double)cropped_width * Source.ParVal.Width / Source.ParVal.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 width, height; + switch (drp_anamorphic.SelectedIndex) + { + case 1: + /* Strict anamorphic */ + double displayWidth = ((double)cropped_width * Source.ParVal.Width / Source.ParVal.Height); + displayWidth = Math.Round(displayWidth, 0); + Size output = new Size((int)displayWidth, cropped_height); + return output; + case 2: + /* "Loose" anamorphic. + - Uses mod16-compliant dimensions, + - Allows users to set the width + */ + width = (int)text_width.Value - (int)crop_left.Value - (int)crop_right.Value; + width = GetModulusValue(width); /* Time to get picture width that divide cleanly.*/ + + height = (width / storage_aspect) + 0.5; + height = GetModulusValue(height); /* 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 pixel_aspect_width = height * source_display_width / cropped_height; + double pixel_aspect_height = width; + + double disWidthLoose = (width * pixel_aspect_width / pixel_aspect_height); + return new Size((int)disWidthLoose, (int)height); + case 3: + + // Get the User Interface Values + double UIdisplayWidth; + double.TryParse(updownDisplayWidth.Text, out UIdisplayWidth); + + /* Anamorphic 3: Power User Jamboree - Set everything based on specified values */ + height = GetModulusValue((double)text_height.Value); + + if (check_KeepAR.Checked) + return new Size((int)Math.Truncate(UIdisplayWidth), (int)height); + + return new Size((int)Math.Truncate(UIdisplayWidth), (int)height); + } + } + + // Return a default value of 0,0 to indicate failure + return new Size(0, 0); + } + private double GetModulusValue(double value) + { + int mod = int.Parse(drp_modulus.SelectedItem.ToString()); + double remainder = value % mod; + + if (remainder == 0) + return value; + + return remainder >= ((double)mod / 2) ? value + (mod - remainder) : value - remainder; + } + private static int GetCropMod2Clean(int value) + { + int remainder = value % 2; + if (remainder == 0) return value; + return (value + remainder); } } -} +} \ No newline at end of file diff --git a/win/C#/Functions/PresetLoader.cs b/win/C#/Functions/PresetLoader.cs index 051f3092c..136641474 100644 --- a/win/C#/Functions/PresetLoader.cs +++ b/win/C#/Functions/PresetLoader.cs @@ -5,6 +5,7 @@ It may be used under the terms of the GNU General Public License. */ using System; +using System.Drawing; using System.Windows.Forms; namespace Handbrake.Functions @@ -82,7 +83,7 @@ namespace Handbrake.Functions mainWindow.PictureSettings.crop_right.Value = right; } } - + // Set the anamorphic mode 0,1,2,3 mainWindow.PictureSettings.drp_anamorphic.SelectedIndex = presetQuery.AnamorphicMode; @@ -98,16 +99,12 @@ namespace Handbrake.Functions // Max Width/Height override Width/Height if (presetQuery.MaxWidth != 0) - { mainWindow.PictureSettings.text_width.Value = presetQuery.MaxWidth; - mainWindow.PictureSettings.MaximumWidth = presetQuery.MaxWidth; - } if (presetQuery.MaxHeight != 0) - { mainWindow.PictureSettings.text_height.Value = presetQuery.MaxHeight; - mainWindow.PictureSettings.MaximumHeight = presetQuery.MaxHeight; - } + + mainWindow.PictureSettings.PresetMaximumResolution = new Size(presetQuery.MaxWidth, presetQuery.MaxHeight); // Case where both height and max height are 0 - For built-in presets if (presetQuery.MaxHeight == 0 && presetQuery.Height == 0) @@ -117,8 +114,6 @@ namespace Handbrake.Functions if (mainWindow.selectedTitle != null && mainWindow.selectedTitle.Resolution.Width != 0) mainWindow.PictureSettings.text_width.Value = mainWindow.selectedTitle.Resolution.Width; - mainWindow.PictureSettings.setMax(); - // Custom Anamorphic Controls mainWindow.PictureSettings.updownDisplayWidth.Text = presetQuery.displayWidthValue.ToString(); mainWindow.PictureSettings.updownParHeight.Text = presetQuery.pixelAspectWidth.ToString(); diff --git a/win/C#/Functions/QueryGenerator.cs b/win/C#/Functions/QueryGenerator.cs index bb80c1e74..a6c59ee81 100644 --- a/win/C#/Functions/QueryGenerator.cs +++ b/win/C#/Functions/QueryGenerator.cs @@ -119,30 +119,30 @@ namespace Handbrake.Functions #region Picture Settings Tab // Use MaxWidth for built-in presets and width for user settings. - if (mainWindow.PictureSettings.MaximumWidth == 0) + if (mainWindow.PictureSettings.PresetMaximumResolution.Width == 0) { - if (mainWindow.PictureSettings.text_width.Text != "") + if (mainWindow.PictureSettings.text_width.Value != 0) if (mainWindow.PictureSettings.drp_anamorphic.SelectedIndex != 1) // Prevent usage for strict anamorphic query += " -w " + mainWindow.PictureSettings.text_width.Text; } else { - if (mainWindow.PictureSettings.text_width.Text != "") + if (mainWindow.PictureSettings.text_width.Value != 0) if (mainWindow.PictureSettings.drp_anamorphic.SelectedIndex != 1) query += " -X " + mainWindow.PictureSettings.text_width.Text; } // Use MaxHeight for built-in presets and height for user settings. - if (mainWindow.PictureSettings.MaximumHeight == 0) + if (mainWindow.PictureSettings.PresetMaximumResolution.Height == 0) { - if (mainWindow.PictureSettings.text_height.Text != "0") + if (mainWindow.PictureSettings.text_height.Value != 0) if (mainWindow.PictureSettings.text_height.Text != "") if (mainWindow.PictureSettings.drp_anamorphic.SelectedIndex == 0 || mainWindow.PictureSettings.drp_anamorphic.SelectedIndex == 3) // Prevent usage for strict anamorphic query += " -l " + mainWindow.PictureSettings.text_height.Text; } else { - if (mainWindow.PictureSettings.text_height.Text != "") + if (mainWindow.PictureSettings.text_height.Value != 0) if (mainWindow.PictureSettings.drp_anamorphic.SelectedIndex == 0 || mainWindow.PictureSettings.drp_anamorphic.SelectedIndex == 3) query += " -Y " + mainWindow.PictureSettings.text_height.Text; } diff --git a/win/C#/frmMain.Designer.cs b/win/C#/frmMain.Designer.cs index 2ddc303d2..acd18f3b2 100644 --- a/win/C#/frmMain.Designer.cs +++ b/win/C#/frmMain.Designer.cs @@ -896,19 +896,8 @@ namespace Handbrake // // PictureSettings // - this.PictureSettings.CroppingValues = new int[] { - 0, - 0, - 0, - 0}; - this.PictureSettings.DisplayResolution = new System.Drawing.Size(0, 0); this.PictureSettings.Enabled = false; - this.PictureSettings.EncodeHeight = 0; - this.PictureSettings.EncodeWidth = 0; this.PictureSettings.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.PictureSettings.Location = new System.Drawing.Point(0, 0); - this.PictureSettings.MaximumHeight = 2560; - this.PictureSettings.MaximumWidth = 2560; this.PictureSettings.Name = "PictureSettings"; this.PictureSettings.Size = new System.Drawing.Size(666, 279); this.PictureSettings.TabIndex = 0; diff --git a/win/C#/frmMain.cs b/win/C#/frmMain.cs index 428e3ae27..684bd97b1 100644 --- a/win/C#/frmMain.cs +++ b/win/C#/frmMain.cs @@ -207,7 +207,7 @@ namespace Handbrake check_optimiseMP4.CheckedChanged += new EventHandler(changePresetLabel); // Picture Settings - PictureSettings.PictureSettingsChanged += new EventHandler(changePresetLabel); + //PictureSettings.PictureSettingsChanged += new EventHandler(changePresetLabel); // Filter Settings Filters.FilterSettingsChanged += new EventHandler(changePresetLabel); @@ -235,7 +235,7 @@ namespace Handbrake check_optimiseMP4.CheckedChanged -= new EventHandler(changePresetLabel); // Picture Settings - PictureSettings.PictureSettingsChanged -= new EventHandler(changePresetLabel); + //PictureSettings.PictureSettingsChanged -= new EventHandler(changePresetLabel); // Filter Settings Filters.FilterSettingsChanged -= new EventHandler(changePresetLabel); @@ -629,7 +629,7 @@ namespace Handbrake } else { - if (encodeQueue.count() != 0 || (!string.IsNullOrEmpty(sourcePath) && string.IsNullOrEmpty(text_destination.Text))) + if (encodeQueue.count() != 0 || (!string.IsNullOrEmpty(sourcePath) && !string.IsNullOrEmpty(text_destination.Text))) { String query = rtf_query.Text != "" ? rtf_query.Text : queryGen.generateTheQuery(this); -- cgit v1.2.3