Isotr0py / pillow-jpegxl-plugin

Pillow plugin for JPEG-XL, using Rust for bindings.
GNU General Public License v3.0
18 stars 5 forks source link

[BUG] Failure to write RGBA (1.1.0.post1) #21

Closed jojje closed 7 months ago

jojje commented 7 months ago

Crashes when trying to write a 4 channel (RGBA) image. (Three channel images work though)

This is particularly annoying since reading even a non-alpha PNG image via PIL produces a 4-channel image, causing even the simplest conversion such as Image.open('src.png').save('dst.jxl') to run into this crash.

To reproduce

from PIL import Image
import pillow_jxl
import numpy as np

rgba = np.zeros((256, 256, 4), dtype='uint8')
Image.fromarray(rgba).save('out.jxl')

Error:

thread '<unnamed>' panicked at src\lib.rs:76:59:
called `Result::unwrap()` on an `Err` value: ApiUsage
stack backtrace:
   0: rust_begin_unwind
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\std\src/panicking.rs:645:5
   1: core::panicking::panic_fmt
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\core\src/panicking.rs:72:14
   2: core::result::unwrap_failed
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\core\src/result.rs:1653:5
   3: pillow_jxl::Encoder::__call__
   4: pillow_jxl::_::<impl pillow_jxl::Encoder>::__pymethod___call____
   5: pyo3::impl_::trampoline::trampoline
   6: pillow_jxl::_::<impl pyo3::impl_::pyclass::PyMethods<pillow_jxl::Encoder> for pyo3::impl_::pyclass::PyClassImplCollector<pillow_jxl::Encoder>>::py_methods::ITEMS::trampoline
   7: <unknown>
   8: <unknown>
   ...

Alternative reproduction using docker

Dockerfile.txt

$ docker build -t test -f Dockerfile.txt .
$ docker run --rm test

System information

Also verified as failing the same way on linux.

Isotr0py commented 7 months ago

Thanks for reporting the issue!

New 1.1.1 version should fix this issue.