From 64e15a878106652f723bd0d72c3a32a3e7e184c8 Mon Sep 17 00:00:00 2001 From: sr55 Date: Sat, 30 Jan 2021 17:20:03 +0000 Subject: WinGui: Add support for the colourspace filter. --- .../Queue/FilterSettingsDescConverter.cs | 7 +- .../HandBrakeWPF/Properties/Resources.Designer.cs | 18 +++ win/CS/HandBrakeWPF/Properties/Resources.resx | 6 + .../Properties/ResourcesTooltips.Designer.cs | 9 ++ .../HandBrakeWPF/Properties/ResourcesTooltips.resx | 7 +- .../Services/Encode/Factories/EncodeTaskFactory.cs | 14 ++ .../Services/Encode/Model/EncodeTask.cs | 6 + .../Presets/Factories/JsonPresetFactory.cs | 13 ++ .../ViewModelItems/Filters/ColourspaceFilter.cs | 141 +++++++++++++++++++++ win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs | 13 +- win/CS/HandBrakeWPF/Views/FiltersView.xaml | 20 ++- 11 files changed, 249 insertions(+), 5 deletions(-) create mode 100644 win/CS/HandBrakeWPF/ViewModelItems/Filters/ColourspaceFilter.cs (limited to 'win/CS/HandBrakeWPF') diff --git a/win/CS/HandBrakeWPF/Converters/Queue/FilterSettingsDescConverter.cs b/win/CS/HandBrakeWPF/Converters/Queue/FilterSettingsDescConverter.cs index d9ef55f22..0707457f2 100644 --- a/win/CS/HandBrakeWPF/Converters/Queue/FilterSettingsDescConverter.cs +++ b/win/CS/HandBrakeWPF/Converters/Queue/FilterSettingsDescConverter.cs @@ -61,11 +61,16 @@ namespace HandBrakeWPF.Converters.Queue filters.Add(Resources.SummaryView_Rotation); } + if (task.Colourspace != null && task.Colourspace.Key != ColourSpaceFilter.Off) + { + filters.Add(Resources.SummaryView_Colourspace); + } + if (filters.Count == 0) { return Resources.SummaryView_NoFilters; } - + return string.Join(", ", filters).TrimEnd(',').Trim(); } diff --git a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs index 601dabd99..115f5befe 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 Colourspace:. + /// + public static string FiltersView_ColourSpace { + get { + return ResourceManager.GetString("FiltersView_ColourSpace", resourceCulture); + } + } + /// /// Looks up a localized string similar to Custom:. /// @@ -6141,6 +6150,15 @@ namespace HandBrakeWPF.Properties { } } + /// + /// Looks up a localized string similar to Colourspace. + /// + public static string SummaryView_Colourspace { + get { + return ResourceManager.GetString("SummaryView_Colourspace", resourceCulture); + } + } + /// /// Looks up a localized string similar to Deblock. /// diff --git a/win/CS/HandBrakeWPF/Properties/Resources.resx b/win/CS/HandBrakeWPF/Properties/Resources.resx index 34943b9e6..76cd45b47 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.resx +++ b/win/CS/HandBrakeWPF/Properties/Resources.resx @@ -2417,4 +2417,10 @@ Fields are limited to: (Requires Restart) + + Colourspace: + + + Colourspace + \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.Designer.cs b/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.Designer.cs index 4e2e746bd..2e053e9f7 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 Colourspace Filter.. + /// + public static string FiltersView_ColourSpace { + get { + return ResourceManager.GetString("FiltersView_ColourSpace", resourceCulture); + } + } + /// /// Looks up a localized string similar to Custom Denoise parameters. /// diff --git a/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.resx b/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.resx index b65e11e36..8690319ae 100644 --- a/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.resx +++ b/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.resx @@ -112,10 +112,10 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Deblock reduces blocky artifacts caused by low quality video compression. @@ -465,4 +465,7 @@ Lapsharp's Sprite tune is useful for 1-/4-/8-/16-bit 2-dimensional games. Sprite When enabled the auto name system will always use the default path. When disabled, it will use the path in the destination box on the main window if populated, otherwise it will use the default path. + + Colourspace 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 da1fcf678..faba29387 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeTaskFactory.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeTaskFactory.cs @@ -486,6 +486,20 @@ namespace HandBrakeWPF.Services.Encode.Factories } } + // Colourspace + if (job.Colourspace != null && job.Colourspace.Key != "off") + { + string unparsedJson = HandBrakeFilterHelpers.GenerateFilterSettingJson((int)hb_filter_ids.HB_FILTER_COLORSPACE, job.Colourspace.Key, null, job.CustomColourspace); + if (!string.IsNullOrEmpty(unparsedJson)) + { + JsonDocument settings = JsonDocument.Parse(unparsedJson); + + Filter filterItem = new Filter { ID = (int)hb_filter_ids.HB_FILTER_COLORSPACE, 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 710127d0c..bd50f19cf 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/Model/EncodeTask.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/Model/EncodeTask.cs @@ -91,6 +91,8 @@ namespace HandBrakeWPF.Services.Encode.Model this.SharpenTune = task.SharpenTune; this.SharpenCustom = task.SharpenCustom; this.Padding = task.Padding; + this.Colourspace = task.Colourspace; + this.CustomColourspace = task.CustomColourspace; this.DisplayWidth = task.DisplayWidth; this.EndPoint = task.EndPoint; @@ -237,6 +239,10 @@ namespace HandBrakeWPF.Services.Encode.Model public string CustomDeblock { get; set; } public PaddingFilter Padding { get; set; } + + public FilterPreset Colourspace { get; set; } + + public string CustomColourspace { get; set; } /* Video */ diff --git a/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs b/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs index 4559f61f5..bf116c183 100644 --- a/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs +++ b/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs @@ -88,6 +88,16 @@ namespace HandBrakeWPF.Services.Presets.Factories /* Filter Settings */ preset.Task.Grayscale = importedPreset.VideoGrayScale; + if (!string.IsNullOrEmpty(importedPreset.PictureColorspacePreset)) + { + preset.Task.Colourspace = new FilterPreset(HandBrakeFilterHelpers.GetFilterPresets((int)hb_filter_ids.HB_FILTER_COLORSPACE).FirstOrDefault(s => s.ShortName == importedPreset.PictureColorspacePreset)); + preset.Task.CustomColourspace = importedPreset.PictureColorspaceCustom; + } + else + { + preset.Task.Colourspace = new FilterPreset("Off", "off"); + } + if (!string.IsNullOrEmpty(importedPreset.PictureDeblockPreset)) { preset.Task.DeblockPreset = new FilterPreset(HandBrakeFilterHelpers.GetFilterPresets((int)hb_filter_ids.HB_FILTER_DEBLOCK).FirstOrDefault(s => s.ShortName == importedPreset.PictureDeblockPreset)); @@ -635,6 +645,9 @@ namespace HandBrakeWPF.Services.Presets.Factories preset.PictureSharpenTune = export.Task.SharpenTune != null ? export.Task.SharpenTune.Key : string.Empty; preset.PictureSharpenCustom = export.Task.SharpenCustom; + preset.PictureColorspacePreset = export.Task.Colourspace?.Key; + preset.PictureColorspaceCustom = export.Task.CustomColourspace; + // 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/ColourspaceFilter.cs b/win/CS/HandBrakeWPF/ViewModelItems/Filters/ColourspaceFilter.cs new file mode 100644 index 000000000..5d251bc99 --- /dev/null +++ b/win/CS/HandBrakeWPF/ViewModelItems/Filters/ColourspaceFilter.cs @@ -0,0 +1,141 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Defines the ColourSpaceFilter 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 ColourSpaceFilter : PropertyChangedBase + { + public static readonly string Off = "off"; + public static readonly string Custom = "custom"; + + private readonly Action triggerTabChanged; + + public ColourSpaceFilter(EncodeTask currentTask, Action triggerTabChanged) + { + this.triggerTabChanged = triggerTabChanged; + this.CurrentTask = currentTask; + + this.SetPresets(); + } + + public EncodeTask CurrentTask { get; private set; } + + public object Presets { get; set; } + + public bool ShowColourspaceCustom => this.SelectedPreset != null && this.SelectedPreset.Key == Custom; + + public FilterPreset SelectedPreset + { + get => this.CurrentTask.Colourspace; + + set + { + if (Equals(value, this.CurrentTask.Colourspace)) + { + return; + } + + this.CurrentTask.Colourspace = value; + + this.NotifyOfPropertyChange(() => this.SelectedPreset); + this.NotifyOfPropertyChange(() => this.ShowColourspaceCustom); + this.NotifyOfPropertyChange(() => this.ShowColourspaceCustom); + this.triggerTabChanged(); + } + } + + public string CustomColourspace + { + get => this.CurrentTask.CustomColourspace; + + set + { + if (value == this.CurrentTask.CustomColourspace) + { + return; + } + + this.CurrentTask.CustomColourspace = value; + this.NotifyOfPropertyChange(() => this.CustomColourspace); + } + } + + 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_COLORSPACE).FirstOrDefault(s => s.ShortName == "off")); + this.CustomColourspace = string.Empty; + return; + } + + this.SelectedPreset = preset.Task.Colourspace; + this.CustomColourspace = preset.Task.CustomColourspace; + } + + public void UpdateTask(EncodeTask task) + { + this.CurrentTask = task; + this.NotifyOfPropertyChange(() => this.SelectedPreset); + this.NotifyOfPropertyChange(() => this.CustomColourspace); + + this.NotifyOfPropertyChange(() => this.ShowColourspaceCustom); + } + + public bool MatchesPreset(Preset preset) + { + if (this.SelectedPreset?.Key != preset.Task?.Colourspace?.Key) + { + return false; + } + + if (this.CustomColourspace != preset?.Task?.CustomColourspace) + { + 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_COLORSPACE)) + { + presets.Add(new FilterPreset(tune)); + } + + this.Presets = presets; + this.NotifyOfPropertyChange(() => this.Presets); + } + } +} diff --git a/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs index f43bb6af5..d1e58f589 100644 --- a/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs @@ -18,7 +18,7 @@ namespace HandBrakeWPF.ViewModels using HandBrakeWPF.ViewModelItems.Filters; using HandBrakeWPF.ViewModels.Interfaces; - using EncodeTask = HandBrakeWPF.Services.Encode.Model.EncodeTask; + using EncodeTask = Services.Encode.Model.EncodeTask; public class FiltersViewModel : ViewModelBase, IFiltersViewModel { @@ -32,6 +32,7 @@ namespace HandBrakeWPF.ViewModels this.DeinterlaceFilter = new DeinterlaceFilterItem(this.CurrentTask, () => this.OnTabStatusChanged(null)); 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)); } public event EventHandler TabStatusChanged; @@ -48,6 +49,8 @@ namespace HandBrakeWPF.ViewModels public DeblockFilter DeblockFilter { get; set; } + public ColourSpaceFilter ColourSpaceFilter { get; set; } + public GrayscaleFilter GrayscaleFilter { get; set; } public void SetPreset(Preset preset, EncodeTask task) @@ -59,6 +62,7 @@ namespace HandBrakeWPF.ViewModels this.DetelecineFilter.SetPreset(preset, task); this.DeinterlaceFilter.SetPreset(preset, task); this.DeblockFilter.SetPreset(preset, task); + this.ColourSpaceFilter.SetPreset(preset, task); } public void UpdateTask(EncodeTask task) @@ -71,6 +75,7 @@ namespace HandBrakeWPF.ViewModels this.DeinterlaceFilter.UpdateTask(task); this.DeblockFilter.UpdateTask(task); this.GrayscaleFilter.UpdateTask(task); + this.ColourSpaceFilter.UpdateTask(task); } public bool MatchesPreset(Preset preset) @@ -105,6 +110,11 @@ namespace HandBrakeWPF.ViewModels return false; } + if (!this.ColourSpaceFilter.MatchesPreset(preset)) + { + return false; + } + return true; } @@ -117,6 +127,7 @@ namespace HandBrakeWPF.ViewModels this.DeinterlaceFilter.SetSource(source, title, preset, task); this.DeblockFilter.SetSource(source, title, preset, task); this.GrayscaleFilter.SetSource(source, title, preset, task); + this.ColourSpaceFilter.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 5a14d9f8f..a164c9ac9 100644 --- a/win/CS/HandBrakeWPF/Views/FiltersView.xaml +++ b/win/CS/HandBrakeWPF/Views/FiltersView.xaml @@ -41,6 +41,7 @@ + @@ -191,8 +192,25 @@ + + + + + + + + + + + + - -- cgit v1.2.3