Skip to content

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.

2 participants