Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full support for jpeg xl #831

Closed
4 tasks done
TheHardew opened this issue Mar 8, 2022 · 24 comments
Closed
4 tasks done

Full support for jpeg xl #831

TheHardew opened this issue Mar 8, 2022 · 24 comments
Labels
enhancement New feature or request released

Comments

@TheHardew
Copy link

Describe your suggested feature

Please add support for reading jpeg xl image files. It can losslessly compress existing jpeg files by about 20%, Adobe and Facebook have already declared that they will support the format (in fact you can already upload some jpeg xl files to facebook). I believe it could become really popular.

Jpeg xl in cbz can already be displayed with google chrome (with the jxl flag turned on) or with tachiyomi, however cover image generation fails.

You can look here to check how tachiyomi handles it: https://github.com/tachiyomiorg/image-decoder

Other details

No response

Acknowledgements

  • I have searched the existing issues and this is a new ticket, NOT a duplicate or related to another open issue.
  • I have written a short but informative title.
  • I have updated the app to the latest version.
  • I will fill out all of the requested information in this form.
@TheHardew TheHardew added the enhancement New feature or request label Mar 8, 2022
@gotson
Copy link
Owner

gotson commented Mar 9, 2022

As you noticed, there is already limited support for jxl which I added recently, so indeed browser will display, and tachiyomi too.

Komga doesn't need to decode images for everything, only for some actions, like :

  • generating covers
  • converting on the fly (if you read via opds for example, some formats would be converted)
  • duplicate page detection
  • dimension analysis

You can use custom covers to go around the cover generation issue.

Komga relies on 3rd party libraries for image decoding, mostly the very good https://github.com/haraldk/TwelveMonkeys

There is no java library for jxl yet, and the best bet is haraldk/TwelveMonkeys#643

That's a long shot though.

Keep in mind that standard adoption is slow, take webp for instance. It's not yet supported everywhere.

@gotson gotson added the blocked Blocked by another issue label Mar 9, 2022
@gotson gotson changed the title Support jpeg xl Full support for jpeg xl Mar 9, 2022
@BuZZ-dEE
Copy link

BuZZ-dEE commented Mar 9, 2022

There is a bounty for TwelveMonkeys JPEG-XL read and write support.

Bountysource

🚀 Pump it. 🚀

@TheHardew
Copy link
Author

For twelvemonkeys do you need a decoder written only in java or can it link to libjxl in C? I'm trying to judge how likely it is someone will be able to write it.

@gotson
Copy link
Owner

gotson commented Mar 10, 2022

For twelvemonkeys do you need a decoder written only in java or can it link to libjxl in C? I'm trying to judge how likely it is someone will be able to write it.

Twelvemonkeys is pure Java.

The problem with decoders in C is that you need to interface with JNI and write custom C code for the interop. I already use one for webp, but you need to compile it for all systems, which is tedious.

Project Panama should help in that regards, but is not finalized yet, and would require a very recent version of Java.

@gotson gotson removed the blocked Blocked by another issue label Apr 11, 2022
@gotson
Copy link
Owner

gotson commented Apr 11, 2022

I have released the first version of https://github.com/gotson/NightMonkeys which has an imageio plugin for jpeg xl. This can be integrated in Komga, but requires to launch Java with specific version and arguments.

@TheHardew do you use Komga via jar or Docker, or another method?

@TheHardew
Copy link
Author

TheHardew commented Apr 11, 2022

I use the jar. I was wondering why I had 8k empty files in /tmp starting with "imageio".

Edit: To be precise, I use the Arch User Repository package, but it would probably be quite easy to edit that.

@gotson
Copy link
Owner

gotson commented Apr 11, 2022

The jar would be easier to accommodate, you would need jdk 18 and some extra command line parameters, and also the jxl library installed locally.

What's your os?

@gotson
Copy link
Owner

gotson commented Apr 11, 2022

Edit: To be precise, I use the Arch User Repository package, but it would probably be quite easy to edit that.

It's a third party maintained integration, so 🤷🏻‍♂️

@TheHardew
Copy link
Author

I have jre-openjdk 18-2.1. What are the parameters?

@gotson
Copy link
Owner

gotson commented Apr 11, 2022

What's your os?

@TheHardew
Copy link
Author

Arch Linux.
I have Komga 0.153.2-1, Java 18, libjxl v0.7.0 79d85890.

@TheHardew
Copy link
Author

All the Arch package does is it installs the jar and the /usr/bin/komga file:

#!/bin/sh
exec /usr/bin/java -jar '/usr/share/java/komga/komga.jar' "$@"

@TheHardew
Copy link
Author

I set LD_LIBRARY_PATH to /usr/lib because that's where libjxl.so is. I started Komga with /usr/bin/java --enable-native-access=ALL-UNNAMED --add-modules jdk.incubator.foreign -jar /usr/share/java/komga/komga.jar. It did not work. When I get home I'll try to use the latest release version of libjxl, instead of this one compiled from git.

@gotson
Copy link
Owner

gotson commented Apr 11, 2022

I set LD_LIBRARY_PATH to /usr/lib because that's where libjxl.so is. I started Komga with /usr/bin/java --enable-native-access=ALL-UNNAMED --add-modules jdk.incubator.foreign -jar /usr/share/java/komga/komga.jar. It did not work. When I get home I'll try to use the latest release version of libjxl, instead of this one compiled from git.

Well of course it did not work, I have not released anything 🤷🏻

@gotson gotson closed this as completed in dd5b7d0 Apr 12, 2022
@TheHardew
Copy link
Author

TheHardew commented Apr 12, 2022

Works wonderfully, thank you very much!

@gotson
Copy link
Owner

gotson commented Apr 13, 2022

Works wonderfully, thank you very much!

bit surprised since i haven't released Komga with that lib included

@TheHardew
Copy link
Author

TheHardew commented Apr 13, 2022

I built it myself.

github-actions bot pushed a commit that referenced this issue Apr 22, 2022
# [0.154.0](v0.153.2...v0.154.0) (2022-04-22)

### Bug Fixes

* translated using Weblate ([18b181b](18b181b))
* **webui:** extract translation strings for DropZone.vue ([2966c85](2966c85)), closes [#856](#856)
* **webui:** read button on card would not always work ([4dd1e7a](4dd1e7a)), closes [#830](#830)

### Features

* read support for jpeg xl ([dd5b7d0](dd5b7d0)), closes [#831](#831)
* **webui:** set the currently viewed page as poster for book/series/readlist ([49b7f59](49b7f59)), closes [#838](#838)
@github-actions
Copy link
Contributor

🎉 This issue has been resolved in version 0.154.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@ghost
Copy link

ghost commented May 2, 2022

In case anyone else stumbles across this issue and is struggling to get Komga to recognize their native JXL library: The library file has to be renamed or symlinked to libjxl.so. Komga won't recognize the native library if it's called, e.g. libjxl.so.0.6.1 or libjxl.so.0.7.0. (@gotson Is this intentional or a bug?)

This is how I set it up, using Debian 11 as an example:

  1. Download and install libjxl and its dependencies. The required packages are only available in Debian Sid and Experimental, so they have to be installed using dpkg instead of apt.
whalehub@pdh:~# curl -LO http://ftp.debian.org/debian/pool/main/h/highway/libhwy0_0.16.0-1_amd64.deb
whalehub@pdh:~# curl -LO http://ftp.debian.org/debian/pool/main/j/jpeg-xl/libjxl0.7_0.7.0~git20220325.7594374+ds-3_amd64.deb
whalehub@pdh:~# sudo dpkg -i libhwy0_0.16.0-1_amd64.deb libjxl0.7_0.7.0~git20220325.7594374+ds-3_amd64.deb
  1. Create a symbolic link to the file name that is expected by Komga:
whalehub@pdh:~# cd /usr/lib/x86_64-linux-gnu
whalehub@pdh:~# sudo ln -s libjxl.so.0.7.0 libjxl.so
  1. Set the LD_LIBRARY_PATH variable to the library folder (preferably in a systemd service file):
whalehub@pdh:~# LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu
  1. Launch Komga.
whalehub@pdh:~# java --add-modules jdk.incubator.foreign --enable-native-access=ALL-UNNAMED -jar /usr/local/bin/komga.jar
  1. Verify that Komga successfully loads the native library.
INFO 2581598 --- [main] c.g.g.n.j.i.plugins.JxlImageReaderSpi    : Loaded libjxl v0.7.0
INFO 2581598 --- [main] o.g.k.i.image.ImageConverter             : Using native WebP library
INFO 2581598 --- [main] o.g.k.i.image.ImageConverter             : Supported read formats: [JPG, JPEG 2000, tiff, bmp, PCX, bigtiff, wbp, gif, WBMP, PNG, RAW, JPEG, PNM, BigTIFF, tif, TIFF, wbmp, jpeg, jpeg-lossless, jbig2, jxl, jpg, JPEG2000, BMP, pcx, WBP, GIF, Jpeg XL, png, BIGTIFF, raw, JPEG-LOSSLESS, webp, JBIG2, pnm, TIF, jpeg2000, WEBP, WebP, jpeg 2000]
INFO 2581598 --- [main] o.g.k.i.image.ImageConverter             : Supported read mediaTypes: [image/vnd.wap.wbmp, image/jpeg, image/x-portable-graymap, image/bmp, image/gif, image/x-windows-pcx, image/x-pc-paintbrush, image/x-raw, image/webp, image/x-pcx, image/x-portable-bitmap, image/png, image/x-jb2, image/pcx, image/x-windows-bmp, image/x-webp, image/jpeg2000, image/x-bmp, image/jp2, image/x-png, image/x-portable-pixmap, image/x-jbig2, image/tiff, image/x-tiff, image/x-portable-anymap, image/jxl]

@gotson
Copy link
Owner

gotson commented May 2, 2022

In case anyone else stumbles across this issue and is struggling to get Komga to recognize their native JXL library: The library file has to be renamed or symlinked to libjxl.so. Komga won't recognize the native library if it's called, e.g. libjxl.so.0.6.1 or libjxl.so.0.7.0. (@gotson Is this intentional or a bug?)

This is how I set it up, using Debian 11 as an example:

  1. Download and install libjxl and its dependencies. The required packages are only available in Debian Sid and Experimental, so they have to be installed using dpkg instead of apt.
whalehub@pdh:~# curl -LO http://ftp.debian.org/debian/pool/main/h/highway/libhwy0_0.16.0-1_amd64.deb
whalehub@pdh:~# curl -LO http://ftp.debian.org/debian/pool/main/j/jpeg-xl/libjxl0.7_0.7.0~git20220325.7594374+ds-3_amd64.deb
whalehub@pdh:~# sudo dpkg -i libhwy0_0.16.0-1_amd64.deb libjxl0.7_0.7.0~git20220325.7594374+ds-3_amd64.deb
  1. Create a symbolic link to the file name that is expected by Komga:
whalehub@pdh:~# cd /usr/lib/x86_64-linux-gnu
whalehub@pdh:~# sudo ln -s libjxl.so.0.7.0 libjxl.so
  1. Set the LD_LIBRARY_PATH variable to the library folder (preferably in a systemd service file):
whalehub@pdh:~# LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu
  1. Launch Komga.
whalehub@pdh:~# java --add-modules jdk.incubator.foreign --enable-native-access=ALL-UNNAMED -jar /usr/local/bin/komga.jar
  1. Verify that Komga successfully loads the native library.
INFO 2581598 --- [main] c.g.g.n.j.i.plugins.JxlImageReaderSpi    : Loaded libjxl v0.7.0
INFO 2581598 --- [main] o.g.k.i.image.ImageConverter             : Using native WebP library
INFO 2581598 --- [main] o.g.k.i.image.ImageConverter             : Supported read formats: [JPG, JPEG 2000, tiff, bmp, PCX, bigtiff, wbp, gif, WBMP, PNG, RAW, JPEG, PNM, BigTIFF, tif, TIFF, wbmp, jpeg, jpeg-lossless, jbig2, jxl, jpg, JPEG2000, BMP, pcx, WBP, GIF, Jpeg XL, png, BIGTIFF, raw, JPEG-LOSSLESS, webp, JBIG2, pnm, TIF, jpeg2000, WEBP, WebP, jpeg 2000]
INFO 2581598 --- [main] o.g.k.i.image.ImageConverter             : Supported read mediaTypes: [image/vnd.wap.wbmp, image/jpeg, image/x-portable-graymap, image/bmp, image/gif, image/x-windows-pcx, image/x-pc-paintbrush, image/x-raw, image/webp, image/x-pcx, image/x-portable-bitmap, image/png, image/x-jb2, image/pcx, image/x-windows-bmp, image/x-webp, image/jpeg2000, image/x-bmp, image/jp2, image/x-png, image/x-portable-pixmap, image/x-jbig2, image/tiff, image/x-tiff, image/x-portable-anymap, image/jxl]

Java expects the naming as you mention, that's how it is. There should always be those normal names, the ones with added numbers are not standard AFAIK.

Installing with homebrew creates those links by default.

@ghost

This comment was marked as off-topic.

@gotson

This comment was marked as off-topic.

@ghost

This comment was marked as off-topic.

@gotson

This comment was marked as off-topic.

Repository owner locked as resolved and limited conversation to collaborators May 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request released
Projects
None yet
Development

No branches or pull requests

3 participants