Skip to content

Commit

Permalink
Use int.from_bytes()
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Dec 1, 2023
1 parent 30eb414 commit 2e8dd3b
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/PIL/DdsImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,9 @@ def decode(self, buffer):
data = bytearray()
bytecount = bitcount // 8
while len(data) < self.state.xsize * self.state.ysize * len(masks):
value = self.fd.read(bytecount)
int_value = sum(value[i] << i * 8 for i in range(bytecount))
value = int.from_bytes(self.fd.read(bytecount), "little")
for i, mask in enumerate(masks):
masked_value = int_value & mask
masked_value = value & mask
# Remove the zero padding, and scale it to 8 bits
data += o8(
int(((masked_value >> mask_offsets[i]) / mask_totals[i]) * 255)
Expand Down

0 comments on commit 2e8dd3b

Please sign in to comment.