olokelo / jxlpy

Cython bindings and Pillow plugin for JPEG XL
MIT License
49 stars 12 forks source link

Not working with recent Pillow (10.1.0) #18

Closed cmahnke closed 8 months ago

cmahnke commented 11 months ago

This plugin isn't working with a recent version of Pillow (10.1.0)

    im = Image.open(args.image)
  File "/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/PIL/Image.py", line 3284, in open
    im = _open_core(fp, filename, prefix, formats)
  File "/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/PIL/Image.py", line 3270, in _open_core
    im = factory(fp, filename)
  File "/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/PIL/ImageFile.py", line 117, in __init__
    self._open()
  File "/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/jxlpy/JXLImagePlugin.py", line 31, in _open
    self.mode = self.rawmode = self._decoder.get_colorspace()

Reverting Pillow to 10.0.1 or 9.5.0 fixes the problem, both tested on Python 3.10.

pip install Pillow==9.5.0

or

pip install Pillow==10.0.1

Probably related to this API change.

rphlo commented 11 months ago

https://github.com/olokelo/jxlpy/pull/19 this should fix the issue

olokelo commented 11 months ago

Thank you for noticing the issue @cmahnke and big thanks for PR @rphlo.

I've got no time to work on this library lately and sorry for it not being updated. It was my side project in summer of 2021 but not much has changed since then in the code. I was planning earlier this year to completely rewrite jxlpy without the cython dependency so that it would be easier to integrate it directly into Pillow. It would work somewhat similar to this project. However I have no idea as to when I will have time to dive into that and if I even succeed.

Thanks everyone for using jxlpy but please keep in mind it might get discontinued soon.

cmahnke commented 11 months ago

Thanks for the update @olokelo even though this is sad news. And thanks @rphlo for your PR!

Anyways, there are already some forks, maybe we can create an issue to ask if any of the ones who forked and maybe also already did some improvements to their forks. I take the liberty to create a short list compiled from the Insights -> Network page:

rphlo commented 11 months ago

@olokelo Thanks for the initial work. With safari setting JPEG XL as a first class citizen, and chrome team re-introducing it in its project, I think this library will soon gather more interest.

olokelo commented 11 months ago

Thank you @cmahnke , I've looked into forks and I was able to get the newest release of jxlpy from foosoftsrl working with libjxl 0.8.2.

pip install git+https://github.com/foosoftsrl/jxlpy.git

The build_prerequisites.sh script deals with compiling required dependencies for libjxl which helps a lot with installation. I just had to install brotli_static to compile everything successfully. It wasn't easy for me to compile libjxl in github actions reliably. That's why there are no wheels for recent Python versions.

I'm a bit surprised jxlpy is still alive and working. However I believe it should be rewritten to directly access Python API from C. It might be easier to integrate in Python projects and this would not bring unnecessary additional dependencies. That's also probably the only way Pillow (the famous Python library to deal with images) would integrate it. JPEG XL also has a lot complexity. Even Pillow wouldn't be able to use all of the features (for example additional channels, progressive loading, jpeg recompression). Also libjxl isn't the lightest library and has its own dependencies.

For now there's pyvips which supports JPEG XL and interfaces with Python using CFFI.

I will try to rewrite jxlpy in cleaner way based on forks and this avif library. If I fail, I will probably look for a more competent maintainer. As @rphlo said JPEG XL is raising again and it would be nice for Python have a library for it.

protoism commented 10 months ago

Hi guys, thanks for reviving the project.

cmahnke commented 8 months ago

@olokelo Can you please do a release containg the fix by rphlo? That would close this issue and #17 as well.

olokelo commented 8 months ago

Thanks, the new release 0.9.3 is now on PyPI. It should fix this issue.