libjxl icon indicating copy to clipboard operation
libjxl copied to clipboard

Feature request: Support for `cjxl` to handle text chunks in PNGs

Open eddiezato opened this issue 2 years ago • 1 comments

Currently cjxl can't handle text chunks (tEXt/iTXt/zTXt) in PNG files and transfer metadata to JXL. It would be useful to have support of this.

eddiezato avatar Jun 15 '22 08:06 eddiezato

To be more specific, this is about recognizing Exif/XMP/ICC metadata being stored in text chunks (as raw payload under Raw profile type ... keyword) since early PNG spec didn't have dedicated metadata chunks like eXIf.

https://exiftool.org/TagNames/PNG.html#TextualData

This is still the case for XMP using the XML:com.adobe.xmp keyword.

kmilos avatar Jun 15 '22 09:06 kmilos

Is this why cjxl "0911152001.png" -d 0 -e 9 "0911152001.png.d0e9.jxl" doesn't preserve the metadata from this image? or is that a separate issue?

convert 0911152001.png -quality 100 -define jxl:effort=9 0911152001.png.q100e9.jxl from imagemagick, on the other hand, does preserve the metadata when converting to jxl

(original image was jpg, which was converted to png, provided below)

0911152001

lectrode avatar Jan 06 '23 03:01 lectrode

Is this why cjxl "0911152001.png" -d 0 -e 9 "0911152001.png.d0e9.jxl" doesn't preserve the metadata from this image?

Yes.

$ exiv2 -pS ../210919341-5df28b79-3339-48da-a5b8-a6f19733d96b.png
STRUCTURE OF PNG FILE: ../210919341-5df28b79-3339-48da-a5b8-a6f19733d96b.png
 address | chunk |  length | data                           | checksum
       8 | IHDR  |      13 | ...@...$....                   | 0x8d002add
      33 | zTXt  |    5426 | Raw profile type exif..x...Wr# | 0x2075c0fd
    5471 | iCCP  |     387 | ICC profile..x.}.=H.@.._S."..; | 0x4db1a3cb
    5870 | iTXt  |    3448 | XML:com.adobe.xmp.....<?xpacke | 0x048f4a5c
    9330 | pHYs  |       9 | .........                      | 0x009a9c18
    9351 | tIME  |       7 | .......                        | 0x712bdafa
    9370 | tEXt  |      81 | Comment.charset=InvalidCharset | 0x66195c5f
    9463 | IDAT  |    8192 | x.T...%[email protected]..... | 0xe64a5dbc

If you convert the jpg to png using (a relatively recent version of) ImageMagick as well you will see the Exif is no longer stored in a "Raw profile type exif" zTXt chunk but a proper eXIf chunk instead, and cjxl would detect the metadata then.

kmilos avatar Jan 06 '23 10:01 kmilos

This is working since 0d89f89, but it hasn't made it into a release yet. Prior to that change, cjxl(_ng) didn't add metadata to the JXL output.

I believe the library has supported reading "Raw profile type" chunks for both Exif and XMP for quite a while - it's just that release 0.7.0 doesn't do anything with them after reading them.

Here's a new-ish version of cjxl converting that file:

$ cjxl 210919341-5df28b79-3339-48da-a5b8-a6f19733d96b.png 210919341-5df28b79-3339-48da-a5b8-a6f19733d96b.jxl -e 1
JPEG XL encoder v0.8.0 0a6bafee [AVX2,SSE4,SSSE3,Unknown]
Read 4160x2340 image, 8684443 bytes, 196.0 MP/s
Encoding [Container | VarDCT, d1.000, effort: 1 | 5174-byte Exif | 3426-byte XMP], 
Compressed to 844598 bytes including container (0.694 bpp).
4160 x 2340, 9.33 MP/s [9.33, 9.33], 1 reps, 8 threads.

$ jxlinfo 210919341-5df28b79-3339-48da-a5b8-a6f19733d96b.jxl 
JPEG XL file format container (ISO/IEC 18181-2)
JPEG XL image, 4160x2340, lossy, 8-bit RGB
Brotli-compressed Exif metadata: 4637 compressed bytes
Brotli-compressed xml  metadata: 696 compressed bytes
Color space: RGB, D65, sRGB primaries, sRGB transfer function, rendering intent: Perceptual

(Not all decoders understand Brotli-compressed boxes, so you might want to use --compress_boxes=0)

alistair7 avatar Jan 06 '23 17:01 alistair7

Thank you - very informative.

I can confirm that converting with the latest cjxl git does indeed retain the metadata as expected.

The main concern is making sure the metadata exists in the new/replacement image. If I have to compile a newer metadata viewer for now to view that info, that's not a blocker. Hopefully that won't be required for too much longer.

lectrode avatar Jan 07 '23 06:01 lectrode

FYI, IM 7.1.0-58 should have much improved Exif/XMP support for JPEG XL files.

kmilos avatar Jan 23 '23 10:01 kmilos