Bug 216645 - [iOS 14] WebP images do not handle color profiles correctly
Summary: [iOS 14] WebP images do not handle color profiles correctly
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Images (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-09-17 07:33 PDT by Ali Juma
Modified: 2020-11-11 19:27 PST (History)
6 users (show)

See Also:


Attachments
Incorrectly rendered WebP image (40.52 KB, image/webp)
2020-09-17 07:33 PDT, Ali Juma
no flags Details
Expected image (338.62 KB, image/png)
2020-09-17 07:35 PDT, Ali Juma
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ali Juma 2020-09-17 07:33:31 PDT
Created attachment 409031 [details]
Incorrectly rendered WebP image

WebKit supports WebP images in iOS 14, but ICC profile support seems to be broken. I've attached an example WebP image that isn't rendered correctly in Safari.

This is also filed as feedback FB7793986.
Comment 1 Ali Juma 2020-09-17 07:35:33 PDT
Created attachment 409032 [details]
Expected image

Here (as a PNG image) is the expected output for the WebP image.
Comment 2 Alexey Proskuryakov 2020-09-17 11:36:17 PDT
rdar://64790996
Comment 3 Jon Sneyers 2020-10-28 01:25:53 PDT
It looks like Chrome on iOS 14 and UIImage on iOS 14 have the same problem: it seems like an ICC profile in a WebP gets ignored, causing e.g. images with the Display P3 profile to look desaturated (presumably because they are misinterpreted as sRGB).

I don't have access to the Core Image source code so I don't know how WebP suppport was implemented, but it's quite easy to forget about ICC profiles. To not ignore the ICC profile, you need to not just call the simple one-stop high-level decode function WebPDecodeRGBA(), but you also need to include webp/demux.h and do something like this:

  WebPDemuxer* demux = WebPDemux(&webp_data);
  uint32_t flags = WebPDemuxGetI(demux, WEBP_FF_FORMAT_FLAGS);
  // ... (Extract metadata).
  WebPChunkIterator chunk_iter;
  if (flags & ICCP_FLAG) WebPDemuxGetChunk(demux, "ICCP", 1, &chunk_iter);
  // ... (Consume the ICC profile in 'chunk_iter.chunk').
  WebPDemuxReleaseChunkIterator(&chunk_iter);
  WebPDemuxDelete(demux);

I hope this helps and we can avoid having to convert/clamp WebP images to the sRGB gamut!
Comment 4 jzern 2020-11-11 19:27:35 PST
I had filed FB8759612 similarly for Mac OS.

Not much more to add except the original webkit patch and a few other links, from the feedback assistant:

---

https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/renderer/platform/testing/data/webp-color-profile-lossy.webp

WebP images can contain an embedded ICC profile that affects the rendering of the final image.

Here are some relevant links to an old webkit patch and the tracking bug for chrome:

https://bugs.webkit.org/show_bug.cgi?id=112747
https://bugs.chromium.org/p/chromium/issues/detail?id=172308

The ‘purpur’ text should be purple in this image. See the jpg for reference:
https://houz.org/tmp/farbkreis.jpg