mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-24 00:46:16 +03:00
Do not calculate destination length each time
This commit is contained in:
parent
d31148bb86
commit
f69168523e
|
@ -291,7 +291,8 @@ class BmpRleDecoder(ImageFile.PyDecoder):
|
|||
rle4 = self.args[1]
|
||||
data = bytearray()
|
||||
x = 0
|
||||
while len(data) < self.state.xsize * self.state.ysize:
|
||||
dest_length = self.state.xsize * self.state.ysize
|
||||
while len(data) < dest_length:
|
||||
pixels = self.fd.read(1)
|
||||
byte = self.fd.read(1)
|
||||
if not pixels or not byte:
|
||||
|
|
|
@ -497,7 +497,8 @@ class DdsRgbDecoder(ImageFile.PyDecoder):
|
|||
|
||||
data = bytearray()
|
||||
bytecount = bitcount // 8
|
||||
while len(data) < self.state.xsize * self.state.ysize * len(masks):
|
||||
dest_length = self.state.xsize * self.state.ysize * len(masks)
|
||||
while len(data) < dest_length:
|
||||
value = int.from_bytes(self.fd.read(bytecount), "little")
|
||||
for i, mask in enumerate(masks):
|
||||
masked_value = value & mask
|
||||
|
|
|
@ -307,7 +307,8 @@ class PpmDecoder(ImageFile.PyDecoder):
|
|||
out_byte_count = 4 if self.mode == "I" else 1
|
||||
out_max = 65535 if self.mode == "I" else 255
|
||||
bands = Image.getmodebands(self.mode)
|
||||
while len(data) < self.state.xsize * self.state.ysize * bands * out_byte_count:
|
||||
dest_length = self.state.xsize * self.state.ysize * bands * out_byte_count
|
||||
while len(data) < dest_length:
|
||||
pixels = self.fd.read(in_byte_count * bands)
|
||||
if len(pixels) < in_byte_count * bands:
|
||||
# eof
|
||||
|
|
|
@ -53,7 +53,8 @@ class QoiDecoder(ImageFile.PyDecoder):
|
|||
|
||||
data = bytearray()
|
||||
bands = Image.getmodebands(self.mode)
|
||||
while len(data) < self.state.xsize * self.state.ysize * bands:
|
||||
dest_length = self.state.xsize * self.state.ysize * bands
|
||||
while len(data) < dest_length:
|
||||
byte = self.fd.read(1)[0]
|
||||
if byte == 0b11111110: # QOI_OP_RGB
|
||||
value = self.fd.read(3) + self._previous_pixel[3:]
|
||||
|
|
Loading…
Reference in New Issue
Block a user