From: Damiano Galassi Date: Thu, 2 May 2019 14:58:29 +0000 (+0200) Subject: MacGui: update UI for the new deblock filter. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=851c732ad36525175db37ad9f59b31361ba8f876;p=handbrake MacGui: update UI for the new deblock filter. --- diff --git a/macosx/Base.lproj/HBFiltersViewController.xib b/macosx/Base.lproj/HBFiltersViewController.xib index aa4f8668d..037194ef4 100644 --- a/macosx/Base.lproj/HBFiltersViewController.xib +++ b/macosx/Base.lproj/HBFiltersViewController.xib @@ -1,8 +1,8 @@ - + - + @@ -122,40 +122,6 @@ Default: skip-left=1:skip-right=1:skip-top=4:skip-bottom=4:plane=0 - - - - - - - - - - - - - - Off - - - - - - - - - - - - - - - NSIsNotNil - - - - - @@ -815,6 +781,115 @@ Lapsharp default: y-strength=0.2:y-kernel=isolap:cb-strength=0.2:cb-kernel=isola + + + + + + + + + + + + + + + NSIsNotNil + + + + + HBDeblockTransformer + + + + + + + + + + + + + + + + + + + + + HBDeblockTuneTransformer + + + + + + NSNegateBoolean + + + + + + + + + + + + + + + NSNegateBoolean + + + + + + + + Custom Deblock parameters. + +strength=s:thresh=t:blocksize=b + + + + + + + + + + + + NSNegateBoolean + + + + + + + + + + + + + + + + + + + + NSNegateBoolean + + + + + @@ -836,6 +911,7 @@ Lapsharp default: y-strength=0.2:y-kernel=isolap:cb-strength=0.2:cb-kernel=isola + @@ -847,7 +923,6 @@ Lapsharp default: y-strength=0.2:y-kernel=isolap:cb-strength=0.2:cb-kernel=isola - @@ -855,13 +930,14 @@ Lapsharp default: y-strength=0.2:y-kernel=isolap:cb-strength=0.2:cb-kernel=isola + - + @@ -869,9 +945,12 @@ Lapsharp default: y-strength=0.2:y-kernel=isolap:cb-strength=0.2:cb-kernel=isola + + + @@ -879,8 +958,10 @@ Lapsharp default: y-strength=0.2:y-kernel=isolap:cb-strength=0.2:cb-kernel=isola - + + + @@ -904,7 +985,8 @@ Lapsharp default: y-strength=0.2:y-kernel=isolap:cb-strength=0.2:cb-kernel=isola - + + @@ -916,6 +998,7 @@ Lapsharp default: y-strength=0.2:y-kernel=isolap:cb-strength=0.2:cb-kernel=isola + diff --git a/macosx/HBFilters+UIAdditions.h b/macosx/HBFilters+UIAdditions.h index 8664e2aca..609252c96 100644 --- a/macosx/HBFilters+UIAdditions.h +++ b/macosx/HBFilters+UIAdditions.h @@ -28,6 +28,9 @@ + (NSDictionary *)sharpenTunesDict; + (NSDictionary *)sharpenTypesDict; ++ (NSDictionary *)deblockPresetDict; ++ (NSDictionary *)deblockTunesDict; + - (BOOL)customDetelecineSelected; @property (nonatomic, readonly) BOOL customCombDetectionSelected; @@ -39,7 +42,8 @@ - (BOOL)customSharpenSelected; - (BOOL)sharpenTunesAvailable; -- (NSString *)deblockSummary; +- (BOOL)deblockTunesAvailable; +- (BOOL)customDeblockSelected; @property (nonatomic, readonly) NSArray *detelecineSettings; @@ -52,6 +56,9 @@ @property (nonatomic, readonly) NSArray *sharpenPresets; @property (nonatomic, readonly) NSArray *sharpenTunes; +@property (nonatomic, readonly) NSArray *deblockPresets; +@property (nonatomic, readonly) NSArray *deblockTunes; + @end /** @@ -93,6 +100,12 @@ @interface HBSharpenTransformer : HBGenericDictionaryTransformer @end +@interface HBDeblockTuneTransformer : HBGenericDictionaryTransformer +@end + +@interface HBDeblockTransformer : HBGenericDictionaryTransformer +@end + @interface HBCustomFilterTransformer : NSValueTransformer @end diff --git a/macosx/HBFilters+UIAdditions.m b/macosx/HBFilters+UIAdditions.m index 9fd9115f4..9afde7a85 100644 --- a/macosx/HBFilters+UIAdditions.m +++ b/macosx/HBFilters+UIAdditions.m @@ -25,9 +25,9 @@ static NSArray * filterParamsToNamesArray(hb_filter_param_t * (f)(int), int filt if ([name isEqualToString:@"Off"]) { name = NSLocalizedStringFromTableInBundle(@"Off", nil, [NSBundle bundleForClass:[HBFilters class]], "HBFilters -> off display name"); } -// else if ([name isEqualToString:@"Custom"]) { -// name = NSLocalizedStringFromTableInBundle(@"Custom", nil, [NSBundle bundleForClass:[HBFilters class]], "HBFilters -> custom display name"); -// } + else if ([name isEqualToString:@"Custom"]) { + name = NSLocalizedStringFromTableInBundle(@"Custom", nil, [NSBundle bundleForClass:[HBFilters class]], "HBFilters -> custom display name"); + } [presets addObject:name]; } @@ -50,6 +50,9 @@ static NSDictionary * filterParamsToNamesDict(hb_filter_param_t * (f)(int), int if ([name isEqualToString:@"Off"]) { name = NSLocalizedStringFromTableInBundle(@"Off", nil, [NSBundle bundleForClass:[HBFilters class]], "HBFilters -> off display name"); } + else if ([name isEqualToString:@"Custom"]) { + name = NSLocalizedStringFromTableInBundle(@"Custom", nil, [NSBundle bundleForClass:[HBFilters class]], "HBFilters -> custom display name"); + } [presets setObject:@(preset->short_name) forKey:name]; } @@ -204,6 +207,30 @@ static NSDictionary * filterParamsToNamesDict(hb_filter_param_t * (f)(int), int @end +@implementation HBDeblockTuneTransformer + +- (instancetype)init +{ + if (self = [super init]) + self.dict = [HBFilters deblockTunesDict]; + + return self; +} + +@end + +@implementation HBDeblockTransformer + +- (instancetype)init +{ + if (self = [super init]) + self.dict = [HBFilters deblockPresetDict]; + + return self; +} + +@end + @implementation HBCustomFilterTransformer + (Class)transformedValueClass @@ -242,6 +269,9 @@ static NSDictionary *sharpenPresetDict = nil; static NSDictionary *sharpenTunesDict = nil; static NSDictionary *sharpenTypesDict = nil; +static NSDictionary *deblockPresetDict = nil; +static NSDictionary *deblockTunesDict = nil; + @implementation HBFilters (UIAdditions) #pragma mark - Valid values @@ -363,6 +393,24 @@ static NSDictionary *sharpenTypesDict = nil; return sharpenTypesDict; } ++ (NSDictionary *)deblockPresetDict +{ + if (!deblockPresetDict) + { + deblockPresetDict = filterParamsToNamesDict(hb_filter_param_get_presets, HB_FILTER_DEBLOCK); + } + return deblockPresetDict; +} + ++ (NSDictionary *)deblockTunesDict +{ + if (!deblockTunesDict) + { + deblockTunesDict = filterParamsToNamesDict(hb_filter_param_get_tunes, HB_FILTER_DEBLOCK); + } + return deblockTunesDict; +} + - (NSArray *)detelecineSettings { return filterParamsToNamesArray(hb_filter_param_get_presets, HB_FILTER_DETELECINE); @@ -429,6 +477,16 @@ static NSDictionary *sharpenTypesDict = nil; } } +- (NSArray *)deblockPresets +{ + return filterParamsToNamesArray(hb_filter_param_get_presets, HB_FILTER_DEBLOCK); +} + +- (NSArray *)deblockTunes +{ + return filterParamsToNamesArray(hb_filter_param_get_tunes, HB_FILTER_DEBLOCK); +} + - (BOOL)customDetelecineSelected { return [self.detelecine isEqualToString:@"custom"] ? YES : NO; @@ -479,16 +537,14 @@ static NSDictionary *sharpenTypesDict = nil; return ([self.sharpen isEqualToString:@"unsharp"] || [self.sharpen isEqualToString:@"lapsharp"]) && ![self.sharpenPreset isEqualToString:@"custom"]; } -- (NSString *)deblockSummary +- (BOOL)deblockTunesAvailable { - if (self.deblock == 0) - { - return HBKitLocalizedString(@"Off", @"HBFilters -> filter summary"); - } - else - { - return [NSString stringWithFormat: @"%.0ld", (long)self.deblock]; - } + return ![self.deblock isEqualToString:@"off"] && ![self.deblock isEqualToString:@"custom"]; +} + +- (BOOL)customDeblockSelected +{ + return [self.deblock isEqualToString:@"custom"]; } @end diff --git a/macosx/HBFilters.h b/macosx/HBFilters.h index 775829de1..fa29493a6 100644 --- a/macosx/HBFilters.h +++ b/macosx/HBFilters.h @@ -36,7 +36,9 @@ extern NSString * const HBFiltersChangedNotification; @property (nonatomic, readwrite, copy) NSString *sharpenTune; @property (nonatomic, readwrite, copy) NSString *sharpenCustomString; -@property (nonatomic, readwrite) int deblock; +@property (nonatomic, readwrite, copy) NSString *deblock; +@property (nonatomic, readwrite, copy) NSString *deblockTune; +@property (nonatomic, readwrite, copy) NSString *deblockCustomString; @property (nonatomic, readwrite) BOOL grayscale; diff --git a/macosx/HBFilters.m b/macosx/HBFilters.m index 81cbb0613..ec806d643 100644 --- a/macosx/HBFilters.m +++ b/macosx/HBFilters.m @@ -42,6 +42,9 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification"; _sharpenCustomString = @""; _sharpenPreset = @"medium"; _sharpenTune = @"none"; + _deblock = @"off"; + _deblockTune = @"none"; + _deblockCustomString = @""; _notificationsEnabled = YES; } @@ -58,7 +61,7 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification"; } } -#pragma mark - Setters +#pragma mark - Detelecine - (void)setDetelecine:(NSString *)detelecine { @@ -126,6 +129,8 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification"; return retval; } +#pragma mark - Comb Detect + - (void)setCombDetection:(NSString *)combDetection { if (![combDetection isEqualToString:_combDetection]) @@ -191,6 +196,8 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification"; return retval; } +#pragma mark - Deinterlace + - (void)setDeinterlace:(NSString *)deinterlace { if (![deinterlace isEqualToString:_deinterlace]) @@ -308,6 +315,8 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification"; return retval; } +#pragma mark - Denoise + - (void)setDenoise:(NSString *)denoise { if (![denoise isEqualToString:_denoise]) @@ -424,6 +433,7 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification"; return retval; } +#pragma mark - Sharpen - (void)setSharpen:(NSString *)sharpen { @@ -574,16 +584,94 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification"; return retval; } -- (void)setDeblock:(int)deblock +#pragma mark - Deblock + +- (void)setDeblock:(NSString *)deblock { - if (deblock != _deblock) + if (![deblock isEqualToString:_deblock]) { [[self.undo prepareWithInvocationTarget:self] setDeblock:_deblock]; } - _deblock = deblock; + if (deblock) + { + _deblock = [deblock copy]; + } + else + { + _deblock = @"off"; + } + + [self postChangedNotification]; +} + +- (void)setDeblockTune:(NSString *)deblockTune +{ + if (![deblockTune isEqualToString:_deblockTune]) + { + [[self.undo prepareWithInvocationTarget:self] setDeblockTune:_deblockTune]; + } + if (deblockTune) + { + _deblockTune = [deblockTune copy]; + } + else + { + _deblockTune = @"none"; + } + [self postChangedNotification]; } +- (void)setDeblockCustomString:(NSString *)deblockCustomString +{ + if (![deblockCustomString isEqualToString:_deblockCustomString]) + { + [[self.undo prepareWithInvocationTarget:self] setDeblock:_deblockCustomString]; + } + if (deblockCustomString) + { + _deblockCustomString = [deblockCustomString copy]; + } + else + { + _deblockCustomString = @""; + } + + [self postChangedNotification]; +} + +- (BOOL)validateDeblockCustomString:(id *)ioValue error:(NSError * __autoreleasing *)outError +{ + BOOL retval = YES; + + if (nil != *ioValue) + { + NSString *customValue = *ioValue; + + int filter_id = HB_FILTER_DEBLOCK; + hb_dict_t *filter_dict = hb_generate_filter_settings(filter_id, + "custom", + NULL, + customValue.UTF8String); + + if (filter_dict == NULL) + { + retval = NO; + if (outError) + { + NSDictionary *userInfo = @{NSLocalizedDescriptionKey: HBKitLocalizedString(@"Invalid deblock custom settings.", + @"HBFilters -> invalid deblock custom string description"), + NSLocalizedRecoverySuggestionErrorKey: HBKitLocalizedString(@"Deblock syntax: strength=s:thresh=t:blocksize=b", @"HBJob -> invalid deblock custom settings error recovery suggestion")}; + *outError = [NSError errorWithDomain:@"HBFilterError" code:0 userInfo:userInfo]; + } + } + } + + return retval; +} + +#pragma mark - Grayscale + - (void)setGrayscale:(BOOL)grayscale { if (grayscale != _grayscale) @@ -594,6 +682,8 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification"; [self postChangedNotification]; } +#pragma mark - Rotate + - (void)setRotate:(int)rotate { if (rotate != _rotate) @@ -604,6 +694,8 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification"; [self postChangedNotification]; } +#pragma mark - Flip + - (void)setFlip:(BOOL)flip { if (flip != _flip) @@ -614,13 +706,15 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification"; [self postChangedNotification]; } +#pragma mark - KVO + + (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key { NSSet *retval = nil; if ([key isEqualToString:@"summary"]) { - retval = [NSSet setWithObjects:@"detelecine", @"detelecineCustomString", @"deinterlace", @"deinterlacePreset", @"deinterlaceCustomString", @"denoise", @"denoisePreset", @"denoiseTune", @"denoiseCustomString", @"deblock", @"grayscale", @"sharpen", @"sharpenPreset", @"sharpenTune", @"sharpenCustomString", nil]; + retval = [NSSet setWithObjects:@"detelecine", @"detelecineCustomString", @"deinterlace", @"deinterlacePreset", @"deinterlaceCustomString", @"denoise", @"denoisePreset", @"denoiseTune", @"denoiseCustomString", @"deblock", @"deblockTune", @"deblockCustomString", @"grayscale", @"sharpen", @"sharpenPreset", @"sharpenTune", @"sharpenCustomString", nil]; } else if ([key isEqualToString:@"customDetelecineSelected"]) { @@ -644,12 +738,17 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification"; { retval = [NSSet setWithObjects:@"sharpen", @"sharpenPreset", nil]; } - else if ([key isEqualToString:@"sharpenEnabled"] || + else if ([key isEqualToString:@"sharpenEnabled"] || [key isEqualToString:@"sharpenPresets"] || [key isEqualToString:@"sharpenTunes"]) { retval = [NSSet setWithObject:@"sharpen"]; } + else if ([key isEqualToString:@"deblockTunesAvailable"] || + [key isEqualToString:@"customDeblockSelected"]) + { + retval = [NSSet setWithObject:@"deblock"]; + } else if ([key isEqualToString:@"deinterlaceEnabled"]) { retval = [NSSet setWithObject:@"deinterlace"]; @@ -659,10 +758,6 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification"; { retval = [NSSet setWithObjects:@"deinterlace", @"deinterlacePreset", nil]; } - else if ([key isEqualToString:@"deblockSummary"]) - { - retval = [NSSet setWithObject:@"deblock"]; - } else { retval = [NSSet set]; @@ -700,7 +795,10 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification"; copy->_sharpenTune = [_sharpenTune copy]; copy->_sharpenCustomString = [_sharpenCustomString copy]; - copy->_deblock = _deblock; + copy->_deblock = [_deblock copy]; + copy->_deblockTune = [_deblockTune copy]; + copy->_deblockCustomString = [_deblockCustomString copy]; + copy->_grayscale = _grayscale; copy->_rotate = _rotate; copy->_flip = _flip; @@ -740,7 +838,10 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification"; encodeObject(_sharpenTune); encodeObject(_sharpenCustomString); - encodeInt(_deblock); + encodeObject(_deblock); + encodeObject(_deblockTune); + encodeObject(_deblockCustomString); + encodeBool(_grayscale); encodeInt(_rotate); encodeBool(_flip); @@ -770,7 +871,10 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification"; decodeObjectOrFail(_sharpenTune, NSString); decodeObjectOrFail(_sharpenCustomString, NSString); - decodeInt(_deblock); + decodeObjectOrFail(_deblock, NSString); + decodeObjectOrFail(_deblockTune, NSString); + decodeObjectOrFail(_deblockCustomString, NSString); + decodeBool(_grayscale); decodeInt(_rotate); decodeBool(_flip); @@ -807,7 +911,10 @@ fail: preset[@"PictureSharpenTune"] = self.sharpenTune; preset[@"PictureSharpenCustom"] = self.sharpenCustomString; - preset[@"PictureDeblock"] = @(self.deblock); + preset[@"PictureDeblockPreset"] = self.deblock; + preset[@"PictureDeblockTune"] = self.deblockTune; + preset[@"PictureDeblockCustom"] = self.deblockCustomString; + preset[@"VideoGrayScale"] = @(self.grayscale); preset[@"PictureRotate"] = [NSString stringWithFormat:@"angle=%d:hflip=%d", self.rotate, self.flip]; } @@ -836,7 +943,6 @@ fail: self.denoise = preset[@"PictureDenoiseFilter"]; self.denoisePreset = preset[@"PictureDenoisePreset"]; self.denoiseTune = preset[@"PictureDenoiseTune"]; - self.denoiseCustomString = preset[@"PictureDenoiseCustom"]; // Sharpen @@ -845,7 +951,11 @@ fail: self.sharpenTune = preset[@"PictureSharpenTune"]; self.sharpenCustomString = preset[@"PictureSharpenCustom"]; - self.deblock = [preset[@"PictureDeblock"] intValue]; + // Deblock + self.deblock = preset[@"PictureDeblockPreset"]; + self.deblockTune = preset[@"PictureDeblockTune"]; + self.deblockCustomString = preset[@"PictureDeblockCustom"]; + self.grayscale = [preset[@"VideoGrayScale"] boolValue]; // Rotate diff --git a/macosx/HBJob+HBJobConversion.m b/macosx/HBJob+HBJobConversion.m index c9d01885f..073612b26 100644 --- a/macosx/HBJob+HBJobConversion.m +++ b/macosx/HBJob+HBJobConversion.m @@ -469,11 +469,17 @@ hb_dict_free(&filter_dict); } - // Deblock (uses pp7 default) - if (self.filters.deblock) + // Deblock + if (![self.filters.deblock isEqualToString:@"off"]) { - filter = hb_filter_init(HB_FILTER_DEBLOCK); - hb_add_filter(job, filter, [NSString stringWithFormat:@"qp=%d", self.filters.deblock].UTF8String); + int filter_id = HB_FILTER_DEBLOCK; + hb_dict_t *filter_dict = hb_generate_filter_settings(filter_id, + self.filters.deblock.UTF8String, + self.filters.deblockTune.UTF8String, + self.filters.deblockCustomString.UTF8String); + filter = hb_filter_init(filter_id); + hb_add_filter_dict(job, filter, filter_dict); + hb_value_free(&filter_dict); } // Add Crop/Scale filter diff --git a/macosx/HBJob+UIAdditions.m b/macosx/HBJob+UIAdditions.m index 75c7729fe..4f711bacb 100644 --- a/macosx/HBJob+UIAdditions.m +++ b/macosx/HBJob+UIAdditions.m @@ -304,9 +304,19 @@ static NSDictionary *shortHeightAttr; } // Deblock - if (filters.deblock > 0) + if (![filters.deblock isEqualToString:@"off"]) { - [summary appendFormat:@", %@ (%d)", HBKitLocalizedString(@"Deblock", @"Filters description"), filters.deblock]; + [summary appendFormat:@", %@ (%@", HBKitLocalizedString(@"Deblock", @"Filters description"), [[[HBFilters deblockPresetDict] allKeysForObject:filters.deblock] firstObject]]; + if (![filters.deblock isEqualToString:@"custom"]) + { + [summary appendFormat:@", %@", [[[HBFilters deblockTunesDict] allKeysForObject:filters.deblockTune] firstObject]]; + } + else + { + [summary appendFormat:@", %@", filters.deblockCustomString]; + } + + [summary appendString:@")"]; } // Denoise @@ -354,7 +364,6 @@ static NSDictionary *shortHeightAttr; } [summary appendString:@")"]; - } // Grayscale @@ -850,7 +859,7 @@ static NSDictionary *shortHeightAttr; } // Deblock - if (filters.deblock > 0) + if (![filters.deblock isEqualToString:@"off"]) { [summary appendString:HBKitLocalizedString(@"Deblock", @"HBJob -> filters short description")]; [summary appendString:@", "];