mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-04-20 17:22:00 +03:00
implemented the coverage tool on _save instead of seek
This commit is contained in:
parent
37eecafb75
commit
5701d33cbb
|
@ -14,7 +14,7 @@ def calculate_coverage(test_name):
|
|||
"branches1": Image.branches,
|
||||
"branches2": PdfParser.XrefTable.branches,
|
||||
"branches3": SpiderImagePlugin.SpiderImageFile.branches1,
|
||||
"branches4": SpiderImagePlugin.SpiderImageFile.branches2,
|
||||
"branches4": SpiderImagePlugin.branches2,
|
||||
# Add more
|
||||
}
|
||||
|
||||
|
|
|
@ -56,6 +56,13 @@ def isInt(f):
|
|||
|
||||
iforms = [1, 3, -11, -12, -21, -22]
|
||||
|
||||
branches2 = {
|
||||
"1": False,
|
||||
"2": False,
|
||||
"3": False,
|
||||
"4": False
|
||||
}
|
||||
|
||||
|
||||
# There is no magic number to identify Spider files, so just check a
|
||||
# series of header locations to see if they have reasonable values.
|
||||
|
@ -116,13 +123,6 @@ class SpiderImageFile(ImageFile.ImageFile):
|
|||
"14": False
|
||||
}
|
||||
|
||||
branches2 = {
|
||||
"1": False,
|
||||
"2": False,
|
||||
"3": False,
|
||||
"4": False
|
||||
}
|
||||
|
||||
def _open(self) -> None:
|
||||
# check header
|
||||
n = 27 * 4 # read 27 float values
|
||||
|
@ -220,17 +220,11 @@ class SpiderImageFile(ImageFile.ImageFile):
|
|||
|
||||
def seek(self, frame: int) -> None:
|
||||
if self.istack == 0:
|
||||
SpiderImageFile.branches2["1"] = True
|
||||
msg = "attempt to seek in a non-stack file"
|
||||
raise EOFError(msg)
|
||||
else: # ADDED FOR BRANCH MARKING
|
||||
SpiderImageFile.branches2["2"] = True
|
||||
|
||||
if not self._seek_check(frame):
|
||||
SpiderImageFile.branches2["3"] = True
|
||||
return
|
||||
else: # ADDED FOR BRANCH MARKING
|
||||
SpiderImageFile.branches2["4"] = True
|
||||
|
||||
self.stkoffset = self.hdrlen + frame * (self.hdrlen + self.imgbytes)
|
||||
self.fp = self._fp
|
||||
|
@ -319,12 +313,18 @@ def makeSpiderHeader(im: Image.Image) -> list[bytes]:
|
|||
|
||||
def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
||||
if im.mode[0] != "F":
|
||||
branches2["1"] = True
|
||||
im = im.convert("F")
|
||||
else:
|
||||
branches2["2"] = True
|
||||
|
||||
hdr = makeSpiderHeader(im)
|
||||
if len(hdr) < 256:
|
||||
branches2["3"] = True
|
||||
msg = "Error creating Spider header"
|
||||
raise OSError(msg)
|
||||
else:
|
||||
branches2["4"] = True
|
||||
|
||||
# write the SPIDER header
|
||||
fp.writelines(hdr)
|
||||
|
|
Loading…
Reference in New Issue
Block a user