Determine JPEG2000 mode purely from ihdr header box #5654
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #3556
Image comes from https://github.com/openpreserve/format-corpus/blob/master/jp2k-test/icc/balloon_eciRGBv2_aware.jp2 - according to https://github.com/openpreserve/format-corpus/blob/master/README.md and https://github.com/openpreserve/format-corpus/blob/master/jp2k-test/readme.md, it is either public domain or CC0. I've truncated it just to be smaller for our test suite.
We currently determine the mode
unkc
is true, from the "ihdr" header box, orunkc
is not true, and a "colr" header box is present withmeth
of 1, we... also determine the mode from the "ihdr" header box, orWhat is
unkc
, you say?https://www.ics.uci.edu/~dan/class/267/papers/jpeg2000.pdf, emphasis mine.
From there, I have made this jump in logic - if the value of
unkc
is not supposed to affect interpretation, then looking at this present code -Pillow/src/PIL/Jpeg2KImagePlugin.py
Lines 167 to 180 in b8b4bf4
why don't we just imagine that the
if unkc:
condition is always true, and determine the mode purely from the "ihdr" header box?