Skip to content

Commit

Permalink
WinGui: Add support for negative values on the video quality slider. …
Browse files Browse the repository at this point in the history
…Slider will also be a little more stable when switching encoders (to an extent)

(cherry picked from commit 94df95a)
  • Loading branch information
sr55 committed Jan 6, 2023
1 parent 3e9974c commit c6b3b5b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
39 changes: 19 additions & 20 deletions win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,6 @@ public bool IsVariableFramerate
}
}

public bool IsLossless
{
get => 0.0.Equals(this.DisplayRF) && this.SelectedVideoEncoder.IsX264;
}

public int QualityMax
{
get => this.qualityMax;
Expand Down Expand Up @@ -225,7 +220,6 @@ public int RF

this.NotifyOfPropertyChange(() => this.RF);
this.NotifyOfPropertyChange(() => this.DisplayRF);
this.NotifyOfPropertyChange(() => this.IsLossless);
this.OnTabStatusChanged(new TabStatusEventArgs("filters", ChangedOption.Quality));
}
}
Expand Down Expand Up @@ -680,7 +674,6 @@ public void UpdateTask(EncodeTask task)
this.NotifyOfPropertyChange(() => this.QualityMin);
this.NotifyOfPropertyChange(() => this.RF);
this.NotifyOfPropertyChange(() => this.DisplayRF);
this.NotifyOfPropertyChange(() => this.IsLossless);
this.NotifyOfPropertyChange(() => this.VideoBitrate);
this.NotifyOfPropertyChange(() => this.Task.Quality);
this.NotifyOfPropertyChange(() => this.Task.TwoPass);
Expand Down Expand Up @@ -751,7 +744,7 @@ public bool MatchesPreset(Preset preset)

if (this.SelectedVideoEncoder != null)
{
if (this.SelectedVideoEncoder.Presets.Any())
if (this.SelectedVideoEncoder.Presets != null && this.SelectedVideoEncoder.Presets.Any())
{
if (!Equals(preset.Task.VideoPreset, this.Task.VideoPreset))
{
Expand Down Expand Up @@ -967,22 +960,28 @@ private void SetRF(double? quality)
cqStep = this.userSettingService.GetUserSetting<double>(UserSettingConstants.X264Step);
}

if (cqStep != 1)
if (limits.Ascending) // Theora
{
return Math.Round(51.0 - (sliderValue * cqStep), 2); // x264, x265
return sliderValue;
}

if (limits.Ascending)
else // x264, x265, MPEG-4, MPEG-2, AV1, QuickSync
{
return sliderValue; // Theora
}
if (limits.Low > 0)
{
sliderValue -= (int)limits.Low; // Handles the non 0 Starting point. MPEG-4, MPEG-2
}

if (limits.Low > 0)
{
sliderValue -= (int)limits.Low; // Handles the non 0 Starting point. TODO -> Add support for negative quality values.
if (cqStep != 1)
{
float augment = limits.Low > 0 ? 0 : (limits.Low * -1); // Handle negative ranges
return Math.Round(limits.High - (sliderValue * cqStep) - (-augment * cqStep), 2);
}
else
{
float augment = limits.Low > 0 ? 0 : (limits.Low * -1); // Handle negative ranges
return limits.High - sliderValue - augment;
}
}

return (double)limits.High - sliderValue; // VP8, VP9, MPEG-2, MPEG-4, QuickSync
}

private void SetQualitySliderBounds()
Expand All @@ -1006,7 +1005,7 @@ private void SetQualitySliderBounds()

if (cqStep != 1)
{
this.QualityMin = Math.Max((int)limits.Low, 0); // TODO -> Add support for negative quality values.
this.QualityMin = Math.Max((int)limits.Low, 0);
this.QualityMax = (int)Math.Round(limits.High / cqStep, 0);
}
else
Expand Down
3 changes: 0 additions & 3 deletions win/CS/HandBrakeWPF/Views/VideoView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@
ToolTip="{x:Static Properties:ResourcesTooltips.Video_Quality}" />
<TextBlock Text="{Binding DisplayRF}" MinWidth="30" />
<TextBlock Text="{Binding Rfqp}" FontWeight="Bold" Margin="5,0,0,0" />

<TextBlock Text="{x:Static Properties:Resources.Video_LosslessWarning}" Visibility="{Binding IsLossless, Converter={StaticResource boolToVisConverter}}"
Margin="10,0,0,0" ToolTip="{x:Static Properties:Resources.Video_LosslessWarningTooltip}" FontWeight="Bold" />
</StackPanel>

<Slider Value="{Binding RF, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Stretch" Maximum="{Binding QualityMax}" Minimum="{Binding QualityMin}"
Expand Down

0 comments on commit c6b3b5b

Please sign in to comment.