diff --git a/Example/SDWebImageWebPCoderExample-macOS/examples/pexels-alexander-grey-1428169/after.webp b/Example/SDWebImageWebPCoderExample-macOS/examples/pexels-alexander-grey-1428169/after.webp deleted file mode 100644 index dfd5e75..0000000 Binary files a/Example/SDWebImageWebPCoderExample-macOS/examples/pexels-alexander-grey-1428169/after.webp and /dev/null differ diff --git a/Example/SDWebImageWebPCoderExample-macOS/examples/pexels-alexander-grey-1428169/before.jpg b/Example/SDWebImageWebPCoderExample-macOS/examples/pexels-alexander-grey-1428169/before.jpg deleted file mode 100644 index 1043ebd..0000000 Binary files a/Example/SDWebImageWebPCoderExample-macOS/examples/pexels-alexander-grey-1428169/before.jpg and /dev/null differ diff --git a/Example/SDWebImageWebPCoderExample-macOS/examples/pexels-malia-evans-12652728/after.webp b/Example/SDWebImageWebPCoderExample-macOS/examples/pexels-malia-evans-12652728/after.webp deleted file mode 100644 index ceb56d0..0000000 Binary files a/Example/SDWebImageWebPCoderExample-macOS/examples/pexels-malia-evans-12652728/after.webp and /dev/null differ diff --git a/Example/SDWebImageWebPCoderExample-macOS/examples/pexels-malia-evans-12652728/before.jpeg b/Example/SDWebImageWebPCoderExample-macOS/examples/pexels-malia-evans-12652728/before.jpeg deleted file mode 100644 index 5c96c4c..0000000 Binary files a/Example/SDWebImageWebPCoderExample-macOS/examples/pexels-malia-evans-12652728/before.jpeg and /dev/null differ diff --git a/Example/SDWebImageWebPCoderExample-macOS/examples/png/after.webp b/Example/SDWebImageWebPCoderExample-macOS/examples/png/after.webp deleted file mode 100644 index 5e9086f..0000000 Binary files a/Example/SDWebImageWebPCoderExample-macOS/examples/png/after.webp and /dev/null differ diff --git a/Example/SDWebImageWebPCoderExample-macOS/examples/png/before.png b/Example/SDWebImageWebPCoderExample-macOS/examples/png/before.png deleted file mode 100644 index c1b4674..0000000 Binary files a/Example/SDWebImageWebPCoderExample-macOS/examples/png/before.png and /dev/null differ diff --git a/SDWebImageWebPCoder/Classes/SDImageWebPCoder.m b/SDWebImageWebPCoder/Classes/SDImageWebPCoder.m index e2088d2..31acd23 100644 --- a/SDWebImageWebPCoder/Classes/SDImageWebPCoder.m +++ b/SDWebImageWebPCoder/Classes/SDImageWebPCoder.m @@ -883,14 +883,20 @@ 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 could not assume that input CGImage's color mode is always RGB888/RGBA8888. Convert all other cases to target color mode using vImage + // We must prefer the input CGImage's color space, which may contains ICC profile + CGColorSpaceRef colorSpace = CGImageGetColorSpace(imageRef); + if (!colorSpace) { + colorSpace = [SDImageCoderHelper colorSpaceGetDeviceRGB]; + } vImage_CGImageFormat destFormat = { .bitsPerComponent = 8, .bitsPerPixel = hasAlpha ? 32 : 24, - .colorSpace = [SDImageCoderHelper colorSpaceGetDeviceRGB], + .colorSpace = colorSpace, .bitmapInfo = hasAlpha ? kCGImageAlphaLast | kCGBitmapByteOrderDefault : kCGImageAlphaNone | kCGBitmapByteOrderDefault // RGB888/RGBA8888 (Non-premultiplied to works for libwebp) }; vImage_Buffer dest; + // We could not assume that input CGImage's color mode is always RGB888/RGBA8888. Convert all other cases to target color mode using vImage + // But vImageBuffer_InitWithCGImage will do convert automatically (unless you use `kvImageNoAllocate`), so no need to call `vImageConvert` by ourselves vImage_Error error = vImageBuffer_InitWithCGImage(&dest, &destFormat, NULL, imageRef, kvImageNoFlags); if (error != kvImageNoError) { return nil;