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]
|
depth = rawdata[24]
|
||||||
if depth not in [1, 2, 4, 8, 16]:
|
if depth not in [1, 2, 4, 8, 16]:
|
||||||
raise ValueError("invalid bit depth: %d" % depth)
|
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")
|
logger.debug("read_images() embeds a PNG")
|
||||||
cleanup()
|
cleanup()
|
||||||
return [
|
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 "
|
"Image contains an alpha channel which will be stored "
|
||||||
"as a separate soft mask (/SMask) image in PDF."
|
"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:
|
else:
|
||||||
newcolor = color
|
newcolor = color
|
||||||
smaskidat = None
|
smaskidat = None
|
||||||
|
|
Loading…
Reference in a new issue