From 1316f5b340b81d690c3c166961b0fb8367443b2c Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Tue, 26 Feb 2019 13:26:47 +0800 Subject: [PATCH] Fix the issue when WebP contains the ICC Profile with colorSpace other than RGB, which cause the CGImageCreate failed --- SDWebImageWebPCoder/Classes/SDImageWebPCoder.m | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/SDWebImageWebPCoder/Classes/SDImageWebPCoder.m b/SDWebImageWebPCoder/Classes/SDImageWebPCoder.m index d8bf67b..61f29fe 100644 --- a/SDWebImageWebPCoder/Classes/SDImageWebPCoder.m +++ b/SDWebImageWebPCoder/Classes/SDImageWebPCoder.m @@ -434,6 +434,14 @@ NSData *profileData = [NSData dataWithBytes:chunk_iter.chunk.bytes length:chunk_iter.chunk.size]; colorSpaceRef = CGColorSpaceCreateWithICCProfile((__bridge CFDataRef)profileData); WebPDemuxReleaseChunkIterator(&chunk_iter); + if (colorSpaceRef) { + // `CGImageCreate` does not support colorSpace other than RGB (such as Monochrome), we must filter the colorSpace mode + CGColorSpaceModel model = CGColorSpaceGetModel(colorSpaceRef); + if (model != kCGColorSpaceModelRGB) { + CGColorSpaceRelease(colorSpaceRef); + colorSpaceRef = NULL; + } + } } }