GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix the WebP encoding which loss the image's input color space · SDWebImage/SDWebImageWebPCoder@8113caf

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Example/SDWebImageWebPCoderExample-macOS/examples
    • pexels-alexander-grey-1428169
      • after.webp
      • before.jpg
    • pexels-malia-evans-12652728
      • after.webp
      • before.jpeg
    • png
      • after.webp
      • before.png
  • SDWebImageWebPCoder/Classes
    • SDImageWebPCoder.m
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Example/SDWebImageWebPCoderExample-macOS/examples/pexels-alexander-grey-1428169/after.webp‎

Copy file name to clipboard
-160 KB
Binary file not shown.
Collapse file

‎Example/SDWebImageWebPCoderExample-macOS/examples/pexels-alexander-grey-1428169/before.jpg‎

Copy file name to clipboard
-246 KB
Binary file not shown.
Collapse file

‎Example/SDWebImageWebPCoderExample-macOS/examples/pexels-malia-evans-12652728/after.webp‎

Copy file name to clipboard
-74.5 KB
Binary file not shown.
Collapse file

‎Example/SDWebImageWebPCoderExample-macOS/examples/pexels-malia-evans-12652728/before.jpeg‎

Copy file name to clipboard
-211 KB
Binary file not shown.
Collapse file

‎Example/SDWebImageWebPCoderExample-macOS/examples/png/after.webp‎

Copy file name to clipboard
-40.6 KB
Binary file not shown.
Collapse file

‎Example/SDWebImageWebPCoderExample-macOS/examples/png/before.png‎

Copy file name to clipboard
-979 KB
Binary file not shown.
Collapse file

‎SDWebImageWebPCoder/Classes/SDImageWebPCoder.m‎

Copy file name to clipboardExpand all lines: SDWebImageWebPCoder/Classes/SDImageWebPCoder.m
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -883,14 +883,20 @@ - (nullable NSData *)sd_encodedWebpDataWithImage:(nullable CGImageRef)imageRef
883883
}
884884

885885
uint8_t *rgba = NULL; // RGBA Buffer managed by CFData, don't call `free` on it, instead call `CFRelease` on `dataRef`
886-
// We could not assume that input CGImage's color mode is always RGB888/RGBA8888. Convert all other cases to target color mode using vImage
886+
// We must prefer the input CGImage's color space, which may contains ICC profile
887+
CGColorSpaceRef colorSpace = CGImageGetColorSpace(imageRef);
888+
if (!colorSpace) {
889+
colorSpace = [SDImageCoderHelper colorSpaceGetDeviceRGB];
890+
}
887891
vImage_CGImageFormat destFormat = {
888892
.bitsPerComponent = 8,
889893
.bitsPerPixel = hasAlpha ? 32 : 24,
890-
.colorSpace = [SDImageCoderHelper colorSpaceGetDeviceRGB],
894+
.colorSpace = colorSpace,
891895
.bitmapInfo = hasAlpha ? kCGImageAlphaLast | kCGBitmapByteOrderDefault : kCGImageAlphaNone | kCGBitmapByteOrderDefault // RGB888/RGBA8888 (Non-premultiplied to works for libwebp)
892896
};
893897
vImage_Buffer dest;
898+
// We could not assume that input CGImage's color mode is always RGB888/RGBA8888. Convert all other cases to target color mode using vImage
899+
// But vImageBuffer_InitWithCGImage will do convert automatically (unless you use `kvImageNoAllocate`), so no need to call `vImageConvert` by ourselves
894900
vImage_Error error = vImageBuffer_InitWithCGImage(&dest, &destFormat, NULL, imageRef, kvImageNoFlags);
895901
if (error != kvImageNoError) {
896902
return nil;

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.