summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamiano Galassi <[email protected]>2021-02-26 16:06:20 +0100
committerDamiano Galassi <[email protected]>2021-02-26 16:06:20 +0100
commit47cfff5767e822c281146c3d57d9c83678f7cbeb (patch)
tree1b9a875e22a4c67c56f1dbd4f6d64c2e28c203ff
parentf707724396b57923211f162e9c2936cc49f4a3cd (diff)
MacGui: generate the filters keys shown in the custom textfields instead of hardcoding them.
-rw-r--r--macosx/HBFilters.m128
1 files changed, 117 insertions, 11 deletions
diff --git a/macosx/HBFilters.m b/macosx/HBFilters.m
index 5596d8ade..e2a676bf8 100644
--- a/macosx/HBFilters.m
+++ b/macosx/HBFilters.m
@@ -48,6 +48,8 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification";
_deblock = @"off";
_deblockTune = @"none";
_deblockCustomString = @"";
+ _colorspace = @"off";
+ _colorspaceCustomString = @"";
_notificationsEnabled = YES;
}
@@ -64,6 +66,110 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification";
}
}
+#define LAPSHARP_DEFAULT_PRESET "medium"
+#define UNSHARP_DEFAULT_PRESET "medium"
+#define CHROMA_SMOOTH_DEFAULT_PRESET "medium"
+#define NLMEANS_DEFAULT_PRESET "medium"
+#define DEINTERLACE_DEFAULT_PRESET "default"
+#define DECOMB_DEFAULT_PRESET "default"
+#define DETELECINE_DEFAULT_PRESET "default"
+#define COMB_DETECT_DEFAULT_PRESET "default"
+#define HQDN3D_DEFAULT_PRESET "medium"
+#define DEBLOCK_DEFAULT_PRESET "medium"
+#define COLORSPACE_DEFAULT_PRESET "bt709"
+
+- (NSString *)filterKeysDescription:(int)filter_id
+{
+ char **keys = hb_filter_get_keys(filter_id);
+ char *colon = "";
+
+ NSMutableString *result = [[NSMutableString alloc] init];
+ [result appendString:HBKitLocalizedString(@"Syntax: ", @"HBFilters -> invalid filter custom settings error recovery suggestion")];
+
+ for (int ii = 0; keys[ii] != NULL; ii++)
+ {
+ int c = tolower(keys[ii][0]);
+ [result appendFormat:@"%s%s=%c", colon, keys[ii], c];
+ colon = ":";
+ }
+ hb_str_vfree(keys);
+
+ [result appendString:@"\n\n"];
+ [result appendString:HBKitLocalizedString(@"Default: ", @"HBFilters -> invalid filter custom settings error recovery suggestion")];
+
+ const char *preset = "default";
+ switch (filter_id)
+ {
+ case HB_FILTER_UNSHARP:
+ preset = UNSHARP_DEFAULT_PRESET;
+ break;
+ case HB_FILTER_LAPSHARP:
+ preset = LAPSHARP_DEFAULT_PRESET;
+ break;
+ case HB_FILTER_CHROMA_SMOOTH:
+ preset = CHROMA_SMOOTH_DEFAULT_PRESET;
+ break;
+ case HB_FILTER_NLMEANS:
+ preset = NLMEANS_DEFAULT_PRESET;
+ break;
+ case HB_FILTER_DEINTERLACE:
+ preset = DEINTERLACE_DEFAULT_PRESET;
+ break;
+ case HB_FILTER_DECOMB:
+ preset = DECOMB_DEFAULT_PRESET;
+ break;
+ case HB_FILTER_DETELECINE:
+ preset = DETELECINE_DEFAULT_PRESET;
+ break;
+ case HB_FILTER_HQDN3D:
+ preset = HQDN3D_DEFAULT_PRESET;
+ break;
+ case HB_FILTER_COMB_DETECT:
+ preset = COMB_DETECT_DEFAULT_PRESET;
+ break;
+ case HB_FILTER_DEBLOCK:
+ preset = DEBLOCK_DEFAULT_PRESET;
+ break;
+ default:
+ break;
+ }
+ switch (filter_id)
+ {
+ case HB_FILTER_DEINTERLACE:
+ case HB_FILTER_NLMEANS:
+ case HB_FILTER_CHROMA_SMOOTH:
+ case HB_FILTER_COLORSPACE:
+ case HB_FILTER_UNSHARP:
+ case HB_FILTER_LAPSHARP:
+ case HB_FILTER_DECOMB:
+ case HB_FILTER_DETELECINE:
+ case HB_FILTER_HQDN3D:
+ case HB_FILTER_COMB_DETECT:
+ case HB_FILTER_DEBLOCK:
+ {
+ hb_dict_t *settings;
+ settings = hb_generate_filter_settings(filter_id, preset, NULL, NULL);
+ char *str = hb_filter_settings_string(filter_id, settings);
+ hb_value_free(&settings);
+
+ char **split = hb_str_vsplit(str, ':');
+ colon = "";
+
+ for (int ii = 0; split[ii] != NULL; ii++)
+ {
+ [result appendFormat:@"%s%s", colon, split[ii]];
+ colon = ":";
+ }
+ hb_str_vfree(split);
+ free(str);
+ } break;
+ default:
+ break;
+ }
+
+ return result;
+}
+
#pragma mark - Detelecine
- (void)setDetelecine:(NSString *)detelecine
@@ -123,7 +229,7 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification";
{
NSDictionary *userInfo = @{NSLocalizedDescriptionKey: HBKitLocalizedString(@"Invalid custom detelecine settings.",
@"HBFilters -> invalid detelecine custom string description"),
- NSLocalizedRecoverySuggestionErrorKey: HBKitLocalizedString(@"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")};
+ NSLocalizedRecoverySuggestionErrorKey: [self filterKeysDescription:filter_id]};
*outError = [NSError errorWithDomain:@"HBFilterError" code:0 userInfo:userInfo];
}
}
@@ -190,7 +296,7 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification";
{
NSDictionary *userInfo = @{NSLocalizedDescriptionKey: HBKitLocalizedString(@"Invalid custom comb detect settings.",
@"HBFilters -> invalid comb detect custom string description"),
- NSLocalizedRecoverySuggestionErrorKey: HBKitLocalizedString(@"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")};
+ NSLocalizedRecoverySuggestionErrorKey: [self filterKeysDescription:filter_id]};
*outError = [NSError errorWithDomain:@"HBFilterError" code:0 userInfo:userInfo];
}
}
@@ -301,14 +407,14 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification";
{
NSDictionary *userInfo = @{NSLocalizedDescriptionKey: HBKitLocalizedString(@"Invalid Yadif custom settings.",
@"HBFilters -> invalid Yadif custom string description"),
- NSLocalizedRecoverySuggestionErrorKey: HBKitLocalizedString(@"Yadif syntax: mode=m:parity=p\n\nYadif default: mode=3", @"HBJob -> invalid Yadif custom settings error recovery suggestion")};
+ NSLocalizedRecoverySuggestionErrorKey: [self filterKeysDescription:filter_id]};
*outError = [NSError errorWithDomain:@"HBFilterError" code:0 userInfo:userInfo];
}
else if (filter_id == HB_FILTER_DECOMB)
{
NSDictionary *userInfo = @{NSLocalizedDescriptionKey: HBKitLocalizedString(@"Invalid Decomb custom settings.",
@"HBFilters -> invalid Decomb custom string description"),
- NSLocalizedRecoverySuggestionErrorKey: HBKitLocalizedString(@"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")};
+ NSLocalizedRecoverySuggestionErrorKey: [self filterKeysDescription:filter_id]};
*outError = [NSError errorWithDomain:@"HBFilterError" code:0 userInfo:userInfo];
}
}
@@ -419,14 +525,14 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification";
{
NSDictionary *userInfo = @{NSLocalizedDescriptionKey: HBKitLocalizedString(@"Invalid custom HQDN3D settings",
@"HBFilters -> invalid denoise custom string description"),
- NSLocalizedRecoverySuggestionErrorKey: HBKitLocalizedString(@"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")};
+ NSLocalizedRecoverySuggestionErrorKey: [self filterKeysDescription:filter_id]};
*outError = [NSError errorWithDomain:@"HBFilterError" code:0 userInfo:userInfo];
}
else if (filter_id == HB_FILTER_NLMEANS)
{
NSDictionary *userInfo = @{NSLocalizedDescriptionKey: HBKitLocalizedString(@"Invalid custom NLMeans settings",
@"HBFilters -> invalid denoise custom string description"),
- NSLocalizedRecoverySuggestionErrorKey: HBKitLocalizedString(@"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")};
+ NSLocalizedRecoverySuggestionErrorKey: [self filterKeysDescription:filter_id]};
*outError = [NSError errorWithDomain:@"HBFilterError" code:0 userInfo:userInfo];
}
}
@@ -513,7 +619,7 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification";
{
NSDictionary *userInfo = @{NSLocalizedDescriptionKey: HBKitLocalizedString(@"Invalid chroma smooth custom settings.",
@"HBFilters -> invalid chroma smooth custom string description"),
- NSLocalizedRecoverySuggestionErrorKey: HBKitLocalizedString(@"Chroma Smooth syntax: cb-strength=c:cb-size=c:cr-strength=c:cr-size=c", @"HBJob -> invalid chroma smooth settings error recovery suggestion")};
+ NSLocalizedRecoverySuggestionErrorKey: [self filterKeysDescription:filter_id]};
*outError = [NSError errorWithDomain:@"HBFilterError" code:0 userInfo:userInfo];
}
}
@@ -656,14 +762,14 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification";
{
NSDictionary *userInfo = @{NSLocalizedDescriptionKey: HBKitLocalizedString(@"Invalid unsharp custom settings.",
@"HBFilters -> invalid unsharp custom string description"),
- NSLocalizedRecoverySuggestionErrorKey: HBKitLocalizedString(@"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")};
+ NSLocalizedRecoverySuggestionErrorKey: [self filterKeysDescription:filter_id]};
*outError = [NSError errorWithDomain:@"HBFilterError" code:0 userInfo:userInfo];
}
else if (filter_id == HB_FILTER_LAPSHARP)
{
NSDictionary *userInfo = @{NSLocalizedDescriptionKey: HBKitLocalizedString(@"Invalid lapsharp custom settings.",
@"HBFilters -> invalid lapsharp custom string description"),
- NSLocalizedRecoverySuggestionErrorKey: HBKitLocalizedString(@"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")};
+ NSLocalizedRecoverySuggestionErrorKey: [self filterKeysDescription:filter_id]};
*outError = [NSError errorWithDomain:@"HBFilterError" code:0 userInfo:userInfo];
}
}
@@ -750,7 +856,7 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification";
{
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")};
+ NSLocalizedRecoverySuggestionErrorKey: [self filterKeysDescription:filter_id]};
*outError = [NSError errorWithDomain:@"HBFilterError" code:0 userInfo:userInfo];
}
}
@@ -830,7 +936,7 @@ NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification";
{
NSDictionary *userInfo = @{NSLocalizedDescriptionKey: HBKitLocalizedString(@"Invalid colorspace custom settings.",
@"HBFilters -> invalid chroma smooth custom string description"),
- NSLocalizedRecoverySuggestionErrorKey: HBKitLocalizedString(@"Colorspace syntax: primaries=p:transfer=t:matrix=m:tonemap=t:param=p:desat=d", @"HBJob -> invalid chroma smooth settings error recovery suggestion")};
+ NSLocalizedRecoverySuggestionErrorKey: [self filterKeysDescription:filter_id]};
*outError = [NSError errorWithDomain:@"HBFilterError" code:0 userInfo:userInfo];
}
}