mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-11 00:32:27 +03:00
Fixed reading uncompressed BLP2 with alpha
This commit is contained in:
parent
169025df6c
commit
3ec928251c
|
@ -2,7 +2,12 @@ import pytest
|
||||||
|
|
||||||
from PIL import BlpImagePlugin, Image
|
from PIL import BlpImagePlugin, Image
|
||||||
|
|
||||||
from .helper import assert_image_equal, assert_image_equal_tofile, hopper
|
from .helper import (
|
||||||
|
assert_image_equal,
|
||||||
|
assert_image_equal_tofile,
|
||||||
|
assert_image_similar,
|
||||||
|
hopper,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_load_blp1():
|
def test_load_blp1():
|
||||||
|
@ -33,6 +38,13 @@ def test_save(tmp_path):
|
||||||
with Image.open(f) as reloaded:
|
with Image.open(f) as reloaded:
|
||||||
assert_image_equal(im.convert("RGB"), reloaded)
|
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)
|
||||||
|
|
||||||
im = hopper()
|
im = hopper()
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
im.save(f)
|
im.save(f)
|
||||||
|
|
|
@ -406,7 +406,10 @@ class BLP2Decoder(_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))
|
d = (r, g, b)
|
||||||
|
if self._blp_alpha_depth:
|
||||||
|
d += (a,)
|
||||||
|
data.extend(d)
|
||||||
|
|
||||||
elif self._blp_encoding == Encoding.DXT:
|
elif self._blp_encoding == Encoding.DXT:
|
||||||
if self._blp_alpha_encoding == AlphaEncoding.DXT1:
|
if self._blp_alpha_encoding == AlphaEncoding.DXT1:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user