summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--macosx/HBFilters+UIAdditions.m65
-rw-r--r--macosx/HBFilters.m44
-rw-r--r--macosx/HBJob+HBJobConversion.m79
3 files changed, 77 insertions, 111 deletions
diff --git a/macosx/HBFilters+UIAdditions.m b/macosx/HBFilters+UIAdditions.m
index aae7b6bb5..dc867fbe5 100644
--- a/macosx/HBFilters+UIAdditions.m
+++ b/macosx/HBFilters+UIAdditions.m
@@ -5,10 +5,43 @@
It may be used under the terms of the GNU General Public License. */
#import "HBFilters+UIAdditions.h"
+#import "hb.h"
+
+/**
+ * Converts a hb_filter_param_t * array to a NSArray of NSString.
+ *
+ * @param f a function which returns a hb_filter_param_t * array
+ *
+ * @return a NSArray that contains the name field of hb_filter_param_t.
+ */
+static NSArray * filterParamsToNamesArray(hb_filter_param_t * (f)(int), int filter_id) {
+ NSMutableArray *presets = [NSMutableArray array];
+
+ for (hb_filter_param_t *preset = f(filter_id); preset->name != NULL; preset++)
+ {
+ [presets addObject:@(preset->name)];
+ }
+
+ return [presets copy];
+}
-extern NSDictionary *_HandBrake_denoiseTypesDict;
-extern NSDictionary *_HandBrake_denoisePresetsDict;
-extern NSDictionary *_HandBrake_nlmeansTunesDict;
+/**
+ * Converts a hb_filter_param_t * array to a NSDictionary, with name as the key and short_name as the value.
+ *
+ * @param f a function which returns a hb_filter_param_t * array
+ *
+ * @return a NSDictionary
+ */
+static NSDictionary * filterParamsToNamesDict(hb_filter_param_t * (f)(int), int filter_id) {
+ NSMutableDictionary *presets = [NSMutableDictionary dictionary];
+
+ for (hb_filter_param_t *preset = f(filter_id); preset->name != NULL; preset++)
+ {
+ [presets setObject:NSLocalizedString(@(preset->short_name), nil) forKey:@(preset->name)];
+ }
+
+ return [presets copy];
+}
@implementation HBGenericDictionaryTransformer
@@ -98,32 +131,34 @@ extern NSDictionary *_HandBrake_nlmeansTunesDict;
+ (NSDictionary *)denoisePresetDict
{
- return _HandBrake_denoisePresetsDict;
+ return filterParamsToNamesDict(hb_filter_param_get_presets, HB_FILTER_NLMEANS);
}
+ (NSDictionary *)nlmeansTunesDict
{
- return _HandBrake_nlmeansTunesDict;
+ return filterParamsToNamesDict(hb_filter_param_get_tunes, HB_FILTER_NLMEANS);
}
+ (NSDictionary *)denoiseTypesDict
{
- return _HandBrake_denoiseTypesDict;
+ return @{NSLocalizedString(@"Off", nil): @"off",
+ NSLocalizedString(@"NLMeans", nil): @"nlmeans",
+ NSLocalizedString(@"HQDN3D", nil): @"hqdn3d"};;
}
- (NSArray *)detelecineSettings
{
- return @[@"Off", @"Custom", @"Default"];
+ return filterParamsToNamesArray(hb_filter_param_get_presets, HB_FILTER_DETELECINE);
}
- (NSArray *)decombSettings
{
- return @[@"Off", @"Custom", @"Default", @"Fast", @"Bob"];
+ return filterParamsToNamesArray(hb_filter_param_get_presets, HB_FILTER_DECOMB);
}
- (NSArray *)deinterlaceSettings
{
- return @[@"Off", @"Custom", @"Fast", @"Slow", @"Slower", @"Bob"];
+ return filterParamsToNamesArray(hb_filter_param_get_presets, HB_FILTER_DEINTERLACE);
}
- (NSArray *)denoiseTypes
@@ -133,12 +168,12 @@ extern NSDictionary *_HandBrake_nlmeansTunesDict;
- (NSArray *)denoisePresets
{
- return @[@"Custom", @"Ultralight", @"Light", @"Medium", @"Strong"];
+ return filterParamsToNamesArray(hb_filter_param_get_presets, HB_FILTER_NLMEANS);
}
- (NSArray *)denoiseTunes
{
- return @[@"None", @"Film", @"Grain", @"High Motion", @"Animation"];
+ return filterParamsToNamesArray(hb_filter_param_get_tunes, HB_FILTER_NLMEANS);
}
- (NSString *)summary
@@ -224,14 +259,14 @@ extern NSDictionary *_HandBrake_nlmeansTunesDict;
/* Denoise */
if (![self.denoise isEqualToString:@"off"])
{
- [summary appendFormat:@" - Denoise (%@", [[_HandBrake_denoiseTypesDict allKeysForObject:self.denoise] firstObject]];
- if (![self.denoisePreset isEqualToString:@"none"])
+ [summary appendFormat:@" - Denoise (%@", self.denoise];
+ if (![self.denoisePreset isEqualToString:@"custom"])
{
- [summary appendFormat:@", %@", [[_HandBrake_denoisePresetsDict allKeysForObject:self.denoisePreset] firstObject]];
+ [summary appendFormat:@", %@", self.denoisePreset];
if ([self.denoise isEqualToString:@"nlmeans"])
{
- [summary appendFormat:@", %@", [[_HandBrake_nlmeansTunesDict allKeysForObject:self.denoiseTune] firstObject]];
+ [summary appendFormat:@", %@", self.denoiseTune];
}
}
else
diff --git a/macosx/HBFilters.m b/macosx/HBFilters.m
index c2f97c411..c47399524 100644
--- a/macosx/HBFilters.m
+++ b/macosx/HBFilters.m
@@ -6,13 +6,10 @@
#import "HBFilters.h"
#import "NSCodingMacro.h"
+#include "hb.h"
NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification";
-NSDictionary *_HandBrake_denoiseTypesDict;
-NSDictionary *_HandBrake_denoisePresetsDict;
-NSDictionary *_HandBrake_nlmeansTunesDict;
-
@interface HBFilters ()
@property (nonatomic, readwrite, getter=areNotificationsEnabled) BOOL notificationsEnabled;
@@ -21,28 +18,6 @@ NSDictionary *_HandBrake_nlmeansTunesDict;
@implementation HBFilters
-+ (void)initialize
-{
- if (self == [HBFilters class])
- {
- _HandBrake_denoiseTypesDict = @{NSLocalizedString(@"Off", nil): @"off",
- NSLocalizedString(@"NLMeans", nil): @"nlmeans",
- NSLocalizedString(@"HQDN3D", nil): @"hqdn3d"};
-
- _HandBrake_denoisePresetsDict = @{NSLocalizedString(@"Custom", nil): @"none",
- NSLocalizedString(@"Ultralight", nil): @"ultralight",
- NSLocalizedString(@"Light", nil): @"light",
- NSLocalizedString(@"Medium", nil) : @"medium",
- NSLocalizedString(@"Strong", nil) : @"strong"};
-
- _HandBrake_nlmeansTunesDict = @{NSLocalizedString(@"None", nil): @"none",
- NSLocalizedString(@"Film", nil): @"film",
- NSLocalizedString(@"Grain", nil): @"grain",
- NSLocalizedString(@"High Motion", nil): @"highmotion",
- NSLocalizedString(@"Animation", nil) : @"animation"};
- }
-}
-
- (instancetype)init
{
self = [super init];
@@ -423,31 +398,24 @@ NSDictionary *_HandBrake_nlmeansTunesDict;
else
{
// New format, read the values directly
- if ([[_HandBrake_denoiseTypesDict allValues] containsObject:preset[@"PictureDenoiseFilter"]])
+ if ([@[@"off", @"nlmeans", @"hqdn3d"] containsObject:preset[@"PictureDenoiseFilter"]])
{
self.denoise = preset[@"PictureDenoiseFilter"];
}
else
{
- self.denoise = [[_HandBrake_denoiseTypesDict allValues] firstObject];
+ self.denoise = @"off";
}
- if ([[_HandBrake_denoisePresetsDict allValues] containsObject:preset[@"PictureDenoisePreset"]])
+ if (hb_validate_filter_preset(HB_FILTER_DENOISE, [preset[@"PictureDenoisePreset"] UTF8String], [preset[@"PictureDenoiseTune"] UTF8String]))
{
self.denoisePreset = preset[@"PictureDenoisePreset"];
- }
- else
- {
- self.denoisePreset = [[_HandBrake_denoisePresetsDict allValues] firstObject];
- }
-
- if ([[_HandBrake_nlmeansTunesDict allValues] containsObject:preset[@"PictureDenoiseTune"]])
- {
self.denoiseTune = preset[@"PictureDenoiseTune"];
}
else
{
- self.denoiseTune = [[_HandBrake_nlmeansTunesDict allKeys] firstObject];
+ self.denoisePreset = @"medium";
+ self.denoiseTune = @"none";
}
self.denoiseCustomString = preset[@"PictureDenoiseCustom"];
diff --git a/macosx/HBJob+HBJobConversion.m b/macosx/HBJob+HBJobConversion.m
index 65e25fe8b..bf12014a0 100644
--- a/macosx/HBJob+HBJobConversion.m
+++ b/macosx/HBJob+HBJobConversion.m
@@ -401,74 +401,37 @@
// Detelecine
hb_filter_object_t *filter;
- if (self.filters.detelecine == 1)
+ if (self.filters.detelecine)
{
- filter = hb_filter_init(HB_FILTER_DETELECINE);
- // use a custom detelecine string
- hb_add_filter(job, filter, self.filters.detelecineCustomString.UTF8String);
- }
- else if (self.filters.detelecine == 2)
- {
- filter = hb_filter_init(HB_FILTER_DETELECINE);
- // Use libhb's default values
- hb_add_filter(job, filter, NULL);
+ int filter_id = HB_FILTER_DETELECINE;
+ const char *filter_str = hb_generate_filter_settings_by_index(filter_id,
+ (int)self.filters.detelecine,
+ self.filters.detelecineCustomString.UTF8String);
+ filter = hb_filter_init(filter_id);
+ hb_add_filter(job, filter, filter_str);
}
if (self.filters.useDecomb && self.filters.decomb)
{
// Decomb
- filter = hb_filter_init(HB_FILTER_DECOMB);
- if (self.filters.decomb == 1)
- {
- // use a custom decomb string */
- hb_add_filter(job, filter, self.filters.decombCustomString.UTF8String);
- }
- else if (self.filters.decomb == 2)
- {
- // use libhb defaults
- hb_add_filter(job, filter, NULL);
- }
- else if (self.filters.decomb == 3)
- {
- // use old defaults (decomb fast)
- hb_add_filter(job, filter, "7:2:6:9:1:80");
- }
- else if (self.filters.decomb == 4)
- {
- // decomb 3 with bobbing enabled
- hb_add_filter(job, filter, "455");
- }
+ int filter_id = HB_FILTER_DECOMB;
+ const char *filter_str = hb_generate_filter_settings_by_index(filter_id,
+ (int)self.filters.decomb,
+ self.filters.decombCustomString.UTF8String);
+ filter = hb_filter_init(filter_id);
+ hb_add_filter(job, filter, filter_str);
}
else if (!self.filters.useDecomb && self.filters.deinterlace)
{
// Deinterlace
- filter = hb_filter_init(HB_FILTER_DEINTERLACE);
- if (self.filters.deinterlace == 1)
- {
- // we add the custom string if present
- hb_add_filter(job, filter, self.filters.deinterlaceCustomString.UTF8String);
- }
- else if (self.filters.deinterlace == 2)
- {
- // Run old deinterlacer fd by default
- hb_add_filter(job, filter, "0");
- }
- else if (self.filters.deinterlace == 3)
- {
- // Yadif mode 0 (without spatial deinterlacing)
- hb_add_filter(job, filter, "1");
- }
- else if (self.filters.deinterlace == 4)
- {
- // Yadif (with spatial deinterlacing)
- hb_add_filter(job, filter, "3");
- }
- else if (self.filters.deinterlace == 5)
- {
- // Yadif (with spatial deinterlacing and bobbing)
- hb_add_filter(job, filter, "15");
- }
+ int filter_id = HB_FILTER_DEINTERLACE;
+ const char *filter_str = hb_generate_filter_settings_by_index(filter_id,
+ (int)self.filters.deinterlace,
+ self.filters.deinterlaceCustomString.UTF8String);
+ filter = hb_filter_init(filter_id);
+ hb_add_filter(job, filter, filter_str);
}
+
// Denoise
if (![self.filters.denoise isEqualToString:@"off"])
{
@@ -498,7 +461,7 @@
// NOTE: even though there is a valid deblock setting of 0 for the filter, for
// the macgui's purposes a value of 0 actually means to not even use the filter
// current hb_filter_deblock.settings valid ranges are from 5 - 15
- if (self.filters.deblock != 0)
+ if (self.filters.deblock)
{
filter = hb_filter_init(HB_FILTER_DEBLOCK);
hb_add_filter(job, filter, [NSString stringWithFormat:@"%ld", (long)self.filters.deblock].UTF8String);