From 354fd7c264888794a9f5406989a7fa478cbd7ad8 Mon Sep 17 00:00:00 2001 From: Johannes Schauer Marin Rodrigues Date: Sun, 3 Oct 2021 21:03:22 +0200 Subject: [PATCH] src/img2pdf.py: format with black --- src/img2pdf.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/img2pdf.py b/src/img2pdf.py index b53d659..1cd4b50 100755 --- a/src/img2pdf.py +++ b/src/img2pdf.py @@ -760,9 +760,8 @@ class pdfdoc(object): artborder=None, iccp=None, ): - assert ( - (color != Colorspace.RGBA and color != Colorspace.LA) - or (imgformat == ImageFormat.PNG and smaskdata is not None) + assert (color != Colorspace.RGBA and color != Colorspace.LA) or ( + imgformat == ImageFormat.PNG and smaskdata is not None ) if self.engine == Engine.pikepdf: @@ -822,7 +821,11 @@ class pdfdoc(object): else: iccpdict = PdfDict(stream=convert_load(iccp)) 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 elif color == Colorspace.RGB or color == Colorspace.RGBA: iccpdict[PdfName.N] = 3 @@ -1217,11 +1220,10 @@ def get_imgmetadata( # Search online for the 72.009 dpi problem for more info. ndpi = (int(round(ndpi[0])), int(round(ndpi[1]))) ics = imgdata.mode - + # GIF and PNG files with transparency are supported - if ( - (imgformat == ImageFormat.PNG or imgformat == ImageFormat.GIF) - and (ics in ["RGBA", "LA"] or "transparency" in imgdata.info) + if (imgformat == ImageFormat.PNG or imgformat == ImageFormat.GIF) and ( + ics in ["RGBA", "LA"] or "transparency" in imgdata.info ): # Must check the IHDR chunk for the bit depth, because PIL would lossily # 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() return result + def to_png_data(img): # 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 @@ -1857,6 +1860,7 @@ def to_png_data(img): raise ValueError("invalid bit depth: %d" % depth) return pngidat, palette, depth + # converts a length in pixels to a length in PDF units (1/72 of an inch) def px_to_pt(length, dpi): return 72.0 * length / dpi