Rust & C ABI integration
Embed the pure-Rust qualix crate or C header include/qualix.h across desktop, mobile, and native engines with shared-surface decoding.
The core qualix crate is #![forbid(unsafe_code)] Rust with only one runtime dependency (lz4_flex block decompression). Native players depend on qualix = { ..., default-features = false } to exclude encoder search tables and minimize binary size.
Pure-Rust playback & shared surface (open_into)
Rustuse qualix::{DEFAULT_BUDGET, Decoder};use std::io::Cursor;let data: &[u8] = include_bytes!("../assets/opening.qlx");let mut decoder = Decoder::open(Cursor::new(data), DEFAULT_BUDGET)?;let info = decoder.info();let frame = decoder.decode(0)?;upload_texture(frame.pixels, frame.dirty_rows.start, frame.dirty_rows.end);
On unified-memory architectures (such as Metal MTLBuffer on Apple Silicon), Decoder::open_into lends a caller-owned pixel buffer directly as the decoder's sole reference canvas, eliminating full-frame copies:
Rustlet mut shared_surface = vec![0u8; info.frame_bytes()?];let mut decoder = Decoder::open_into(reader, DEFAULT_BUDGET, &mut shared_surface[..])?;// Wait for GPU texture reads to finish before the next decode() calllet frame = decoder.decode(target_frame)?;
C ABI (include/qualix.h)
The qualix-ffi crate builds static/shared libraries (libqualix_decoder.a / .dylib / .so / .dll) with deterministic C ownership contracts capable of reading unaligned QPK member slices directly:
C#include "qualix.h"QlxInfo info;QlxDecoder *clip = NULL;if (qlx_probe(pack_slice, slice_len, &info) == 0 && qlx_open(pack_slice, slice_len, QLX_DEFAULT_BUDGET, &clip, &info) == 0) { QlxFrame frame; if (qlx_decode(clip, frame_idx, &frame) == 0) { upload_rows(frame.pixels, frame.first_row, frame.end_row); } qlx_close(clip);}
The C ABI also exports qlx_open_into (lent exclusive surface) and qlx_open_stream (synchronous QlxReadAt callback with internal 64 KiB read buffering accounted within budget).
Native HDR reference player (Metal + EDR)
examples/metal-player.m links libqualix_decoder.a against Metal and QuartzCore for extended linear BT.2020 & Apple EDR output:
Shellcargo build --release --locked -p qualix-fficlang -O2 -fobjc-arc -Wno-deprecated-declarations -Iinclude examples/metal-player.m examples/metal/render.m \ target/release/libqualix_decoder.a -framework Cocoa -framework MetalKit \ -framework Metal -framework QuartzCore -o qualix-player./qualix-player --check-hdr./qualix-player opening.qlx 1./qualix-player --capture-linear opening.qlx render.rgba16f
- Unified memory vs dirty-row upload: On unified-memory hardware, the decoder writes directly into
MTLBufferbacking storage; settingQLX_METAL_COPY_UPLOAD=1exercises the dirty-band[first_row, end_row)upload path on a separate GPU texture. - Color & presentation telemetry:
PQ10converts via EOTF into 100 cd/m² normalized linear BT.2020 andHLG10via inverse OETF into scene-linearRGBA16Floatwith EDR metadata.QLX_TRACE_PRESENTATION=1records monotonic presentation timestamps per frame.