Add SDImageFormatHEIF represent mif1 && msf1 brands
Fix the current hard-coded system version checking with Image/IO source uttypes checking
This commit is contained in:
parent
676a4b53b7
commit
7ddb75710c
|
@ -68,6 +68,7 @@
|
||||||
@"http://littlesvr.ca/apng/images/SteamEngine.webp",
|
@"http://littlesvr.ca/apng/images/SteamEngine.webp",
|
||||||
@"http://littlesvr.ca/apng/images/world-cup-2014-42.webp",
|
@"http://littlesvr.ca/apng/images/world-cup-2014-42.webp",
|
||||||
@"https://isparta.github.io/compare-webp/image/gif_webp/webp/2.webp",
|
@"https://isparta.github.io/compare-webp/image/gif_webp/webp/2.webp",
|
||||||
|
@"https://nokiatech.github.io/heif/content/images/ski_jump_1440x960.heic",
|
||||||
@"https://nr-platform.s3.amazonaws.com/uploads/platform/published_extension/branding_icon/275/AmazonS3.png",
|
@"https://nr-platform.s3.amazonaws.com/uploads/platform/published_extension/branding_icon/275/AmazonS3.png",
|
||||||
@"http://via.placeholder.com/200x200.jpg",
|
@"http://via.placeholder.com/200x200.jpg",
|
||||||
nil];
|
nil];
|
||||||
|
|
|
@ -17,7 +17,8 @@ typedef NS_ENUM(NSInteger, SDImageFormat) {
|
||||||
SDImageFormatGIF,
|
SDImageFormatGIF,
|
||||||
SDImageFormatTIFF,
|
SDImageFormatTIFF,
|
||||||
SDImageFormatWebP,
|
SDImageFormatWebP,
|
||||||
SDImageFormatHEIC
|
SDImageFormatHEIC,
|
||||||
|
SDImageFormatHEIF
|
||||||
};
|
};
|
||||||
|
|
||||||
@interface NSData (ImageContentType)
|
@interface NSData (ImageContentType)
|
||||||
|
|
|
@ -16,8 +16,9 @@
|
||||||
|
|
||||||
// Currently Image/IO does not support WebP
|
// Currently Image/IO does not support WebP
|
||||||
#define kSDUTTypeWebP ((__bridge CFStringRef)@"public.webp")
|
#define kSDUTTypeWebP ((__bridge CFStringRef)@"public.webp")
|
||||||
// AVFileTypeHEIC is defined in AVFoundation via iOS 11, we use this without import AVFoundation
|
// AVFileTypeHEIC/AVFileTypeHEIF is defined in AVFoundation via iOS 11, we use this without import AVFoundation
|
||||||
#define kSDUTTypeHEIC ((__bridge CFStringRef)@"public.heic")
|
#define kSDUTTypeHEIC ((__bridge CFStringRef)@"public.heic")
|
||||||
|
#define kSDUTTypeHEIF ((__bridge CFStringRef)@"public.heif")
|
||||||
|
|
||||||
@implementation NSData (ImageContentType)
|
@implementation NSData (ImageContentType)
|
||||||
|
|
||||||
|
@ -59,6 +60,9 @@
|
||||||
|| [testString isEqualToString:@"ftyphevx"]) {
|
|| [testString isEqualToString:@"ftyphevx"]) {
|
||||||
return SDImageFormatHEIC;
|
return SDImageFormatHEIC;
|
||||||
}
|
}
|
||||||
|
if ([testString isEqualToString:@"ftypmif1"] || [testString isEqualToString:@"ftypmsf1"]) {
|
||||||
|
return SDImageFormatHEIF;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -87,6 +91,9 @@
|
||||||
case SDImageFormatHEIC:
|
case SDImageFormatHEIC:
|
||||||
UTType = kSDUTTypeHEIC;
|
UTType = kSDUTTypeHEIC;
|
||||||
break;
|
break;
|
||||||
|
case SDImageFormatHEIF:
|
||||||
|
UTType = kSDUTTypeHEIF;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
// default is kUTTypePNG
|
// default is kUTTypePNG
|
||||||
UTType = kUTTypePNG;
|
UTType = kUTTypePNG;
|
||||||
|
@ -112,6 +119,8 @@
|
||||||
imageFormat = SDImageFormatWebP;
|
imageFormat = SDImageFormatWebP;
|
||||||
} else if (CFStringCompare(uttype, kSDUTTypeHEIC, 0) == kCFCompareEqualTo) {
|
} else if (CFStringCompare(uttype, kSDUTTypeHEIC, 0) == kCFCompareEqualTo) {
|
||||||
imageFormat = SDImageFormatHEIC;
|
imageFormat = SDImageFormatHEIC;
|
||||||
|
} else if (CFStringCompare(uttype, kSDUTTypeHEIF, 0) == kCFCompareEqualTo) {
|
||||||
|
imageFormat = SDImageFormatHEIF;
|
||||||
} else {
|
} else {
|
||||||
imageFormat = SDImageFormatUndefined;
|
imageFormat = SDImageFormatUndefined;
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,6 +74,9 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
|
||||||
case SDImageFormatHEIC:
|
case SDImageFormatHEIC:
|
||||||
// Check HEIC decoding compatibility
|
// Check HEIC decoding compatibility
|
||||||
return [[self class] canDecodeFromHEICFormat];
|
return [[self class] canDecodeFromHEICFormat];
|
||||||
|
case SDImageFormatHEIF:
|
||||||
|
// Check HEIF decoding compatibility
|
||||||
|
return [[self class] canDecodeFromHEIFFormat];
|
||||||
default:
|
default:
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
@ -87,6 +90,9 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
|
||||||
case SDImageFormatHEIC:
|
case SDImageFormatHEIC:
|
||||||
// Check HEIC decoding compatibility
|
// Check HEIC decoding compatibility
|
||||||
return [[self class] canDecodeFromHEICFormat];
|
return [[self class] canDecodeFromHEICFormat];
|
||||||
|
case SDImageFormatHEIF:
|
||||||
|
// Check HEIF decoding compatibility
|
||||||
|
return [[self class] canDecodeFromHEIFFormat];
|
||||||
default:
|
default:
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
@ -372,6 +378,9 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
|
||||||
case SDImageFormatHEIC:
|
case SDImageFormatHEIC:
|
||||||
// Check HEIC encoding compatibility
|
// Check HEIC encoding compatibility
|
||||||
return [[self class] canEncodeToHEICFormat];
|
return [[self class] canEncodeToHEICFormat];
|
||||||
|
case SDImageFormatHEIF:
|
||||||
|
// Check HEIF encoding compatibility
|
||||||
|
return [[self class] canEncodeToHEIFFormat];
|
||||||
default:
|
default:
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
@ -440,28 +449,24 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
|
||||||
static BOOL canDecode = NO;
|
static BOOL canDecode = NO;
|
||||||
static dispatch_once_t onceToken;
|
static dispatch_once_t onceToken;
|
||||||
dispatch_once(&onceToken, ^{
|
dispatch_once(&onceToken, ^{
|
||||||
#pragma clang diagnostic push
|
CFStringRef imageUTType = [NSData sd_UTTypeFromSDImageFormat:SDImageFormatHEIC];
|
||||||
#pragma clang diagnostic ignored "-Wunguarded-availability"
|
NSArray *imageUTTypes = (__bridge_transfer NSArray *)CGImageSourceCopyTypeIdentifiers();
|
||||||
#if TARGET_OS_SIMULATOR || SD_WATCH
|
if ([imageUTTypes containsObject:(__bridge NSString *)(imageUTType)]) {
|
||||||
canDecode = NO;
|
canDecode = YES;
|
||||||
#elif SD_MAC
|
|
||||||
NSProcessInfo *processInfo = [NSProcessInfo processInfo];
|
|
||||||
if ([processInfo respondsToSelector:@selector(operatingSystemVersion)]) {
|
|
||||||
// macOS 10.13+
|
|
||||||
canDecode = processInfo.operatingSystemVersion.minorVersion >= 13;
|
|
||||||
} else {
|
|
||||||
canDecode = NO;
|
|
||||||
}
|
}
|
||||||
#elif SD_UIKIT
|
});
|
||||||
NSProcessInfo *processInfo = [NSProcessInfo processInfo];
|
return canDecode;
|
||||||
if ([processInfo respondsToSelector:@selector(operatingSystemVersion)]) {
|
}
|
||||||
// iOS 11+ && tvOS 11+
|
|
||||||
canDecode = processInfo.operatingSystemVersion.majorVersion >= 11;
|
+ (BOOL)canDecodeFromHEIFFormat {
|
||||||
} else {
|
static BOOL canDecode = NO;
|
||||||
canDecode = NO;
|
static dispatch_once_t onceToken;
|
||||||
|
dispatch_once(&onceToken, ^{
|
||||||
|
CFStringRef imageUTType = [NSData sd_UTTypeFromSDImageFormat:SDImageFormatHEIF];
|
||||||
|
NSArray *imageUTTypes = (__bridge_transfer NSArray *)CGImageSourceCopyTypeIdentifiers();
|
||||||
|
if ([imageUTTypes containsObject:(__bridge NSString *)(imageUTType)]) {
|
||||||
|
canDecode = YES;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
#pragma clang diagnostic pop
|
|
||||||
});
|
});
|
||||||
return canDecode;
|
return canDecode;
|
||||||
}
|
}
|
||||||
|
@ -487,6 +492,27 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
|
||||||
return canEncode;
|
return canEncode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (BOOL)canEncodeToHEIFFormat {
|
||||||
|
static BOOL canEncode = NO;
|
||||||
|
static dispatch_once_t onceToken;
|
||||||
|
dispatch_once(&onceToken, ^{
|
||||||
|
NSMutableData *imageData = [NSMutableData data];
|
||||||
|
CFStringRef imageUTType = [NSData sd_UTTypeFromSDImageFormat:SDImageFormatHEIF];
|
||||||
|
|
||||||
|
// Create an image destination.
|
||||||
|
CGImageDestinationRef imageDestination = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)imageData, imageUTType, 1, NULL);
|
||||||
|
if (!imageDestination) {
|
||||||
|
// Can't encode to HEIF
|
||||||
|
canEncode = NO;
|
||||||
|
} else {
|
||||||
|
// Can encode to HEIF
|
||||||
|
CFRelease(imageDestination);
|
||||||
|
canEncode = YES;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return canEncode;
|
||||||
|
}
|
||||||
|
|
||||||
#if SD_UIKIT || SD_WATCH
|
#if SD_UIKIT || SD_WATCH
|
||||||
+ (BOOL)shouldScaleDownImage:(nonnull UIImage *)image {
|
+ (BOOL)shouldScaleDownImage:(nonnull UIImage *)image {
|
||||||
BOOL shouldScaleDown = YES;
|
BOOL shouldScaleDown = YES;
|
||||||
|
|
Loading…
Reference in New Issue