|
|
@@ -74,6 +74,9 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
|
|
|
case SDImageFormatHEIC:
|
|
|
// Check HEIC decoding compatibility
|
|
|
return [[self class] canDecodeFromHEICFormat];
|
|
|
+ case SDImageFormatHEIF:
|
|
|
+ // Check HEIF decoding compatibility
|
|
|
+ return [[self class] canDecodeFromHEIFFormat];
|
|
|
default:
|
|
|
return YES;
|
|
|
}
|
|
|
@@ -87,6 +90,9 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
|
|
|
case SDImageFormatHEIC:
|
|
|
// Check HEIC decoding compatibility
|
|
|
return [[self class] canDecodeFromHEICFormat];
|
|
|
+ case SDImageFormatHEIF:
|
|
|
+ // Check HEIF decoding compatibility
|
|
|
+ return [[self class] canDecodeFromHEIFFormat];
|
|
|
default:
|
|
|
return YES;
|
|
|
}
|
|
|
@@ -372,6 +378,9 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
|
|
|
case SDImageFormatHEIC:
|
|
|
// Check HEIC encoding compatibility
|
|
|
return [[self class] canEncodeToHEICFormat];
|
|
|
+ case SDImageFormatHEIF:
|
|
|
+ // Check HEIF encoding compatibility
|
|
|
+ return [[self class] canEncodeToHEIFFormat];
|
|
|
default:
|
|
|
return YES;
|
|
|
}
|
|
|
@@ -440,28 +449,24 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
|
|
|
static BOOL canDecode = NO;
|
|
|
static dispatch_once_t onceToken;
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
-#pragma clang diagnostic push
|
|
|
-#pragma clang diagnostic ignored "-Wunguarded-availability"
|
|
|
-#if TARGET_OS_SIMULATOR || SD_WATCH
|
|
|
- canDecode = NO;
|
|
|
-#elif SD_MAC
|
|
|
- NSProcessInfo *processInfo = [NSProcessInfo processInfo];
|
|
|
- if ([processInfo respondsToSelector:@selector(operatingSystemVersion)]) {
|
|
|
- // macOS 10.13+
|
|
|
- canDecode = processInfo.operatingSystemVersion.minorVersion >= 13;
|
|
|
- } else {
|
|
|
- canDecode = NO;
|
|
|
+ CFStringRef imageUTType = [NSData sd_UTTypeFromSDImageFormat:SDImageFormatHEIC];
|
|
|
+ NSArray *imageUTTypes = (__bridge_transfer NSArray *)CGImageSourceCopyTypeIdentifiers();
|
|
|
+ if ([imageUTTypes containsObject:(__bridge NSString *)(imageUTType)]) {
|
|
|
+ canDecode = YES;
|
|
|
}
|
|
|
-#elif SD_UIKIT
|
|
|
- NSProcessInfo *processInfo = [NSProcessInfo processInfo];
|
|
|
- if ([processInfo respondsToSelector:@selector(operatingSystemVersion)]) {
|
|
|
- // iOS 11+ && tvOS 11+
|
|
|
- canDecode = processInfo.operatingSystemVersion.majorVersion >= 11;
|
|
|
- } else {
|
|
|
- canDecode = NO;
|
|
|
+ });
|
|
|
+ return canDecode;
|
|
|
+}
|
|
|
+
|
|
|
++ (BOOL)canDecodeFromHEIFFormat {
|
|
|
+ static BOOL 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;
|
|
|
}
|
|
|
@@ -487,6 +492,27 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
|
|
|
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
|
|
|
+ (BOOL)shouldScaleDownImage:(nonnull UIImage *)image {
|
|
|
BOOL shouldScaleDown = YES;
|