mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-31 20:36:34 +03:00
Fixes BLP1 picture handling
This commit is contained in:
parent
9df95e77c5
commit
bed2ed7438
|
@ -245,7 +245,7 @@ class BlpImageFile(ImageFile.ImageFile):
|
|||
|
||||
if self.magic == b"BLP1":
|
||||
decoder = "BLP1"
|
||||
self.mode = "RGB"
|
||||
self.mode = "RGBA"
|
||||
elif self.magic == b"BLP2":
|
||||
decoder = "BLP2"
|
||||
self.mode = "RGBA" if self._blp_alpha_depth else "RGB"
|
||||
|
@ -331,7 +331,7 @@ class BLP1Decoder(_BLPBaseDecoder):
|
|||
except struct.error:
|
||||
break
|
||||
b, g, r, a = palette[offset]
|
||||
data.extend([r, g, b])
|
||||
data.extend([r, g, b, 0xFF]) # is there a case where alpha is used?
|
||||
|
||||
self.set_as_raw(bytes(data))
|
||||
else:
|
||||
|
@ -353,9 +353,19 @@ class BLP1Decoder(_BLPBaseDecoder):
|
|||
data = jpeg_header + data
|
||||
data = BytesIO(data)
|
||||
image = JpegImageFile(data)
|
||||
self.tile = image.tile # :/
|
||||
self.fd = image.fp
|
||||
self.mode = image.mode
|
||||
image.mode = "RGBA"
|
||||
image.tile = [("jpeg", (0, 0) + self.size, 0, ("RGBA", ""))]
|
||||
|
||||
b, g, r, a = image.split()
|
||||
if not any(
|
||||
[a.getpixel((x, y)) for x in range(a.width) for y in range(a.height)]
|
||||
):
|
||||
# try to unprotect completely transparent pictures
|
||||
from PIL import ImageOps
|
||||
|
||||
a = ImageOps.invert(a)
|
||||
image = Image.merge("RGBA", (r, g, b, a))
|
||||
self.set_as_raw(image.tobytes())
|
||||
|
||||
|
||||
class BLP2Decoder(_BLPBaseDecoder):
|
||||
|
|
Loading…
Reference in New Issue
Block a user