AVIF irot Box: How Image Rotation Works
This article explains how the AVIF image format uses the
irot (Image Rotation) box to execute 90, 180, and
270-degree image rotations. Derived from the High Efficiency Image File
Format (HEIF) and the ISO Base Media File Format (ISOBMFF)
specifications, the irot box provides a lightweight,
non-destructive mechanism to specify display orientation using a compact
2-bit field, eliminating the need to decode and re-encode compressed
pixel data.
Structure of the irot
Box
AVIF relies on ISOBMFF item properties to associate descriptive
metadata with the primary image item. The irot box is
defined as an essential or non-essential transformative item
property.
The box consists of a standard 8-byte ISOBMFF header followed by a single byte of payload:
- Box Size: 4 bytes (standard box header)
- Box Type: 4 bytes (ASCII characters
'irot') - Reserved Bits: 6 bits (must be set to
0) - Angle Field: 2 bits (unsigned integer specifying rotation)
The Angle Field Values
The ISO/IEC 23008-12 (HEIF) specification defines the 2-bit
angle field as an anti-clockwise (counter-clockwise)
rotation in units of 90 degrees. The mathematical formula applied to
determine the rotation angle is:
\[\text{Rotation Angle (Anti-Clockwise)} = \text{angle} \times 90^\circ\]
The four possible binary states map directly to specific orientations:
0(00in binary): \(0^\circ\) rotation (original image orientation is preserved).1(01in binary): \(90^\circ\) anti-clockwise rotation (equivalent to \(270^\circ\) clockwise rotation).2(10in binary): \(180^\circ\) anti-clockwise rotation (equivalent to \(180^\circ\) clockwise rotation).3(11in binary): \(270^\circ\) anti-clockwise rotation (equivalent to \(90^\circ\) clockwise rotation).
Processing and Display Pipeline
When an AVIF decoder renders an image containing an irot
property, it executes the following steps:
- Pixel Decoding: The decoder extracts and reconstructs the pixel grid from the AV1 image bitstream in its native stored orientation.
- Transform Application: The rendering pipeline reads
the
anglevalue from the associatedirotbox in theipco(Item Property Container) box. - Canvas Orientation: The image is rotated anti-clockwise by \(\text{angle} \times 90^\circ\) prior to final display. If the angle is 1 or 3, the display canvas automatically swaps the image width and height dimensions.
Interaction with Mirroring
(imir)
If an image item includes both an irot box and an
imir (Image Mirroring) box, the order of application is
strictly determined by their association order in the ipma
(Item Property Association) box. Renderers must apply properties
sequentially as listed in the item association to ensure that composite
transformations (such as flipping followed by rotation) render correctly
across different decoding implementations.