Skip to content

Add JPEG XL Open/Read support via libjxl#7848

Open
olokelo wants to merge 87 commits intopython-pillow:mainfrom
olokelo:jxl-support2
Open

Add JPEG XL Open/Read support via libjxl#7848
olokelo wants to merge 87 commits intopython-pillow:mainfrom
olokelo:jxl-support2

Conversation

@olokelo
Copy link
Copy Markdown

@olokelo olokelo commented Mar 2, 2024

Helps #4247

This PR enables opening and reading JPEG XL images and animations.
Supported image modes are: RGB, RGBA, RGBa, L, LA, La.
A relatively recent libjxl version is needed to compile Pillow with libjxl support.
The main changes are the addition of _jxl.c and JxlImagePlugin.py.
I'm also the author of jxlpy so this PR was influenced by the work of contributors there. This PR is also largely based on WebPImagePlugin.py which had similar implementation.

Why?
JPEG XL has recently seen increased adoption especially in Apple ecosystem. A lot of users are requesting Pillow support for JPEG XL as their products use Pillow and need to be able to handle jxl files.

I'm open to suggestions and comments. I understand such change would need a lot of testing and probably changes. After all Pillow would need to become somewhat dependent on libjxl. Creating documentation will not be a big problem however I decided to wait for feedback from Pillow core developers.

Comment thread src/PIL/features.py Outdated
Comment thread Tests/test_jxl_leaks.py Outdated
Comment thread Tests/test_file_jxl_metadata.py Outdated
Comment thread src/PIL/JxlImagePlugin.py Outdated
@olokelo olokelo mentioned this pull request Mar 2, 2024
@brunoais
Copy link
Copy Markdown

brunoais commented Mar 2, 2024

May you please commit the images as LFS?

@olokelo
Copy link
Copy Markdown
Author

olokelo commented Mar 2, 2024

Do you mean those .jxl files under Tests/images I've committed? I'm not really sure how to do that.

@brunoais
Copy link
Copy Markdown

brunoais commented Mar 3, 2024

The explanation is outlined here: https://docs.github.com/en/repositories/working-with-files/managing-large-files/configuring-git-large-file-storage
Nevermind. I just noticed they are not putting the test images as lfs:
image

They already setup lfs and they only use for other larger stuff. Let it stay as you did.

@radarhere radarhere added the JPEG label Mar 11, 2024
@olokelo
Copy link
Copy Markdown
Author

olokelo commented Mar 11, 2024

Mac OS builds were failing because clang complained about goto labels being declared before variables in scope.
I also merged @radarhere's commits that remove the jxl feature which was causing troubles before.
Now it should be fine. Almost all checks pass except codecov.

Comment thread src/PIL/JxlImagePlugin.py Outdated
Comment thread src/PIL/__init__.py Outdated
Comment thread Tests/test_file_jxl_metadata.py
Comment thread Tests/test_jxl_leaks.py Outdated
Comment thread Tests/test_jxl_leaks.py Outdated
Comment thread Tests/test_jxl_leaks.py Outdated
Comment thread src/_jxl.c
Comment thread src/PIL/JxlImagePlugin.py Outdated
Comment thread src/PIL/JxlImagePlugin.py Outdated
Comment thread src/PIL/JxlImagePlugin.py Outdated
Comment thread src/PIL/JxlImagePlugin.py
@hugovk

This comment was marked as resolved.

@olokelo

This comment was marked as resolved.

Comment thread src/PIL/JxlImagePlugin.py Outdated
Comment thread src/PIL/JxlImagePlugin.py
@radarhere

This comment was marked as resolved.

@hugovk
Copy link
Copy Markdown
Member

hugovk commented Jan 2, 2026

How much bigger does this make the wheels?

We need to keep in mind increased wheel size effects everyone, even if they don't use JXL (not the case with opt-in plugins).

When we added AVIF, we initially had problems with the wheels being too big: #8856

@radarhere
Copy link
Copy Markdown
Member

It does increase the size significantly. The current total size of our wheels is 531.5mb. In this PR, it is 730.2mb.

@h-vetinari

This comment was marked as resolved.

@h-vetinari

This comment was marked as resolved.

@hugovk
Copy link
Copy Markdown
Member

hugovk commented Apr 26, 2026

It does increase the size significantly. The current total size of our wheels is 531.5mb. In this PR, it is 730.2mb.

This seems like too much. I know we have fewer wheels right now, but it will soon increase for 3.15+3.15t, and a ~37% increase is a lot. And it will be paid by everyone, including those not using JPEG XL.

I think we should consider some of the suggestions I made at #9101 (comment).

@h-vetinari
Copy link
Copy Markdown

I think we should consider some of the suggestions I made at #9101 (comment).

I think that's a very worthwhile initiative, though IMO that should be pursued independently; IOW, I wouldn't like to see jpegxl support held up over this.

@aclark4life
Copy link
Copy Markdown
Member

I think that's a very worthwhile initiative, though IMO that should be pursued independently; IOW, I wouldn't like to see jpegxl support held up over this.

We can try to decide on and implement some alternative to "including in the wheel" prior to the next release.

@hugovk
Copy link
Copy Markdown
Member

hugovk commented Apr 27, 2026

I think that's a very worthwhile initiative, though IMO that should be pursued independently; IOW, I wouldn't like to see jpegxl support held up over this.

The thing is, the current size increase is a blocker for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.