src/img2pdf.py: do not use PNG encoding for CMYK input

This commit is contained in:
Johannes 'josch' Schauer 2018-07-17 16:47:27 +02:00
parent 3142824bab
commit 47a1e0c81e
Signed by untrusted user: josch
GPG key ID: F2CBA5C78FBD83E1

View file

@ -830,15 +830,22 @@ def read_images(rawdata, colorspace, first_frame_only=False):
newimg = imgdata newimg = imgdata
else: else:
raise ValueError("unknown or unsupported colorspace: %s" % color.name) raise ValueError("unknown or unsupported colorspace: %s" % color.name)
# cheapo version to retrieve a PNG encoding of the payload is to # the PNG format does not support CMYK, so we fall back to normal
# just save it with PIL. In the future this could be replaced by # compression
# dedicated function applying the Paeth PNG filter to the raw pixel if color in [Colorspace.CMYK, Colorspace["CMYK;I"]]:
pngbuffer = BytesIO() imggz = zlib.compress(newimg.tobytes())
newimg.save(pngbuffer, format="png") result.append((color, ndpi, imgformat, imggz, imgwidthpx,
pngidat, palette = parse_png(pngbuffer.getvalue()) imgheightpx, []))
imgformat = ImageFormat.PNG else:
result.append((color, ndpi, imgformat, pngidat, imgwidthpx, # cheapo version to retrieve a PNG encoding of the payload is to
imgheightpx, palette)) # just save it with PIL. In the future this could be replaced by
# dedicated function applying the Paeth PNG filter to the raw pixel
pngbuffer = BytesIO()
newimg.save(pngbuffer, format="png")
pngidat, palette = parse_png(pngbuffer.getvalue())
imgformat = ImageFormat.PNG
result.append((color, ndpi, imgformat, pngidat, imgwidthpx,
imgheightpx, palette))
img_page_count += 1 img_page_count += 1
# the python-pil version 2.3.0-1ubuntu3 in Ubuntu does not have the # the python-pil version 2.3.0-1ubuntu3 in Ubuntu does not have the
# close() method # close() method