encodeAvif
Encode bitmap as an AVIF file at quality, 0 to 100 (default 50), with the other settings of HeifEncodeOptions: 8-bit 4:2:0, effort 2, tiles of 512 for a larger picture. See the overload with options.
Throws
if quality is outside 0..100, or the picture is too large for a HEIF reader
Encode bitmap as an AVIF file (#176): HEIF (ISO/IEC 23008-12) with AV1 pictures, coded by the core's own intra AV1 encoder, as the AV1 Image File Format 1.1 describes. AV1 is royalty-free, so the encoder is part of the core and needs no module.
Each picture is one AV1 key frame with a reduced still picture header, as libavif writes a still image. HeifEncodeOptions.quality sets the quantizer: base_q_idx 240 at 0, 117 at 50, 43 at 80 and 1 from 97 on, straight between, so 50 and 80 score next to avifenc's -q 50 and -q 80. HeifEncodeOptions.lossless codes at base_q_idx 0, AV1's lossless mode with its Walsh-Hadamard transform, and the file decodes to exactly bitmap. HeifEncodeOptions.effort widens the encoder's search: 1 is fast, 3 tries every mode and transform the encoder knows. Colour converts to Y, Cb and Cr with BT.601's matrix in full range and is signalled as sRGB, both in colr and in the sequence header; a lossless file uses the identity matrix in 4:4:4. A gray bitmap codes luma alone (AV1's monochrome), and alpha below 255 adds an alpha auxiliary image. A picture wider or taller than HeifEncodeOptions.tileSize is a grid of AV1 items, which the runner of setTileRunner encodes; with no tile size, a picture codes as one frame of AV1 tiles of at most 4096 samples across. HeifEncodeOptions.thumbnailSize, HeifEncodeOptions.orientation and metadata are written as encodeHeic writes them. cancellationCheck runs at least once a tile and once a row of superblocks, and what it throws comes out of this call as it is.
Throws
if the picture is too large for a HEIF reader (65535 on a side, or more than 256 tiles on a side of a grid)
Encode animation as an animated AVIF file (#177): an AV1 image sequence, a track of every frame with its delay, that decodeAnimation plays and libavif and ffmpeg read. The first frame is also the primary image item, sharing its bytes, as libavif writes a sequence, so a reader of still images shows it.
The first frame is an AV1 key frame and the frames after it are inter frames, which predict each block from the frame before or the one before that, by a motion search, and from effort 2 from both averaged; set HeifEncodeOptions.keyFrameInterval for a key frame at least every that many frames. Each frame lasts its KiteFrame.delayMillis (1 ms for a delay of 0) on a track of timescale 1000, and KiteAnimation.loopCount goes in the edit list as libavif reads a play count, 0 playing for ever. A frame with alpha below 255 adds an alpha track of its own, auxiliary to the colour track. Quality, lossless, chroma, depth, effort, orientation and metadata act as encodeAvif says for a still, on every frame; a lossless file decodes to exactly the frames. HeifEncodeOptions.tileSize and HeifEncodeOptions.thumbnailSize apply to stills only: a sequence codes each frame as one AV1 frame. cancellationCheck runs at least once a frame and once a row of superblocks, and what it throws comes out of this call as it is.
Throws
if a frame's bitmap is not the animation's size, a delay is negative, or the picture is too large for a HEIF reader (65535 on a side)