AVIF clap Box: Clean Aperture Boundary Cropping
The AVIF image format uses the Clean Aperture property, contained
within the clap box, to perform non-destructive cropping
and define the exact visible display boundaries of an image. Sourced
from the underlying ISO Base Media File Format (ISOBMFF), the
clap box allows decoders to discard unwanted padding,
correct aspect ratios, and display specific regions of an image without
altering or re-encoding the compressed AV1 bitstream.
Purpose of the clap
Box
Video codecs like AV1 compress data most efficiently when pixel dimensions are divisible by standard block sizes, such as 8x8, 16x16, or larger coding units. When an original image's dimensions do not align with these boundaries, encoders must pad the canvas with extra pixels before compression.
The clap box provides the metadata required to crop out
this extraneous padding during playback or rendering. Because it exists
as an item property outside the compressed image data, cropping is
entirely lossless and avoids the generation degradation of
re-encoding.
Structural Parameters
The clap box defines the visible crop rectangle using
four fractional values, each represented by a 32-bit signed numerator
and an unsigned 32-bit denominator:
cleanApertureWidth(widthN/widthD): The exact fractional width of the clean aperture rectangle in pixels.cleanApertureHeight(heightN/heightD): The exact fractional height of the clean aperture rectangle in pixels.horizOff(horizOffN/horizOffD): The horizontal offset of the clean aperture center relative to the center of the reference image canvas.vertOff(vertOffN/vertOffD): The vertical offset of the clean aperture center relative to the center of the reference image canvas.
Using rational numbers ensures that boundary calculations remain mathematically precise, eliminating floating-point rounding errors across different hardware architectures.
Calculation of Cropping Coordinates
To determine the active display window, an AVIF decoder applies the
clap parameters to the decoded canvas dimensions (\(W_{raw}\) and \(H_{raw}\)):
Establish the Reference Center: The center of the decoded canvas is located at coordinates: \[\text{Center}_X = \frac{W_{raw} - 1}{2}\] \[\text{Center}_Y = \frac{H_{raw} - 1}{2}\]
Determine the Aperture Center: The calculated offsets are added to the canvas center to find the midpoint of the visible rectangle: \[\text{Target}_X = \text{Center}_X + \left(\frac{\text{horizOffN}}{\text{horizOffD}}\right)\] \[\text{Target}_Y = \text{Center}_Y + \left(\frac{\text{vertOffN}}{\text{vertOffD}}\right)\]
Compute the Bounding Edges: The final visible pixel boundaries are determined by extending half the clean aperture dimensions from the computed target center: \[\text{Left} = \text{Target}_X - \frac{\text{cleanApertureWidth} - 1}{2}\] \[\text{Right} = \text{Target}_X + \frac{\text{cleanApertureWidth} - 1}{2}\] \[\text{Top} = \text{Target}_Y - \frac{\text{cleanApertureHeight} - 1}{2}\] \[\text{Bottom} = \text{Target}_Y + \frac{\text{cleanApertureHeight} - 1}{2}\]
The decoder then clips any pixel data falling outside of these calculated left, right, top, and bottom limits.
Rendering and Conformance Constraints
AVIF specifications require that the clean aperture rectangle must
lie entirely within the spatial bounds of the underlying coded image. If
any computed coordinate lands outside the range \([0, W_{raw} - 1]\) or \([0, H_{raw} - 1]\), the file is considered
malformed, and compliant decoders will either discard the
clap box or reject the image. When valid, the decoder
yields a clean, cropped image identical to the author’s intended
composition.