Merge pull request #6250 from radarhere/jpeg2000

This commit is contained in:
Hugo van Kemenade 2022-04-29 13:54:00 +03:00 committed by GitHub
commit 7d5162cb37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 8 deletions

View File

@ -4,15 +4,13 @@ import warnings
import pytest
from PIL import IcnsImagePlugin, Image, _binary, features
from PIL import IcnsImagePlugin, Image, _binary
from .helper import assert_image_equal, assert_image_similar_tofile
from .helper import assert_image_equal, assert_image_similar_tofile, skip_unless_feature
# sample icon file
TEST_FILE = "Tests/images/pillow.icns"
ENABLE_JPEG2K = features.check_codec("jpg_2000")
def test_sanity():
# Loading this icon by default should result in the largest size
@ -111,14 +109,12 @@ def test_older_icon():
assert im2.size == (wr, hr)
@skip_unless_feature("jpg_2000")
def test_jp2_icon():
# This icon uses JPEG 2000 images instead of the PNG images.
# The advantage of doing this is that OS X 10.5 supports JPEG 2000
# but not PNG; some commercial software therefore does just this.
if not ENABLE_JPEG2K:
return
with Image.open("Tests/images/pillow3.icns") as im:
for w, h, r in im.info["sizes"]:
wr = w * r
@ -149,6 +145,7 @@ def test_not_an_icns_file():
IcnsImagePlugin.IcnsFile(fp)
@skip_unless_feature("jpg_2000")
def test_icns_decompression_bomb():
with Image.open(
"Tests/images/oom-8ed3316a4109213ca96fb8a256a0bfefdece1461.icns"

View File

@ -7,7 +7,7 @@ import warnings
import pytest
from PIL import Image, ImageDraw, ImagePalette, UnidentifiedImageError
from PIL import Image, ImageDraw, ImagePalette, UnidentifiedImageError, features
from .helper import (
assert_image_equal,
@ -161,6 +161,8 @@ class TestImage:
assert im.size == (128, 128)
for ext in (".jpg", ".jp2"):
if ext == ".jp2" and not features.check_codec("jpg_2000"):
pytest.skip("jpg_2000 not available")
temp_file = str(tmp_path / ("temp." + ext))
if os.path.exists(temp_file):
os.remove(temp_file)