Skip to content

Commit 3ec9282

Browse files
committed
Fixed reading uncompressed BLP2 with alpha
1 parent 169025d commit 3ec9282

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Tests/test_file_blp.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
from PIL import BlpImagePlugin, Image
44

5-
from .helper import assert_image_equal, assert_image_equal_tofile, hopper
5+
from .helper import (
6+
assert_image_equal,
7+
assert_image_equal_tofile,
8+
assert_image_similar,
9+
hopper,
10+
)
611

712

813
def test_load_blp1():
@@ -33,6 +38,13 @@ def test_save(tmp_path):
3338
with Image.open(f) as reloaded:
3439
assert_image_equal(im.convert("RGB"), reloaded)
3540

41+
with Image.open("Tests/images/transparent.png") as im:
42+
f = str(tmp_path / "temp.blp")
43+
im.convert("P").save(f)
44+
45+
with Image.open(f) as reloaded:
46+
assert_image_similar(im, reloaded, 8)
47+
3648
im = hopper()
3749
with pytest.raises(ValueError):
3850
im.save(f)

src/PIL/BlpImagePlugin.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,10 @@ def _load(self):
406406
except struct.error:
407407
break
408408
b, g, r, a = palette[offset]
409-
data.extend((r, g, b))
409+
d = (r, g, b)
410+
if self._blp_alpha_depth:
411+
d += (a,)
412+
data.extend(d)
410413

411414
elif self._blp_encoding == Encoding.DXT:
412415
if self._blp_alpha_encoding == AlphaEncoding.DXT1:

0 commit comments

Comments
 (0)