From 27f366140509b18897f0dc54194a1a0d55cf0bb6 Mon Sep 17 00:00:00 2001 From: sr55 Date: Fri, 2 Jun 2017 22:03:16 +0100 Subject: WinGui: Support for the new sharpen filter. --- .../HandBrake.ApplicationServices.csproj | 1 + .../Interop/HbLib/hb_filter_ids.cs | 2 + .../Interop/Json/Presets/HBPreset.cs | 5 + .../Interop/Model/Encoding/Sharpen.cs | 28 +++++ .../HandBrakeWPF/Converters/EnumComboConverter.cs | 13 ++ .../Converters/Filters/SharpenPresetConverter.cs | 58 +++++++++ .../Converters/Filters/SharpenTuneConverter.cs | 58 +++++++++ win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 4 + win/CS/HandBrakeWPF/Model/Filters/FilterPreset.cs | 53 ++++++++ win/CS/HandBrakeWPF/Model/Filters/FilterTune.cs | 53 ++++++++ .../Properties/ResourcesTooltips.Designer.cs | 54 ++++++++ .../HandBrakeWPF/Properties/ResourcesTooltips.resx | 36 ++++++ .../Properties/ResourcesUI.Designer.cs | 9 ++ win/CS/HandBrakeWPF/Properties/ResourcesUI.resx | 3 + .../Services/Encode/Factories/EncodeFactory.cs | 19 +++ .../Services/Encode/Model/EncodeTask.cs | 13 +- .../Presets/Factories/JsonPresetFactory.cs | 37 ++++++ win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs | 136 ++++++++++++++++++++- win/CS/HandBrakeWPF/Views/FiltersView.xaml | 58 +++++++-- 19 files changed, 626 insertions(+), 14 deletions(-) create mode 100644 win/CS/HandBrake.ApplicationServices/Interop/Model/Encoding/Sharpen.cs create mode 100644 win/CS/HandBrakeWPF/Converters/Filters/SharpenPresetConverter.cs create mode 100644 win/CS/HandBrakeWPF/Converters/Filters/SharpenTuneConverter.cs create mode 100644 win/CS/HandBrakeWPF/Model/Filters/FilterPreset.cs create mode 100644 win/CS/HandBrakeWPF/Model/Filters/FilterTune.cs (limited to 'win/CS') diff --git a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj index c5f5555e9..a14159890 100644 --- a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj +++ b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj @@ -128,6 +128,7 @@ + diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HbLib/hb_filter_ids.cs b/win/CS/HandBrake.ApplicationServices/Interop/HbLib/hb_filter_ids.cs index 76059fe8b..63e279410 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/HbLib/hb_filter_ids.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/HbLib/hb_filter_ids.cs @@ -27,6 +27,8 @@ namespace HandBrake.ApplicationServices.Interop.HbLib HB_FILTER_NLMEANS, HB_FILTER_RENDER_SUB, HB_FILTER_CROP_SCALE, + HB_FILTER_LAPSHARP, + HB_FILTER_UNSHARP, HB_FILTER_ROTATE, HB_FILTER_GRAYSCALE, HB_FILTER_PAD, diff --git a/win/CS/HandBrake.ApplicationServices/Interop/Json/Presets/HBPreset.cs b/win/CS/HandBrake.ApplicationServices/Interop/Json/Presets/HBPreset.cs index 7e1e94697..6ddb9c0c2 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/Json/Presets/HBPreset.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/Json/Presets/HBPreset.cs @@ -166,6 +166,11 @@ namespace HandBrake.ApplicationServices.Interop.Json.Presets /// public string PictureDenoiseTune { get; set; } + public string PictureSharpenCustom { get; set; } + public string PictureSharpenFilter { get; set; } + public string PictureSharpenPreset { get; set; } + public string PictureSharpenTune { get; set; } + /// /// Gets or sets the picture detelecine. /// diff --git a/win/CS/HandBrake.ApplicationServices/Interop/Model/Encoding/Sharpen.cs b/win/CS/HandBrake.ApplicationServices/Interop/Model/Encoding/Sharpen.cs new file mode 100644 index 000000000..7f5b9e75a --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Interop/Model/Encoding/Sharpen.cs @@ -0,0 +1,28 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Defines the Sharpen type. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrake.ApplicationServices.Interop.Model.Encoding +{ + using HandBrake.ApplicationServices.Attributes; + + /// + /// The Sharpen. + /// + public enum Sharpen + { + [ShortName("off")] + Off, + + [ShortName("unsharp")] + UnSharp, + + [ShortName("lapsharp")] + LapSharp + } +} diff --git a/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs b/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs index 91c30311a..c9afb8c14 100644 --- a/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs +++ b/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs @@ -91,6 +91,10 @@ namespace HandBrakeWPF.Converters { return EnumHelper.GetEnumDisplayValues(typeof(CombDetect)); } + if (value is IEnumerable) + { + return EnumHelper.GetEnumDisplayValues(typeof(Sharpen)); + } // Single Items if (targetType == typeof(VideoEncoder) || value.GetType() == typeof(VideoEncoder)) @@ -140,6 +144,10 @@ namespace HandBrakeWPF.Converters { return EnumHelper.GetDisplay((CombDetect)value); } + if (targetType == typeof(Sharpen) || value.GetType() == typeof(Sharpen)) + { + return EnumHelper.GetDisplay((Sharpen)value); + } return null; } @@ -210,6 +218,11 @@ namespace HandBrakeWPF.Converters { return EnumHelper.GetValue(value.ToString()); } + + if (targetType == typeof(Sharpen) || value.GetType() == typeof(Sharpen)) + { + return EnumHelper.GetValue(value.ToString()); + } return null; } } diff --git a/win/CS/HandBrakeWPF/Converters/Filters/SharpenPresetConverter.cs b/win/CS/HandBrakeWPF/Converters/Filters/SharpenPresetConverter.cs new file mode 100644 index 000000000..417b0d155 --- /dev/null +++ b/win/CS/HandBrakeWPF/Converters/Filters/SharpenPresetConverter.cs @@ -0,0 +1,58 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// A converter to fetch the sharpen presets +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Converters.Filters +{ + using System; + using System.ComponentModel; + using System.Globalization; + using System.Windows.Data; + + using HandBrake.ApplicationServices.Interop; + using HandBrake.ApplicationServices.Interop.HbLib; + using HandBrake.ApplicationServices.Interop.Model.Encoding; + + using HandBrakeWPF.Model.Filters; + + public class SharpenPresetConverter : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + if (values.Length == 2) + { + Sharpen selectedSharpen = (Sharpen)values[1]; + if (selectedSharpen == Sharpen.LapSharp) + { + BindingList presets = new BindingList(); + foreach (HBPresetTune preset in HandBrakeFilterHelpers.GetFilterPresets((int)hb_filter_ids.HB_FILTER_LAPSHARP)) + { + presets.Add(new FilterPreset(preset)); + } + return presets; + } + else if (selectedSharpen == Sharpen.UnSharp) + { + BindingList presets = new BindingList(); + foreach (HBPresetTune preset in HandBrakeFilterHelpers.GetFilterPresets((int)hb_filter_ids.HB_FILTER_UNSHARP)) + { + presets.Add(new FilterPreset(preset)); + } + return presets; + } + } + + return new BindingList(); + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + return null; + } + } +} diff --git a/win/CS/HandBrakeWPF/Converters/Filters/SharpenTuneConverter.cs b/win/CS/HandBrakeWPF/Converters/Filters/SharpenTuneConverter.cs new file mode 100644 index 000000000..72d40e3ae --- /dev/null +++ b/win/CS/HandBrakeWPF/Converters/Filters/SharpenTuneConverter.cs @@ -0,0 +1,58 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// A converter to fetch the sharpen tunes +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Converters.Filters +{ + using System; + using System.ComponentModel; + using System.Globalization; + using System.Windows.Data; + + using HandBrake.ApplicationServices.Interop; + using HandBrake.ApplicationServices.Interop.HbLib; + using HandBrake.ApplicationServices.Interop.Model.Encoding; + + using HandBrakeWPF.Model.Filters; + + public class SharpenTuneConverter : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + if (values.Length == 2) + { + Sharpen selectedSharpen = (Sharpen)values[1]; + if (selectedSharpen == Sharpen.LapSharp) + { + BindingList tunes = new BindingList(); + foreach (HBPresetTune tune in HandBrakeFilterHelpers.GetFilterTunes((int)hb_filter_ids.HB_FILTER_LAPSHARP)) + { + tunes.Add(new FilterTune(tune)); + } + return tunes; + } + else if (selectedSharpen == Sharpen.UnSharp) + { + BindingList tunes = new BindingList(); + foreach (HBPresetTune tune in HandBrakeFilterHelpers.GetFilterTunes((int)hb_filter_ids.HB_FILTER_UNSHARP)) + { + tunes.Add(new FilterTune(tune)); + } + return tunes; + } + } + + return new BindingList(); + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + return null; + } + } +} diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index 44c58bc0f..393bba2a4 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -155,6 +155,8 @@ + + @@ -178,6 +180,8 @@ + + diff --git a/win/CS/HandBrakeWPF/Model/Filters/FilterPreset.cs b/win/CS/HandBrakeWPF/Model/Filters/FilterPreset.cs new file mode 100644 index 000000000..8745e68f6 --- /dev/null +++ b/win/CS/HandBrakeWPF/Model/Filters/FilterPreset.cs @@ -0,0 +1,53 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Preset Filter +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Model.Filters +{ + using HandBrake.ApplicationServices.Interop.Model.Encoding; + + public class FilterPreset + { + public FilterPreset() + { + } + + public FilterPreset(string displayName, string key) + { + this.DisplayName = displayName; + this.Key = key; + } + + public FilterPreset(HBPresetTune presetTune) + { + this.DisplayName = presetTune.Name; + this.Key = presetTune.ShortName; + } + + public string DisplayName { get; set; } + public string Key { get; set; } + + protected bool Equals(FilterPreset other) + { + return string.Equals(this.Key, other.Key); + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != this.GetType()) return false; + return Equals((FilterPreset)obj); + } + + public override int GetHashCode() + { + return (this.Key != null ? this.Key.GetHashCode() : 0); + } + } +} diff --git a/win/CS/HandBrakeWPF/Model/Filters/FilterTune.cs b/win/CS/HandBrakeWPF/Model/Filters/FilterTune.cs new file mode 100644 index 000000000..6f804a551 --- /dev/null +++ b/win/CS/HandBrakeWPF/Model/Filters/FilterTune.cs @@ -0,0 +1,53 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Preset Tune +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Model.Filters +{ + using HandBrake.ApplicationServices.Interop.Model.Encoding; + + public class FilterTune + { + public FilterTune() + { + } + + public FilterTune(string displayName, string key) + { + this.DisplayName = displayName; + this.Key = key; + } + + public FilterTune(HBPresetTune presetTune) + { + this.DisplayName = presetTune.Name; + this.Key = presetTune.ShortName; + } + + public string DisplayName { get; set; } + public string Key { get; set; } + + protected bool Equals(FilterTune other) + { + return string.Equals(this.Key, other.Key); + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != this.GetType()) return false; + return Equals((FilterTune)obj); + } + + public override int GetHashCode() + { + return this.Key != null ? this.Key.GetHashCode() : 0; + } + } +} diff --git a/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.Designer.cs b/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.Designer.cs index ca1faa57d..5f16110fe 100644 --- a/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.Designer.cs +++ b/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.Designer.cs @@ -75,6 +75,23 @@ namespace HandBrakeWPF.Properties { } } + /// + /// Looks up a localized string similar to Custom Sharpen parameters. + /// + ///Unsharp syntax: y-strength=y:y-size=y:cb-strength=c:cb-size=c:cr-strength=c:cr-size=c + /// + ///Unsharp default: y-strength=0.25:y-size=7:cb-strength=0.25:cb-size=7 + /// + ///Lapsharp syntax: y-strength=y:y-kernel=y:cb-strength=c:cb-kernel=c:cr-strength=c:cr-kernel=c + /// + ///Lapsharp default: y-strength=0.2:y-kernel=isolap:cb-strength=0.2:cb-kernel=isolap. + /// + public static string FilterView_CustomSharpenParams { + get { + return ResourceManager.GetString("FilterView_CustomSharpenParams", resourceCulture); + } + } + /// /// Looks up a localized string similar to Deblock reduces blocky artifacts caused by low quality video compression.. /// @@ -248,6 +265,43 @@ namespace HandBrakeWPF.Properties { } } + /// + /// Looks up a localized string similar to Sharpening enhances the appearance of detail, especially edges. Overly strong Sharpen settings may damage picture quality and by creating ringing artifacts and enhancing noise, which can reduce compression efficiency. + /// + ///Unsharp is a general purpose unsharp masking filter. It sharpens by blurring, then calculating the difference between the blurred picture and the original. + /// + ///Lapsharp sharpens by using convolution kernels approximating Laplacian edge filters, sometimes producing higher quality results than [rest of string was truncated]";. + /// + public static string FilterView_Sharpen { + get { + return ResourceManager.GetString("FilterView_Sharpen", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Sharpen filter preset. Sets the strength of the filter.. + /// + public static string FilterView_SharpenPreset { + get { + return ResourceManager.GetString("FilterView_SharpenPreset", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Sharpen tune. Further adjusts the Sharpen preset to optimize settings for specific scenarios. + /// + ///None uses the default preset settings. + /// + ///Unsharp can be tuned for Fine, Medium-Fine, Medium, Medium-Coarse, or Coarse sharpening. Select one based on the output picture resolution and fineness of detail to enhance. + /// + ///Lapsharp's Film tune refines settings for use with most live action content. Film uses an isotropic Laplacian kernel to sharpen all edges similarly, and luminance (brightness) information is sharp [rest of string was truncated]";. + /// + public static string FilterView_SharpenTune { + get { + return ResourceManager.GetString("FilterView_SharpenTune", resourceCulture); + } + } + /// /// Looks up a localized string similar to Add a new preset.. /// diff --git a/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.resx b/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.resx index fe02d4fa0..4792a539f 100644 --- a/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.resx +++ b/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.resx @@ -418,4 +418,40 @@ Bob attempts to better preserve motion for a slight penalty to perceived resolut Keep Aspect Ratio maintains the original display aspect of the source. Disabling this may result in a stretched or squeezed picture. + + Custom Sharpen parameters. + +Unsharp syntax: y-strength=y:y-size=y:cb-strength=c:cb-size=c:cr-strength=c:cr-size=c + +Unsharp default: y-strength=0.25:y-size=7:cb-strength=0.25:cb-size=7 + +Lapsharp syntax: y-strength=y:y-kernel=y:cb-strength=c:cb-kernel=c:cr-strength=c:cr-kernel=c + +Lapsharp default: y-strength=0.2:y-kernel=isolap:cb-strength=0.2:cb-kernel=isolap + + + Sharpening enhances the appearance of detail, especially edges. Overly strong Sharpen settings may damage picture quality and by creating ringing artifacts and enhancing noise, which can reduce compression efficiency. + +Unsharp is a general purpose unsharp masking filter. It sharpens by blurring, then calculating the difference between the blurred picture and the original. + +Lapsharp sharpens by using convolution kernels approximating Laplacian edge filters, sometimes producing higher quality results than unsharp masking. + + + Sharpen filter preset. Sets the strength of the filter. + + + Sharpen tune. Further adjusts the Sharpen preset to optimize settings for specific scenarios. + +None uses the default preset settings. + +Unsharp can be tuned for Fine, Medium-Fine, Medium, Medium-Coarse, or Coarse sharpening. Select one based on the output picture resolution and fineness of detail to enhance. + +Lapsharp's Film tune refines settings for use with most live action content. Film uses an isotropic Laplacian kernel to sharpen all edges similarly, and luminance (brightness) information is sharpened more than chrominance (color) information. + +Lapsharp's Grain tune is similar to Film, but uses an isotropic Laplacian of Gaussian kernel to reduce the effect on noise and grain. Useful for preserving grain and as a general alternative to the Film tune. + +Lapsharp's Animation tune is useful for cel animation such as anime and cartoons. Animation is identical to Film, but overall strength is reduced to avoid creating artifacts. + +Lapsharp's Sprite tune is useful for 1-/4-/8-/16-bit 2-dimensional games. Sprite uses a 4-neighbor Laplacian kernel that enhances vertical and horizontal edges more than diagonal edges. + \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Properties/ResourcesUI.Designer.cs b/win/CS/HandBrakeWPF/Properties/ResourcesUI.Designer.cs index f6a7898f0..594420109 100644 --- a/win/CS/HandBrakeWPF/Properties/ResourcesUI.Designer.cs +++ b/win/CS/HandBrakeWPF/Properties/ResourcesUI.Designer.cs @@ -501,6 +501,15 @@ namespace HandBrakeWPF.Properties { } } + /// + /// Looks up a localized string similar to Sharpen. + /// + public static string FiltersView_Sharpen { + get { + return ResourceManager.GetString("FiltersView_Sharpen", resourceCulture); + } + } + /// /// Looks up a localized string similar to Tune:. /// diff --git a/win/CS/HandBrakeWPF/Properties/ResourcesUI.resx b/win/CS/HandBrakeWPF/Properties/ResourcesUI.resx index 6dce889d2..34edf84b0 100644 --- a/win/CS/HandBrakeWPF/Properties/ResourcesUI.resx +++ b/win/CS/HandBrakeWPF/Properties/ResourcesUI.resx @@ -908,4 +908,7 @@ This will not affect your current settings in the Subtitle tab. Searching for start time + + Sharpen + \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeFactory.cs b/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeFactory.cs index 6647b7fdf..efa595c4b 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeFactory.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeFactory.cs @@ -488,6 +488,25 @@ namespace HandBrakeWPF.Services.Encode.Factories } } + // Sharpen + if (job.Sharpen != Sharpen.Off) + { + hb_filter_ids id = job.Sharpen == Sharpen.LapSharp + ? hb_filter_ids.HB_FILTER_LAPSHARP + : hb_filter_ids.HB_FILTER_UNSHARP; + + IntPtr settingsPtr = HBFunctions.hb_generate_filter_settings_json((int)id, job.SharpenPreset.Key, job.SharpenTune.Key, job.SharpenCustom); + string unparsedJson = Marshal.PtrToStringAnsi(settingsPtr); + + if (!string.IsNullOrEmpty(unparsedJson)) + { + JToken settings = JObject.Parse(unparsedJson); + + Filter filterItem = new Filter { ID = (int)id, Settings = settings }; + filter.FilterList.Add(filterItem); + } + } + // Deblock if (job.Deblock >= 5) { diff --git a/win/CS/HandBrakeWPF/Services/Encode/Model/EncodeTask.cs b/win/CS/HandBrakeWPF/Services/Encode/Model/EncodeTask.cs index 4d0da57fe..84d1eb7eb 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/Model/EncodeTask.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/Model/EncodeTask.cs @@ -17,6 +17,7 @@ namespace HandBrakeWPF.Services.Encode.Model using HandBrake.ApplicationServices.Interop.Model; using HandBrake.ApplicationServices.Interop.Model.Encoding; + using HandBrakeWPF.Model.Filters; using HandBrakeWPF.Services.Encode.Model.Models; using AllowedPassthru = HandBrakeWPF.Services.Encode.Model.Models.AllowedPassthru; @@ -33,9 +34,6 @@ namespace HandBrakeWPF.Services.Encode.Model using VideoProfile = HandBrakeWPF.Services.Encode.Model.Models.Video.VideoProfile; using VideoTune = HandBrakeWPF.Services.Encode.Model.Models.Video.VideoTune; - /// - /// An Encode Task - /// public class EncodeTask : PropertyChangedBase { #region Private Fields @@ -108,6 +106,10 @@ namespace HandBrakeWPF.Services.Encode.Model this.Detelecine = task.Detelecine; this.FlipVideo = task.FlipVideo; this.Rotation = task.Rotation; + this.Sharpen = task.Sharpen; + this.SharpenPreset = task.SharpenPreset; + this.SharpenTune = task.SharpenTune; + this.SharpenCustom = task.SharpenCustom; this.DisplayWidth = task.DisplayWidth; this.EndPoint = task.EndPoint; @@ -368,6 +370,11 @@ namespace HandBrakeWPF.Services.Encode.Model /// Flip the video. /// public bool FlipVideo { get; set; } + + public Sharpen Sharpen { get; set; } + public FilterPreset SharpenPreset { get; set; } + public FilterTune SharpenTune { get; set; } + public string SharpenCustom { get; set; } #endregion #region Video diff --git a/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs b/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs index a1b2b30a5..55eb3f1b9 100644 --- a/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs +++ b/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs @@ -9,12 +9,14 @@ namespace HandBrakeWPF.Services.Presets.Factories { + using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Globalization; using System.Linq; using HandBrake.ApplicationServices.Interop; + using HandBrake.ApplicationServices.Interop.HbLib; using HandBrake.ApplicationServices.Interop.Json.Presets; using HandBrake.ApplicationServices.Interop.Model; using HandBrake.ApplicationServices.Interop.Model.Encoding; @@ -22,6 +24,7 @@ namespace HandBrakeWPF.Services.Presets.Factories using HandBrake.ApplicationServices.Utilities; using HandBrakeWPF.Model.Audio; + using HandBrakeWPF.Model.Filters; using HandBrakeWPF.Model.Picture; using HandBrakeWPF.Model.Subtitles; using HandBrakeWPF.Services.Encode.Model.Models; @@ -100,6 +103,35 @@ namespace HandBrakeWPF.Services.Presets.Factories preset.Task.Grayscale = importedPreset.VideoGrayScale; preset.Task.Deblock = importedPreset.PictureDeblock; + if (importedPreset.PictureSharpenFilter != null) + { + preset.Task.Sharpen = EnumHelper.GetValue(importedPreset.PictureSharpenFilter); + hb_filter_ids filterId = hb_filter_ids.HB_FILTER_INVALID; + switch (preset.Task.Sharpen) + { + case Sharpen.LapSharp: + filterId = hb_filter_ids.HB_FILTER_LAPSHARP; + break; + case Sharpen.UnSharp: + filterId = hb_filter_ids.HB_FILTER_UNSHARP; + break; + } + + if (filterId != hb_filter_ids.HB_FILTER_INVALID) + { + preset.Task.SharpenPreset = new FilterPreset(HandBrakeFilterHelpers.GetFilterPresets((int)filterId).FirstOrDefault(s => s.ShortName == importedPreset.PictureSharpenPreset)); + preset.Task.SharpenTune = new FilterTune(HandBrakeFilterHelpers.GetFilterTunes((int)filterId).FirstOrDefault(s => s.ShortName == importedPreset.PictureSharpenTune)); + preset.Task.SharpenCustom = importedPreset.PictureSharpenCustom; + } + else + { + // Default Values. + preset.Task.SharpenPreset = new FilterPreset("Medium", "medium"); + preset.Task.SharpenTune = new FilterTune("None", "none"); + preset.Task.SharpenCustom = string.Empty; + } + } + switch (importedPreset.PictureDeinterlaceFilter) { case "decomb": @@ -613,6 +645,11 @@ namespace HandBrakeWPF.Services.Presets.Factories preset.PictureDetelecine = EnumHelper.GetShortName(export.Task.Detelecine); preset.PictureDetelecineCustom = export.Task.CustomDetelecine; + preset.PictureSharpenFilter = EnumHelper.GetShortName(export.Task.Sharpen); + preset.PictureSharpenPreset = export.Task.SharpenPreset != null ? export.Task.SharpenPreset.Key : string.Empty; + preset.PictureSharpenTune = export.Task.SharpenTune != null ? export.Task.SharpenTune.Key : string.Empty; + preset.PictureSharpenCustom = export.Task.SharpenCustom; + // Video preset.VideoEncoder = EnumHelper.GetShortName(export.Task.VideoEncoder); preset.VideoFramerate = export.Task.Framerate.ToString(); diff --git a/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs index 67476f57f..d3afd0e8b 100644 --- a/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs @@ -12,11 +12,15 @@ namespace HandBrakeWPF.ViewModels using System.Collections.Generic; using System.ComponentModel; using System.Globalization; + using System.Linq; using Caliburn.Micro; + using HandBrake.ApplicationServices.Interop; + using HandBrake.ApplicationServices.Interop.HbLib; using HandBrake.ApplicationServices.Interop.Model.Encoding; + using HandBrakeWPF.Model.Filters; using HandBrakeWPF.Services.Interfaces; using HandBrakeWPF.Services.Presets.Model; using HandBrakeWPF.Services.Scan.Model; @@ -594,11 +598,131 @@ namespace HandBrakeWPF.ViewModels } } + #region Sharpen Filter + + public IEnumerable SharpenOptions + { + get + { + return EnumHelper.GetEnumList(); + } + } + + public object SharpenPresets { get; set; } + + public object SharpenTunes { get; set; } + + public Sharpen SelectedSharpen + { + get + { + return this.CurrentTask.Sharpen; + } + + set + { + if (value == this.CurrentTask.Sharpen) return; + this.CurrentTask.Sharpen = value; + this.NotifyOfPropertyChange(() => this.SelectedSharpen); + this.NotifyOfPropertyChange(() => this.ShowSharpenOptions); + this.NotifyOfPropertyChange(() => this.ShowSharpenTune); + this.NotifyOfPropertyChange(() => this.ShowSharpenCustom); + + // Default preset and tune. + switch (value) + { + case Sharpen.LapSharp: + if (this.SelectedSharpenPreset == null) + this.SelectedSharpenPreset = new FilterPreset(HandBrakeFilterHelpers.GetFilterPresets((int)hb_filter_ids.HB_FILTER_LAPSHARP).FirstOrDefault(s => s.ShortName == "medium")); + if (this.SelectedSharpenTune == null) + this.SelectedSharpenTune = new FilterTune(HandBrakeFilterHelpers.GetFilterTunes((int)hb_filter_ids.HB_FILTER_LAPSHARP).FirstOrDefault(s => s.ShortName == "none")); + break; + case Sharpen.UnSharp: + if (this.SelectedSharpenPreset == null) + this.SelectedSharpenPreset = new FilterPreset(HandBrakeFilterHelpers.GetFilterPresets((int)hb_filter_ids.HB_FILTER_UNSHARP).FirstOrDefault(s => s.ShortName == "medium")); + if (this.SelectedSharpenTune == null) + this.SelectedSharpenTune = new FilterTune(HandBrakeFilterHelpers.GetFilterTunes((int)hb_filter_ids.HB_FILTER_UNSHARP).FirstOrDefault(s => s.ShortName == "none")); + break; + } + + this.NotifyOfPropertyChange(() => this.SelectedSharpenTune); + this.NotifyOfPropertyChange(() => this.SelectedSharpenPreset); + } + } + + public FilterPreset SelectedSharpenPreset + { + get + { + return this.CurrentTask.SharpenPreset; + } + set + { + if (Equals(value, this.CurrentTask.SharpenPreset)) return; + this.CurrentTask.SharpenPreset = value; + this.NotifyOfPropertyChange(() => this.SelectedSharpenPreset); + this.NotifyOfPropertyChange(() => this.ShowSharpenTune); + this.NotifyOfPropertyChange(() => this.ShowSharpenCustom); + } + } + + public FilterTune SelectedSharpenTune + { + get + { + return this.CurrentTask.SharpenTune; + } + set + { + if (value == this.CurrentTask.SharpenTune) return; + this.CurrentTask.SharpenTune = value; + this.NotifyOfPropertyChange(() => this.SelectedSharpenTune); + } + } + + public string CustomSharpen + { + get + { + return this.CurrentTask.SharpenCustom; + } + set + { + if (value == this.CurrentTask.SharpenCustom) return; + this.CurrentTask.SharpenCustom = value; + this.NotifyOfPropertyChange(() => this.CustomSharpen); + } + } + + public bool ShowSharpenTune + { + get + { + return this.SelectedSharpenPreset != null && this.SelectedSharpenPreset.DisplayName != "Custom"; + } + } + + public bool ShowSharpenCustom + { + get + { + return this.SelectedSharpenPreset != null && this.SelectedSharpenPreset.DisplayName == "Custom"; + } + } + + public bool ShowSharpenOptions + { + get + { + return this.SelectedSharpen != Sharpen.Off; + } + } + #endregion - #region Implemented Interfaces + #endregion - #region ITabInterface + #region Implemented Interfaces /// /// Setup this tab for the specified preset. @@ -641,6 +765,12 @@ namespace HandBrakeWPF.ViewModels this.SelectedDenoisePreset = preset.Task.DenoisePreset; this.SelectedDenoiseTune = preset.Task.DenoiseTune; + // Sharpen + this.SelectedSharpen = preset.Task.Sharpen; + this.SelectedSharpenPreset = preset.Task.SharpenPreset; + this.SelectedSharpenTune = preset.Task.SharpenTune; + this.CustomSharpen = preset.Task.SharpenCustom; + // Custom Values this.CustomDecomb = preset.Task.CustomDecomb; this.CustomDeinterlace = preset.Task.CustomDeinterlace; @@ -716,7 +846,5 @@ namespace HandBrakeWPF.ViewModels } #endregion - - #endregion } } \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Views/FiltersView.xaml b/win/CS/HandBrakeWPF/Views/FiltersView.xaml index 14ce4b75d..3dbc38ea5 100644 --- a/win/CS/HandBrakeWPF/Views/FiltersView.xaml +++ b/win/CS/HandBrakeWPF/Views/FiltersView.xaml @@ -11,6 +11,8 @@ + + @@ -37,6 +39,7 @@ + @@ -143,22 +146,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + - - - + - -- cgit v1.2.3