Use existing variable names from ImageFile

This commit is contained in:
Andrew Murray 2023-02-25 13:40:44 +11:00 committed by Aarni Koskela
parent 8e18415cc5
commit fcc59a4001
4 changed files with 25 additions and 24 deletions

View File

@ -765,17 +765,17 @@ class Image:
bufsize = max(65536, self.size[0] * 4) # see RawEncode.c
data = []
output = []
while True:
length, error_code, chunk = e.encode(bufsize)
data.append(chunk)
if error_code:
bytes_consumed, errcode, data = e.encode(bufsize)
output.append(data)
if errcode:
break
if error_code < 0:
msg = f"encoder error {error_code} in tobytes"
if errcode < 0:
msg = f"encoder error {errcode} in tobytes"
raise RuntimeError(msg)
return b"".join(data)
return b"".join(output)
def tobitmap(self, name="image"):
"""

View File

@ -530,20 +530,20 @@ def _encode_tile(im, fp, tile, bufsize, fh, exc=None):
encoder.setimage(im.im, b)
if encoder.pushes_fd:
encoder.setfd(fp)
length, error_code = encoder.encode_to_pyfd()
errcode = encoder.encode_to_pyfd()[1]
else:
if exc:
# compress to Python file-compatible object
while True:
length, error_code, chunk = encoder.encode(bufsize)
fp.write(chunk)
if error_code:
errcode, data = encoder.encode(bufsize)[1:]
fp.write(data)
if errcode:
break
else:
# slight speedup: compress to real file object
error_code = encoder.encode_to_file(fh, bufsize)
if error_code < 0:
msg = f"encoder error {error_code} when writing image file"
errcode = encoder.encode_to_file(fh, bufsize)
if errcode < 0:
msg = f"encoder error {errcode} when writing image file"
raise OSError(msg) from exc
finally:
encoder.cleanup()

View File

@ -86,7 +86,6 @@ class PcfFontFile(FontFile.FontFile):
for ch, ix in enumerate(encoding):
if ix is not None:
ix_metrics = metrics[ix]
(
xsize,
ysize,
@ -96,7 +95,7 @@ class PcfFontFile(FontFile.FontFile):
ascent,
descent,
attributes,
) = ix_metrics
) = metrics[ix]
self.glyph[ch] = (
(width, 0),
(left, descent - ysize, xsize + left, descent),
@ -220,9 +219,11 @@ class PcfFontFile(FontFile.FontFile):
mode = "1"
for i in range(nbitmaps):
x, y = metrics[i][0], metrics[i][1]
b, e = offsets[i], offsets[i + 1]
bitmaps.append(Image.frombytes("1", (x, y), data[b:e], "raw", mode, pad(x)))
left, right = metrics[i][:2]
b, e = offsets[i : i + 2]
bitmaps.append(
Image.frombytes("1", (left, right), data[b:e], "raw", mode, pad(left))
)
return bitmaps

View File

@ -1845,13 +1845,13 @@ def _save(im, fp, filename):
e.setimage(im.im, (0, 0) + im.size)
while True:
# undone, change to self.decodermaxblock:
length, error_code, chunk = e.encode(16 * 1024)
errcode, data = e.encode(16 * 1024)[1:]
if not _fp:
fp.write(chunk)
if error_code:
fp.write(data)
if errcode:
break
if error_code < 0:
msg = f"encoder error {error_code} when writing image file"
if errcode < 0:
msg = f"encoder error {errcode} when writing image file"
raise OSError(msg)
else: