OSDN Git Service

remove crf flag and all uses of it
[handbrake-jp/handbrake-jp-git.git] / win / C# / Controls / PictureSettings.cs
index 8352f52..4f87c33 100644 (file)
@@ -12,10 +12,10 @@ namespace Handbrake.Controls
         private readonly CultureInfo Culture = new CultureInfo("en-US", false);\r
         public event EventHandler PictureSettingsChanged;\r
 \r
-        private Boolean preventChangingWidth, preventChangingHeight, preventChangingCustom, preventChangingDisplayWidth;\r
-        private int _PresetMaximumWidth, _PresetMaximumHeight;\r
-        private double cachedDar;\r
-        private Title _SourceTitle;\r
+        private Boolean _preventChangingWidth, _preventChangingHeight, _preventChangingCustom, _preventChangingDisplayWidth;\r
+        private int _presetMaximumWidth, _presetMaximumHeight;\r
+        private double _cachedDar;\r
+        private Title _sourceTitle;\r
 \r
         public PictureSettings()\r
         {\r
@@ -32,41 +32,50 @@ namespace Handbrake.Controls
         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]\r
         public Title Source\r
         {\r
-            get { return _SourceTitle; }\r
+            private get { return _sourceTitle; }\r
             set\r
             {\r
-                _SourceTitle = value;\r
-                Enabled = _SourceTitle != null;\r
+                _sourceTitle = value;\r
+                Enabled = _sourceTitle != null;\r
 \r
                 // Set the Aspect Ratio\r
-                lbl_Aspect.Text = _SourceTitle.AspectRatio.ToString(Culture);\r
-                lbl_src_res.Text = _SourceTitle.Resolution.Width + " x " + _SourceTitle.Resolution.Height;\r
+                lbl_Aspect.Text = _sourceTitle.AspectRatio.ToString(Culture);\r
+                lbl_src_res.Text = _sourceTitle.Resolution.Width + " x " + _sourceTitle.Resolution.Height;\r
 \r
                 // Set the Recommended Cropping values\r
-                crop_top.Value = GetCropMod2Clean(_SourceTitle.AutoCropDimensions[0]);\r
-                crop_bottom.Value = GetCropMod2Clean(_SourceTitle.AutoCropDimensions[1]);\r
-                crop_left.Value = GetCropMod2Clean(_SourceTitle.AutoCropDimensions[2]);\r
-                crop_right.Value = GetCropMod2Clean(_SourceTitle.AutoCropDimensions[3]);\r
+                crop_top.Value = GetCropMod2Clean(_sourceTitle.AutoCropDimensions[0]);\r
+                crop_bottom.Value = GetCropMod2Clean(_sourceTitle.AutoCropDimensions[1]);\r
+                crop_left.Value = GetCropMod2Clean(_sourceTitle.AutoCropDimensions[2]);\r
+                crop_right.Value = GetCropMod2Clean(_sourceTitle.AutoCropDimensions[3]);\r
 \r
                 // Set the Resolution Boxes\r
                 if (drp_anamorphic.SelectedIndex == 0)\r
                 {\r
                     if (text_width.Value == 0) // Only update the values if the fields don't already have values.\r
-                        text_width.Value = _SourceTitle.Resolution.Width;\r
+                        text_width.Value = _sourceTitle.Resolution.Width;\r
 \r
                     check_KeepAR.Checked = true; // Forces Resolution to be correct.\r
                 }\r
                 else\r
                 {\r
-                    text_width.Value = _SourceTitle.Resolution.Width;\r
-                    text_height.Value = _SourceTitle.Resolution.Height - (int)crop_top.Value - (int)crop_bottom.Value;\r
-                    labelDisplaySize.Text = calculateAnamorphicSizes().Width + "x" + calculateAnamorphicSizes().Height;\r
+                    if (text_width.Value == 0 && text_height.Value == 0)// Only update the values if the fields don't already have values.\r
+                    {\r
+                        text_width.Value = _sourceTitle.Resolution.Width;\r
+                        text_height.Value = _sourceTitle.Resolution.Height - (int)crop_top.Value - (int)crop_bottom.Value;\r
+                    }\r
+\r
+                    labelDisplaySize.Text = CalculateAnamorphicSizes().Width + "x" + CalculateAnamorphicSizes().Height;\r
                 }\r
 \r
-                updownDisplayWidth.Value = calculateAnamorphicSizes().Width;\r
-                updownParWidth.Value = _SourceTitle.ParVal.Width;\r
-                updownParHeight.Value = _SourceTitle.ParVal.Height;\r
-                cachedDar = (double)updownDisplayWidth.Value / (double)text_height.Value;\r
+                //updownDisplayWidth.Value = CalculateAnamorphicSizes().Width;\r
+                updownParWidth.Value = _sourceTitle.ParVal.Width;\r
+                updownParHeight.Value = _sourceTitle.ParVal.Height;\r
+                //_cachedDar = (double)updownDisplayWidth.Value / (double)text_height.Value;\r
+\r
+\r
+                Size croppedDar = CalculateAnamorphicSizes();\r
+                _cachedDar = (double) croppedDar.Width/croppedDar.Height;\r
+                updownDisplayWidth.Value = croppedDar.Width;\r
             }\r
         }\r
 \r
@@ -78,11 +87,11 @@ namespace Handbrake.Controls
         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]\r
         public Size PresetMaximumResolution\r
         {\r
-            get { return new Size(_PresetMaximumWidth, _PresetMaximumHeight); }\r
+            get { return new Size(_presetMaximumWidth, _presetMaximumHeight); }\r
             set\r
             {\r
-                _PresetMaximumWidth = value.Width;\r
-                _PresetMaximumHeight = value.Height;\r
+                _presetMaximumWidth = value.Width;\r
+                _presetMaximumHeight = value.Height;\r
 \r
                 if (value.Width != 0 && value.Height != 0)\r
                     lbl_max.Text = "Max Width / Height";\r
@@ -98,7 +107,10 @@ namespace Handbrake.Controls
         // Picture Controls\r
         private void text_width_ValueChanged(object sender, EventArgs e)\r
         {\r
-            if (preventChangingWidth)\r
+            if (Properties.Settings.Default.disableResCalc)\r
+                return;\r
+\r
+            if (_preventChangingWidth)\r
                 return;\r
 \r
             // Make sure the new value doesn't exceed the maximum\r
@@ -111,28 +123,32 @@ namespace Handbrake.Controls
                 case 0:\r
                     if (check_KeepAR.Checked && Source != null)\r
                     {\r
-                        preventChangingHeight = true;\r
+                        _preventChangingHeight = true;\r
 \r
                         int width = (int)text_width.Value;\r
 \r
-                        double crop_width = Source.Resolution.Width - (double)crop_left.Value - (double)crop_right.Value;\r
-                        double crop_height = Source.Resolution.Height - (double)crop_top.Value - (double)crop_bottom.Value;\r
-                        double newHeight = (width * Source.Resolution.Width * sourceAspect.Height * crop_height) /\r
-                                           (Source.Resolution.Height * sourceAspect.Width * crop_width);\r
+                        double crop_width = Source.Resolution.Width - (int)crop_left.Value - (int)crop_right.Value;\r
+                        double crop_height = Source.Resolution.Height - (int)crop_top.Value - (int)crop_bottom.Value;\r
+\r
+                        if (SourceAspect.Width == 0 && SourceAspect.Height == 0)\r
+                            break;\r
+\r
+                        double newHeight = ((double)width * Source.Resolution.Width * SourceAspect.Height * crop_height) /\r
+                                           (Source.Resolution.Height * SourceAspect.Width * crop_width);\r
                         text_height.Value = (decimal)GetModulusValue(newHeight);\r
 \r
-                        preventChangingHeight = false;\r
+                        _preventChangingHeight = false;\r
                     }\r
                     break;\r
                 case 3:\r
                     if (check_KeepAR.CheckState == CheckState.Unchecked && Source != null)\r
                     {\r
-                        if (preventChangingCustom)\r
+                        if (_preventChangingCustom)\r
                             break;\r
 \r
-                        preventChangingDisplayWidth = true; \r
+                        _preventChangingDisplayWidth = true;\r
                         updownDisplayWidth.Value = text_width.Value * updownParWidth.Value / updownParHeight.Value;\r
-                        preventChangingDisplayWidth = false;\r
+                        _preventChangingDisplayWidth = false;\r
 \r
                         labelDisplaySize.Text = Math.Truncate(updownDisplayWidth.Value) + "x" + text_height.Value;\r
                     }\r
@@ -144,15 +160,18 @@ namespace Handbrake.Controls
                     }\r
                     break;\r
                 default:\r
-                    labelDisplaySize.Text = calculateAnamorphicSizes().Width + "x" + calculateAnamorphicSizes().Height;\r
+                    labelDisplaySize.Text = CalculateAnamorphicSizes().Width + "x" + CalculateAnamorphicSizes().Height;\r
                     break;\r
             }\r
 \r
-            preventChangingWidth = false;\r
+            _preventChangingWidth = false;\r
         }\r
         private void text_height_ValueChanged(object sender, EventArgs e)\r
         {\r
-            if (preventChangingHeight)\r
+            if (Properties.Settings.Default.disableResCalc)\r
+                return;\r
+\r
+            if (_preventChangingHeight)\r
                 return;\r
 \r
             if (Source != null)\r
@@ -164,17 +183,17 @@ namespace Handbrake.Controls
                 case 0:\r
                     if (check_KeepAR.Checked && Source != null)\r
                     {\r
-                        preventChangingWidth = true;\r
+                        _preventChangingWidth = true;\r
 \r
-                        double crop_width = Source.Resolution.Width - (double)crop_left.Value - (double)crop_right.Value;\r
-                        double crop_height = Source.Resolution.Height - (double)crop_top.Value - (double)crop_bottom.Value;\r
+                        double crop_width = Source.Resolution.Width - (int)crop_left.Value - (int)crop_right.Value;\r
+                        double crop_height = Source.Resolution.Height - (int)crop_top.Value - (int)crop_bottom.Value;\r
 \r
-                        double new_width = ((double)text_height.Value * Source.Resolution.Height * sourceAspect.Width * crop_width) /\r
-                                            (Source.Resolution.Width * sourceAspect.Height * crop_height);\r
+                        double new_width = ((double)text_height.Value * Source.Resolution.Height * SourceAspect.Width * crop_width) /\r
+                                            (Source.Resolution.Width * SourceAspect.Height * crop_height);\r
 \r
                         text_width.Value = (decimal)GetModulusValue(new_width);\r
 \r
-                        preventChangingWidth = false;\r
+                        _preventChangingWidth = false;\r
                     }\r
                     break;\r
                 case 3:\r
@@ -187,29 +206,32 @@ namespace Handbrake.Controls
                         // - Changes PIXEL HEIGHT to STORAGE WIDTH\r
                         // DAR = DISPLAY WIDTH / DISPLAY HEIGHT (cache after every modification)\r
 \r
-                        double rawCalculatedDisplayWidth = (double)text_height.Value * cachedDar;\r
+                        double rawCalculatedDisplayWidth = (double)text_height.Value * _cachedDar;\r
 \r
-                        preventChangingDisplayWidth = true; // Start Guards\r
-                        preventChangingWidth = true;\r
+                        _preventChangingDisplayWidth = true; // Start Guards\r
+                        _preventChangingWidth = true;\r
 \r
                         updownDisplayWidth.Value = (decimal)rawCalculatedDisplayWidth;\r
                         updownParWidth.Value = updownDisplayWidth.Value;\r
                         updownParHeight.Value = text_width.Value;\r
 \r
-                        preventChangingWidth = false; // Reset Guards\r
-                        preventChangingDisplayWidth = false;\r
+                        _preventChangingWidth = false; // Reset Guards\r
+                        _preventChangingDisplayWidth = false;\r
                     }\r
 \r
                     break;\r
                 default:\r
-                    labelDisplaySize.Text = calculateAnamorphicSizes().Width + "x" + calculateAnamorphicSizes().Height;\r
+                    labelDisplaySize.Text = CalculateAnamorphicSizes().Width + "x" + CalculateAnamorphicSizes().Height;\r
                     break;\r
             }\r
 \r
-            preventChangingHeight = false;\r
+            _preventChangingHeight = false;\r
         }\r
         private void check_KeepAR_CheckedChanged(object sender, EventArgs e)\r
         {\r
+            if (Properties.Settings.Default.disableResCalc)\r
+                return;\r
+\r
             //Force TextWidth to recalc height\r
             if (check_KeepAR.Checked)\r
                 text_width_ValueChanged(this, new EventArgs());\r
@@ -227,15 +249,18 @@ namespace Handbrake.Controls
         }\r
         private void updownDisplayWidth_ValueChanged(object sender, EventArgs e)\r
         {\r
-            if (preventChangingDisplayWidth == false && check_KeepAR.CheckState == CheckState.Unchecked)\r
+            if (Properties.Settings.Default.disableResCalc)\r
+                return;\r
+\r
+            if (_preventChangingDisplayWidth == false && check_KeepAR.CheckState == CheckState.Unchecked)\r
             {\r
-                preventChangingCustom = true;\r
+                _preventChangingCustom = true;\r
                 updownParWidth.Value = updownDisplayWidth.Value;\r
                 updownParHeight.Value = text_width.Value;\r
-                preventChangingCustom = false;\r
+                _preventChangingCustom = false;\r
             }\r
 \r
-            if (preventChangingDisplayWidth == false  && check_KeepAR.CheckState == CheckState.Checked)\r
+            if (_preventChangingDisplayWidth == false && check_KeepAR.CheckState == CheckState.Checked)\r
             {\r
                 // - Changes HEIGHT to keep DAR\r
                 // - Changes PIXEL WIDTH to new DISPLAY WIDTH\r
@@ -243,20 +268,21 @@ namespace Handbrake.Controls
                 // DAR = DISPLAY WIDTH / DISPLAY HEIGHT (cache after every modification)\r
 \r
                 // Calculate new Height Value\r
-                int modulus = 16;\r
-                int.TryParse(drp_modulus.SelectedItem.ToString(), out modulus);\r
+                int modulus;\r
+                if(!int.TryParse(drp_modulus.SelectedItem.ToString(), out modulus))\r
+                    modulus = 16;\r
 \r
-                int rawCalculatedHeight = (int) ((int)updownDisplayWidth.Value/cachedDar);\r
+                int rawCalculatedHeight = (int)((int)updownDisplayWidth.Value / _cachedDar);\r
                 int modulusHeight = rawCalculatedHeight - (rawCalculatedHeight % modulus);\r
 \r
                 // Update value\r
-                preventChangingHeight = true;\r
+                _preventChangingHeight = true;\r
                 text_height.Value = (decimal)modulusHeight;\r
                 updownParWidth.Value = updownDisplayWidth.Value;\r
                 updownParHeight.Value = text_width.Value;\r
-                preventChangingHeight = false;  \r
+                _preventChangingHeight = false;\r
             }\r
-           \r
+\r
         }\r
 \r
         // Anamorphic Controls\r
@@ -269,7 +295,7 @@ namespace Handbrake.Controls
                     text_height.Enabled = true;\r
                     check_KeepAR.Enabled = true;\r
 \r
-                    setCustomAnamorphicOptionsVisible(false);\r
+                    SetCustomAnamorphicOptionsVisible(false);\r
                     labelStaticDisplaySize.Visible = false;\r
                     labelDisplaySize.Visible = false;\r
 \r
@@ -285,7 +311,7 @@ namespace Handbrake.Controls
                     text_height.Enabled = false;\r
                     check_KeepAR.Enabled = false;\r
 \r
-                    setCustomAnamorphicOptionsVisible(false);\r
+                    SetCustomAnamorphicOptionsVisible(false);\r
                     labelStaticDisplaySize.Visible = true;\r
                     labelDisplaySize.Visible = true;\r
                     drp_modulus.SelectedIndex = 0;\r
@@ -297,7 +323,7 @@ namespace Handbrake.Controls
                     text_height.Enabled = false;\r
                     check_KeepAR.Enabled = false;\r
 \r
-                    setCustomAnamorphicOptionsVisible(false);\r
+                    SetCustomAnamorphicOptionsVisible(false);\r
                     labelStaticDisplaySize.Visible = true;\r
                     labelDisplaySize.Visible = true;\r
                     drp_modulus.SelectedIndex = 0;\r
@@ -309,15 +335,18 @@ namespace Handbrake.Controls
                     text_height.Enabled = true;\r
                     check_KeepAR.Enabled = true;\r
 \r
-                    setCustomAnamorphicOptionsVisible(true);\r
+                    SetCustomAnamorphicOptionsVisible(true);\r
                     labelStaticDisplaySize.Visible = true;\r
                     labelDisplaySize.Visible = true;\r
 \r
                     check_KeepAR.Checked = true;\r
+                    updownParWidth.Enabled = !check_KeepAR.Checked;\r
+                    updownParHeight.Enabled = !check_KeepAR.Checked;\r
                     break;\r
+\r
             }\r
 \r
-            labelDisplaySize.Text = calculateAnamorphicSizes().Width + "x" + calculateAnamorphicSizes().Height;\r
+            labelDisplaySize.Text = CalculateAnamorphicSizes().Width + "x" + CalculateAnamorphicSizes().Height;\r
 \r
             if (check_KeepAR.Checked)\r
                 text_width_ValueChanged(this, new EventArgs());\r
@@ -327,14 +356,14 @@ namespace Handbrake.Controls
         }\r
         private void drp_modulus_SelectedIndexChanged(object sender, EventArgs e)\r
         {\r
-            preventChangingWidth = true;\r
-            preventChangingHeight = true;\r
+            _preventChangingWidth = true;\r
+            _preventChangingHeight = true;\r
 \r
             text_width.Value = (decimal)GetModulusValue((double)text_width.Value);\r
             text_height.Value = (decimal)GetModulusValue((double)text_height.Value);\r
 \r
-            preventChangingWidth = false;\r
-            preventChangingHeight = false;\r
+            _preventChangingWidth = false;\r
+            _preventChangingHeight = false;\r
 \r
             text_width.Increment = int.Parse(drp_modulus.SelectedItem.ToString());\r
             text_height.Increment = int.Parse(drp_modulus.SelectedItem.ToString());\r
@@ -357,7 +386,7 @@ namespace Handbrake.Controls
         }\r
 \r
         // GUI Functions\r
-        private void setCustomAnamorphicOptionsVisible(bool visible)\r
+        private void SetCustomAnamorphicOptionsVisible(bool visible)\r
         {\r
             lbl_modulus.Visible = visible;\r
             lbl_displayWidth.Visible = visible;\r
@@ -371,21 +400,17 @@ namespace Handbrake.Controls
         }\r
 \r
         // Calculation Functions\r
-        private Size sourceAspect\r
+        private Size SourceAspect\r
         {\r
             get\r
             {\r
-                if (Source != null)\r
-                {\r
-                    if (Source.AspectRatio == 1.78F)\r
-                        return new Size(16, 9);\r
-                    if (Source.AspectRatio == 1.33F)\r
-                        return new Size(4, 3);\r
-                }\r
-                return new Size(0, 0);\r
+                if (Source != null) // display aspect = (width * par_width) / (height * par_height)\r
+                    return new Size((Source.ParVal.Width * Source.Resolution.Width), (Source.ParVal.Height * Source.Resolution.Height));\r
+\r
+                return new Size(0, 0); // Fall over to 16:9 and hope for the best\r
             }\r
         }\r
-        private Size calculateAnamorphicSizes()\r
+        private Size CalculateAnamorphicSizes()\r
         {\r
             if (Source != null)\r
             {\r
@@ -406,6 +431,7 @@ namespace Handbrake.Controls
                 double width, height;\r
                 switch (drp_anamorphic.SelectedIndex)\r
                 {\r
+                    default:\r
                     case 1:\r
                         /* Strict anamorphic */\r
                         double displayWidth = ((double)cropped_width * Source.ParVal.Width / Source.ParVal.Height);\r
@@ -430,6 +456,8 @@ namespace Handbrake.Controls
                         double pixel_aspect_height = width;\r
 \r
                         double disWidthLoose = (width * pixel_aspect_width / pixel_aspect_height);\r
+                        if (double.IsNaN(disWidthLoose))\r
+                            disWidthLoose = 0;\r
                         return new Size((int)disWidthLoose, (int)height);\r
                     case 3:\r
 \r
@@ -466,5 +494,13 @@ namespace Handbrake.Controls
             if (remainder == 0) return value;\r
             return (value + remainder);\r
         }\r
+\r
+        // Hidden UI feature to drop the MaxWidth / Height with the MaxWidth/Height label is double clicked\r
+        private void lbl_max_DoubleClick(object sender, EventArgs e)\r
+        {\r
+            PresetMaximumResolution = new Size(0,0);\r
+            if (PictureSettingsChanged != null)\r
+                PictureSettingsChanged(this, new EventArgs());\r
+        }\r
     }\r
 }
\ No newline at end of file