From 45f24decdf2bb41c8eac24ead218d05fbd92955a Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Wed, 18 Jul 2018 14:53:51 +0200 Subject: [PATCH] MacGui: validate the custom filters settings in the GUI. --- macosx/Base.lproj/HBFiltersViewController.xib | 85 ++++++--- macosx/HBFilters.m | 178 ++++++++++++++++++ 2 files changed, 232 insertions(+), 31 deletions(-) diff --git a/macosx/Base.lproj/HBFiltersViewController.xib b/macosx/Base.lproj/HBFiltersViewController.xib index 9c154dd3e..073c58741 100644 --- a/macosx/Base.lproj/HBFiltersViewController.xib +++ b/macosx/Base.lproj/HBFiltersViewController.xib @@ -1,9 +1,8 @@ - + - - + @@ -73,14 +72,14 @@ - + Custom Detelecine parameters. Syntax: skip-left=s:skip-right=s:skip-top=s:skip-bottom=s:strict-breaks=s:plane=p:parity=p:disable=d Default: skip-left=1:skip-right=1:skip-top=4:skip-bottom=4:plane=0 - + @@ -94,7 +93,11 @@ Default: skip-left=1:skip-right=1:skip-top=4:skip-bottom=4:plane=0 NSNegateBoolean - + + + + + @@ -165,7 +168,7 @@ Default: skip-left=1:skip-right=1:skip-top=4:skip-bottom=4:plane=0 - + @@ -211,7 +214,7 @@ Decomb switches between multiple interpolation algorithms for speed and quality. - + Custom Deinterlace parameters. Yadif syntax: mode=m:parity=p @@ -222,7 +225,7 @@ Decomb syntax: mode=m:magnitude-thresh=m:variance-thresh=v:laplacian-thresh=l:di Decomb default: mode=7 - + @@ -235,7 +238,11 @@ Decomb default: mode=7 NSNegateBoolean - + + + + + @@ -255,7 +262,7 @@ Decomb default: mode=7 - + Deinterlace filter preset. Default is well balanced for speed and quality. @@ -266,7 +273,7 @@ EEDI2 uses a slower, higher quality interpolation algorithm for Decomb. Useful f Bob attempts to better preserve motion for a slight penalty to perceived resolution. - + @@ -381,14 +388,14 @@ Bob attempts to better preserve motion for a slight penalty to perceived resolut - + Custom Interlace Detection parameters. Syntax: mode=m:spatial-metric=s:motion-thresh=m:spatial-thresh=s:filter-mode=f:block-thresh=b:block-width=b:block-height=b:disable=d Default: mode=3:spatial-metric=2:motion-thresh=1:spatial-thresh=1:filter-mode=2:block-thresh=40:block-width=16:block-height=16 - + @@ -396,12 +403,16 @@ Default: mode=3:spatial-metric=2:motion-thresh=1:spatial-thresh=1:filter-mode=2: - NSNegateBoolean + + + + + @@ -463,9 +474,9 @@ Lapsharp sharpens using convolution kernels approximating Laplacian edge filters - + - + @@ -573,9 +584,9 @@ HQDN3D is an adaptive low-pass filter, faster than NLMeans but less effective at - + - + @@ -599,7 +610,7 @@ HQDN3D is an adaptive low-pass filter, faster than NLMeans but less effective at - + Denoise tune. Further adjusts the Denoise preset to optimize settings for specific scenarios. None uses the default preset settings. @@ -639,7 +650,7 @@ Sprite is useful for 1-/4-/8-/16-bit 2-dimensional games. Sprite is not designed - + @@ -655,7 +666,7 @@ Sprite is useful for 1-/4-/8-/16-bit 2-dimensional games. Sprite is not designed - + Custom Denoise parameters. NLMeans syntax: y-strength=y:y-origin-tune=y:y-patch-size=y:y-range=y:y-frame-count=y:y-prefilter=y:cb-strength=c:cb-origin-tune=c:cb-patch-size=c:cb-range=c:cb-frame-count=c:cb-prefilter=c:cr-strength=c:cr-origin-tune=c:cr-patch-size=c:cr-range=c:cr-frame-count=c:cr-prefilter=c:threads=t @@ -666,7 +677,7 @@ HQDN3D syntax: y-spatial=y:cb-spatial=c:cr-spatial=c:y-temporal=y:cb-temporal=c: HQDN3D default: y-spatial=3:cb-spatial=2:cr-spatial=2:y-temporal=2:cb-temporal=3:cr-temporal=3 - + @@ -679,11 +690,15 @@ HQDN3D default: y-spatial=3:cb-spatial=2:cr-spatial=2:y-temporal=2:cb-temporal=3 NSNegateBoolean - + + + + + - + @@ -699,7 +714,7 @@ HQDN3D default: y-spatial=3:cb-spatial=2:cr-spatial=2:y-temporal=2:cb-temporal=3 - + Sharpen tune. Further adjusts the Sharpen preset to optimize settings for specific scenarios. None uses the default preset settings. @@ -737,7 +752,7 @@ Lapsharp's Sprite tune is useful for 1-/4-/8-/16-bit 2-dimensional games. Sprite - + @@ -753,7 +768,7 @@ Lapsharp's Sprite tune is useful for 1-/4-/8-/16-bit 2-dimensional games. Sprite - + Custom Sharpen parameters. Unsharp syntax: y-strength=y:y-size=y:cb-strength=c:cb-size=c:cr-strength=c:cr-size=c @@ -764,7 +779,7 @@ Lapsharp syntax: y-strength=y:y-kernel=y:cb-strength=c:cb-kernel=c:cr-strength=c Lapsharp default: y-strength=0.2:y-kernel=isolap:cb-strength=0.2:cb-kernel=isolap - + @@ -777,11 +792,15 @@ Lapsharp default: y-strength=0.2:y-kernel=isolap:cb-strength=0.2:cb-kernel=isola NSNegateBoolean - + + + + + - + @@ -817,6 +836,7 @@ Lapsharp default: y-strength=0.2:y-kernel=isolap:cb-strength=0.2:cb-kernel=isola + @@ -872,10 +892,12 @@ Lapsharp default: y-strength=0.2:y-kernel=isolap:cb-strength=0.2:cb-kernel=isola + + @@ -883,6 +905,7 @@ Lapsharp default: y-strength=0.2:y-kernel=isolap:cb-strength=0.2:cb-kernel=isola + diff --git a/macosx/HBFilters.m b/macosx/HBFilters.m index 2393a39a7..434b9d532 100644 --- a/macosx/HBFilters.m +++ b/macosx/HBFilters.m @@ -95,6 +95,33 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification"; [self postChangedNotification]; } +- (BOOL)validateDetelecineCustomString:(id *)ioValue error:(NSError * __autoreleasing *)outError +{ + BOOL retval = YES; + + if (nil != *ioValue) + { + NSString *customValue = *ioValue; + + int filter_id = HB_FILTER_DETELECINE; + hb_dict_t *filter_dict = hb_generate_filter_settings(filter_id, + "custom", + NULL, + customValue.UTF8String); + + if (filter_dict == NULL) + { + retval = NO; + NSDictionary *userInfo = @{NSLocalizedDescriptionKey: NSLocalizedString(@"Invalid custom detelecine settings.", + @"HBFilters -> invalid detelecine custom string description"), + NSLocalizedRecoverySuggestionErrorKey: NSLocalizedString(@"Syntax: skip-left=s:skip-right=s:skip-top=s:skip-bottom=s:strict-breaks=s:plane=p:parity=p:disable=d\n\nDefault: skip-left=1:skip-right=1:skip-top=4:skip-bottom=4:plane=0", @"HBJob -> invalid detelecine custom settings error recovery suggestion")}; + *outError = [NSError errorWithDomain:@"HBFilterError" code:0 userInfo:userInfo]; + } + } + + return retval; +} + - (void)setCombDetection:(NSString *)combDetection { if (![combDetection isEqualToString:_combDetection]) @@ -130,6 +157,33 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification"; [self postChangedNotification]; } +- (BOOL)validateCombDetectionCustomString:(id *)ioValue error:(NSError * __autoreleasing *)outError +{ + BOOL retval = YES; + + if (nil != *ioValue) + { + NSString *customValue = *ioValue; + + int filter_id = HB_FILTER_COMB_DETECT; + hb_dict_t *filter_dict = hb_generate_filter_settings(filter_id, + "custom", + NULL, + customValue.UTF8String); + + if (filter_dict == NULL) + { + retval = NO; + NSDictionary *userInfo = @{NSLocalizedDescriptionKey: NSLocalizedString(@"Invalid custom comb detect settings.", + @"HBFilters -> invalid comb detect custom string description"), + NSLocalizedRecoverySuggestionErrorKey: NSLocalizedString(@"Syntax: mode=m:spatial-metric=s:motion-thresh=m:spatial-thresh=s:filter-mode=f:block-thresh=b:block-width=b:block-height=b:disable=d\n\nDefault: mode=3:spatial-metric=2:motion-thresh=1:spatial-thresh=1:filter-mode=2:block-thresh=40:block-width=16:block-height=16", @"HBJob -> invalid comb detect custom settings error recovery suggestion")}; + *outError = [NSError errorWithDomain:@"HBFilterError" code:0 userInfo:userInfo]; + } + } + + return retval; +} + - (void)setDeinterlace:(NSString *)deinterlace { if (![deinterlace isEqualToString:_deinterlace]) @@ -203,6 +257,47 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification"; [self postChangedNotification]; } +- (BOOL)validateDeinterlaceCustomString:(id *)ioValue error:(NSError * __autoreleasing *)outError +{ + BOOL retval = YES; + + if (nil != *ioValue) + { + NSString *customValue = *ioValue; + + int filter_id = HB_FILTER_DECOMB; + if ([self.deinterlace isEqualToString:@"deinterlace"]) + { + filter_id = HB_FILTER_DEINTERLACE; + } + hb_dict_t *filter_dict = hb_generate_filter_settings(filter_id, + "custom", + NULL, + customValue.UTF8String); + + if (filter_dict == NULL) + { + retval = NO; + if (filter_id == HB_FILTER_DEINTERLACE) + { + NSDictionary *userInfo = @{NSLocalizedDescriptionKey: NSLocalizedString(@"Invalid Yadif custom settings.", + @"HBFilters -> invalid Yadif custom string description"), + NSLocalizedRecoverySuggestionErrorKey: NSLocalizedString(@"Yadif syntax: mode=m:parity=p\n\nYadif default: mode=3", @"HBJob -> invalid Yadif custom settings error recovery suggestion")}; + *outError = [NSError errorWithDomain:@"HBFilterError" code:0 userInfo:userInfo]; + } + else if (filter_id == HB_FILTER_DECOMB) + { + NSDictionary *userInfo = @{NSLocalizedDescriptionKey: NSLocalizedString(@"Invalid Decomb custom settings.", + @"HBFilters -> invalid Decomb custom string description"), + NSLocalizedRecoverySuggestionErrorKey: NSLocalizedString(@"Decomb syntax: mode=m:magnitude-thresh=m:variance-thresh=v:laplacian-thresh=l:dilation-thresh=d:erosion-thresh=e:noise-thresh=n:search-distance=s:postproc=p:parity=p\n\nDecomb default: mode=7", @"HBJob -> invalid Decomb custom settings error recovery suggestion")}; + *outError = [NSError errorWithDomain:@"HBFilterError" code:0 userInfo:userInfo]; + } + } + } + + return retval; +} + - (void)setDenoise:(NSString *)denoise { if (![denoise isEqualToString:_denoise]) @@ -275,6 +370,48 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification"; [self postChangedNotification]; } +- (BOOL)validateDenoiseCustomString:(id *)ioValue error:(NSError * __autoreleasing *)outError +{ + BOOL retval = YES; + + if (nil != *ioValue) + { + NSString *customValue = *ioValue; + + int filter_id = HB_FILTER_HQDN3D; + if ([self.denoise isEqualToString:@"nlmeans"]) + { + filter_id = HB_FILTER_NLMEANS; + } + hb_dict_t *filter_dict = hb_generate_filter_settings(filter_id, + "custom", + NULL, + customValue.UTF8String); + + if (filter_dict == NULL) + { + retval = NO; + if (filter_id == HB_FILTER_HQDN3D) + { + NSDictionary *userInfo = @{NSLocalizedDescriptionKey: NSLocalizedString(@"Invalid custom HQDN3D settings", + @"HBFilters -> invalid denoise custom string description"), + NSLocalizedRecoverySuggestionErrorKey: NSLocalizedString(@"HQDN3D syntax: y-spatial=y:cb-spatial=c:cr-spatial=c:y-temporal=y:cb-temporal=c:cr-temporal=c\n\nDefault settings: y-spatial=3:cb-spatial=2:cr-spatial=2:y-temporal=2:cb-temporal=3:cr-temporal=3", @"HBJob -> invalid name error recovery suggestion")}; + *outError = [NSError errorWithDomain:@"HBFilterError" code:0 userInfo:userInfo]; + } + else if (filter_id == HB_FILTER_NLMEANS) + { + NSDictionary *userInfo = @{NSLocalizedDescriptionKey: NSLocalizedString(@"Invalid custom NLMeans settings", + @"HBFilters -> invalid denoise custom string description"), + NSLocalizedRecoverySuggestionErrorKey: NSLocalizedString(@"NLMeans syntax: y-strength=y:y-origin-tune=y:y-patch-size=y:y-range=y:y-frame-count=y:y-prefilter=y:cb-strength=c:cb-origin-tune=c:cb-patch-size=c:cb-range=c:cb-frame-count=c:cb-prefilter=c:cr-strength=c:cr-origin-tune=c:cr-patch-size=c:cr-range=c:cr-frame-count=c:cr-prefilter=c:threads=t\n\nDefault settings: y-strength=6:y-origin-tune=1:y-patch-size=7:y-range=3:y-frame-count=2:y-prefilter=0:cb-strength=6:cb-origin-tune=1:cb-patch-size=7:cb-range=3:cb-frame-count=2:cb-prefilter=0", @"HBJob -> invalid name error recovery suggestion")}; + *outError = [NSError errorWithDomain:@"HBFilterError" code:0 userInfo:userInfo]; + } + } + } + + return retval; +} + + - (void)setSharpen:(NSString *)sharpen { if (![sharpen isEqualToString:_sharpen]) @@ -380,6 +517,47 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification"; [self postChangedNotification]; } +- (BOOL)validateSharpenCustomString:(id *)ioValue error:(NSError * __autoreleasing *)outError +{ + BOOL retval = YES; + + if (nil != *ioValue) + { + NSString *customValue = *ioValue; + + int filter_id = HB_FILTER_UNSHARP; + if ([self.sharpen isEqualToString:@"lapsharp"]) + { + filter_id = HB_FILTER_LAPSHARP; + } + hb_dict_t *filter_dict = hb_generate_filter_settings(filter_id, + "custom", + NULL, + customValue.UTF8String); + + if (filter_dict == NULL) + { + retval = NO; + if (filter_id == HB_FILTER_UNSHARP) + { + NSDictionary *userInfo = @{NSLocalizedDescriptionKey: NSLocalizedString(@"Invalid unsharp custom settings.", + @"HBFilters -> invalid unsharp custom string description"), + NSLocalizedRecoverySuggestionErrorKey: NSLocalizedString(@"Unsharp syntax: y-strength=y:y-size=y:cb-strength=c:cb-size=c:cr-strength=c:cr-size=c\n\nUnsharp default: y-strength=0.25:y-size=7:cb-strength=0.25:cb-size=7", @"HBJob -> invalid unsharp custom settings error recovery suggestion")}; + *outError = [NSError errorWithDomain:@"HBFilterError" code:0 userInfo:userInfo]; + } + else if (filter_id == HB_FILTER_LAPSHARP) + { + NSDictionary *userInfo = @{NSLocalizedDescriptionKey: NSLocalizedString(@"Invalid lapsharp custom settings.", + @"HBFilters -> invalid lapsharp custom string description"), + NSLocalizedRecoverySuggestionErrorKey: NSLocalizedString(@"Lapsharp syntax: y-strength=y:y-kernel=y:cb-strength=c:cb-kernel=c:cr-strength=c:cr-kernel=c\n\nLapsharp default: y-strength=0.2:y-kernel=isolap:cb-strength=0.2:cb-kernel=isolap", @"HBJob -> invalid lapsharp custom settings error recovery suggestion")}; + *outError = [NSError errorWithDomain:@"HBFilterError" code:0 userInfo:userInfo]; + } + } + } + + return retval; +} + - (void)setDeblock:(int)deblock { if (deblock != _deblock) -- 2.40.0