Skip to content

Commit

Permalink
Fix 9-bit JPEG 2000 images not using I;16
Browse files Browse the repository at this point in the history
  • Loading branch information
scaramallion committed Mar 24, 2024
1 parent 19cd94b commit ce060a8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
Binary file added Tests/images/9bit.j2k
Binary file not shown.
6 changes: 6 additions & 0 deletions Tests/test_file_jpeg2k.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,9 @@ def test_plt_marker() -> None:
hdr = out.read(2)
length = _binary.i16be(hdr)
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)
2 changes: 1 addition & 1 deletion src/PIL/Jpeg2KImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def _parse_codestream(fp):

size = (xsiz - xosiz, ysiz - yosiz)
if csiz == 1:
if (yrsiz[0] & 0x7F) > 8:
if (yrsiz[0] & 0x7F) + 1 > 8:
mode = "I;16"
else:
mode = "L"
Expand Down

0 comments on commit ce060a8

Please sign in to comment.