mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-03 22:06:18 +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":
|
if self.magic == b"BLP1":
|
||||||
decoder = "BLP1"
|
decoder = "BLP1"
|
||||||
self.mode = "RGB"
|
self.mode = "RGBA"
|
||||||
elif self.magic == b"BLP2":
|
elif self.magic == b"BLP2":
|
||||||
decoder = "BLP2"
|
decoder = "BLP2"
|
||||||
self.mode = "RGBA" if self._blp_alpha_depth else "RGB"
|
self.mode = "RGBA" if self._blp_alpha_depth else "RGB"
|
||||||
|
@ -331,7 +331,7 @@ class BLP1Decoder(_BLPBaseDecoder):
|
||||||
except struct.error:
|
except struct.error:
|
||||||
break
|
break
|
||||||
b, g, r, a = palette[offset]
|
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))
|
self.set_as_raw(bytes(data))
|
||||||
else:
|
else:
|
||||||
|
@ -353,9 +353,19 @@ class BLP1Decoder(_BLPBaseDecoder):
|
||||||
data = jpeg_header + data
|
data = jpeg_header + data
|
||||||
data = BytesIO(data)
|
data = BytesIO(data)
|
||||||
image = JpegImageFile(data)
|
image = JpegImageFile(data)
|
||||||
self.tile = image.tile # :/
|
image.mode = "RGBA"
|
||||||
self.fd = image.fp
|
image.tile = [("jpeg", (0, 0) + self.size, 0, ("RGBA", ""))]
|
||||||
self.mode = image.mode
|
|
||||||
|
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):
|
class BLP2Decoder(_BLPBaseDecoder):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user