AVIF Clean Aperture Box Cropping Explained
The AVIF image format relies on the Clean Aperture box
(clap) to define display-level cropping without altering or
re-encoding the underlying compressed AV1 bitstream. Derived from the
ISO Base Media File Format (ISOBMFF) and constrained by the Multi-Image
Application Format (MIAF), the clap box provides rational
mathematical values that designate the visible rectangular area of an
image. This article details the structure of the clean aperture box, its
mathematical calculation model, and how compliant AVIF decoders
interpret it to crop images for display.
The Role of the
clap Box in AVIF
AVIF separates the encoded pixel canvas from the final rendered
output. When an image is encoded with padding, edge artifacts, or an
aspect ratio different from the target display, the encoder includes a
clap property box within the image item properties
(iprp).
Because it is an item property rather than a bitstream alteration,
applying a crop via a clap box is entirely lossless and
reversible. Decoders decode the full AV1 frame first, then apply the
clap boundaries to determine the final presentation
canvas.
Structure and Fields
of the clap Property
The clap box uses fractional arithmetic rather than
fixed integer pixels to prevent rounding errors across varying
subsampling schemes. It contains four fractional parameters, each
represented as a numerator (N) and a denominator
(D):
cleanApertureWidth(cleanApertureWidthN/cleanApertureWidthD): The exact width of the cropped viewing area.cleanApertureHeight(cleanApertureHeightN/cleanApertureHeightD): The exact height of the cropped viewing area.horizOff(horizOffN/horizOffD): The horizontal offset of the center of the crop rectangle relative to the center of the coded image canvas.vertOff(vertOffN/vertOffD): The vertical offset of the center of the crop rectangle relative to the center of the coded image canvas.
All values are signed 32-bit integers for numerators and unsigned 32-bit integers for denominators.
Calculating the Display Rectangle
To derive the pixel coordinates of the visible area from the coded dimensions (\(W_c\) and \(H_c\)), decoders compute the position of the cropping rectangle relative to the image center:
Center Calculation: \[\text{Center}_x = \frac{W_c}{2} + \frac{\text{horizOffN}}{\text{horizOffD}}\] \[\text{Center}_y = \frac{H_c}{2} + \frac{\text{vertOffN}}{\text{vertOffD}}\]
Boundary Derivation: \[\text{Left} = \text{Center}_x - \frac{\text{cleanApertureWidthN}}{2 \times \text{cleanApertureWidthD}}\] \[\text{Top} = \text{Center}_y - \frac{\text{cleanApertureHeightN}}{2 \times \text{cleanApertureHeightD}}\] \[\text{Right} = \text{Left} + \frac{\text{cleanApertureWidthN}}{\text{cleanApertureWidthD}}\] \[\text{Bottom} = \text{Top} + \frac{\text{cleanApertureHeightN}}{\text{cleanApertureHeightD}}\]
MIAF Alignment and Constraints
The AVIF specification mandates adherence to MIAF (ISO/IEC 23000-22)
constraints regarding clap usage:
- Pixel Alignment: The calculated
Left,Top,Right, andBottomvalues must resolve to exact integer coordinates. Non-integer resulting bounds are considered invalid. - Canvas Boundaries: The resulting rectangle must reside entirely within the boundaries of the coded pixel array (\(0 \le \text{Left} < \text{Right} \le W_c\) and \(0 \le \text{Top} < \text{Bottom} \le H_c\)).
- Chroma Subsampling Requirements: When chroma subsampling (such as 4:2:0 or 4:2:2) is used, the crop origins and dimensions must align with the chroma grid to prevent subsampling boundary mismatches.
If a clap box violates any of these constraints or
yields an empty display area, compliant AVIF decoders must ignore the
clap box and render the full coded canvas.