Skip to content

Commit

Permalink
use bytes/bytearray int constructor instead of string multiplication
Browse files Browse the repository at this point in the history
  • Loading branch information
Yay295 committed Jun 25, 2024
1 parent 4b7464d commit dfe3fcb
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/PIL/TgaImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,18 @@ def _open(self) -> None:
start, size, mapdepth = i16(s, 3), i16(s, 5), s[7]
if mapdepth == 16:
colormap = self.fp.read(2 * size)
palette_data = bytearray(b"\0" * 2 * start)
palette_data = bytearray(2 * start)
for a, b in zip(colormap[::2], colormap[1::2]):
palette_data += bytearray((a, b ^ 128))
self.palette = ImagePalette.raw("BGRA;15", bytes(palette_data))
self.palette.mode = "RGBA"
elif mapdepth == 24:
self.palette = ImagePalette.raw(
"BGR", b"\0" * 3 * start + self.fp.read(3 * size)
"BGR", bytes(3 * start) + self.fp.read(3 * size)
)
elif mapdepth == 32:
self.palette = ImagePalette.raw(
"BGRA", b"\0" * 4 * start + self.fp.read(4 * size)
"BGRA", bytes(4 * start) + self.fp.read(4 * size)
)
else:
msg = "unknown TGA map depth"
Expand Down

0 comments on commit dfe3fcb

Please sign in to comment.