Skip to content

Commit 304bed2

Browse files
committed
Fix the issue when monochome colorspace cause the WebP encoding failed
Just translate into RGBA first, don't need extra code to re-implements monochrome WebP encoding
1 parent db46039 commit 304bed2

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

SDWebImageWebPCoder/Classes/SDImageWebPCoder.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,12 @@ - (nullable NSData *)sd_encodedWebpDataWithImage:(nullable CGImageRef)imageRef
885885
uint8_t *rgba = NULL; // RGBA Buffer managed by CFData, don't call `free` on it, instead call `CFRelease` on `dataRef`
886886
// We must prefer the input CGImage's color space, which may contains ICC profile
887887
CGColorSpaceRef colorSpace = CGImageGetColorSpace(imageRef);
888+
// We only supports RGB colorspace, filter the un-supported one (like Monochrome, CMYK, etc)
889+
if (CGColorSpaceGetModel(colorSpace) != kCGColorSpaceModelRGB) {
890+
// Ignore and convert, we don't know how to encode this colorspace directlly to WebP
891+
// This may cause little visible difference because of colorpsace conversion
892+
colorSpace = NULL;
893+
}
888894
if (!colorSpace) {
889895
colorSpace = [SDImageCoderHelper colorSpaceGetDeviceRGB];
890896
}

0 commit comments

Comments
 (0)