mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-11 16:52:29 +03:00
Use member names to initialize module
This commit is contained in:
parent
05aee33c5e
commit
6c3f0b5ad2
|
@ -41,31 +41,31 @@ class TestFileJpegXl:
|
||||||
Does it have the bits we expect?
|
Does it have the bits we expect?
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with Image.open("Tests/images/hopper.jxl") as image:
|
with Image.open("Tests/images/hopper.jxl") as im:
|
||||||
assert image.mode == "RGB"
|
assert im.mode == "RGB"
|
||||||
assert image.size == (128, 128)
|
assert im.size == (128, 128)
|
||||||
assert image.format == "JPEG XL"
|
assert im.format == "JPEG XL"
|
||||||
image.load()
|
im.load()
|
||||||
image.getdata()
|
im.getdata()
|
||||||
|
|
||||||
# generated with:
|
# generated with:
|
||||||
# djxl hopper.jxl hopper_jxl_bits.ppm
|
# djxl hopper.jxl hopper_jxl_bits.ppm
|
||||||
assert_image_similar_tofile(image, "Tests/images/hopper_jxl_bits.ppm", 1)
|
assert_image_similar_tofile(im, "Tests/images/hopper_jxl_bits.ppm", 1)
|
||||||
|
|
||||||
def test_read_i16(self) -> None:
|
def test_read_i16(self) -> None:
|
||||||
"""
|
"""
|
||||||
Can we read 16-bit Grayscale Jpeg XL image?
|
Can we read 16-bit Grayscale Jpeg XL image?
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with Image.open("Tests/images/jxl/16bit_subcutaneous.cropped.jxl") as image:
|
with Image.open("Tests/images/jxl/16bit_subcutaneous.cropped.jxl") as im:
|
||||||
assert image.mode == "I;16"
|
assert im.mode == "I;16"
|
||||||
assert image.size == (128, 64)
|
assert im.size == (128, 64)
|
||||||
assert image.format == "JPEG XL"
|
assert im.format == "JPEG XL"
|
||||||
image.load()
|
im.load()
|
||||||
image.getdata()
|
im.getdata()
|
||||||
|
|
||||||
assert_image_similar_tofile(
|
assert_image_similar_tofile(
|
||||||
image, "Tests/images/jxl/16bit_subcutaneous.cropped.png", 1
|
im, "Tests/images/jxl/16bit_subcutaneous.cropped.png", 1
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_JpegXlDecode_with_invalid_args(self) -> None:
|
def test_JpegXlDecode_with_invalid_args(self) -> None:
|
||||||
|
|
|
@ -27,21 +27,20 @@ except ImportError:
|
||||||
|
|
||||||
|
|
||||||
def test_read_exif_metadata() -> None:
|
def test_read_exif_metadata() -> None:
|
||||||
with Image.open("Tests/images/flower.jxl") as image:
|
with Image.open("Tests/images/flower.jxl") as im:
|
||||||
assert image.format == "JPEG XL"
|
assert im.format == "JPEG XL"
|
||||||
exif_data = image.info.get("exif", None)
|
exif_data = im.info["exif"]
|
||||||
assert exif_data
|
|
||||||
|
|
||||||
exif = image.getexif()
|
exif = im.getexif()
|
||||||
|
|
||||||
# Camera make
|
# Camera make
|
||||||
assert exif[271] == "Canon"
|
assert exif[271] == "Canon"
|
||||||
|
|
||||||
with Image.open("Tests/images/flower.jpg") as jpeg_image:
|
with Image.open("Tests/images/flower.jpg") as im_jpeg:
|
||||||
expected_exif = jpeg_image.info["exif"]
|
expected_exif = im_jpeg.info["exif"]
|
||||||
|
|
||||||
# jpeg xl always returns exif without 'Exif\0\0' prefix
|
# jpeg xl always returns exif without 'Exif\0\0' prefix
|
||||||
assert exif_data == expected_exif[6:]
|
assert exif_data == expected_exif[6:]
|
||||||
|
|
||||||
|
|
||||||
def test_read_exif_metadata_without_prefix() -> None:
|
def test_read_exif_metadata_without_prefix() -> None:
|
||||||
|
@ -50,18 +49,16 @@ def test_read_exif_metadata_without_prefix() -> None:
|
||||||
assert im.info["exif"][:6] != b"Exif\x00\x00"
|
assert im.info["exif"][:6] != b"Exif\x00\x00"
|
||||||
|
|
||||||
exif = im.getexif()
|
exif = im.getexif()
|
||||||
assert exif[305] == "Adobe Photoshop CS6 (Macintosh)"
|
assert exif[305] == "Adobe Photoshop CS6 (Macintosh)"
|
||||||
|
|
||||||
|
|
||||||
def test_read_icc_profile() -> None:
|
def test_read_icc_profile() -> None:
|
||||||
with Image.open("Tests/images/flower2.jxl") as image:
|
with Image.open("Tests/images/flower2.jxl") as im:
|
||||||
assert image.format == "JPEG XL"
|
assert im.format == "JPEG XL"
|
||||||
assert image.info.get("icc_profile", None)
|
icc = im.info["icc_profile"]
|
||||||
|
|
||||||
icc = image.info["icc_profile"]
|
with Image.open("Tests/images/flower2.jxl") as im_jpeg:
|
||||||
|
expected_icc = im_jpeg.info["icc_profile"]
|
||||||
with Image.open("Tests/images/flower2.jxl") as jpeg_image:
|
|
||||||
expected_icc = jpeg_image.info["icc_profile"]
|
|
||||||
|
|
||||||
assert icc == expected_icc
|
assert icc == expected_icc
|
||||||
|
|
||||||
|
@ -114,10 +111,10 @@ def test_4_byte_exif(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||||
|
|
||||||
monkeypatch.setattr(JpegXlImagePlugin, "_jpegxl", _mock_jpegxl)
|
monkeypatch.setattr(JpegXlImagePlugin, "_jpegxl", _mock_jpegxl)
|
||||||
|
|
||||||
with Image.open("Tests/images/hopper.jxl") as image:
|
with Image.open("Tests/images/hopper.jxl") as im:
|
||||||
assert "exif" not in image.info
|
assert "exif" not in im.info
|
||||||
|
|
||||||
|
|
||||||
def test_read_exif_metadata_empty() -> None:
|
def test_read_exif_metadata_empty() -> None:
|
||||||
with Image.open("Tests/images/hopper.jxl") as image:
|
with Image.open("Tests/images/hopper.jxl") as im:
|
||||||
assert image.getexif() == {}
|
assert im.getexif() == {}
|
||||||
|
|
|
@ -635,7 +635,6 @@ setup_module(PyObject *m) {
|
||||||
|
|
||||||
// TODO(oloke) ready object types?
|
// TODO(oloke) ready object types?
|
||||||
PyObject *d = PyModule_GetDict(m);
|
PyObject *d = PyModule_GetDict(m);
|
||||||
|
|
||||||
PyObject *v = PyUnicode_FromString(JpegXlDecoderVersion_str());
|
PyObject *v = PyUnicode_FromString(JpegXlDecoderVersion_str());
|
||||||
PyDict_SetItemString(d, "libjxl_version", v ? v : Py_None);
|
PyDict_SetItemString(d, "libjxl_version", v ? v : Py_None);
|
||||||
Py_XDECREF(v);
|
Py_XDECREF(v);
|
||||||
|
@ -649,10 +648,9 @@ PyInit__jpegxl(void) {
|
||||||
|
|
||||||
static PyModuleDef module_def = {
|
static PyModuleDef module_def = {
|
||||||
PyModuleDef_HEAD_INIT,
|
PyModuleDef_HEAD_INIT,
|
||||||
"_jpegxl", /* m_name */
|
.m_name = "_jpegxl",
|
||||||
NULL, /* m_doc */
|
.m_size = -1,
|
||||||
-1, /* m_size */
|
.m_methods = jpegxlMethods,
|
||||||
jpegxlMethods, /* m_methods */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
m = PyModule_Create(&module_def);
|
m = PyModule_Create(&module_def);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user