This commit is contained in:
Meithal 2021-07-05 00:20:15 +02:00
parent d9c14e9ccd
commit 919f38e3d9
7 changed files with 18 additions and 2 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 270 B

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 270 B

View File

@ -20,6 +20,12 @@ def test_load_blp2_dxt1a():
assert_image_equal_tofile(im, "Tests/images/blp/blp2_dxt1a.png")
def test_load_blp1():
with Image.open("Tests/images/blp/war3mapMap.blp") as im:
im.convert("RGB")
assert_image_equal_tofile(im, "Tests/images/blp/war3mapMap.png")
@pytest.mark.parametrize(
"test_file",
[

View File

@ -28,7 +28,7 @@ BLP files come in many different flavours:
- DXT3 compression is used if alpha_encoding == 1.
- DXT5 compression is used if alpha_encoding == 7.
"""
print("foo")
import struct
from io import BytesIO
@ -245,7 +245,7 @@ class BlpImageFile(ImageFile.ImageFile):
if self.magic == b"BLP1":
decoder = "BLP1"
self.mode = "RGBA"
self.mode = "BGRA"
elif self.magic == b"BLP2":
decoder = "BLP2"
self.mode = "RGBA" if self._blp_alpha_depth else "RGB"
@ -361,6 +361,16 @@ class BLP1Decoder(_BLPBaseDecoder):
image.tile = [("jpeg", (0, 0) + self.size, 0, ("RGBA", ""))]
b, g, r, a = image.split()
print(b, g, r, a)
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())