diff --git a/SDWebImage/SDWebImageImageIOCoder.h b/SDWebImage/SDWebImageImageIOCoder.h index 524d9bbe..04f68fb9 100644 --- a/SDWebImage/SDWebImageImageIOCoder.h +++ b/SDWebImage/SDWebImageImageIOCoder.h @@ -17,8 +17,11 @@ For a full GIF support, we recommend `FLAnimatedImage` or our less performant `SDWebImageGIFCoder` HEIC - This coder also supports HEIC format because ImageIO supports it natively. But it depends on the system capabilities, so it won't work on all devices. - Hardware works if: (iOS 11 || macOS 10.13) && (isMac || isIPhoneAndA10FusionChipAbove) && (!Simulator) + This coder also supports HEIC format because ImageIO supports it natively. But it depends on the system capabilities, so it won't work on all devices, see: https://devstreaming-cdn.apple.com/videos/wwdc/2017/511tj33587vdhds/511/511_working_with_heif_and_hevc.pdf + Decode(Software): !Simulator && (iOS 11 || tvOS 11 || macOS 10.13) + Decode(Hardware): !Simulator && ((iOS 11 && A9Chip) || (macOS 10.13 && 6thGenerationIntelCPU)) + Encode(Software): macOS 10.13 + Encode(Hardware): !Simulator && ((iOS 11 && A10FusionChip) || (macOS 10.13 && 6thGenerationIntelCPU)) */ @interface SDWebImageImageIOCoder : NSObject diff --git a/SDWebImage/SDWebImageImageIOCoder.m b/SDWebImage/SDWebImageImageIOCoder.m index 2f50c36c..25c2d194 100644 --- a/SDWebImage/SDWebImageImageIOCoder.m +++ b/SDWebImage/SDWebImageImageIOCoder.m @@ -70,6 +70,9 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over case SDImageFormatWebP: // Do not support WebP decoding return NO; + case SDImageFormatHEIC: + // Check HEIC decoding compatibility + return [[self class] canDecodeFromHEICFormat]; default: return YES; } @@ -80,6 +83,9 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over case SDImageFormatWebP: // Do not support WebP progressive decoding return NO; + case SDImageFormatHEIC: + // Check HEIC decoding compatibility + return [[self class] canDecodeFromHEICFormat]; default: return YES; } @@ -470,6 +476,33 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over return YES; } ++ (BOOL)canDecodeFromHEICFormat { + static BOOL canDecode = NO; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ +#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; + } +#elif SD_UIKIT + NSProcessInfo *processInfo = [NSProcessInfo processInfo]; + if ([processInfo respondsToSelector:@selector(operatingSystemVersion)]) { + // iOS 11+ && tvOS 11+ + canDecode = processInfo.operatingSystemVersion.majorVersion >= 11; + } else { + canDecode = NO; + } +#endif + }); + return canDecode; +} + + (BOOL)canEncodeToHEICFormat { static BOOL canEncode = NO; static dispatch_once_t onceToken;