Authored by DreamPiggy

Adopt the current requirement, change ImageIO coder's canDeocdeFromHEIC to actual implementation

@@ -17,8 +17,11 @@ @@ -17,8 +17,11 @@
17 For a full GIF support, we recommend `FLAnimatedImage` or our less performant `SDWebImageGIFCoder` 17 For a full GIF support, we recommend `FLAnimatedImage` or our less performant `SDWebImageGIFCoder`
18 18
19 HEIC 19 HEIC
20 - 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.  
21 - Hardware works if: (iOS 11 || macOS 10.13) && (isMac || isIPhoneAndA10FusionChipAbove) && (!Simulator) 20 + 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
  21 + Decode(Software): !Simulator && (iOS 11 || tvOS 11 || macOS 10.13)
  22 + Decode(Hardware): !Simulator && ((iOS 11 && A9Chip) || (macOS 10.13 && 6thGenerationIntelCPU))
  23 + Encode(Software): macOS 10.13
  24 + Encode(Hardware): !Simulator && ((iOS 11 && A10FusionChip) || (macOS 10.13 && 6thGenerationIntelCPU))
22 */ 25 */
23 @interface SDWebImageImageIOCoder : NSObject <SDWebImageProgressiveCoder> 26 @interface SDWebImageImageIOCoder : NSObject <SDWebImageProgressiveCoder>
24 27
@@ -70,6 +70,9 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over @@ -70,6 +70,9 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
70 case SDImageFormatWebP: 70 case SDImageFormatWebP:
71 // Do not support WebP decoding 71 // Do not support WebP decoding
72 return NO; 72 return NO;
  73 + case SDImageFormatHEIC:
  74 + // Check HEIC decoding compatibility
  75 + return [[self class] canDecodeFromHEICFormat];
73 default: 76 default:
74 return YES; 77 return YES;
75 } 78 }
@@ -80,6 +83,9 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over @@ -80,6 +83,9 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
80 case SDImageFormatWebP: 83 case SDImageFormatWebP:
81 // Do not support WebP progressive decoding 84 // Do not support WebP progressive decoding
82 return NO; 85 return NO;
  86 + case SDImageFormatHEIC:
  87 + // Check HEIC decoding compatibility
  88 + return [[self class] canDecodeFromHEICFormat];
83 default: 89 default:
84 return YES; 90 return YES;
85 } 91 }
@@ -470,6 +476,33 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over @@ -470,6 +476,33 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
470 return YES; 476 return YES;
471 } 477 }
472 478
  479 ++ (BOOL)canDecodeFromHEICFormat {
  480 + static BOOL canDecode = NO;
  481 + static dispatch_once_t onceToken;
  482 + dispatch_once(&onceToken, ^{
  483 +#if TARGET_OS_SIMULATOR || SD_WATCH
  484 + canDecode = NO;
  485 +#elif SD_MAC
  486 + NSProcessInfo *processInfo = [NSProcessInfo processInfo];
  487 + if ([processInfo respondsToSelector:@selector(operatingSystemVersion)]) {
  488 + // macOS 10.13+
  489 + canDecode = processInfo.operatingSystemVersion.minorVersion >= 13;
  490 + } else {
  491 + canDecode = NO;
  492 + }
  493 +#elif SD_UIKIT
  494 + NSProcessInfo *processInfo = [NSProcessInfo processInfo];
  495 + if ([processInfo respondsToSelector:@selector(operatingSystemVersion)]) {
  496 + // iOS 11+ && tvOS 11+
  497 + canDecode = processInfo.operatingSystemVersion.majorVersion >= 11;
  498 + } else {
  499 + canDecode = NO;
  500 + }
  501 +#endif
  502 + });
  503 + return canDecode;
  504 +}
  505 +
473 + (BOOL)canEncodeToHEICFormat { 506 + (BOOL)canEncodeToHEICFormat {
474 static BOOL canEncode = NO; 507 static BOOL canEncode = NO;
475 static dispatch_once_t onceToken; 508 static dispatch_once_t onceToken;