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

This commit is contained in:
DreamPiggy 2017-12-29 17:38:24 +08:00
parent cc9265e187
commit 08b913ed19
2 changed files with 38 additions and 2 deletions

View File

@ -17,8 +17,11 @@
For a full GIF support, we recommend `FLAnimatedImage` or our less performant `SDWebImageGIFCoder` For a full GIF support, we recommend `FLAnimatedImage` or our less performant `SDWebImageGIFCoder`
HEIC 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. 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
Hardware works if: (iOS 11 || macOS 10.13) && (isMac || isIPhoneAndA10FusionChipAbove) && (!Simulator) 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 <SDWebImageProgressiveCoder> @interface SDWebImageImageIOCoder : NSObject <SDWebImageProgressiveCoder>

View File

@ -70,6 +70,9 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
case SDImageFormatWebP: case SDImageFormatWebP:
// Do not support WebP decoding // Do not support WebP decoding
return NO; return NO;
case SDImageFormatHEIC:
// Check HEIC decoding compatibility
return [[self class] canDecodeFromHEICFormat];
default: default:
return YES; return YES;
} }
@ -80,6 +83,9 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
case SDImageFormatWebP: case SDImageFormatWebP:
// Do not support WebP progressive decoding // Do not support WebP progressive decoding
return NO; return NO;
case SDImageFormatHEIC:
// Check HEIC decoding compatibility
return [[self class] canDecodeFromHEICFormat];
default: default:
return YES; return YES;
} }
@ -470,6 +476,33 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
return YES; 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 { + (BOOL)canEncodeToHEICFormat {
static BOOL canEncode = NO; static BOOL canEncode = NO;
static dispatch_once_t onceToken; static dispatch_once_t onceToken;