Fix decoding of RGB JPEG with Adobe APP14 marker #1444
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.
Describe the changes
DICOM allows JPEG steams where the image has been directly compressed in RGB color space without first transforming the image into YCbCr color space. Pillow doesn't (and cannot!) decode the pixel data correctly, because it doesn't know whether a color transformation has been applied (in DICOM specified via Photometric Interpretation). We previously addressed this issue via #878.
In the meantime, pillow has become capable of detecting the Adobe APP14 marker segment in the JPEG header (which specifies the color transformation via the transform flag) and can now decode the JPEG stream correctly if the marker segment is present (see python-pillow/Pillow#5408). The change in decoding behavior now conflicts with the decoding logic implemented in pydicom.
This PR addressed this conflict. Specifically, if the Adobe APP14 marker segment is detected in the JPEG header by Pillow, pydicom lets Pillow handle the decoding and color transformation. If the marker is absent, pydicom will provide further information to Pillow to avoid an incorrect/unnecessary color transformation.
Tasks
doc/_build/html/index.html
)