Переглянути джерело

Merge pull request #2627 from dreampiggy/bugfix_webp_icc_monochrome

Fix the issue when WebP contains the ICC Profile with colorSpace other than RGB, which cause the CGImageCreate failed
DreamPiggy 7 роки тому
батько
коміт
46fae667ea
1 змінених файлів з 8 додано та 0 видалено
  1. 8 0
      SDWebImage/SDWebImageWebPCoder.m

+ 8 - 0
SDWebImage/SDWebImageWebPCoder.m

@@ -347,6 +347,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;
+                }
+            }
         }
     }