Skip to content

Commit cd1c9f1

Browse files
committed
revert consolidated mask, all extra pixels are just 0
1 parent 020f890 commit cd1c9f1

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

src/PIL/DdsImagePlugin.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -513,33 +513,26 @@ def decode(self, buffer: bytes | Image.SupportsArrayInterface) -> tuple[int, int
513513
data = bytearray()
514514
bytecount = bitcount // 8
515515
dest_length = self.state.xsize * self.state.ysize * len(masks)
516-
consolidated_mask = list(zip(masks, mask_offsets, mask_totals))
517516
# consume the data
518517
has_more = True
519518
while len(data) < dest_length and has_more:
520519
chunk = self.fd.read(bytecount)
520+
# work around BufferedIO not being seekable
521521
has_more = len(chunk) > 0
522522
value = int.from_bytes(chunk, "little")
523-
for mask, offset, total in consolidated_mask:
523+
for i, mask, in enumerate(masks):
524524
masked_value = value & mask
525525
# Remove the zero padding, and scale it to 8 bits
526526
data += o8(
527-
int((masked_value >> offset) * total)
527+
int((masked_value >> mask_offsets[i]) * mask_totals[i])
528528
)
529529

530-
# extra padding pixels
530+
# extra padding pixels -- always all 0
531531
if len(data) < dest_length:
532-
value = int.from_bytes(b'', "little")
533532
pixel = bytearray()
534-
for mask, offset, total in consolidated_mask:
535-
masked_value = value & mask
536-
# Remove the zero padding, and scale it to 8 bits
537-
pixel += o8(
538-
int((masked_value >> offset) * total)
539-
)
540-
541-
ct_pixels = math.ceil((dest_length - len(data)) / bytecount)
542-
data += pixel * ct_pixels
533+
pixel += o8(0)
534+
ct_bytes = dest_length - len(data)
535+
data += pixel * ct_bytes
543536

544537

545538
self.set_as_raw(data)

0 commit comments

Comments
 (0)