mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-23 07:10:33 +03:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
8e0c5db1e0
commit
a57ebeaaf4
|
@ -1,13 +1,13 @@
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from PIL import Image, JxlImagePlugin, features
|
from PIL import Image, JxlImagePlugin, features
|
||||||
|
|
||||||
from .helper import (
|
from .helper import (
|
||||||
assert_image_equal,
|
|
||||||
assert_image_similar,
|
|
||||||
assert_image_similar_tofile,
|
assert_image_similar_tofile,
|
||||||
hopper,
|
|
||||||
skip_unless_feature,
|
skip_unless_feature,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ except ImportError:
|
||||||
# cjxl v0.9.2 41b8cdab
|
# cjxl v0.9.2 41b8cdab
|
||||||
# hopper.jxl: cjxl hopper.png hopper.jxl -q 75 -e 8
|
# hopper.jxl: cjxl hopper.png hopper.jxl -q 75 -e 8
|
||||||
|
|
||||||
|
|
||||||
class TestUnsupportedJxl:
|
class TestUnsupportedJxl:
|
||||||
def test_unsupported(self) -> None:
|
def test_unsupported(self) -> None:
|
||||||
if HAVE_JXL:
|
if HAVE_JXL:
|
||||||
|
@ -35,6 +36,7 @@ class TestUnsupportedJxl:
|
||||||
if HAVE_JXL:
|
if HAVE_JXL:
|
||||||
JxlImagePlugin.SUPPORTED = True
|
JxlImagePlugin.SUPPORTED = True
|
||||||
|
|
||||||
|
|
||||||
@skip_unless_feature("jxl")
|
@skip_unless_feature("jxl")
|
||||||
class TestFileJxl:
|
class TestFileJxl:
|
||||||
def setup_method(self) -> None:
|
def setup_method(self) -> None:
|
||||||
|
@ -68,5 +70,3 @@ class TestFileJxl:
|
||||||
|
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
_jxl.PILJxlDecoder()
|
_jxl.PILJxlDecoder()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,7 @@ import pytest
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from .helper import (
|
from .helper import assert_image_similar_tofile
|
||||||
assert_image_similar_tofile
|
|
||||||
)
|
|
||||||
|
|
||||||
_webp = pytest.importorskip("PIL._jxl", reason="JXL support not installed")
|
_webp = pytest.importorskip("PIL._jxl", reason="JXL support not installed")
|
||||||
|
|
||||||
|
@ -29,4 +27,3 @@ def test_read_rgba() -> None:
|
||||||
image.tobytes()
|
image.tobytes()
|
||||||
|
|
||||||
assert_image_similar_tofile(image, "Tests/images/transparent.png", 1.0)
|
assert_image_similar_tofile(image, "Tests/images/transparent.png", 1.0)
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from packaging.version import parse as parse_version
|
|
||||||
|
|
||||||
from PIL import Image, features
|
from PIL import Image
|
||||||
|
|
||||||
from .helper import (
|
from .helper import (
|
||||||
assert_image_equal,
|
assert_image_equal,
|
||||||
|
@ -53,7 +52,7 @@ def test_seeking() -> None:
|
||||||
im2.seek(frame)
|
im2.seek(frame)
|
||||||
im2.load()
|
im2.load()
|
||||||
|
|
||||||
assert_image_equal(im1.convert('RGB'), im2.convert('RGB'))
|
assert_image_equal(im1.convert("RGB"), im2.convert("RGB"))
|
||||||
|
|
||||||
total_dur += im1.info["duration"]
|
total_dur += im1.info["duration"]
|
||||||
assert im1.info["duration"] == im2.info["duration"]
|
assert im1.info["duration"] == im2.info["duration"]
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from io import BytesIO
|
|
||||||
from pathlib import Path
|
|
||||||
from types import ModuleType
|
from types import ModuleType
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from .helper import mark_if_feature_version, skip_unless_feature
|
from .helper import skip_unless_feature
|
||||||
|
|
||||||
pytestmark = [
|
pytestmark = [
|
||||||
skip_unless_feature("jxl"),
|
skip_unless_feature("jxl"),
|
||||||
|
@ -26,6 +24,7 @@ except ImportError:
|
||||||
# python -c "from PIL import Image; im=Image.open('Tests/images/flower2.webp'); f=open('/tmp/xmp.xml', 'wb'); f.write(im.info['xmp']); f.close()"
|
# python -c "from PIL import Image; im=Image.open('Tests/images/flower2.webp'); f=open('/tmp/xmp.xml', 'wb'); f.write(im.info['xmp']); f.close()"
|
||||||
# cjxl flower2.jpg flower2.jxl --lossless_jpeg=0 -q 75 -e 8 -x xmp=/tmp/xmp.xml
|
# cjxl flower2.jpg flower2.jxl --lossless_jpeg=0 -q 75 -e 8 -x xmp=/tmp/xmp.xml
|
||||||
|
|
||||||
|
|
||||||
def test_read_exif_metadata() -> None:
|
def test_read_exif_metadata() -> None:
|
||||||
file_path = "Tests/images/flower.jxl"
|
file_path = "Tests/images/flower.jxl"
|
||||||
with Image.open(file_path) as image:
|
with Image.open(file_path) as image:
|
||||||
|
@ -85,4 +84,3 @@ def test_getxmp() -> None:
|
||||||
im.getxmp()["xmpmeta"]["xmptk"]
|
im.getxmp()["xmpmeta"]["xmptk"]
|
||||||
== "Adobe XMP Core 5.3-c011 66.145661, 2012/02/06-14:56:27 "
|
== "Adobe XMP Core 5.3-c011 66.145661, 2012/02/06-14:56:27 "
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
from io import BytesIO
|
from __future__ import annotations
|
||||||
from . import Image, ImageFile
|
|
||||||
import struct
|
import struct
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
|
from . import Image, ImageFile
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from . import _jxl
|
from . import _jxl
|
||||||
|
@ -18,9 +21,12 @@ except ImportError:
|
||||||
## it only applies to animated jpeg xl images
|
## it only applies to animated jpeg xl images
|
||||||
# OPEN_COUNTS_FRAMES = True
|
# OPEN_COUNTS_FRAMES = True
|
||||||
|
|
||||||
|
|
||||||
def _accept(prefix):
|
def _accept(prefix):
|
||||||
is_jxl = prefix[:2] == b'\xff\x0a' \
|
is_jxl = (
|
||||||
or prefix[:12] == b'\x00\x00\x00\x0c\x4a\x58\x4c\x20\x0d\x0a\x87\x0a'
|
prefix[:2] == b"\xff\x0a"
|
||||||
|
or prefix[:12] == b"\x00\x00\x00\x0c\x4a\x58\x4c\x20\x0d\x0a\x87\x0a"
|
||||||
|
)
|
||||||
if is_jxl and not SUPPORTED:
|
if is_jxl and not SUPPORTED:
|
||||||
return "image file could not be identified because JXL support not installed"
|
return "image file could not be identified because JXL support not installed"
|
||||||
return is_jxl
|
return is_jxl
|
||||||
|
@ -35,7 +41,9 @@ class JxlImageFile(ImageFile.ImageFile):
|
||||||
def _open(self):
|
def _open(self):
|
||||||
self._decoder = _jxl.PILJxlDecoder(self.fp.read())
|
self._decoder = _jxl.PILJxlDecoder(self.fp.read())
|
||||||
|
|
||||||
width, height, mode, has_anim, tps_num, tps_denom, n_loops, n_frames = self._decoder.get_info()
|
width, height, mode, has_anim, tps_num, tps_denom, n_loops, n_frames = (
|
||||||
|
self._decoder.get_info()
|
||||||
|
)
|
||||||
self._size = width, height
|
self._size = width, height
|
||||||
self.info["loop"] = n_loops
|
self.info["loop"] = n_loops
|
||||||
self.is_animated = has_anim
|
self.is_animated = has_anim
|
||||||
|
@ -57,13 +65,17 @@ class JxlImageFile(ImageFile.ImageFile):
|
||||||
icc = self._decoder.get_icc()
|
icc = self._decoder.get_icc()
|
||||||
exif = self._decoder.get_exif()
|
exif = self._decoder.get_exif()
|
||||||
xmp = self._decoder.get_xmp()
|
xmp = self._decoder.get_xmp()
|
||||||
if icc: self.info["icc_profile"] = icc
|
if icc:
|
||||||
|
self.info["icc_profile"] = icc
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if exif: self.info["exif"] = self._fix_exif(exif)
|
if exif:
|
||||||
|
self.info["exif"] = self._fix_exif(exif)
|
||||||
except:
|
except:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
if xmp: self.info["xmp"] = xmp
|
if xmp:
|
||||||
|
self.info["xmp"] = xmp
|
||||||
|
|
||||||
self._rewind()
|
self._rewind()
|
||||||
|
|
||||||
|
@ -115,8 +127,9 @@ class JxlImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
def _seek_check(self, frame):
|
def _seek_check(self, frame):
|
||||||
# if image is not animated then only the 0th frame is available
|
# if image is not animated then only the 0th frame is available
|
||||||
if (not self.is_animated and frame != 0) or \
|
if (not self.is_animated and frame != 0) or (
|
||||||
(self.n_frames is not None and (frame >= self.n_frames or frame < 0)):
|
self.n_frames is not None and (frame >= self.n_frames or frame < 0)
|
||||||
|
):
|
||||||
msg = "attempt to seek outside sequence"
|
msg = "attempt to seek outside sequence"
|
||||||
raise EOFError(msg)
|
raise EOFError(msg)
|
||||||
|
|
||||||
|
|
|
@ -270,8 +270,7 @@ def pilinfo(out=None, supported_formats=True):
|
||||||
("transp_webp", "WEBP Transparency"),
|
("transp_webp", "WEBP Transparency"),
|
||||||
("webp_mux", "WEBPMUX"),
|
("webp_mux", "WEBPMUX"),
|
||||||
("webp_anim", "WEBP Animation"),
|
("webp_anim", "WEBP Animation"),
|
||||||
("jxl", "JPEG XL")
|
("jxl", "JPEG XL")("jpg", "JPEG"),
|
||||||
("jpg", "JPEG"),
|
|
||||||
("jpg_2000", "OPENJPEG (JPEG2000)"),
|
("jpg_2000", "OPENJPEG (JPEG2000)"),
|
||||||
("zlib", "ZLIB (PNG/ZIP)"),
|
("zlib", "ZLIB (PNG/ZIP)"),
|
||||||
("libtiff", "LIBTIFF"),
|
("libtiff", "LIBTIFF"),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user