Merge pull request #3727 from dreampiggy/bugfix/heics_animated_encoding

Fix our HEIC coder to encode `timed image sequences` instead of `non-timed image gallery` for HEIC encoding
This commit is contained in:
DreamPiggy 2024-07-23 14:32:15 +08:00 committed by GitHub
commit cba8ec9667
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 3 deletions

View File

@ -75,7 +75,11 @@ static NSString * kSDCGImagePropertyHEICSUnclampedDelayTime = @"UnclampedDelayTi
} }
+ (NSString *)imageUTType { + (NSString *)imageUTType {
return (__bridge NSString *)kSDUTTypeHEIC; // See: https://nokiatech.github.io/heif/technical.html
// Actually HEIC has another concept called `non-timed Image Sequence`, which can be encoded using `public.heic`
// But current SDWebImage does not has this design, I don't know whether there are use case for this
// So we just replace and always use `timed Image Sequence`, means, animated image for encoding
return (__bridge NSString *)kSDUTTypeHEICS;
} }
+ (NSString *)dictionaryProperty { + (NSString *)dictionaryProperty {

View File

@ -832,11 +832,11 @@ static BOOL SDImageIOPNGPluginBuggyNeedWorkaround(void) {
} }
NSMutableData *imageData = [NSMutableData data]; NSMutableData *imageData = [NSMutableData data];
CFStringRef imageUTType = [NSData sd_UTTypeFromImageFormat:format]; NSString *imageUTType = self.class.imageUTType;
// Create an image destination. Animated Image does not support EXIF image orientation TODO // Create an image destination. Animated Image does not support EXIF image orientation TODO
// The `CGImageDestinationCreateWithData` will log a warning when count is 0, use 1 instead. // The `CGImageDestinationCreateWithData` will log a warning when count is 0, use 1 instead.
CGImageDestinationRef imageDestination = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)imageData, imageUTType, frames.count ?: 1, NULL); CGImageDestinationRef imageDestination = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)imageData, (__bridge CFStringRef)imageUTType, frames.count ?: 1, NULL);
if (!imageDestination) { if (!imageDestination) {
// Handle failure. // Handle failure.
return nil; return nil;
@ -922,6 +922,11 @@ static BOOL SDImageIOPNGPluginBuggyNeedWorkaround(void) {
CFRelease(imageDestination); CFRelease(imageDestination);
// In some beta version, ImageIO `CGImageDestinationFinalize` returns success, but the data buffer is 0 bytes length.
if (imageData.length == 0) {
return nil;
}
return [imageData copy]; return [imageData copy];
} }