qView icon indicating copy to clipboard operation
qView copied to clipboard

Display P3 color profile not respected with HEIC file

Open Andreas0602 opened this issue 1 year ago • 10 comments

Environment:

  • OS: macOS 13.5 Ventura
  • qView version: nightly 2023-08-08.1

Information:

Demo.zip

When showing the HEIC image in the attached ZIP file, qView will not take the image's color profile "Display P3" into account. As a result, colors will be shown incorrectly.

When showing the same image in JPG format (from the attached ZIP file), the problem does not occur.

You can easily see the problem when you open both files in qView, look at the red jacket of the man on left side of the picture, and quickly toggle between both windows by means of the keyboard shortcut for moving the focus to the next window (command < on a German keyboard, for other languages see here).

Andreas0602 avatar Aug 08 '23 10:08 Andreas0602

@jdpurcell Correct me if I'm wrong but I think the current implementation only checks for the color space of the monitor.

jurplel avatar Aug 08 '23 16:08 jurplel

I think the current implementation only checks for the color space of the monitor.

If this were the root cause of the error, then why does the error only occur with the HEIC file, but not with the JPG file?

Andreas0602 avatar Aug 08 '23 17:08 Andreas0602

I could be wrong of course, but I believe that qView fails to detect the color profile of the HEIC file.

Andreas0602 avatar Aug 08 '23 17:08 Andreas0602

oh, interesting. Maybe the built-in Qt HEIC image plugin does not support color profiles. The kimageformats one definitely does as can be seen here: https://invent.kde.org/frameworks/kimageformats/-/merge_requests/16/diffs#8ff64707ffb67922cb5aa27b7e57623fdc0d8e87

Sure looks like the built-in Qt one doesn't: https://github.com/qt/qtimageformats/blob/dev/src/plugins/imageformats/macheif/qmacheifhandler.cpp

Maybe this can be resolved by changing the image format plugin to the one from kimageformats, then.

i hate image format plugins

jurplel avatar Aug 08 '23 17:08 jurplel

FYI: XnView MP had exactly the same problem. I reported it here: https://newsgroup.xnview.com/viewtopic.php?f=104&t=45719

The developer of XnView MP fixed the problem. It was very strange: The problem occurred only with HEIC images in vertical/portrait format. Horizontal/landscape images did not have this problem.

Andreas0602 avatar Aug 08 '23 17:08 Andreas0602

Oh that is really strange indeed. XnViewMP should have nothing in common with qView codebase wise, afaik

jurplel avatar Aug 08 '23 18:08 jurplel

qView's implementation does consider both the image's and the monitor's color space. However for this image, using Qt's HEIC support, I can see qView isn't finding a color space in the image and assuming it's sRGB. Interestingly that works out pretty well in this case, at least judging by how the image looks compared to the Preview app, as qView looks very similar although the red clothing isn't as vibrant. If I make it assume the image is Display P3 it actually looks even more off, with everything looking oversaturated. I suspect what's happening is that Qt's HEIC decoder is factoring in the color space, but instead of decoding it as-is and reporting the color space, it converts the decoded image to sRBG automatically and doesn't expose anything in QImage::colorSpace().

So as @jurplel suggested, if kimageformat's HEIC decoder works better in this regard, it could help. I don't know how to get it working though so I'm unable to do any testing.

jdpurcell avatar Aug 09 '23 23:08 jdpurcell

Very interesting--thank you for the detailed writeup!

For this upcoming version, since I actually want to ship a version before the heat death of the universe, I am going to skip trying to get kimageformats HEIF plugin building on macOS--I had some issues with it so I cut it for now. Not sure if it would help anyway based on your description.

jurplel avatar Aug 09 '23 23:08 jurplel

@jurplel Based on the limited testing I could figure out how to do, i.e. a special build with some additional debug output, I am seeing that on macOS it's not detecting a color space from the image, whereas on Windows it detected Display P3 from the image. So assuming the difference is due to the Windows version having the kimageformats-based plugin, it may indeed be worthwhile to get the kimageformats HEIF plugin building on macOS if at all practical.

EDIT: Also tried with Qt 6.5.2 on macOS out of curiosity but it didn't make a difference.

jdpurcell avatar Aug 20 '23 22:08 jdpurcell

Yeah, I should work on that at some point.

jurplel avatar Aug 21 '23 02:08 jurplel

Good news! I got the kimageformats HEIF plugin building. I think it was resolved after a package update from bumping vcpkgGitCommitId, but I made a lot of other changes recently in my kimageformats-binaries fork so I'm not sure.

As for the qView side, I just needed to avoid including the HEIF plugin from qtimageformats. I tested with the demo images provided in the original bug report, and it fixes the color difference on the red jacket.

jdpurcell avatar May 09 '24 22:05 jdpurcell

That's good to hear. Thank you very much @jdpurcell! Looking forward to having this correction in a nightly build.

Andreas0602 avatar May 10 '24 08:05 Andreas0602

If you could make a PR for that (here/kimageformats-binaries), I will pull it in

jurplel avatar May 19 '24 20:05 jurplel