mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-04-19 08:41:59 +03:00
explicitly type Image._size
This commit is contained in:
parent
35a70e4b97
commit
1e18d68ff5
|
@ -170,6 +170,8 @@ class BmpImageFile(ImageFile.ImageFile):
|
|||
|
||||
# ------------------ Special case : header is reported 40, which
|
||||
# ---------------------- is shorter than real size for bpp >= 16
|
||||
assert isinstance(file_info["width"], int)
|
||||
assert isinstance(file_info["height"], int)
|
||||
self._size = file_info["width"], file_info["height"]
|
||||
|
||||
# ------- If color count was not found in the header, compute from bits
|
||||
|
|
|
@ -190,7 +190,7 @@ class EpsImageFile(ImageFile.ImageFile):
|
|||
self.fp.seek(offset)
|
||||
|
||||
self._mode = "RGB"
|
||||
self._size = None
|
||||
image_size: tuple[int, int] | None = None
|
||||
|
||||
byte_arr = bytearray(255)
|
||||
bytes_mv = memoryview(byte_arr)
|
||||
|
@ -213,7 +213,7 @@ class EpsImageFile(ImageFile.ImageFile):
|
|||
raise SyntaxError(msg)
|
||||
|
||||
def _read_comment(s: str) -> bool:
|
||||
nonlocal reading_trailer_comments
|
||||
nonlocal image_size, reading_trailer_comments
|
||||
try:
|
||||
m = split.match(s)
|
||||
except re.error as e:
|
||||
|
@ -228,16 +228,18 @@ class EpsImageFile(ImageFile.ImageFile):
|
|||
if k == "BoundingBox":
|
||||
if v == "(atend)":
|
||||
reading_trailer_comments = True
|
||||
elif not self._size or (trailer_reached and reading_trailer_comments):
|
||||
elif image_size is None or (
|
||||
trailer_reached and reading_trailer_comments
|
||||
):
|
||||
try:
|
||||
# Note: The DSC spec says that BoundingBox
|
||||
# fields should be integers, but some drivers
|
||||
# put floating point values there anyway.
|
||||
box = [int(float(i)) for i in v.split()]
|
||||
self._size = box[2] - box[0], box[3] - box[1]
|
||||
image_size = box[2] - box[0], box[3] - box[1]
|
||||
self.tile = [
|
||||
ImageFile._Tile(
|
||||
"eps", (0, 0) + self.size, offset, (length, box)
|
||||
"eps", (0, 0) + image_size, offset, (length, box)
|
||||
)
|
||||
]
|
||||
except Exception:
|
||||
|
@ -334,8 +336,8 @@ class EpsImageFile(ImageFile.ImageFile):
|
|||
else:
|
||||
break
|
||||
|
||||
self._size = columns, rows
|
||||
return
|
||||
image_size = columns, rows
|
||||
break
|
||||
elif bytes_mv[:5] == b"%%EOF":
|
||||
break
|
||||
elif trailer_reached and reading_trailer_comments:
|
||||
|
@ -346,7 +348,9 @@ class EpsImageFile(ImageFile.ImageFile):
|
|||
trailer_reached = True
|
||||
bytes_read = 0
|
||||
|
||||
if not self._size:
|
||||
if image_size:
|
||||
self._size = image_size
|
||||
else:
|
||||
msg = "cannot determine EPS bounding box"
|
||||
raise OSError(msg)
|
||||
|
||||
|
|
|
@ -80,7 +80,8 @@ class FpxImageFile(ImageFile.ImageFile):
|
|||
)
|
||||
|
||||
# size (highest resolution)
|
||||
|
||||
assert isinstance(prop[0x1000002], int)
|
||||
assert isinstance(prop[0x1000003], int)
|
||||
self._size = prop[0x1000002], prop[0x1000003]
|
||||
|
||||
size = max(self.size)
|
||||
|
|
|
@ -537,7 +537,7 @@ class Image:
|
|||
# FIXME: turn mode and size into delegating properties?
|
||||
self.im = None
|
||||
self._mode = ""
|
||||
self._size = (0, 0)
|
||||
self._size: tuple[int, int] = (0, 0)
|
||||
self.palette = None
|
||||
self.info = {}
|
||||
self.readonly = 0
|
||||
|
|
|
@ -26,7 +26,7 @@ class QoiImageFile(ImageFile.ImageFile):
|
|||
msg = "not a QOI file"
|
||||
raise SyntaxError(msg)
|
||||
|
||||
self._size = tuple(i32(self.fp.read(4)) for i in range(2))
|
||||
self._size = (i32(self.fp.read(4)), i32(self.fp.read(4)))
|
||||
|
||||
channels = self.fp.read(1)[0]
|
||||
self._mode = "RGB" if channels == 3 else "RGBA"
|
||||
|
|
Loading…
Reference in New Issue
Block a user