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

Added reading of JPEG2000 comments #6909

Merged
merged 1 commit into from
Mar 22, 2023
Merged

Conversation

radarhere
Copy link
Member

#6903 adds writing of JPEG2000 comments, so I thought it would be helpful to also be able to read JPEG2000 comments.

Looking at image data, I saw that shortly after _parse_jp2_header() had seeked forward in the file, there was "jp2c", signalling a "Contiguous codestream box". The next bytes were b"\xff\x4f\xff\x51", as Pillow checked for a few lines earlier before running _parse_codestream().

So using _parse_codestream() as a basis, this PR reads the type of the marker, the length, and the rest of the data in the marker, until reaching a "comment" marker, or breaking if the data ends, or if "start of tile" or "end of codestream" is reached first. See https://github.com/corkami/formats/blob/master/image/jpeg.md#jpeg-2000 for the marker types.

I've added a test image, just saved with Pillow.

@hugovk hugovk merged commit 31e8e01 into python-pillow:main Mar 22, 2023
@radarhere radarhere deleted the jp2_comment branch March 22, 2023 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants