Fix `sd_blurredImageWithRadius` CGImage implementation bug that does not considerate bitmap other than BGRA

This commit is contained in:
DreamPiggy 2019-12-30 17:18:08 +08:00
parent 0c15223111
commit 40957da785
1 changed files with 13 additions and 1 deletions

View File

@ -588,6 +588,18 @@ static inline CIColor *SDCIColorConvertFromUIColor(UIColor * _Nonnull color) {
CGFloat scale = self.scale;
CGImageRef imageRef = self.CGImage;
//convert to BGRA if it isn't
if (CGImageGetBitsPerPixel(imageRef) != 32 ||
CGImageGetBitsPerComponent(imageRef) != 8 ||
!((CGImageGetBitmapInfo(imageRef) & kCGBitmapAlphaInfoMask))) {
SDGraphicsBeginImageContextWithOptions(self.size, NO, self.scale);
[self drawInRect:CGRectMake(0, 0, self.size.width, self.size.height)];
imageRef = SDGraphicsGetImageFromCurrentImageContext().CGImage;
SDGraphicsEndImageContext();
} else {
CGImageRetain(imageRef);
}
vImage_Buffer effect = {}, scratch = {};
vImage_Buffer *input = NULL, *output = NULL;
@ -602,7 +614,7 @@ static inline CIColor *SDCIColorConvertFromUIColor(UIColor * _Nonnull color) {
};
vImage_Error err;
err = vImageBuffer_InitWithCGImage(&effect, &format, NULL, imageRef, kvImagePrintDiagnosticsToConsole);
err = vImageBuffer_InitWithCGImage(&effect, &format, NULL, imageRef, kvImageNoFlags);
if (err != kvImageNoError) {
NSLog(@"UIImage+Transform error: vImageBuffer_InitWithCGImage returned error code %zi for inputImage: %@", err, self);
return nil;