Fix 9-bit JPEG 2000 images not using I;16

This commit is contained in:
scaramallion 2024-03-24 15:40:11 +11:00
parent 19cd94bdb3
commit ce060a8e8b
3 changed files with 7 additions and 1 deletions

BIN
Tests/images/9bit.j2k Normal file

Binary file not shown.

View File

@ -446,3 +446,9 @@ def test_plt_marker() -> None:
hdr = out.read(2) hdr = out.read(2)
length = _binary.i16be(hdr) length = _binary.i16be(hdr)
out.seek(length - 2, os.SEEK_CUR) out.seek(length - 2, os.SEEK_CUR)
def test_9bit():
# Test 9-bit images are decoded to I;16
with Image.open("Tests/images/9bit.j2k") as im:
assert im.mode == "I;16"
assert im.size == (128, 128)

View File

@ -114,7 +114,7 @@ def _parse_codestream(fp):
size = (xsiz - xosiz, ysiz - yosiz) size = (xsiz - xosiz, ysiz - yosiz)
if csiz == 1: if csiz == 1:
if (yrsiz[0] & 0x7F) > 8: if (yrsiz[0] & 0x7F) + 1 > 8:
mode = "I;16" mode = "I;16"
else: else:
mode = "L" mode = "L"