Skip to content

Fixed orientation when opening YCbCr TIFF images #8556

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

Merged
merged 1 commit into from
Mar 29, 2025

Conversation

radarhere
Copy link
Member

Resolves #8554

When a TIFF image is YCbCr, Pillow calls libtiff's TIFFRGBAImageBegin

readAsRGBA = photometric == PHOTOMETRIC_YCBCR;

if (readAsRGBA) {
_decodeAsRGBA(im, state, tiff);

if (!(TIFFRGBAImageOK(tiff, emsg) && TIFFRGBAImageBegin(&img, tiff, 0, emsg))) {

Looking at that libtiff code, it then calls either PickContigCase or PickSeparateCase. Those set img->get to gtTileContig, gtStripContig, gtTileSeparate or gtStripSeparate. All four of those functions apply orientation to the image based on img->orientation.

Pillow expects to manage image orientation itself. This PR sets img.orientation to prevent libtiff from doing so.

@radarhere radarhere added the TIFF label Nov 16, 2024
@hugovk hugovk merged commit 93cdfeb into python-pillow:main Mar 29, 2025
49 checks passed
@radarhere radarhere deleted the tiff_orientation branch March 29, 2025 20:19
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.

CR2 / TIFF image loads with incorrectly applied orientation / rotation
2 participants