AVIF image codec for PascalAI. Encode and decode AV1-based AVIF images — the next-generation format that beats JPEG by ~50% file size at equal quality, with full alpha channel, HDR, and wide color gamut support. Open and royalty-free.
The encoder accepts raw RGBA pixels plus a TAvifEncodeOptions record for fine control, or use the simplified overloads with quality and speed integers directly.
'aom' (best quality) or 'svt' (much faster encode). Default: 'aom'.
Threads
Integer
Encoder threads. 0 = auto-detect CPU cores.
ExifData
Bytes
Raw EXIF bytes to embed. Pass empty array to skip.
ICCProfile
Bytes
ICC profile bytes for wide color gamut / HDR metadata.
uses libavif;
var w, h: Integer;
var rgba := DecodeFile('/photos/raw.png', w, h); { any RGBA source }{ High quality, keep lossless alpha, fast encode }var opts: TAvifEncodeOptions;
opts.Quality := 72;
opts.QualityAlpha := 100;
opts.Speed := 4;
opts.YUVFormat := 'YUV444';
opts.Codec := 'aom';
opts.Threads := 0; { auto }EncodeEx(rgba, w, h, opts, '/output/photo.avif');
Conversion Helpers API
One-call helpers that read a source image format and write AVIF without handling raw pixels manually.
Function
Description
JPEGToAVIF(srcPath, dstPath, quality)
Convert JPEG file to AVIF lossy.
PNGToAVIF(srcPath, dstPath, quality)
Convert PNG to AVIF. Alpha channel preserved.
WebPToAVIF(srcPath, dstPath, quality)
Convert WebP to AVIF.
TIFFToAVIF(srcPath, dstPath, quality)
Convert TIFF (including 16-bit) to AVIF.
AVIFToJPEG(srcPath, dstPath, quality)
Decode AVIF, re-encode as JPEG.
AVIFToPNG(srcPath, dstPath)
Decode AVIF, save as PNG (lossless round-trip).
BatchConvert(srcDir, dstDir, quality)
Convert all JPEG/PNG files in srcDir to AVIF, writing to dstDir.
Metadata API
Function
Description
GetEXIF(path)
Extract embedded EXIF bytes from AVIF container.
GetXMP(path)
Extract embedded XMP metadata bytes.
GetICCProfile(path)
Extract ICC color profile bytes.
StripMetadata(srcPath, dstPath)
Copy AVIF, removing all EXIF/XMP/ICC. Useful for privacy.
CopyMetadata(srcPath, dstPath)
Copy EXIF+XMP+ICC from srcPath into an existing dstPath.
AVIFVersion()
Returns libavif version string.
TAvifInfo Record
Field
Type
Description
Width
Integer
Image width in pixels.
Height
Integer
Image height in pixels.
BitDepth
Integer
Bit depth per channel: 8, 10, or 12.
HasAlpha
Boolean
True if the image has an alpha channel.
IsHDR
Boolean
True if BitDepth > 8 and transfer characteristics indicate HDR.
YUVFormat
String
Chroma subsampling: 'YUV420', 'YUV422', 'YUV444', or 'MONO'.
ColorPrimaries
Integer
CICP color primaries code (1=BT.709/sRGB, 9=BT.2020).
TransferChar
Integer
Transfer characteristics (1=BT.709, 16=PQ/HDR10, 18=HLG).
FileSize
Integer
File size in bytes.
Quality Guide
AVIF quality uses the same 0–100 scale as JPEG, but produces much smaller files at the same perceptual quality.
Quality
Use case
Typical size vs JPEG
100
Lossless (pixel-perfect archiving)
~10–30% larger than PNG
80–90
Near-lossless, professional photos
~60% smaller than JPEG
60–80
High-quality web photos
~50% smaller than JPEG
40–60
General web delivery, thumbnails
~40% smaller than JPEG
<40
Very small files, lower fidelity
~30% smaller than JPEG
Speed vs quality tradeoff
Speed 0–3 produces the smallest files but can take minutes on high-resolution images. Speed 6 (default) is a good balance. Speed 8–10 is suitable for live encoding but sacrifices ~10% compression efficiency. Use Codec='svt' for dramatically faster encoding at the cost of slightly larger files.