tirr-c / jxl-oxide

Pure Rust implementation of JPEG XL decoder
Apache License 2.0
313 stars 13 forks source link

Decode result looks "washed out" for 709-transfer-function JXL image #318

Open saschanaz opened 4 months ago

saschanaz commented 4 months ago

From a user report in https://github.com/saschanaz/jxl-winthumb/issues/42.

With this JXL in zip, jxl-oxide-cli 0.8.1 (and 0.8.0 too) gives more washed out PNG.

The original PNG for this JXL:

348500482-b548d3fa-c9df-4e67-bcfa-32935a0e3b80

The jxl-oxide-cli result (and actually also djxl result, yeah I probably have to report there too):

348500482-b548d3fa-c9df-4e67-bcfa-32935a0e3b80-reconverted

But given some viewers can render it as the original, it seems the issue could be some decoder option. Any idea what would be the issue?

This is the jxlinfo result:

box: type: "JXL " size: 12, contents size: 4
JPEG XL file format container (ISO/IEC 18181-2)
box: type: "ftyp" size: 20, contents size: 12
box: type: "jxll" size: 9, contents size: 1
box: type: "jxlc" size: 201976, contents size: 201968
JPEG XL image, 1920x1038, lossy, 16-bit RGB+Alpha
num_color_channels: 3
num_extra_channels: 1
extra channel 0:
  type: Alpha
  bits_per_sample: 16
  alpha_premultiplied: 0 (Non-premultiplied)
have_preview: 0
have_animation: 0
Intrinsic dimensions: 1920x1038
Orientation: 1 (Normal)
Color space: RGB, D65, sRGB primaries, 709 transfer function, rendering intent: Relative
tirr-c commented 4 months ago

I don't see any difference between the images you posted, on GitHub app, Android 14. Perhaps it's color management issue of image viewer...

For reference, I'm seeing this:

Screenshot

saschanaz commented 4 months ago

Huh, on Chromium they look same. On Firefox and Microsoft Photos they look different, how mysterious 🤔

Quackdoc commented 4 months ago

this is an interesting image, magick reports gamma being different, it's not so different that it should cause an issue. I do wonder if this is just cjxl encoding the file in a way, that when it's decoded, it produces an ICC firefox and MS Photos doesn't like?

A quick test supports this by ripping the ICC with magick, and applying it to another different PNG and getting the exact same results, with firefox color shifts, which chromium it doesnt.

Gwenview has the same issue, MPV does not.

darktable has all three images look washed out, however it also looks washed out when you apply the ICC to a seperate image which is weird.

all images look fine on nomacs besides the JXL.

https://slow.pics/c/KjrTY0th

saschanaz commented 4 months ago

exiftool says:

ExifTool Version Number         : 12.92
File Name                       : 348500482-b548d3fa-c9df-4e67-bcfa-32935a0e3b80-reconverted.png
Directory                       : C:/Users/Kagami/Pictures
File Size                       : 9.7 MB
File Modification Date/Time     : 2024:07:31 00:02:31+02:00
File Access Date/Time           : 2024:07:31 21:51:37+02:00
File Creation Date/Time         : 2024:07:31 00:02:31+02:00
File Permissions                : -rw-rw-rw-
File Type                       : PNG
File Type Extension             : png
MIME Type                       : image/png
Image Width                     : 1920
Image Height                    : 1038
Bit Depth                       : 16
Color Type                      : RGB with Alpha
Compression                     : Deflate/Inflate
Filter                          : Adaptive
Interlace                       : Noninterlaced
Profile Name                    : 1
Profile CMM Type                : Unknown (jxl )
Profile Version                 : 4.4.0
Profile Class                   : Display Device Profile
Color Space Data                : RGB
Profile Connection Space        : XYZ
Profile Date Time               : 2019:12:01 00:00:00
Profile File Signature          : acsp
Primary Platform                : Apple Computer Inc.
CMM Flags                       : Not Embedded, Independent
Device Manufacturer             :
Device Model                    :
Device Attributes               : Reflective, Glossy, Positive, Color
Rendering Intent                : Media-Relative Colorimetric
Connection Space Illuminant     : 0.9642 1 0.82491
Profile Creator                 : Unknown (jxl )
Profile ID                      : e32201d218f4341aa35b0f240767fa3e
Profile Description             : RGB_D65_SRG_Rel_709
Profile Copyright               : CC0
Media White Point               : 0.9642 1 0.82491
Chromatic Adaptation            : 1.04785 0.0229 -0.05014 0.02957 0.99048 -0.01704 -0.00923 0.01506 0.75197
Red Matrix Column               : 0.43602 0.22249 0.01392
Green Matrix Column             : 0.3851 0.7169 0.09709
Blue Matrix Column              : 0.1431 0.06062 0.7142
Red Tone Reproduction Curve     : (Binary data 32 bytes, use -b option to extract)
Green Tone Reproduction Curve   : (Binary data 32 bytes, use -b option to extract)
Blue Tone Reproduction Curve    : (Binary data 32 bytes, use -b option to extract)
White Point X                   : 0.3127
White Point Y                   : 0.329
Red X                           : 0.64
Red Y                           : 0.33001
Green X                         : 0.3
Green Y                         : 0.6
Blue X                          : 0.15
Blue Y                          : 0.06
Color Primaries                 : BT.709
Transfer Characteristics        : BT.709
Matrix Coefficients             : Identity matrix
Video Full Range Flag           : 1
Image Size                      : 1920x1038
Megapixels                      : 2.0

And for the original PNG:

ExifTool Version Number         : 12.92
File Name                       : 348500482-b548d3fa-c9df-4e67-bcfa-32935a0e3b80.png
Directory                       : C:/Users/Kagami/Pictures
File Size                       : 10 MB
Zone Identifier                 : Exists
File Modification Date/Time     : 2024:07:30 22:59:43+02:00
File Access Date/Time           : 2024:07:31 21:51:49+02:00
File Creation Date/Time         : 2024:07:30 22:59:43+02:00
File Permissions                : -rw-rw-rw-
File Type                       : PNG
File Type Extension             : png
MIME Type                       : image/png
Image Width                     : 1920
Image Height                    : 1038
Bit Depth                       : 16
Color Type                      : RGB with Alpha
Compression                     : Deflate/Inflate
Filter                          : Adaptive
Interlace                       : Noninterlaced
Pixels Per Unit X               : 0
Pixels Per Unit Y               : 1
Pixel Units                     : Unknown
Color Primaries                 : BT.709
Transfer Characteristics        : BT.709
Matrix Coefficients             : Identity matrix
Video Full Range Flag           : 1
White Point X                   : 0.3127
White Point Y                   : 0.329
Red X                           : 0.64
Red Y                           : 0.33
Green X                         : 0.3
Green Y                         : 0.6
Blue X                          : 0.15
Blue Y                          : 0.06
Gamma                           : 1.961
Image Size                      : 1920x1038
Megapixels                      : 2.0

Somehow the decoder makes more complex exif?

tirr-c commented 4 months ago

The original PNG has cICP chunk that signals BT.709 transfer function (without ICC profile), and jxl-oxide and djxl produces PNG with iCCP chunk of equivalent ICC profile.

macOS displays both images with the same "washed out" colors:

image
tirr-c commented 4 months ago

jxl-oxide input.jxl --target-colorspace srgb -o output.png (which converts output to sRGB transfer function):

output

I'm starting to think that some browsers and viewers just assume sRGB and ignore the signalled BT.709 transfer...

saschanaz commented 4 months ago

I filed https://bugzilla.mozilla.org/show_bug.cgi?id=1911182. Let's see what our engineers find there.