Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use I;16 mode for 9-bit JPEG 2000 images #7900

Merged
merged 6 commits into from Mar 25, 2024

Conversation

scaramallion
Copy link
Contributor

@scaramallion scaramallion commented Mar 24, 2024

Fixes #7899 .

Changes proposed in this pull request:

  • Fixes the mode setting for 9-bit J2K images
  • Adds a 9-bit test image

Reference: ISO 15444-1, Table A-11

image

@scaramallion
Copy link
Contributor Author

scaramallion commented Mar 24, 2024

Now that I look at it again, why is it using yrsiz[0] to determine the mode? yrsiz is the vertical separation of the component with respect to the reference grid. I would've though it'd be (ssiz[0] & 0x7F) + 1 for signed images and just ssiz[0] + 1 for unsigned.

@scaramallion
Copy link
Contributor Author

scaramallion commented Mar 24, 2024

Ah, there's another bug further up in parsing the header that's causing the ssiz value to end up in yrsiz, this should be 38 + 3 * i:

for i in range(csiz):
        ssiz[i], xrsiz[i], yrsiz[i] = struct.unpack_from(">BBB", siz, 36 + 3 * i)

image

@scaramallion
Copy link
Contributor Author

Should I fix that as well, or should it be a separate issue?

@radarhere
Copy link
Member

radarhere commented Mar 24, 2024

I think either should be fine.
If it's something producing a problem that you can test for, I'd say create a new PR with a test. Otherwise, if it's just a cleanup to make sure things are named correctly, here is good.

scaramallion and others added 2 commits March 25, 2024 20:13
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
@radarhere radarhere changed the title Fix 9-bit JPEG 2000 images not using I;16 Use I;16 for 9-bit JPEG 2000 images Mar 25, 2024
@radarhere radarhere changed the title Use I;16 for 9-bit JPEG 2000 images Use I;16 mode for 9-bit JPEG 2000 images Mar 25, 2024
@radarhere radarhere merged commit e0b1b38 into python-pillow:main Mar 25, 2024
54 of 55 checks passed
@scaramallion scaramallion deleted the dev-j2k-precision branch March 25, 2024 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JPEG2000: 9-bit images use L mode instead of I;16
2 participants