forked from josch/img2pdf
avoid converting palette PNG with alpha to RGB (closes: #158)
This commit is contained in:
parent
e9e04b6dd9
commit
0cbcb8fa12
2 changed files with 18 additions and 12 deletions
|
@ -2101,7 +2101,16 @@ def read_images(rawdata, colorspace, first_frame_only=False, rot=None):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
if (
|
if 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
|
||||||
|
elif (
|
||||||
color == Colorspace.RGBA
|
color == Colorspace.RGBA
|
||||||
or color == Colorspace.LA
|
or color == Colorspace.LA
|
||||||
or color == Colorspace.PA
|
or color == Colorspace.PA
|
||||||
|
@ -2115,6 +2124,11 @@ def read_images(rawdata, colorspace, first_frame_only=False, rot=None):
|
||||||
newcolor = color
|
newcolor = color
|
||||||
l, a = newimg.split()
|
l, a = newimg.split()
|
||||||
newimg = l
|
newimg = l
|
||||||
|
elif color == Colorspace.PA or (
|
||||||
|
color == Colorspace.P and "transparency" in newimg.info
|
||||||
|
):
|
||||||
|
newcolor = color
|
||||||
|
a = newimg.convert(mode="RGBA").split()[-1]
|
||||||
else:
|
else:
|
||||||
newcolor = Colorspace.RGBA
|
newcolor = Colorspace.RGBA
|
||||||
r, g, b, a = newimg.convert(mode="RGBA").split()
|
r, g, b, a = newimg.convert(mode="RGBA").split()
|
||||||
|
@ -2125,15 +2139,6 @@ def read_images(rawdata, colorspace, first_frame_only=False, rot=None):
|
||||||
"Image contains an alpha channel. Computing a separate "
|
"Image contains an alpha channel. Computing a separate "
|
||||||
"soft mask (/SMask) image to store transparency in PDF."
|
"soft mask (/SMask) image to store transparency 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
|
||||||
|
|
|
@ -4276,9 +4276,10 @@ def gif_transparent_pdf(tmp_path_factory, gif_transparent_img, request):
|
||||||
== b"q\n45.0000 0 0 45.0000 0.0000 0.0000 cm\n/Im0 Do\nQ"
|
== b"q\n45.0000 0 0 45.0000 0.0000 0.0000 cm\n/Im0 Do\nQ"
|
||||||
)
|
)
|
||||||
assert p.pages[0].Resources.XObject.Im0.BitsPerComponent == 8
|
assert p.pages[0].Resources.XObject.Im0.BitsPerComponent == 8
|
||||||
assert p.pages[0].Resources.XObject.Im0.ColorSpace == "/DeviceRGB"
|
assert p.pages[0].Resources.XObject.Im0.ColorSpace[0] == "/Indexed"
|
||||||
|
assert p.pages[0].Resources.XObject.Im0.ColorSpace[1] == "/DeviceRGB"
|
||||||
assert p.pages[0].Resources.XObject.Im0.DecodeParms.BitsPerComponent == 8
|
assert p.pages[0].Resources.XObject.Im0.DecodeParms.BitsPerComponent == 8
|
||||||
assert p.pages[0].Resources.XObject.Im0.DecodeParms.Colors == 3
|
assert p.pages[0].Resources.XObject.Im0.DecodeParms.Colors == 1
|
||||||
assert p.pages[0].Resources.XObject.Im0.DecodeParms.Predictor == 15
|
assert p.pages[0].Resources.XObject.Im0.DecodeParms.Predictor == 15
|
||||||
assert p.pages[0].Resources.XObject.Im0.Filter == "/FlateDecode"
|
assert p.pages[0].Resources.XObject.Im0.Filter == "/FlateDecode"
|
||||||
assert p.pages[0].Resources.XObject.Im0.Height == 60
|
assert p.pages[0].Resources.XObject.Im0.Height == 60
|
||||||
|
|
Loading…
Reference in a new issue