| | |
| | | if (!imageRef) { |
| | | return nil; |
| | | } |
| | | BOOL isDecoded = NO; |
| | | // Thumbnail image post-process |
| | | if (!createFullImage) { |
| | | if (preserveAspectRatio) { |
| | |
| | | if (scaledImageRef) { |
| | | CGImageRelease(imageRef); |
| | | imageRef = scaledImageRef; |
| | | isDecoded = YES; |
| | | } |
| | | } |
| | | } |
| | | // Check whether output CGImage is decoded |
| | | BOOL isLazy = [SDImageCoderHelper CGImageIsLazy:imageRef]; |
| | | if (!lazyDecode) { |
| | | if (!isDecoded) { |
| | | // Use CoreGraphics to trigger immediately decode |
| | | if (isLazy) { |
| | | // Use CoreGraphics to trigger immediately decode to drop lazy CGImage |
| | | CGImageRef decodedImageRef = [SDImageCoderHelper CGImageCreateDecoded:imageRef]; |
| | | if (decodedImageRef) { |
| | | CGImageRelease(imageRef); |
| | | imageRef = decodedImageRef; |
| | | isDecoded = YES; |
| | | isLazy = NO; |
| | | } |
| | | } |
| | | } else if (animatedImage) { |
| | |
| | | UIImage *image = [[UIImage alloc] initWithCGImage:imageRef scale:scale orientation:exifOrientation]; |
| | | #endif |
| | | CGImageRelease(imageRef); |
| | | image.sd_isDecoded = isDecoded; |
| | | image.sd_isDecoded = !isLazy; |
| | | |
| | | return image; |
| | | } |
| | |
| | | } |
| | | |
| | | 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 |
| | | // 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) { |
| | | // Handle failure. |
| | | return nil; |
| | |
| | | #else |
| | | CGImagePropertyOrientation exifOrientation = kCGImagePropertyOrientationUp; |
| | | #endif |
| | | if (exifOrientation != kCGImagePropertyOrientationUp) { |
| | | properties[(__bridge NSString *)kCGImagePropertyOrientation] = @(exifOrientation); |
| | | } |
| | | // Encoding Options |
| | | double compressionQuality = 1; |
| | | if (options[SDImageCoderEncodeCompressionQuality]) { |
| | |
| | | |
| | | 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]; |
| | | } |
| | | |