mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-14 05:36:48 +03:00
Support reading CMYK JPEG2000 images
This commit is contained in:
parent
ff64adee9d
commit
c61a481028
|
@ -289,6 +289,16 @@ def test_rgba(ext: str) -> None:
|
||||||
assert im.mode == "RGBA"
|
assert im.mode == "RGBA"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(
|
||||||
|
not os.path.exists(EXTRA_DIR), reason="Extra image files not installed"
|
||||||
|
)
|
||||||
|
@skip_unless_feature_version("jpg_2000", "2.5.1")
|
||||||
|
def test_cmyk() -> None:
|
||||||
|
with Image.open(f"{EXTRA_DIR}/issue205.jp2") as im:
|
||||||
|
assert im.mode == "CMYK"
|
||||||
|
assert im.getpixel((0, 0)) == (185, 134, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("ext", (".j2k", ".jp2"))
|
@pytest.mark.parametrize("ext", (".j2k", ".jp2"))
|
||||||
def test_16bit_monochrome_has_correct_mode(ext: str) -> None:
|
def test_16bit_monochrome_has_correct_mode(ext: str) -> None:
|
||||||
with Image.open("Tests/images/16bit.cropped" + ext) as im:
|
with Image.open("Tests/images/16bit.cropped" + ext) as im:
|
||||||
|
|
|
@ -176,6 +176,10 @@ def _parse_jp2_header(fp):
|
||||||
mode = "RGB"
|
mode = "RGB"
|
||||||
elif nc == 4:
|
elif nc == 4:
|
||||||
mode = "RGBA"
|
mode = "RGBA"
|
||||||
|
elif tbox == b"colr" and nc == 4:
|
||||||
|
meth, _, _, enumcs = header.read_fields(">BBBI")
|
||||||
|
if meth == 1 and enumcs == 12:
|
||||||
|
mode = "CMYK"
|
||||||
elif tbox == b"pclr" and mode in ("L", "LA"):
|
elif tbox == b"pclr" and mode in ("L", "LA"):
|
||||||
ne, npc = header.read_fields(">HB")
|
ne, npc = header.read_fields(">HB")
|
||||||
bitdepths = header.read_fields(">" + ("B" * npc))
|
bitdepths = header.read_fields(">" + ("B" * npc))
|
||||||
|
|
|
@ -632,6 +632,7 @@ static const struct j2k_decode_unpacker j2k_unpackers[] = {
|
||||||
{"RGBA", OPJ_CLRSPC_SYCC, 3, 1, j2ku_sycc_rgb},
|
{"RGBA", OPJ_CLRSPC_SYCC, 3, 1, j2ku_sycc_rgb},
|
||||||
{"RGBA", OPJ_CLRSPC_SRGB, 4, 1, j2ku_srgba_rgba},
|
{"RGBA", OPJ_CLRSPC_SRGB, 4, 1, j2ku_srgba_rgba},
|
||||||
{"RGBA", OPJ_CLRSPC_SYCC, 4, 1, j2ku_sycca_rgba},
|
{"RGBA", OPJ_CLRSPC_SYCC, 4, 1, j2ku_sycca_rgba},
|
||||||
|
{"CMYK", OPJ_CLRSPC_CMYK, 4, 1, j2ku_srgba_rgba},
|
||||||
};
|
};
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user