Skip to content

Commit

Permalink
Avoid bool dicts
Browse files Browse the repository at this point in the history
  • Loading branch information
mara004 committed Nov 27, 2024
1 parent d39dbf8 commit 2778473
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/pypdfium2/_helpers/bitmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 4 additions & 8 deletions src/pypdfium2/_helpers/pageobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 2778473

Please sign in to comment.