python-pillow / Pillow

Python Imaging Library (Fork)
https://python-pillow.org
Other
11.8k stars 2.13k forks source link

Saving a CMYK image as .jp2/.j2k fails #8062

Open sl2c opened 2 weeks ago

sl2c commented 2 weeks ago

When running

Image.open('cmyk.tif').save('out.jp2')

I get:

OSError: encoder error -2 when writing image file

Same with writing to '.j2k'. Same with other CMYK images I tried. I am using Pillow v. 10.1.0.

cmyk.tif.zip

radarhere commented 2 weeks ago

I've created https://github.com/uclouvain/openjpeg/pull/1529 as the first step in saving JP2 CMYK images.

Without the colour specification box of JP2, it doesn't seem possible to have a CMYK J2K image.

https://community.intel.com/t5/Intel-Integrated-Performance/JPEG2000-and-CMYK-Data-Not-RGB/td-p/862891

JPEG 2000 encoding doesn't support CMYK coding, mostly because it's an extension of JP2 file container (part 2 of the standard)

https://newsgroup.xnview.com/viewtopic.php?t=29274

the JPEG-2000 standard does not specify any means for encoding color space information in a JPEG-2000 code stream, the decoder must make certain assupmtions about the color space of an image. If accurate color representation is important, the JPEG-2000 code stream format should not be employed. The JPEG-2000 JP2 format should be used instead.