Skip to content

Commit a46ca76

Browse files
authored
Merge pull request #13 from SDWebImage/bugfix_webp_icc_monochrome
Fix the issue when WebP contains the ICC Profile with colorSpace other than RGB, which cause the CGImageCreate failed
2 parents 4b256c0 + 1316f5b commit a46ca76

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

SDWebImageWebPCoder/Classes/SDImageWebPCoder.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,14 @@ - (nonnull CGColorSpaceRef)sd_colorSpaceWithDemuxer:(nonnull WebPDemuxer *)demux
434434
NSData *profileData = [NSData dataWithBytes:chunk_iter.chunk.bytes length:chunk_iter.chunk.size];
435435
colorSpaceRef = CGColorSpaceCreateWithICCProfile((__bridge CFDataRef)profileData);
436436
WebPDemuxReleaseChunkIterator(&chunk_iter);
437+
if (colorSpaceRef) {
438+
// `CGImageCreate` does not support colorSpace other than RGB (such as Monochrome), we must filter the colorSpace mode
439+
CGColorSpaceModel model = CGColorSpaceGetModel(colorSpaceRef);
440+
if (model != kCGColorSpaceModelRGB) {
441+
CGColorSpaceRelease(colorSpaceRef);
442+
colorSpaceRef = NULL;
443+
}
444+
}
437445
}
438446
}
439447

0 commit comments

Comments
 (0)