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:

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:

Processing and Display Pipeline

When an AVIF decoder renders an image containing an irot property, it executes the following steps:

  1. Pixel Decoding: The decoder extracts and reconstructs the pixel grid from the AV1 image bitstream in its native stored orientation.
  2. Transform Application: The rendering pipeline reads the angle value from the associated irot box in the ipco (Item Property Container) box.
  3. 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.