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,24 +1597,28 @@ 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)
|
||||||
logger.debug("read_images() embeds a PNG")
|
# we embed the PNG only if it is not at the same time palette based
|
||||||
cleanup()
|
# and has an icc profile because PDF doesn't support icc profiles
|
||||||
return [
|
# on palette images
|
||||||
(
|
if palette == b"" or iccp is None:
|
||||||
color,
|
logger.debug("read_images() embeds a PNG")
|
||||||
ndpi,
|
cleanup()
|
||||||
imgformat,
|
return [
|
||||||
pngidat,
|
(
|
||||||
None,
|
color,
|
||||||
imgwidthpx,
|
ndpi,
|
||||||
imgheightpx,
|
imgformat,
|
||||||
palette,
|
pngidat,
|
||||||
False,
|
None,
|
||||||
depth,
|
imgwidthpx,
|
||||||
rotation,
|
imgheightpx,
|
||||||
iccp,
|
palette,
|
||||||
)
|
False,
|
||||||
]
|
depth,
|
||||||
|
rotation,
|
||||||
|
iccp,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
# If our input is not JPEG or PNG, then we might have a format that
|
# If our input is not JPEG or PNG, then we might have a format that
|
||||||
# supports multiple frames (like TIFF or GIF), so we need a loop to
|
# supports multiple frames (like TIFF or GIF), so we need a loop to
|
||||||
|
@ -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