diff --git a/src/pypdfium2/_helpers/bitmap.py b/src/pypdfium2/_helpers/bitmap.py index 597ac6947..403c68ce4 100644 --- a/src/pypdfium2/_helpers/bitmap.py +++ b/src/pypdfium2/_helpers/bitmap.py @@ -57,10 +57,10 @@ def __init__(self, raw, buffer, width, height, stride, format, rev_byteorder, ne self.format = format self.rev_byteorder = rev_byteorder self.n_channels = pdfium_i.BitmapTypeToNChannels[self.format] - self.mode = { - False: pdfium_i.BitmapTypeToStr, - True: pdfium_i.BitmapTypeToStrReverse, - }[self.rev_byteorder][self.format] + self.mode = ( + pdfium_i.BitmapTypeToStrReverse if self.rev_byteorder else \ + pdfium_i.BitmapTypeToStr + )[self.format] # slot to store arguments for PdfPosConv, set on page rendering self._pos_args = None diff --git a/src/pypdfium2/_helpers/pageobjects.py b/src/pypdfium2/_helpers/pageobjects.py index 7565b1598..f59b8659b 100644 --- a/src/pypdfium2/_helpers/pageobjects.py +++ b/src/pypdfium2/_helpers/pageobjects.py @@ -235,10 +235,8 @@ def load_jpeg(self, source, pages=None, inline=False, autoclose=True): raise ValueError(f"Cannot load JPEG from {source} - not a file path or byte stream.") bufaccess, to_hold = pdfium_i.get_bufreader(buffer) - loader = { - False: pdfium_c.FPDFImageObj_LoadJpegFile, - True: pdfium_c.FPDFImageObj_LoadJpegFileInline, - }[inline] + loader = pdfium_c.FPDFImageObj_LoadJpegFileInline if inline else \ + pdfium_c.FPDFImageObj_LoadJpegFile c_pages, page_count = pdfium_i.pages_c_array(pages) ok = loader(c_pages, page_count, self, bufaccess) @@ -306,10 +304,8 @@ def get_data(self, decode_simple=False): Returns: ctypes.Array: The data of the image stream (as :class:`~ctypes.c_ubyte` array). """ - func = { - False: pdfium_c.FPDFImageObj_GetImageDataRaw, - True: pdfium_c.FPDFImageObj_GetImageDataDecoded, - }[decode_simple] + func = pdfium_c.FPDFImageObj_GetImageDataDecoded if decode_simple else \ + pdfium_c.FPDFImageObj_GetImageDataRaw n_bytes = func(self, None, 0) buffer = (ctypes.c_ubyte * n_bytes)() func(self, buffer, n_bytes)