core
core copied to clipboard
handle CMYK images
trafficstars
In addition to #627, we need to convert input images of the following color spaces to plain RGB at the beginning:
- CMYK
- HSV
- YCbCr
- LAB
I'm sure there are even more modes which Pillow does not support (see here), but let's concentrate on the modes which the PNG plugin does not support: Compare this list of Image modes with that list of PNG modes.
Example stack trace:
Traceback (most recent call last):
File "/build/core/ocrd/ocrd/processor/helpers.py", line 101, in run_api
processor.process()
File "/build/ocrd_segment/ocrd_segment/replace_original.py", line 78, in process
mimetype='image/png')
File "/build/core/ocrd/ocrd/workspace.py", line 820, in save_image_file
image.save(image_bytes, format=MIME_TO_PIL[mimetype])
File "/usr/local/lib/python3.6/dist-packages/PIL/Image.py", line 2151, in save
save_handler(self, fp, filename)
File "/usr/local/lib/python3.6/dist-
packages/PIL/PngImagePlugin.py", line 1222, in _save
raise OSError(f"cannot write mode {mode} as PNG") from e
OSError: cannot write mode CMYK as PNG Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/PIL/PngImagePlugin.py", line 1220, in _save
rawmode, mode = _OUTMODES[mode]
KeyError: 'CMYK'