novomesk / qt-jpegxl-image-plugin

Qt plug-in to allow Qt and KDE based applications to read/write JXL images.
GNU General Public License v3.0
93 stars 8 forks source link

ICC profile not working (invalid color profile created) #10

Closed ghost closed 3 years ago

ghost commented 3 years ago

Environment:

Steps to reproduce:

  1. Convert the jpg files to jxl by cjxl.
  2. Open the JXL (e.g. ICC Rendering Intent Test (cLUT only).jxl) by gwenview.
  3. Open the JPG and PNG by gwenview.

Observed result:

Although the JXL is displayed, the colors are wrong because the ICC profile cannot be applied.

JPG and PNG versions have no such problem.

Console output:

qt.gui.icc: fromIccProfile: Unsupported ICC profile - not three component matrix based
invalid color profile created
full image, format=4
novomesk commented 3 years ago

Qt doesn't support all ICC profiles yet. gwenview does its own color management but it is limited to the most popular formats.

ghost commented 3 years ago

I took a normal PNG file (correct-colors.png) and assigned the Swapped Red and Green profile (which is provided by colord) via GIMP, and exported it to wrong-colors.png. I then converted wrong-colors.png to JXL (wrong-colors.jxl).

When using Gwenview to open the JXL, no error message is displayed:

full image, format=4`

However, the colors are not as expected!

Gwenview correctly applies the profile for wrong-colors.png, but it does not apply the profile for wrong-colors.jxl, so wrong-colors.jxl looks the same as correct-colors.png.

(Note: After applying the swap Red and Green profile, orange lines become green lines, and light blue becomes light purple.)

Which component (Qt, JXL library, etc.) causes this issue?

Test file

P.S. I am using exiv2 from latest git. The issue is present with both unpatched and patched kfilemetadata. Gwenview is stock (unpatched).

novomesk commented 3 years ago

There are two possibilities: 1) gwenview could be patched so it will do its own color management like it does for jpeg and png https://invent.kde.org/graphics/gwenview/-/blob/master/lib/cms/cmsprofile.cpp#L149

2) convert pixel data inside my plug-in to sRGB profile but it would require new dependency, there will be performance penalty and the data conversion could be an issue for some users.

ghost commented 3 years ago

I found that a WebP image with color profile will not display in correct colors in Gwenview, so apparently Gwenview is missing support for other formats.

Regarding solution 1, is it easy to patch Gwenview?

novomesk commented 3 years ago

I have impression that it should be easy, following functions should be used:

QImageReader::read()
QImage::colorSpace()
QColorSpace::iccProfile()
cmsOpenProfileFromMem

I recommend to re-use existing QImageReader reader(&buffer, mFormatHint); if possible. Creating another QImageReader will trigger another decoding pass and slows image opening.

ghost commented 3 years ago

If we can use the above functions, does that mean Gwenview can read the profile from various image formats in a generic way (eliminates the need of Profile::loadFromXxxData for each format)?

novomesk commented 3 years ago

Other formats could be supported via those functions too but only those with Qt plug-ins and using QColorSpace class to signal what profile us used.

novomesk commented 3 years ago

I suggested changes to gwenview: https://invent.kde.org/graphics/gwenview/-/issues/7

I am closing this issue, because nothing more will be done on plugin's side.

You can correctly view JXL files in digiKam master (future 7.3 version probably) when you manually enable jxl extension in digiKam.

Thanks for reporting this, the testfile was very valuable.

novomesk commented 3 years ago

FYI, gwenview from master now applies color management for JXL images with 8bit depth.