Add HDR support to JXL plug-in
Environment/Versions
- GIMP version: 2.99.8
- Package: Windows x64 installer from the developper download page
- Operating System: Windows 10.0.19043
Description of the bug
Datails in shadows in exported 16-bit lossy JXL files are not retained.
Reproduction
Is the bug reproducible? Always
Reproduction steps:
- Open HDR image with more than 10 EV of dynamic range (e.g. one can get sample images from here: https://polyhaven.com/hdris and decrease exposure by 5 EV)
- Change canvas encoding to 16-bit integer with non-linear gamma (I refer to this version as the reference image)
- Export as lossy jxl with max error of 0.1 (cjxl doesn't allow smaller errors at the moment)
- Re-open the file
- Increase exposure by 4 EV
…
Expected result: Compression artefacts should be barely noticeable and it should look identical to the reference image with +4 EV
Actual result: Massive compression artefacts
Additional information
The jxl library requires to specify the intensity_target (amount of nits) when compressing HDR images. The export plugin sets it to the default value of 256 - which is insufficient for HDR:
- https://github.com/libjxl/libjxl/blob/9f41cb45bb17197aae6a5c29e926bc2ee71f1ccb/tools/cjxl.cc#L456
- https://gitlab.gnome.org/GNOME/gimp/-/blob/master/plug-ins/common/file-jpegxl.c#L794
Proposed fix: Use 65504 (which is the maximum value: https://github.com/libjxl/libjxl/issues/314#issuecomment-878569912) if a 16-bit image is exported.
One may argue that this is too high if the image is effectively 10 or 12 bit resulting in too large file sizes. However, the user can still reduce the file size drastically by increasing the allowed error - which focuses on shadow areas for compression.