mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 18:56:17 +03:00
Rename parameter and add more tests
This commit is contained in:
parent
f8a74cbed1
commit
4e7f041795
|
@ -209,41 +209,82 @@ def test_layers():
|
||||||
assert_image_similar(im, test_card, 0.4)
|
assert_image_similar(im, test_card, 0.4)
|
||||||
|
|
||||||
|
|
||||||
def test_use_jp2():
|
def test_no_jp2():
|
||||||
out = BytesIO()
|
|
||||||
test_card.save(out, "JPEG2000", use_jp2=False)
|
|
||||||
out.seek(0)
|
|
||||||
assert out.read(2) == b"\xff\x4f"
|
|
||||||
|
|
||||||
out = BytesIO()
|
out = BytesIO()
|
||||||
out.name = "foo.j2k"
|
out.name = "foo.j2k"
|
||||||
test_card.save(out, "JPEG2000", use_jp2=False)
|
test_card.save(out, "JPEG2000")
|
||||||
out.seek(0)
|
out.seek(0)
|
||||||
assert out.read(2) == b"\xff\x4f"
|
assert out.read(2) == b"\xff\x4f"
|
||||||
|
|
||||||
out = BytesIO()
|
out = BytesIO()
|
||||||
out.name = "foo.jp2"
|
out.name = "foo.jp2"
|
||||||
test_card.save(out, "JPEG2000", use_jp2=False)
|
test_card.save(out, "JPEG2000")
|
||||||
out.seek(4)
|
out.seek(4)
|
||||||
assert out.read(2) != b"jP"
|
assert out.read(2) == b"jP"
|
||||||
|
|
||||||
|
out = BytesIO()
|
||||||
|
test_card.save(out, "JPEG2000", no_jp2=True)
|
||||||
|
out.seek(0)
|
||||||
|
assert out.read(2) == b"\xff\x4f"
|
||||||
|
|
||||||
|
out = BytesIO()
|
||||||
|
test_card.save(out, "JPEG2000", no_jp2=True)
|
||||||
|
out.seek(0)
|
||||||
|
assert out.read(2) == b"\xff\x4f"
|
||||||
|
|
||||||
|
out = BytesIO()
|
||||||
|
out.name = "foo.j2k"
|
||||||
|
test_card.save(out, "JPEG2000", no_jp2=True)
|
||||||
|
out.seek(0)
|
||||||
|
assert out.read(2) == b"\xff\x4f"
|
||||||
|
|
||||||
|
out = BytesIO()
|
||||||
|
out.name = "foo.jp2"
|
||||||
|
test_card.save(out, "JPEG2000", no_jp2=True)
|
||||||
|
out.seek(0)
|
||||||
|
assert out.read(2) == b"\xff\x4f"
|
||||||
|
|
||||||
|
# Use the filename extension to determine format
|
||||||
|
out = BytesIO()
|
||||||
|
out.name = "foo.j2k"
|
||||||
|
test_card.save(out, "JPEG2000", no_jp2=False)
|
||||||
|
out.seek(0)
|
||||||
|
assert out.read(2) == b"\xff\x4f"
|
||||||
|
|
||||||
|
out = BytesIO()
|
||||||
|
out.name = "foo.jp2"
|
||||||
|
test_card.save(out, "JPEG2000", no_jp2=False)
|
||||||
|
out.seek(4)
|
||||||
|
assert out.read(2) == b"jP"
|
||||||
|
|
||||||
|
# Default to JP2 if no filename
|
||||||
|
out = BytesIO()
|
||||||
|
test_card.save(out, "JPEG2000", no_jp2=False)
|
||||||
|
out.seek(4)
|
||||||
|
assert out.read(2) == b"jP"
|
||||||
|
|
||||||
|
out = BytesIO()
|
||||||
|
test_card.save(out, "JPEG2000", no_jp2=False)
|
||||||
|
out.seek(4)
|
||||||
|
assert out.read(2) == b"jP"
|
||||||
|
|
||||||
|
|
||||||
def test_mct():
|
def test_mct():
|
||||||
# Three component
|
# Three component
|
||||||
for val in (0, 1):
|
for val in (0, 1):
|
||||||
out = BytesIO()
|
out = BytesIO()
|
||||||
test_card.save(out, "JPEG2000", mct=val, use_jp2=False)
|
test_card.save(out, "JPEG2000", mct=val, no_jp2=True)
|
||||||
out.seek(0)
|
out.seek(0)
|
||||||
with Image.open(out) as im:
|
with Image.open(out) as im:
|
||||||
im.load()
|
im.load()
|
||||||
assert_image_similar(im, test_card, 1.0e-3)
|
assert_image_similar(im, test_card, 1.0e-3)
|
||||||
assert out.getvalue()[59] == val
|
assert out.getvalue()[59] == val
|
||||||
|
|
||||||
# Single component
|
# Single component should have MCT disabled
|
||||||
for val in (0, 1):
|
for val in (0, 1):
|
||||||
out = BytesIO()
|
out = BytesIO()
|
||||||
with Image.open("Tests/images/16bit.cropped.jp2") as jp2:
|
with Image.open("Tests/images/16bit.cropped.jp2") as jp2:
|
||||||
jp2.save(out, "JPEG2000", mct=val, use_jp2=False)
|
jp2.save(out, "JPEG2000", mct=val, no_jp2=True)
|
||||||
|
|
||||||
out.seek(0)
|
out.seek(0)
|
||||||
with Image.open(out) as im:
|
with Image.open(out) as im:
|
||||||
|
|
|
@ -506,10 +506,10 @@ The :py:meth:`~PIL.Image.Image.save` method supports the following options:
|
||||||
Defaults to ``False``, which uses the lossless DWT 5-3.
|
Defaults to ``False``, which uses the lossless DWT 5-3.
|
||||||
|
|
||||||
**mct**
|
**mct**
|
||||||
If ``0`` then don't use multiple component transformation when encoding,
|
If ``1`` then apply multiple component transformation when encoding,
|
||||||
otherwise use ``1`` to apply to components 0, 1 and 2. MCT works best
|
otherwise use ``0`` for no component transformation (default). MCT works
|
||||||
with a ``mode`` of ``RGB`` and is only available for 3 component image
|
best with a ``mode`` of ``RGB`` and is only applied when the image data has
|
||||||
data.
|
3 components.
|
||||||
|
|
||||||
**progression**
|
**progression**
|
||||||
Controls the progression order; must be one of ``"LRCP"``, ``"RLCP"``,
|
Controls the progression order; must be one of ``"LRCP"``, ``"RLCP"``,
|
||||||
|
@ -529,9 +529,10 @@ The :py:meth:`~PIL.Image.Image.save` method supports the following options:
|
||||||
for compliant 4K files, *at least one* of the dimensions must match
|
for compliant 4K files, *at least one* of the dimensions must match
|
||||||
4096 x 2160.
|
4096 x 2160.
|
||||||
|
|
||||||
**use_jp2**
|
**no_jp2**
|
||||||
If ``False`` then don't wrap the codestream in the JP2 file format when
|
If ``True`` then don't wrap the raw codestream in the JP2 file format when
|
||||||
saving. Defaults to ``True``.
|
saving, otherwise the extension of the filename will be used to determine
|
||||||
|
the format (default).
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
|
|
|
@ -293,10 +293,10 @@ def _save(im, fp, filename):
|
||||||
# Get the keyword arguments
|
# Get the keyword arguments
|
||||||
info = im.encoderinfo
|
info = im.encoderinfo
|
||||||
|
|
||||||
if filename.endswith(".j2k"):
|
if filename.endswith(".j2k") or info.get("no_jp2", False):
|
||||||
kind = "j2k"
|
kind = "j2k"
|
||||||
else:
|
else:
|
||||||
kind = "jp2" if info.get("use_jp2", True) else "j2k"
|
kind = "jp2"
|
||||||
|
|
||||||
offset = info.get("offset", None)
|
offset = info.get("offset", None)
|
||||||
tile_offset = info.get("tile_offset", None)
|
tile_offset = info.get("tile_offset", None)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user