python-pillow / Pillow

Python Imaging Library (Fork)
https://python-pillow.org
Other
12.32k stars 2.23k forks source link

Fixed orientation when opening YCbCr TIFF images #8556

Open radarhere opened 6 days ago

radarhere commented 6 days ago

Resolves #8554

When a TIFF image is YCbCr, Pillow calls libtiff's TIFFRGBAImageBegin https://github.com/python-pillow/Pillow/blob/5bff2f3b2894ec6923c590d0c37b18177d0634bd/src/libImaging/TiffDecode.c#L729 https://github.com/python-pillow/Pillow/blob/5bff2f3b2894ec6923c590d0c37b18177d0634bd/src/libImaging/TiffDecode.c#L739-L740 https://github.com/python-pillow/Pillow/blob/5bff2f3b2894ec6923c590d0c37b18177d0634bd/src/libImaging/TiffDecode.c#L295

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.