1
0
Fork 0
forked from josch/img2pdf

support for palette images for better GIF support

This commit is contained in:
Johannes 'josch' Schauer 2016-02-17 00:35:40 +01:00
parent edba669000
commit d9b2550ceb

View file

@ -56,7 +56,7 @@ FitMode = Enum('FitMode', 'into fill exact shrink enlarge')
PageOrientation = Enum('PageOrientation', 'portrait landscape') PageOrientation = Enum('PageOrientation', 'portrait landscape')
Colorspace = Enum('Colorspace', 'RGB L 1 CMYK CMYK;I RGBA') Colorspace = Enum('Colorspace', 'RGB L 1 CMYK CMYK;I RGBA P')
ImageFormat = Enum('ImageFormat', 'JPEG JPEG2000 TIFF PNG GIF') ImageFormat = Enum('ImageFormat', 'JPEG JPEG2000 TIFF PNG GIF')
@ -617,6 +617,8 @@ def read_images(rawdata, colorspace, first_frame_only=False):
imgdata, imgformat, default_dpi, colorspace, rawdata) imgdata, imgformat, default_dpi, colorspace, rawdata)
if color == Colorspace['1']: if color == Colorspace['1']:
raise MonochromeJpegError("jpeg can't be monochrome") raise MonochromeJpegError("jpeg can't be monochrome")
if color == Colorspace['P']:
raise MonochromeJpegError("jpeg can't have a color palette")
im.close() im.close()
return [(color, ndpi, imgformat, rawdata, imgwidthpx, imgheightpx)] return [(color, ndpi, imgformat, rawdata, imgwidthpx, imgheightpx)]
else: else:
@ -646,7 +648,7 @@ def read_images(rawdata, colorspace, first_frame_only=False):
Colorspace["CMYK;I"]]: Colorspace["CMYK;I"]]:
logging.debug("Colorspace is OK: %s", color) logging.debug("Colorspace is OK: %s", color)
newimg = imgdata newimg = imgdata
elif color in [Colorspace.RGBA]: elif color in [Colorspace.RGBA, Colorspace.P]:
logging.debug("Converting colorspace %s to RGB", color) logging.debug("Converting colorspace %s to RGB", color)
newimg = imgdata.convert('RGB') newimg = imgdata.convert('RGB')
color = Colorspace.RGB color = Colorspace.RGB