Skip to content

Support reading and writing XML and XMP metadata in JPEG 2000 - #10550

Open
TheVicky1 wants to merge 1 commit into
python-pillow:mainfrom
TheVicky1:jpeg2k-metadata
Open

TheVicky1 wants to merge 1 commit into
python-pillow:mainfrom
TheVicky1:jpeg2k-metadata

Conversation

@TheVicky1

Copy link
Copy Markdown
Contributor

Resolves #3048.

Changes:

  1. src/PIL/Jpeg2KImagePlugin.py:
    • Reading: Replaced the rigid read(12) check after jp2h with a BoxReader loop that scans subsequent top-level boxes. Reads xml boxes into self.info["xml"] and recognizes Adobe XMP uuid boxes (be7acfcb-97a9-42e8-9c71-999491e3afac) as well as XML packets containing XMP metadata (self.info["xmp"]).
    • Writing: Added support for the xml (or xmp) keyword argument when saving JP2 images. Injects xml box(es) immediately following the jp2h header box according to ISO/IEC 15444-1 Annex I.
  2. Tests & Docs:
    • Added tests in Tests/test_file_jpeg2k.py covering XML metadata roundtripping (bytes and str), multiple XML boxes, XMP metadata, Adobe UUID box parsing, and simultaneous XML + codestream comment preservation.
    • Added release note entry in docs/releasenotes/13.1.0.rst.

Comment thread docs/releasenotes/13.1.0.rst Resolved
@radarhere radarhere added the JPEG label Nov 18, 2026
@radarhere

radarhere commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

You can see that two of our tests are failing.

@TheVicky1

Copy link
Copy Markdown
Contributor Author

I tracked down the cause of the two test failures (test_restricted_icc_profile and test_icns_decompression_bomb).

Per ISO/IEC 15444-1 (Section I.5.1), when jp2c is the last box in a JP2 file, LBox can be 0 to denote that its contents extend to the end of the file. balloon_eciRGBv2_aware.jp2 and oom-*.icns both use LBox = 0 for jp2c. BoxReader was treating lbox == 0 as invalid (lbox < 8), raising SyntaxError: Invalid header length.

I have updated BoxReader to handle LBox = 0 as the final box extending to the end of the file. All tests are passing now.

@TheVicky1
TheVicky1 requested a review from radarhere November 19, 2026 06:49
@TheVicky1
TheVicky1 force-pushed the jpeg2k-metadata branch 2 times, most recently from 2bff293 to bb406e4 Compare November 19, 2026 07:27

This branch has not been deployed

No deployments
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.

Enhancement request: JPEG2000 w/ metadata

2 participants