From 304bed2c4b647632ee4bd56f7227eda21573027d Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Tue, 30 Jan 2024 15:07:23 +0800 Subject: [PATCH] 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 --- SDWebImageWebPCoder/Classes/SDImageWebPCoder.m | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/SDWebImageWebPCoder/Classes/SDImageWebPCoder.m b/SDWebImageWebPCoder/Classes/SDImageWebPCoder.m index a9ee149..ead8fff 100644 --- a/SDWebImageWebPCoder/Classes/SDImageWebPCoder.m +++ b/SDWebImageWebPCoder/Classes/SDImageWebPCoder.m @@ -885,6 +885,12 @@ WEBP_CSP_MODE ConvertCSPMode(CGBitmapInfo bitmapInfo) { uint8_t *rgba = NULL; // RGBA Buffer managed by CFData, don't call `free` on it, instead call `CFRelease` on `dataRef` // We must prefer the input CGImage's color space, which may contains ICC profile CGColorSpaceRef colorSpace = CGImageGetColorSpace(imageRef); + // We only supports RGB colorspace, filter the un-supported one (like Monochrome, CMYK, etc) + if (CGColorSpaceGetModel(colorSpace) != kCGColorSpaceModelRGB) { + // Ignore and convert, we don't know how to encode this colorspace directlly to WebP + // This may cause little visible difference because of colorpsace conversion + colorSpace = NULL; + } if (!colorSpace) { colorSpace = [SDImageCoderHelper colorSpaceGetDeviceRGB]; }