libjxl produces too-dark HDR images when sRGB is requested
Describe the bug HDR lossy XYB-encoded JXL images are too dark when sRGB is requested from libjxl.
To Reproduce Take an HDR image, XYB-encoded (example attached). Decode it to sRGB with:
$ djxl --color_space=RGB_D65_SRG_Rel_SRG hdr.jxl sdr.png
and view the resulting sRGB PNG with any PNG viewer. The image will be too dark.
Then, decode it to a PQ PNG with:
$ djxl hdr.jxl hdr.png
(this image is tagged as BT.2100/PQ so the explicit color space does not need to be requested). View that PQ png in Chromium, mpv, Preview, or any ICC-aware viewer that tonemaps correctly. The colors will be much more accurately bright and not dark.
Expected behavior The SDR should look like an SDR approximation of the HDR image. Some tradeoffs need to be made, but darkening the whole image is definitely undesirable.
Changing the rendering intent from Rel to Abs, Sat, or Per didn't fix the issue.
Screenshots
^ the above .jpg is a JXL file
sdr.png is 34 MiB but you can view it here: https://files.catbox.moe/9hjw4u.png
Environment djxl 60ab29d7
- OS: Arch Linux x86_64
- Compiler version: gcc 12.2.1
- cjxl/djxl version string: djxl v0.9.0 60ab29d7 [AVX2]
``
Extra information: somehow libjxl is only using ~half of the 0-65535 range for this 16-bit PNG. Here's part of the output of identify -verbose sdr.png:
Channel depth:
Red: 16-bit
Green: 16-bit
Blue: 16-bit
Alpha: 1-bit
Channel statistics:
Pixels: 8294400
Red:
min: 0 (0)
max: 32740 (0.49958)
mean: 6524.4 (0.099556)
median: 5916 (0.0902724)
standard deviation: 5019.01 (0.0765851)
kurtosis: 0.54006
skewness: 0.894579
entropy: 0.946897
Green:
min: 0 (0)
max: 30019 (0.458061)
mean: 7113.79 (0.10855)
median: 6916 (0.105531)
standard deviation: 5159.37 (0.078727)
kurtosis: -0.27073
skewness: 0.513194
entropy: 0.955864
Blue:
min: 0 (0)
max: 29593 (0.45156)
mean: 7540.07 (0.115054)
median: 3124 (0.0476692)
standard deviation: 8041.49 (0.122705)
kurtosis: -1.54838
skewness: 0.493819
entropy: 0.800535
Alpha:
min: 65535 (1)
max: 65535 (1)
mean: 65535 (1)
median: 65535 (1)
standard deviation: -nan (-nan)
kurtosis: -2.76473e+58
skewness: 1.62719e+41
entropy: 0
GIMP reports only partial levels used as well:

Second update: This hdr.jxl has intensity_target tagged at 10000 nits, but since SDR is display-referred we should be using 255 nits for SDR color spaces.
I think this is fixed in master