Skip to content

Commit 06b71f7

Browse files
authored
Merge pull request #7947 from radarhere/jpeg2000_cmyk
2 parents f8ec9f7 + c61a481 commit 06b71f7

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

Tests/test_file_jpeg2k.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,16 @@ def test_rgba(ext: str) -> None:
289289
assert im.mode == "RGBA"
290290

291291

292+
@pytest.mark.skipif(
293+
not os.path.exists(EXTRA_DIR), reason="Extra image files not installed"
294+
)
295+
@skip_unless_feature_version("jpg_2000", "2.5.1")
296+
def test_cmyk() -> None:
297+
with Image.open(f"{EXTRA_DIR}/issue205.jp2") as im:
298+
assert im.mode == "CMYK"
299+
assert im.getpixel((0, 0)) == (185, 134, 0, 0)
300+
301+
292302
@pytest.mark.parametrize("ext", (".j2k", ".jp2"))
293303
def test_16bit_monochrome_has_correct_mode(ext: str) -> None:
294304
with Image.open("Tests/images/16bit.cropped" + ext) as im:

src/PIL/Jpeg2KImagePlugin.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ def _parse_jp2_header(fp):
176176
mode = "RGB"
177177
elif nc == 4:
178178
mode = "RGBA"
179+
elif tbox == b"colr" and nc == 4:
180+
meth, _, _, enumcs = header.read_fields(">BBBI")
181+
if meth == 1 and enumcs == 12:
182+
mode = "CMYK"
179183
elif tbox == b"pclr" and mode in ("L", "LA"):
180184
ne, npc = header.read_fields(">HB")
181185
bitdepths = header.read_fields(">" + ("B" * npc))

src/libImaging/Jpeg2KDecode.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ static const struct j2k_decode_unpacker j2k_unpackers[] = {
632632
{"RGBA", OPJ_CLRSPC_SYCC, 3, 1, j2ku_sycc_rgb},
633633
{"RGBA", OPJ_CLRSPC_SRGB, 4, 1, j2ku_srgba_rgba},
634634
{"RGBA", OPJ_CLRSPC_SYCC, 4, 1, j2ku_sycca_rgba},
635+
{"CMYK", OPJ_CLRSPC_CMYK, 4, 1, j2ku_srgba_rgba},
635636
};
636637

637638
/* -------------------------------------------------------------------- */

0 commit comments

Comments
 (0)