Skip to content

Add support for JPEG-XL (file extension: jxl) #1413

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

Merged
merged 115 commits into from
Apr 18, 2025
Merged

Conversation

StableLlama
Copy link
Contributor

Add the possibility to use images in the JPEG XL file format.

This PS doesn't change any other setting, especially it doesn't touch any places with hard coded file formats.

@bghira
Copy link
Owner

bghira commented Apr 17, 2025

why does this add the import all over the place?

@StableLlama
Copy link
Contributor Author

It does it everywhere PIL is included and then it is used to load or save an image to make sure it has this plugin.

bghira added 27 commits April 17, 2025 19:13
@StableLlama StableLlama marked this pull request as draft April 17, 2025 17:19
@StableLlama
Copy link
Contributor Author

I've got git problems solving the poetry.lock conflict. Till it's solved it's just a draft.

@bghira
Copy link
Owner

bghira commented Apr 17, 2025

i think it's only necessary to do that in the image load function, since that's the one spot this is handled everywhere. but the default file loader is CV2, not PIL.

@StableLlama StableLlama marked this pull request as ready for review April 17, 2025 17:33
@StableLlama
Copy link
Contributor Author

poetry.lock is now fixed. Sorry for the commit history bloat, I'm not that familiar with git so that I could have avoided it. But looking on the file changes them self will the correct truth anyway.

About the image loading I searched for all files that were including Image from PIL and also were using either open() or save(). In my test ST correctly took the images from the multidatabackend.json and placed them in the VAE cache directory.

When I missed it somewhere, e.g. due to CV2, I'm happy to look again. But I'd need a hint where I have to look :)

@StableLlama
Copy link
Contributor Author

Ok, there were only two places that are using CV2 instead of PIL to load an image. I've added a PIL fallback when CV2 doesn't understand a codec

@bghira
Copy link
Owner

bghira commented Apr 17, 2025

where you're adding the import, these scripts aren't always needing JPEG-XL. in general, i'd like to avoid having it as a baseline requirement because it sort of a rare format. we can wrap the import in a try catch and leave a note about JPEG-XL being unavailable.

Also remove the CV2 to PIL fallback from toolkit/datasets/crop.py as requested
@StableLlama
Copy link
Contributor Author

JPEG XL is not common right now, but it has wide momentum and is made available in many different places - and it's a great format for our usecase here. But I don't want to discuss formats, as that tends to be pointless 🙂

Now I've made it completely optional. Right now it's by default not included, but we could easily change it to be included by default with the possibility to exclude it.

The crop.py also isn't using the CV2 to PIL fallback anymore.

@bghira bghira merged commit 7b922c8 into bghira:main Apr 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants