Why iPhone HEIC Portraits Turn Sideways & How Single-Pass Matrix Normalization Fixes Them
The Two Competing Orientation Mechanisms Inside HEIC
Camera sensors read out rows in landscape scan order regardless of how you hold the handset. When shooting a vertical portrait, an iPhone can record that 90-degree rotation in two separate places inside a .heic file: as an authoritative ISO BMFF irot transformative item property inside ipco, and as TIFF tag 0x0112 (Orientation = 6) inside an attached Exif metadata item.
When libheif decodes an item that possesses an irot or imir property, it applies that container transform automatically during RGBA display. However, if a container omits irot and stores rotation solely in EXIF (as in portrait-burst-o6.heic), libheif returns unrotated 32×24 landscape pixels. Conversely, if a file carries both irot and EXIF Orientation = 6 and a naive converter applies EXIF rotation on top of libheif output—or copies Orientation = 6 into the output JPEG—the portrait rotates 180 degrees or 90 degrees too far.
- Inspects ipma transformative properties per item before consulting numeric EXIF Orientation (1 through 8).
- Prefers authoritative container presentation transforms and suppresses duplicate EXIF rotation.
- Applies exact lossless 2D coordinate remapping across all eight TIFF orientation states when container transforms are absent.
Quadrant Landmark Verification
Every run computes mean sRGB landmarks across all four image quadrants before and after normalization so you can verify mathematically that bottom-left pixels moved to top-left under 90-degree clockwise rotation.