Skip to content

Commit ebdfca3

Browse files
authored
Merge pull request #8786 from radarhere/openjpeg
Support reading grayscale JPEG2000 images with 4 channels
2 parents 00593ff + 92cc9bf commit ebdfca3

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

Tests/test_file_jpeg2k.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,18 @@ def test_rgba(ext: str) -> None:
313313
assert im.mode == "RGBA"
314314

315315

316+
def test_grayscale_four_channels() -> None:
317+
with open("Tests/images/rgb_trns_ycbc.jp2", "rb") as fp:
318+
data = fp.read()
319+
320+
# Change color space to OPJ_CLRSPC_GRAY
321+
data = data[:76] + b"\x11" + data[77:]
322+
323+
with Image.open(BytesIO(data)) as im:
324+
im.load()
325+
assert im.mode == "RGBA"
326+
327+
316328
@pytest.mark.skipif(
317329
not os.path.exists(EXTRA_DIR), reason="Extra image files not installed"
318330
)

src/libImaging/Jpeg2KDecode.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ static const struct j2k_decode_unpacker j2k_unpackers[] = {
615615
{"RGBA", OPJ_CLRSPC_GRAY, 2, 0, j2ku_graya_la},
616616
{"RGBA", OPJ_CLRSPC_SRGB, 3, 1, j2ku_srgb_rgb},
617617
{"RGBA", OPJ_CLRSPC_SYCC, 3, 1, j2ku_sycc_rgb},
618+
{"RGBA", OPJ_CLRSPC_GRAY, 4, 1, j2ku_srgba_rgba},
618619
{"RGBA", OPJ_CLRSPC_SRGB, 4, 1, j2ku_srgba_rgba},
619620
{"RGBA", OPJ_CLRSPC_SYCC, 4, 1, j2ku_sycca_rgba},
620621
{"CMYK", OPJ_CLRSPC_CMYK, 4, 1, j2ku_srgba_rgba},

0 commit comments

Comments
 (0)