Rewrite dict creation as dict literal for better performance

This commit is contained in:
Hugo van Kemenade 2022-04-10 19:59:42 +03:00
parent 9d87b26a67
commit 830da5c41e
3 changed files with 5 additions and 9 deletions

View File

@ -76,10 +76,8 @@ class BmpImageFile(ImageFile.ImageFile):
read, seek = self.fp.read, self.fp.seek
if header:
seek(header)
file_info = {}
# read bmp header size @offset 14 (this is part of the header size)
file_info["header_size"] = i32(read(4))
file_info["direction"] = -1
file_info = {"header_size": i32(read(4)), "direction": -1}
# -------------------- If requested, read header at a specific position
# read the rest of the bmp header, without its size

View File

@ -2992,12 +2992,11 @@ _fromarray_typemap = {
((1, 1, 2), "|u1"): ("LA", "LA"),
((1, 1, 3), "|u1"): ("RGB", "RGB"),
((1, 1, 4), "|u1"): ("RGBA", "RGBA"),
# shortcuts:
((1, 1), _ENDIAN + "i4"): ("I", "I"),
((1, 1), _ENDIAN + "f4"): ("F", "F"),
}
# shortcuts
_fromarray_typemap[((1, 1), _ENDIAN + "i4")] = ("I", "I")
_fromarray_typemap[((1, 1), _ENDIAN + "f4")] = ("F", "F")
def _decompression_bomb_check(size):
if MAX_IMAGE_PIXELS is None:

View File

@ -1748,9 +1748,8 @@ def _save(im, fp, filename):
SUBIFD,
]
atts = {}
# bits per sample is a single short in the tiff directory, not a list.
atts[BITSPERSAMPLE] = bits[0]
atts = {BITSPERSAMPLE: bits[0]}
# Merge the ones that we have with (optional) more bits from
# the original file, e.g x,y resolution so that we can
# save(load('')) == original file.