From 047b684310107ec84d16bb767a9345c7c7fe1afe Mon Sep 17 00:00:00 2001 From: sr55 Date: Sat, 30 Jan 2021 18:33:56 +0000 Subject: WinGui: Add support for Chroma Smooth filter. --- .../Interop/Json/Presets/HBPreset.cs | 6 + .../HandBrakeWPF/Properties/Resources.Designer.cs | 9 + win/CS/HandBrakeWPF/Properties/Resources.resx | 3 + .../Properties/ResourcesTooltips.Designer.cs | 9 + .../HandBrakeWPF/Properties/ResourcesTooltips.resx | 3 + .../Services/Encode/Factories/EncodeTaskFactory.cs | 12 ++ .../Services/Encode/Model/EncodeTask.cs | 11 +- .../Presets/Factories/JsonPresetFactory.cs | 15 ++ .../ViewModelItems/Filters/ChromaSmoothFilter.cs | 191 +++++++++++++++++++++ win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs | 11 ++ win/CS/HandBrakeWPF/Views/FiltersView.xaml | 53 ++++-- 11 files changed, 306 insertions(+), 17 deletions(-) create mode 100644 win/CS/HandBrakeWPF/ViewModelItems/Filters/ChromaSmoothFilter.cs diff --git a/win/CS/HandBrake.Interop/Interop/Json/Presets/HBPreset.cs b/win/CS/HandBrake.Interop/Interop/Json/Presets/HBPreset.cs index 4e42409b8..e31d3dcb4 100644 --- a/win/CS/HandBrake.Interop/Interop/Json/Presets/HBPreset.cs +++ b/win/CS/HandBrake.Interop/Interop/Json/Presets/HBPreset.cs @@ -191,6 +191,12 @@ namespace HandBrake.Interop.Interop.Json.Presets public string PictureColorspaceCustom { get; set; } + public string PictureChromaSmoothPreset { get; set; } + + public string PictureChromaSmoothTune { get; set; } + + public string PictureChromaSmoothCustom { get; set; } + /// /// Gets or sets a value indicating whether picture itu par. /// diff --git a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs index 115f5befe..ca70b1b43 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs +++ b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs @@ -970,6 +970,15 @@ namespace HandBrakeWPF.Properties { } } + /// + /// Looks up a localized string similar to Chroma Smooth:. + /// + public static string FiltersView_ChromaSmooth { + get { + return ResourceManager.GetString("FiltersView_ChromaSmooth", resourceCulture); + } + } + /// /// Looks up a localized string similar to Colourspace:. /// diff --git a/win/CS/HandBrakeWPF/Properties/Resources.resx b/win/CS/HandBrakeWPF/Properties/Resources.resx index 76cd45b47..00069e88c 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.resx +++ b/win/CS/HandBrakeWPF/Properties/Resources.resx @@ -2417,6 +2417,9 @@ Fields are limited to: (Requires Restart) + + Chroma Smooth: + Colourspace: diff --git a/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.Designer.cs b/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.Designer.cs index 2e053e9f7..01a4f44a8 100644 --- a/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.Designer.cs +++ b/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.Designer.cs @@ -60,6 +60,15 @@ namespace HandBrakeWPF.Properties { } } + /// + /// Looks up a localized string similar to Chroma Smooth Filter. + /// + public static string FiltersView_ChromaSmooth { + get { + return ResourceManager.GetString("FiltersView_ChromaSmooth", resourceCulture); + } + } + /// /// Looks up a localized string similar to Colourspace Filter.. /// diff --git a/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.resx b/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.resx index 8690319ae..cfc83b6c5 100644 --- a/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.resx +++ b/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.resx @@ -468,4 +468,7 @@ When disabled, it will use the path in the destination box on the main window if Colourspace Filter. + + Chroma Smooth Filter + \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeTaskFactory.cs b/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeTaskFactory.cs index faba29387..cac804d38 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeTaskFactory.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeTaskFactory.cs @@ -499,6 +499,18 @@ namespace HandBrakeWPF.Services.Encode.Factories } } + if (job.ChromaSmooth != null && job.ChromaSmooth.Key != "off") + { + string unparsedJson = HandBrakeFilterHelpers.GenerateFilterSettingJson((int)hb_filter_ids.HB_FILTER_CHROMA_SMOOTH, job.ChromaSmooth.Key, job.ChromaSmoothTune?.Key, job.CustomChromaSmooth); + if (!string.IsNullOrEmpty(unparsedJson)) + { + JsonDocument settings = JsonDocument.Parse(unparsedJson); + + Filter filterItem = new Filter { ID = (int)hb_filter_ids.HB_FILTER_CHROMA_SMOOTH, Settings = settings }; + filter.FilterList.Add(filterItem); + } + } + // Grayscale if (job.Grayscale) diff --git a/win/CS/HandBrakeWPF/Services/Encode/Model/EncodeTask.cs b/win/CS/HandBrakeWPF/Services/Encode/Model/EncodeTask.cs index bd50f19cf..3f1835888 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/Model/EncodeTask.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/Model/EncodeTask.cs @@ -93,6 +93,9 @@ namespace HandBrakeWPF.Services.Encode.Model this.Padding = task.Padding; this.Colourspace = task.Colourspace; this.CustomColourspace = task.CustomColourspace; + this.ChromaSmooth = task.ChromaSmooth; + this.ChromaSmoothTune = task.ChromaSmoothTune; + this.CustomChromaSmooth = task.CustomChromaSmooth; this.DisplayWidth = task.DisplayWidth; this.EndPoint = task.EndPoint; @@ -243,7 +246,13 @@ namespace HandBrakeWPF.Services.Encode.Model public FilterPreset Colourspace { get; set; } public string CustomColourspace { get; set; } - + + public FilterPreset ChromaSmooth { get; set; } + + public FilterTune ChromaSmoothTune { get; set; } + + public string CustomChromaSmooth { get; set; } + /* Video */ public VideoEncodeRateType VideoEncodeRateType { get; set; } diff --git a/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs b/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs index bf116c183..d54330c81 100644 --- a/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs +++ b/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs @@ -97,6 +97,17 @@ namespace HandBrakeWPF.Services.Presets.Factories { preset.Task.Colourspace = new FilterPreset("Off", "off"); } + + if (!string.IsNullOrEmpty(importedPreset.PictureChromaSmoothPreset)) + { + preset.Task.ChromaSmooth = new FilterPreset(HandBrakeFilterHelpers.GetFilterPresets((int)hb_filter_ids.HB_FILTER_CHROMA_SMOOTH).FirstOrDefault(s => s.ShortName == importedPreset.PictureChromaSmoothPreset)); + preset.Task.ChromaSmoothTune = new FilterTune(HandBrakeFilterHelpers.GetFilterTunes((int)hb_filter_ids.HB_FILTER_CHROMA_SMOOTH).FirstOrDefault(s => s.ShortName == importedPreset.PictureChromaSmoothTune)); + preset.Task.CustomChromaSmooth = importedPreset.PictureChromaSmoothCustom; + } + else + { + preset.Task.ChromaSmooth = new FilterPreset("Off", "off"); + } if (!string.IsNullOrEmpty(importedPreset.PictureDeblockPreset)) { @@ -648,6 +659,10 @@ namespace HandBrakeWPF.Services.Presets.Factories preset.PictureColorspacePreset = export.Task.Colourspace?.Key; preset.PictureColorspaceCustom = export.Task.CustomColourspace; + preset.PictureChromaSmoothPreset = export.Task.ChromaSmooth?.Key; + preset.PictureChromaSmoothTune = export.Task.ChromaSmoothTune?.Key; + preset.PictureChromaSmoothCustom = export.Task.CustomChromaSmooth; + // Video preset.VideoEncoder = EnumHelper.GetShortName(export.Task.VideoEncoder); preset.VideoFramerate = export.Task.Framerate.HasValue ? export.Task.Framerate.ToString() : null; diff --git a/win/CS/HandBrakeWPF/ViewModelItems/Filters/ChromaSmoothFilter.cs b/win/CS/HandBrakeWPF/ViewModelItems/Filters/ChromaSmoothFilter.cs new file mode 100644 index 000000000..3895b6648 --- /dev/null +++ b/win/CS/HandBrakeWPF/ViewModelItems/Filters/ChromaSmoothFilter.cs @@ -0,0 +1,191 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Defines the Chroma Smooth Filter type. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.ViewModelItems.Filters +{ + using System.ComponentModel; + using System.Linq; + + using Caliburn.Micro; + + using HandBrake.Interop.Interop; + using HandBrake.Interop.Interop.HbLib; + using HandBrake.Interop.Interop.Model.Encoding; + + using HandBrakeWPF.Model.Filters; + using HandBrakeWPF.Services.Encode.Model; + using HandBrakeWPF.Services.Presets.Model; + using HandBrakeWPF.Services.Scan.Model; + + using Action = System.Action; + + public class ChromaSmoothFilter : PropertyChangedBase + { + public static readonly string Off = "off"; + public static readonly string Custom = "custom"; + + private readonly Action triggerTabChanged; + + public ChromaSmoothFilter(EncodeTask currentTask, Action triggerTabChanged) + { + this.triggerTabChanged = triggerTabChanged; + this.CurrentTask = currentTask; + + this.SetPresets(); + this.SetTunes(); + } + + public EncodeTask CurrentTask { get; private set; } + + public BindingList Presets { get; set; } + + public BindingList Tunes { get; set; } + + public bool ShowTune => this.SelectedPreset != null && this.SelectedPreset.Key != Off && this.SelectedPreset.Key != Custom; + + public bool ShowCustom => this.SelectedPreset != null && this.SelectedPreset.Key == Custom; + + public FilterPreset SelectedPreset + { + get => this.CurrentTask.ChromaSmooth; + + set + { + if (Equals(value, this.CurrentTask.ChromaSmooth)) + { + return; + } + + this.CurrentTask.ChromaSmooth = value; + + this.NotifyOfPropertyChange(() => this.SelectedPreset); + this.NotifyOfPropertyChange(() => this.ShowTune); + this.NotifyOfPropertyChange(() => this.ShowCustom); + + if (this.SelectedTune == null) + { + this.SelectedTune = this.Tunes.FirstOrDefault(); + } + + this.triggerTabChanged(); + } + } + + public FilterTune SelectedTune + { + get => this.CurrentTask.ChromaSmoothTune; + + set + { + if (Equals(value, this.CurrentTask.ChromaSmoothTune)) + { + return; + } + + this.CurrentTask.ChromaSmoothTune = value; + + this.NotifyOfPropertyChange(() => this.SelectedTune); + this.triggerTabChanged(); + } + } + + public string CustomSettings + { + get => this.CurrentTask.CustomChromaSmooth; + + set + { + if (value == this.CurrentTask.CustomChromaSmooth) + { + return; + } + + this.CurrentTask.CustomChromaSmooth = value; + this.NotifyOfPropertyChange(() => this.CustomSettings); + } + } + + public void SetPreset(Preset preset, EncodeTask task) + { + this.CurrentTask = task; + + if (preset == null) + { + this.SelectedPreset = new FilterPreset(HandBrakeFilterHelpers.GetFilterPresets((int)hb_filter_ids.HB_FILTER_CHROMA_SMOOTH).FirstOrDefault(s => s.ShortName == "off")); + this.CustomSettings = string.Empty; + this.SelectedTune = null; + return; + } + + this.SelectedPreset = preset.Task.ChromaSmooth; + this.SelectedTune = preset.Task.ChromaSmoothTune; + this.CustomSettings = preset.Task.CustomChromaSmooth; + } + + public void UpdateTask(EncodeTask task) + { + this.CurrentTask = task; + this.NotifyOfPropertyChange(() => this.SelectedPreset); + this.NotifyOfPropertyChange(() => this.SelectedTune); + this.NotifyOfPropertyChange(() => this.CustomSettings); + + this.NotifyOfPropertyChange(() => this.ShowTune); + this.NotifyOfPropertyChange(() => this.ShowCustom); + } + + public bool MatchesPreset(Preset preset) + { + if (this.SelectedPreset?.Key != preset.Task?.ChromaSmooth?.Key) + { + return false; + } + + if (this.SelectedTune.Key != preset?.Task?.ChromaSmoothTune.Key) + { + return false; + } + + if (this.CustomSettings != preset?.Task?.CustomChromaSmooth) + { + return false; + } + + return true; + } + + public void SetSource(Source source, Title title, Preset preset, EncodeTask task) + { + this.CurrentTask = task; + } + + private void SetPresets() + { + BindingList presets = new BindingList(); + foreach (HBPresetTune tune in HandBrakeFilterHelpers.GetFilterPresets((int)hb_filter_ids.HB_FILTER_CHROMA_SMOOTH)) + { + presets.Add(new FilterPreset(tune)); + } + + this.Presets = presets; + this.NotifyOfPropertyChange(() => this.Presets); + } + + private void SetTunes() + { + BindingList tunes = new BindingList(); + foreach (HBPresetTune tune in HandBrakeFilterHelpers.GetFilterTunes((int)hb_filter_ids.HB_FILTER_CHROMA_SMOOTH)) + { + tunes.Add(new FilterTune(tune)); + } + + this.Tunes = tunes; + this.NotifyOfPropertyChange(() => this.Tunes); + } + } +} diff --git a/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs index d1e58f589..4a4266255 100644 --- a/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs @@ -33,6 +33,7 @@ namespace HandBrakeWPF.ViewModels this.DeblockFilter = new DeblockFilter(this.CurrentTask, () => this.OnTabStatusChanged(null)); this.GrayscaleFilter = new GrayscaleFilter(this.CurrentTask, () => this.OnTabStatusChanged(null)); this.ColourSpaceFilter = new ColourSpaceFilter(this.CurrentTask, () => this.OnTabStatusChanged(null)); + this.ChromaSmoothFilter = new ChromaSmoothFilter(this.CurrentTask, () => this.OnTabStatusChanged(null)); } public event EventHandler TabStatusChanged; @@ -52,6 +53,8 @@ namespace HandBrakeWPF.ViewModels public ColourSpaceFilter ColourSpaceFilter { get; set; } public GrayscaleFilter GrayscaleFilter { get; set; } + + public ChromaSmoothFilter ChromaSmoothFilter { get; set; } public void SetPreset(Preset preset, EncodeTask task) { @@ -63,6 +66,7 @@ namespace HandBrakeWPF.ViewModels this.DeinterlaceFilter.SetPreset(preset, task); this.DeblockFilter.SetPreset(preset, task); this.ColourSpaceFilter.SetPreset(preset, task); + this.ChromaSmoothFilter.SetPreset(preset, task); } public void UpdateTask(EncodeTask task) @@ -76,6 +80,7 @@ namespace HandBrakeWPF.ViewModels this.DeblockFilter.UpdateTask(task); this.GrayscaleFilter.UpdateTask(task); this.ColourSpaceFilter.UpdateTask(task); + this.ChromaSmoothFilter.UpdateTask(task); } public bool MatchesPreset(Preset preset) @@ -115,6 +120,11 @@ namespace HandBrakeWPF.ViewModels return false; } + if (!this.ChromaSmoothFilter.MatchesPreset(preset)) + { + return false; + } + return true; } @@ -128,6 +138,7 @@ namespace HandBrakeWPF.ViewModels this.DeblockFilter.SetSource(source, title, preset, task); this.GrayscaleFilter.SetSource(source, title, preset, task); this.ColourSpaceFilter.SetSource(source, title, preset, task); + this.ChromaSmoothFilter.SetSource(source, title, preset, task); } protected virtual void OnTabStatusChanged(TabStatusEventArgs e) diff --git a/win/CS/HandBrakeWPF/Views/FiltersView.xaml b/win/CS/HandBrakeWPF/Views/FiltersView.xaml index a164c9ac9..38291fef9 100644 --- a/win/CS/HandBrakeWPF/Views/FiltersView.xaml +++ b/win/CS/HandBrakeWPF/Views/FiltersView.xaml @@ -42,6 +42,7 @@ + @@ -93,13 +94,13 @@ - + - + Visibility="{Binding DenoiseFilter.ShowDenoiseTune, Converter={StaticResource boolToVisConverter}}" VerticalAlignment="Center" /> - + + + + + + + + + + + + + - + - - + - @@ -172,22 +193,22 @@ - - + - + - + @@ -195,8 +216,8 @@ - - + - + - -- cgit v1.2.3