Skip to content

How It Works

HarpePluie edited this page Oct 8, 2026 · 1 revision

How It Works

 photo.heic ──▶ container ──▶ HEVC bitstream ──▶ HEVC decoder ──▶ assembly ──▶ RGB(A)
              (heifer-isobmff)   per tile        (heifer-hevc-dec)   (heifer)
  1. Container. A HEIF file is an ISOBMFF file, the same box structure as MP4.
    • heifer-isobmff parses the boxes into items: images, grids, overlays, EXIF, XMP.
    • Items have properties: size (ispe), HEVC configuration (hvcC), colour (colr) and transforms.
    • Items are linked by references: tiles of a grid, alpha plane, thumbnail.
  2. Bitstream. For each tile, heifer extracts the HEVC data and adds the parameter sets (VPS/SPS/PPS) from hvcC.
  3. Decoding. heifer-hevc-dec implements HEVC intra decoding, following ITU-T H.265:
    • NAL units and parameter sets;
    • CABAC entropy decoding;
    • intra prediction (35 modes);
    • inverse transforms;
    • deblocking and SAO filters. Grid tiles are independent, so they are decoded in parallel.
  4. Assembly. heifer then turns the decoded tiles into the final image:
    • it stitches the tiles together;
    • it attaches the alpha plane;
    • it converts YCbCr to RGB;
    • it applies crop, rotation and mirror.

Crates

Crate Role
heifer public API: decode, read_metadata, image integration
heifer-isobmff HEIF container parsing
heifer-hevc-dec HEVC intra decoder
heifer-hevc-enc HEVC encoder (work in progress)

The lower-level crates can be used on their own, for example to extract the HEVC stream of a photo:

let file = heifer_isobmff::HeifFile::parse(&bytes)?;
let tiles = file.referenced_items(file.primary_id, b"dimg");
let hevc = file.hevc_bitstream(tiles[0])?;   // Annex B, readable by heifer-hevc-dec or ffmpeg

Clone this wiki locally