Merge pull request #3426 from dreampiggy/bugfix/UTI_hint_ignore_dynamic_log

Ignore the dynamic UTI type hint to avoid extra log
This commit is contained in:
DreamPiggy 2022-11-08 16:20:33 +08:00 committed by GitHub
commit cdd77d5ebe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 3 deletions

View File

@ -35,6 +35,10 @@ SDImageCoderOptions * _Nonnull SDGetDecodeOptionsFromContext(SDWebImageContext *
if (!typeIdentifierHint) { if (!typeIdentifierHint) {
// UTI has high priority // UTI has high priority
fileExtensionHint = cacheKey.pathExtension; // without dot fileExtensionHint = cacheKey.pathExtension; // without dot
if (fileExtensionHint.length == 0) {
// Ignore file extension which is empty
fileExtensionHint = nil;
}
} }
// First check if user provided decode options // First check if user provided decode options
@ -71,7 +75,11 @@ void SDSetDecodeOptionsToContext(SDWebImageMutableContext * _Nonnull mutableCont
if (!typeIdentifierHint) { if (!typeIdentifierHint) {
NSString *fileExtensionHint = decodeOptions[SDImageCoderDecodeFileExtensionHint]; NSString *fileExtensionHint = decodeOptions[SDImageCoderDecodeFileExtensionHint];
if (fileExtensionHint) { if (fileExtensionHint) {
typeIdentifierHint = (__bridge_transfer NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExtensionHint, NULL); typeIdentifierHint = (__bridge_transfer NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExtensionHint, kUTTypeImage);
// Ignore dynamic UTI
if (UTTypeIsDynamic((__bridge CFStringRef)typeIdentifierHint)) {
typeIdentifierHint = nil;
}
} }
} }
mutableContext[SDWebImageContextImageTypeIdentifierHint] = typeIdentifierHint; mutableContext[SDWebImageContextImageTypeIdentifierHint] = typeIdentifierHint;

View File

@ -372,7 +372,11 @@ static CGImageRef __nullable SDCGImageCreateCopy(CGImageRef cg_nullable image) {
// Check file extension and convert to UTI, from: https://stackoverflow.com/questions/1506251/getting-an-uniform-type-identifier-for-a-given-extension // Check file extension and convert to UTI, from: https://stackoverflow.com/questions/1506251/getting-an-uniform-type-identifier-for-a-given-extension
NSString *fileExtensionHint = options[SDImageCoderDecodeFileExtensionHint]; NSString *fileExtensionHint = options[SDImageCoderDecodeFileExtensionHint];
if (fileExtensionHint) { if (fileExtensionHint) {
typeIdentifierHint = (__bridge_transfer NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExtensionHint, NULL); typeIdentifierHint = (__bridge_transfer NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExtensionHint, kUTTypeImage);
// Ignore dynamic UTI
if (UTTypeIsDynamic((__bridge CFStringRef)typeIdentifierHint)) {
typeIdentifierHint = nil;
}
} }
} else if ([typeIdentifierHint isEqual:NSNull.null]) { } else if ([typeIdentifierHint isEqual:NSNull.null]) {
// Hack if user don't want to imply file extension // Hack if user don't want to imply file extension

View File

@ -124,7 +124,11 @@ static NSString * kSDCGImageDestinationRequestedFileSize = @"kCGImageDestination
// Check file extension and convert to UTI, from: https://stackoverflow.com/questions/1506251/getting-an-uniform-type-identifier-for-a-given-extension // Check file extension and convert to UTI, from: https://stackoverflow.com/questions/1506251/getting-an-uniform-type-identifier-for-a-given-extension
NSString *fileExtensionHint = options[SDImageCoderDecodeFileExtensionHint]; NSString *fileExtensionHint = options[SDImageCoderDecodeFileExtensionHint];
if (fileExtensionHint) { if (fileExtensionHint) {
typeIdentifierHint = (__bridge_transfer NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExtensionHint, NULL); typeIdentifierHint = (__bridge_transfer NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExtensionHint, kUTTypeImage);
// Ignore dynamic UTI
if (UTTypeIsDynamic((__bridge CFStringRef)typeIdentifierHint)) {
typeIdentifierHint = nil;
}
} }
} else if ([typeIdentifierHint isEqual:NSNull.null]) { } else if ([typeIdentifierHint isEqual:NSNull.null]) {
// Hack if user don't want to imply file extension // Hack if user don't want to imply file extension