|
|
@ -760,9 +760,8 @@ class pdfdoc(object):
|
|
|
|
artborder=None,
|
|
|
|
artborder=None,
|
|
|
|
iccp=None,
|
|
|
|
iccp=None,
|
|
|
|
):
|
|
|
|
):
|
|
|
|
assert (
|
|
|
|
assert (color != Colorspace.RGBA and color != Colorspace.LA) or (
|
|
|
|
(color != Colorspace.RGBA and color != Colorspace.LA)
|
|
|
|
imgformat == ImageFormat.PNG and smaskdata is not None
|
|
|
|
or (imgformat == ImageFormat.PNG and smaskdata is not None)
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if self.engine == Engine.pikepdf:
|
|
|
|
if self.engine == Engine.pikepdf:
|
|
|
@ -822,7 +821,11 @@ class pdfdoc(object):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
iccpdict = PdfDict(stream=convert_load(iccp))
|
|
|
|
iccpdict = PdfDict(stream=convert_load(iccp))
|
|
|
|
iccpdict[PdfName.Alternate] = colorspace
|
|
|
|
iccpdict[PdfName.Alternate] = colorspace
|
|
|
|
if color == Colorspace["1"] or color == Colorspace.L or color == Colorspace.LA:
|
|
|
|
if (
|
|
|
|
|
|
|
|
color == Colorspace["1"]
|
|
|
|
|
|
|
|
or color == Colorspace.L
|
|
|
|
|
|
|
|
or color == Colorspace.LA
|
|
|
|
|
|
|
|
):
|
|
|
|
iccpdict[PdfName.N] = 1
|
|
|
|
iccpdict[PdfName.N] = 1
|
|
|
|
elif color == Colorspace.RGB or color == Colorspace.RGBA:
|
|
|
|
elif color == Colorspace.RGB or color == Colorspace.RGBA:
|
|
|
|
iccpdict[PdfName.N] = 3
|
|
|
|
iccpdict[PdfName.N] = 3
|
|
|
@ -1219,9 +1222,8 @@ def get_imgmetadata(
|
|
|
|
ics = imgdata.mode
|
|
|
|
ics = imgdata.mode
|
|
|
|
|
|
|
|
|
|
|
|
# GIF and PNG files with transparency are supported
|
|
|
|
# GIF and PNG files with transparency are supported
|
|
|
|
if (
|
|
|
|
if (imgformat == ImageFormat.PNG or imgformat == ImageFormat.GIF) and (
|
|
|
|
(imgformat == ImageFormat.PNG or imgformat == ImageFormat.GIF)
|
|
|
|
ics in ["RGBA", "LA"] or "transparency" in imgdata.info
|
|
|
|
and (ics in ["RGBA", "LA"] or "transparency" in imgdata.info)
|
|
|
|
|
|
|
|
):
|
|
|
|
):
|
|
|
|
# Must check the IHDR chunk for the bit depth, because PIL would lossily
|
|
|
|
# Must check the IHDR chunk for the bit depth, because PIL would lossily
|
|
|
|
# convert 16-bit RGBA/LA images to 8-bit.
|
|
|
|
# convert 16-bit RGBA/LA images to 8-bit.
|
|
|
@ -1839,6 +1841,7 @@ def read_images(rawdata, colorspace, first_frame_only=False, rot=None):
|
|
|
|
cleanup()
|
|
|
|
cleanup()
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def to_png_data(img):
|
|
|
|
def to_png_data(img):
|
|
|
|
# cheapo version to retrieve a PNG encoding of the payload is to
|
|
|
|
# cheapo version to retrieve a PNG encoding of the payload is to
|
|
|
|
# just save it with PIL. In the future this could be replaced by
|
|
|
|
# just save it with PIL. In the future this could be replaced by
|
|
|
@ -1857,6 +1860,7 @@ def to_png_data(img):
|
|
|
|
raise ValueError("invalid bit depth: %d" % depth)
|
|
|
|
raise ValueError("invalid bit depth: %d" % depth)
|
|
|
|
return pngidat, palette, depth
|
|
|
|
return pngidat, palette, depth
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# converts a length in pixels to a length in PDF units (1/72 of an inch)
|
|
|
|
# converts a length in pixels to a length in PDF units (1/72 of an inch)
|
|
|
|
def px_to_pt(length, dpi):
|
|
|
|
def px_to_pt(length, dpi):
|
|
|
|
return 72.0 * length / dpi
|
|
|
|
return 72.0 * length / dpi
|
|
|
|