forked from josch/img2pdf
support PNG palette images with icc profile (closes: #107)
This commit is contained in:
parent
80393b6efa
commit
09ad147d97
1 changed files with 31 additions and 18 deletions
|
@ -1597,6 +1597,10 @@ def read_images(rawdata, colorspace, first_frame_only=False, rot=None):
|
|||
depth = rawdata[24]
|
||||
if depth not in [1, 2, 4, 8, 16]:
|
||||
raise ValueError("invalid bit depth: %d" % depth)
|
||||
# we embed the PNG only if it is not at the same time palette based
|
||||
# and has an icc profile because PDF doesn't support icc profiles
|
||||
# on palette images
|
||||
if palette == b"" or iccp is None:
|
||||
logger.debug("read_images() embeds a PNG")
|
||||
cleanup()
|
||||
return [
|
||||
|
@ -1805,6 +1809,15 @@ def read_images(rawdata, colorspace, first_frame_only=False, rot=None):
|
|||
"Image contains an alpha channel which will be stored "
|
||||
"as a separate soft mask (/SMask) image in PDF."
|
||||
)
|
||||
elif color in [Colorspace.P, Colorspace.PA] and iccp is not None:
|
||||
# PDF does not support palette images with icc profile
|
||||
if color == Colorspace.P:
|
||||
newcolor = Colorspace.RGB
|
||||
newimg = newimg.convert(mode="RGB")
|
||||
elif color == Colorspace.PA:
|
||||
newcolor = Colorspace.RGBA
|
||||
newimg = newimg.convert(mode="RGBA")
|
||||
smaskidat = None
|
||||
else:
|
||||
newcolor = color
|
||||
smaskidat = None
|
||||
|
|
Loading…
Reference in a new issue