Update the decode solution to allows CoreGraphics avoid using any UIKit method
This is back compatible to old version's RAM behavior
This commit is contained in:
parent
05f7fb9b0d
commit
c0f7023472
|
@ -418,8 +418,8 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
|
|||
}
|
||||
|
||||
UIImage *decodedImage;
|
||||
#if SD_UIKIT
|
||||
SDImageCoderDecodeSolution decodeSolution = self.defaultDecodeSolution;
|
||||
#if SD_UIKIT
|
||||
if (decodeSolution == SDImageCoderDecodeSolutionAutomatic) {
|
||||
// See #3365, CMPhoto iOS 15 only supports JPEG/HEIF format, or it will print an error log :(
|
||||
SDImageFormat format = image.sd_imageFormat;
|
||||
|
@ -439,19 +439,31 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
|
|||
|
||||
CGImageRef imageRef = image.CGImage;
|
||||
if (!imageRef) {
|
||||
// Only decode for CGImage-based
|
||||
return image;
|
||||
}
|
||||
BOOL hasAlpha = [self CGImageContainsAlpha:imageRef];
|
||||
// Prefer to use new Image Renderer to re-draw image, instead of low-level CGBitmapContext and CGContextDrawImage
|
||||
// This can keep both OS compatible and don't fight with Apple's performance optimization
|
||||
SDGraphicsImageRendererFormat *format = [[SDGraphicsImageRendererFormat alloc] init];
|
||||
format.opaque = !hasAlpha;
|
||||
format.scale = image.scale;
|
||||
CGSize imageSize = image.size;
|
||||
SDGraphicsImageRenderer *renderer = [[SDGraphicsImageRenderer alloc] initWithSize:imageSize format:format];
|
||||
decodedImage = [renderer imageWithActions:^(CGContextRef _Nonnull context) {
|
||||
[image drawInRect:CGRectMake(0, 0, imageSize.width, imageSize.height)];
|
||||
}];
|
||||
|
||||
if (decodeSolution == SDImageCoderDecodeSolutionCoreGraphics) {
|
||||
CGImageRef decodedImageRef = [self CGImageCreateDecoded:imageRef];
|
||||
#if SD_MAC
|
||||
decodedImage = [[UIImage alloc] initWithCGImage:decodedImageRef scale:image.scale orientation:kCGImagePropertyOrientationUp];
|
||||
#else
|
||||
decodedImage = [[UIImage alloc] initWithCGImage:decodedImageRef scale:image.scale orientation:image.imageOrientation];
|
||||
#endif
|
||||
CGImageRelease(decodedImageRef);
|
||||
} else {
|
||||
BOOL hasAlpha = [self CGImageContainsAlpha:imageRef];
|
||||
// Prefer to use new Image Renderer to re-draw image, instead of low-level CGBitmapContext and CGContextDrawImage
|
||||
// This can keep both OS compatible and don't fight with Apple's performance optimization
|
||||
SDGraphicsImageRendererFormat *format = SDGraphicsImageRendererFormat.preferredFormat;
|
||||
format.opaque = !hasAlpha;
|
||||
format.scale = image.scale;
|
||||
CGSize imageSize = image.size;
|
||||
SDGraphicsImageRenderer *renderer = [[SDGraphicsImageRenderer alloc] initWithSize:imageSize format:format];
|
||||
decodedImage = [renderer imageWithActions:^(CGContextRef _Nonnull context) {
|
||||
[image drawInRect:CGRectMake(0, 0, imageSize.width, imageSize.height)];
|
||||
}];
|
||||
}
|
||||
SDImageCopyAssociatedObject(image, decodedImage);
|
||||
decodedImage.sd_isDecoded = YES;
|
||||
return decodedImage;
|
||||
|
@ -472,6 +484,10 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
|
|||
tileTotalPixels = destTotalPixels / 3;
|
||||
|
||||
CGImageRef sourceImageRef = image.CGImage;
|
||||
if (!sourceImageRef) {
|
||||
// Only decode for CGImage-based
|
||||
return image;
|
||||
}
|
||||
CGSize sourceResolution = CGSizeZero;
|
||||
sourceResolution.width = CGImageGetWidth(sourceImageRef);
|
||||
sourceResolution.height = CGImageGetHeight(sourceImageRef);
|
||||
|
|
Loading…
Reference in New Issue