diff --git a/Tests/images/blp/blp1_jpeg.jpg b/Tests/images/blp/blp1_jpeg.jpg new file mode 100644 index 000000000..c045c5945 Binary files /dev/null and b/Tests/images/blp/blp1_jpeg.jpg differ diff --git a/Tests/images/blp/blp1_jpeg.png b/Tests/images/blp/blp1_jpeg.png new file mode 100644 index 000000000..21fffbf00 Binary files /dev/null and b/Tests/images/blp/blp1_jpeg.png differ diff --git a/Tests/images/blp/war3mapMap.blp b/Tests/images/blp/war3mapMap.blp new file mode 100644 index 000000000..03afb3aa5 Binary files /dev/null and b/Tests/images/blp/war3mapMap.blp differ diff --git a/Tests/images/blp/war3mapMap.jpg b/Tests/images/blp/war3mapMap.jpg new file mode 100644 index 000000000..c045c5945 Binary files /dev/null and b/Tests/images/blp/war3mapMap.jpg differ diff --git a/Tests/images/blp/war3mapMap.png b/Tests/images/blp/war3mapMap.png new file mode 100644 index 000000000..21fffbf00 Binary files /dev/null and b/Tests/images/blp/war3mapMap.png differ diff --git a/Tests/test_file_blp.py b/Tests/test_file_blp.py index 15bd7e4f8..3e4401996 100644 --- a/Tests/test_file_blp.py +++ b/Tests/test_file_blp.py @@ -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", [ diff --git a/src/PIL/BlpImagePlugin.py b/src/PIL/BlpImagePlugin.py index f62b1bebe..c286a8197 100644 --- a/src/PIL/BlpImagePlugin.py +++ b/src/PIL/BlpImagePlugin.py @@ -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())