From 54fb83612cd94c2f48ba8dbc16035f7e66a49fc2 Mon Sep 17 00:00:00 2001 From: sr55 Date: Fri, 9 Apr 2010 19:52:09 +0000 Subject: 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 --- win/C#/Functions/PresetLoader.cs | 60 +++++++++++++++++++--------------------- 1 file 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; /// @@ -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 } + + /// + /// Convert a Quality Value to a position value for the Video Quality slider + /// + /// The selected video encoder + /// The Quality value + /// The position on the video quality slider + 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 -- cgit v1.2.3