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