Skip to content

Commit

Permalink
Added reading non-JPEG BLP1 as RGBA
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Feb 25, 2022
1 parent 3ec9282 commit db8489a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/PIL/BlpImagePlugin.py
Expand Up @@ -288,15 +288,12 @@ def _open(self):
self.fp.seek(2, os.SEEK_CUR)
self._size = struct.unpack("<II", self.fp.read(8))

if self.magic == b"BLP1":
decoder = "BLP1"
self.mode = "RGB"
elif self.magic == b"BLP2":
decoder = "BLP2"
self.mode = "RGBA" if self._blp_alpha_depth else "RGB"
if self.magic in (b"BLP1", b"BLP2"):
decoder = self.magic.decode()
else:
raise BLPFormatError(f"Bad BLP magic {repr(self.magic)}")

self.mode = "RGBA" if self._blp_alpha_depth else "RGB"
self.tile = [(decoder, (0, 0) + self.size, 0, (self.mode, 0, 1))]


Expand Down Expand Up @@ -360,7 +357,10 @@ def _load(self):
except struct.error:
break
b, g, r, a = palette[offset]
data.extend([r, g, b])
d = (r, g, b)
if self._blp_alpha_depth:
d += (a,)
data.extend(d)

self.set_as_raw(bytes(data))
else:
Expand Down

0 comments on commit db8489a

Please sign in to comment.