-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Enhancement: add support for jpegli as jpeg encoder #4018
Comments
My understanding is that the jpegli encoder discards more data from the blue part of the visual spectrum to achieve smaller files. To achieve this it uses a somewhat non-standard approach, converting RGB pixel values to a custom colour space (XYB) and storing them as if they were YCbCr, attaching an ICC profile with the relevant curves for a decoder to convert back again. This means all decoders given such images would need to properly support ICC profiles, something that is still not the case today. This would also preclude the use of wider gamut RGB profiles such as P3.
Those wishing to use this should be able to do so today with a globally-installed libvips, although I cannot provide any help or support. If the prebuilt binaries were ever to include this, it would be instead of mozjpeg rather than in addition to. This means it would require that the upstream jpegli library have a "switch" to use standard libjpeg YCbCr colour encoding, a feature I don't see today. |
I got the info that Jpegli only uses XYB optionally nowadays, and all comparisons that Google has done were without the XYB ICC color space. jpegli does the same as other encoders, just quantized differently. i.e., no decoding compatibility burned. Jyrki will also reply here as soon as he has the time. |
Ah OK, happy to stand corrected, the documentation for jpegli is rather sparse and I might be mixing it up with bits of JPEG-XL. |
Today's Google announcement https://opensource.googleblog.com/2024/04/introducing-jpegli-new-jpeg-coding-library.html |
For people following this issue, as far as I can tell, if you build your own libvips and replace the jpeg libs during building of libvips, you can make sharp use jpegli already (implicitly). |
How to replace JPEG lib? Can you give command to give while building libvips? |
I think something like this should do it:
and then build libvips. not 100% sure though (and make sure to make a backup of the current libjpeg in case you try it outside of a docker container or so) |
Jpegli is not using XYB by default. Most of the substantial savings are by variable dead zone quantization and more precise intermediate computations. Using XYB will give an additional ~10 % savings in mid-to-high quality. |
@jyrkialakuijala Thanks for the info. Given jpegli is intended as a "drop-in replacement" for libjpeg(-turbo), is there any plan to add support for the |
Jpegli features can currently be switched on/off with individual jpegli_* API functions, like jpegli_enable_adaptive_quantization. We are currently in the process of migrating Jpegli from the libjxl/libjxl repository to the google/jpegli repository and will not change the API until this is completed. Please consider adding an issue to the google/jpegli repository so that we can consider this in the future. |
@lovell you probably have more context on what you'd need, could you open the issue there? (or if you don't have time, please lmk which features sharp would need, and then I'll happily open it) |
I've opened google/jpegli#45 to discuss this upstream in the jpegli repo. |
Feature request
What are you trying to achieve?
The JPEG XL team at Google has built yet another JPEG encoder, jpegli, which is both faster and better than even mozjpeg. It is based on lessons learned from guetzli and libjxl, and offers a very attractive trade-off: it is very fast, compresses better than WebP and even high-speed AVIF, while still producing good old JPEG files that are supported everywhere. - source: https://cloudinary.com/blog/jpeg-xl-and-the-pareto-front.
Why is it worth adding
Google did a visual study using jpegli, made public in 2024: https://github.com/google-research/google-research/tree/master/mucped23
Further blog posts (from last year, could be that jpegli advanced by now):
How to integrate
Jpegli is included in the JXL repo: https://github.com/libjxl/libjxl/blob/main/lib/jpegli/README.md:
libvips discussion: libvips/libvips#3871
When you searched for similar feature requests, what did you find that might be related?
#2731
What would you expect the API to look like?
Probably an option like
[options.mozjpeg]
->[options.jpegli]
.What alternatives have you considered?
see above; jpegli is an alternative to mozjpeg, while being faster and achieving better quality.
The text was updated successfully, but these errors were encountered: