diff options
author | sr55 <[email protected]> | 2010-04-09 19:52:09 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2010-04-09 19:52:09 +0000 |
commit | 54fb83612cd94c2f48ba8dbc16035f7e66a49fc2 (patch) | |
tree | 39a548b25552934532d644c846a9ad7a5b0ee1ce /win/C#/Functions/PresetLoader.cs | |
parent | 4da42bd750c90f1e80ff6170fe82c996035ecae0 (diff) |
WinGui:
- Refactor the code to work out the slider value from the video quality. This fixes a bug when loading presets with ffmpeg and makes the code far easier to understand.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3214 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/C#/Functions/PresetLoader.cs')
-rw-r--r-- | win/C#/Functions/PresetLoader.cs | 60 |
1 files changed, 28 insertions, 32 deletions
diff --git a/win/C#/Functions/PresetLoader.cs b/win/C#/Functions/PresetLoader.cs index f5153e970..fc835a0ec 100644 --- a/win/C#/Functions/PresetLoader.cs +++ b/win/C#/Functions/PresetLoader.cs @@ -7,6 +7,7 @@ namespace Handbrake.Functions {
using System;
using System.Drawing;
+ using System.Globalization;
using System.Windows.Forms;
/// <summary>
@@ -175,41 +176,10 @@ namespace Handbrake.Functions }
// Quality
-
if (presetQuery.VideoQuality != -1)
{
mainWindow.radio_cq.Checked = true;
- if (presetQuery.VideoEncoder == "H.264 (x264)")
- {
- double cqStep = Properties.Settings.Default.x264cqstep;
- int value;
- double x264Step = cqStep;
- double presetValue = presetQuery.VideoQuality;
-
- double x = 51 / x264Step;
-
- double calculated = presetValue / x264Step;
- calculated = x - calculated;
-
- int.TryParse(calculated.ToString(), out value);
-
- // This will sometimes occur when the preset was generated
- // with a different granularity, so, round and try again.
- if (value == 0)
- {
- double val = Math.Round(calculated, 0);
- int.TryParse(val.ToString(), out value);
- }
- if (value <= mainWindow.slider_videoQuality.Maximum)
- mainWindow.slider_videoQuality.Value = value;
- }
- else
- {
- int presetVal;
- int.TryParse(presetQuery.VideoQuality.ToString(), out presetVal);
- if (presetVal > mainWindow.slider_videoQuality.Minimum)
- mainWindow.slider_videoQuality.Value = presetVal;
- }
+ mainWindow.slider_videoQuality.Value = QualityToSliderValue(presetQuery.VideoEncoder, presetQuery.VideoQuality);
}
mainWindow.check_2PassEncode.CheckState = presetQuery.TwoPass ? CheckState.Checked : CheckState.Unchecked;
@@ -247,5 +217,31 @@ namespace Handbrake.Functions #endregion
}
+
+ /// <summary>
+ /// Convert a Quality Value to a position value for the Video Quality slider
+ /// </summary>
+ /// <param name="videoEncoder">The selected video encoder</param>
+ /// <param name="value">The Quality value</param>
+ /// <returns>The position on the video quality slider</returns>
+ private static int QualityToSliderValue(string videoEncoder, float value)
+ {
+ int sliderValue = 0;
+ switch (videoEncoder)
+ {
+ case "MPEG-4 (FFmpeg)":
+ sliderValue = 32 - (int)value;
+ break;
+ case "H.264 (x264)":
+ double cqStep = Properties.Settings.Default.x264cqstep;
+ sliderValue = (int)((51.0 / cqStep) - (value/cqStep));
+ break;
+ case "VP3 (Theora)":
+ sliderValue = (int)value;
+ break;
+ }
+
+ return sliderValue;
+ }
}
}
\ No newline at end of file |