Skip to content

Commit

Permalink
Fixed reading uncompressed BLP2 with alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Feb 25, 2022
1 parent 2863296 commit b33ebc8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
16 changes: 14 additions & 2 deletions Tests/test_file_blp.py
Expand Up @@ -2,7 +2,12 @@

from PIL import BlpImagePlugin, Image

from .helper import assert_image_equal, assert_image_equal_tofile, hopper
from .helper import (
assert_image_equal,
assert_image_similar,
assert_image_equal_tofile,
hopper,
)


def test_load_blp1():
Expand Down Expand Up @@ -31,7 +36,14 @@ def test_save(tmp_path):
im.save(f)

with Image.open(f) as reloaded:
assert_image_equal(im, reloaded.convert("RGB"))
assert_image_equal(im.convert("RGB"), reloaded)

with Image.open("Tests/images/transparent.png") as im:
f = str(tmp_path / "temp.blp")
im.convert("P").save(f)

with Image.open(f) as reloaded:
assert_image_similar(im, reloaded, 8)


@pytest.mark.parametrize(
Expand Down
5 changes: 4 additions & 1 deletion src/PIL/BlpImagePlugin.py
Expand Up @@ -406,7 +406,10 @@ def _load(self):
except struct.error:
break
b, g, r, a = palette[offset]
data.extend((r, g, b))
d = (r, g, b)
if self._blp_alpha_depth:
d += (a,)
data.extend(d)

elif self._blp_encoding == Encoding.DXT:
if self._blp_alpha_encoding == AlphaEncoding.DXT1:
Expand Down

0 comments on commit b33ebc8

Please sign in to comment.