QLX bitstream specification
QLX wire layout: 32-byte header, EOF keyframe seek table, LEB128 spans, opcodes 0-8, bounded prefix residuals, adaptive outer framing, and CBR/VBR budgets.
Every QLX stream contains a single constant-frame-rate video track starting at byte zero of its own member, letting file readers, borrowed memory slices, and QPK entries share identical offsets. Multi-byte scalar integers are little-endian and all pixel profiles occupy four bytes per pixel in raster order.
Header and EOF seek table
| Offset | Type | Field |
|---|---|---|
| 0–3 | 4 bytes | Fixed QLX signature 51 4C 58 07 |
| 4 | u16 | Header size (32) |
| 6 | u8 | Color profile (1 = Srgb8, 2 = Pq10, 3 = Hlg10) |
| 7 | u8 | Fixed quantization 0..4, or 255 for adaptive framing |
| 8, 12 | u32 × 2 | Width, height (1..16384, at most pixels/frame) |
| 16, 20 | u32 × 2 | Positive frame-rate numerator and denominator |
| 24 | u32 | Frame count (1..2²⁴) |
| 28 | u32 | Key interval (1..240) |
Frame begins at seconds. Following the packet sequence, an EOF table stores ceil(frames / key_interval) strictly increasing u64 byte offsets (starting at ≥ 32). Random seeks read at most one keyframe group (plus one materialized reference keyframe when shared). QPK v1 members cap at 4 GiB, while the Rust Decoder over File handles >4 GiB assets.
Color profiles
| ID | Pixel Layout (LE u32) | Transfer & Primaries |
|---|---|---|
1 (Srgb8) |
[R8, G8, B8, A8] |
Full-range sRGB, straight alpha |
2 (Pq10) |
R + (G << 10) + (B << 20) + (A << 30) |
Full-range BT.2020 RGB, PQ EOTF |
3 (Hlg10) |
Same R10G10B10A2 |
Full-range BT.2020 RGB, HLG transfer |
Fixed quantization (q > 0) rounds RGB once before reference generation to nearest multiples of with ties rounded up; straight alpha always preserves its packed native code levels. Display transfer and mastering luminance belong to the enclosing host asset metadata (ITU-R BT.2100).
Fixed-quality packets (0..4) & opcodes
Each packet starts with a u32 word (low 31 bits = payload size; bit 31 = shared-key flag legal on group starts only, followed by a 1..5-byte LEB128 materialized-group distance). Zero-length delta packets hold the canvas unchanged. Ordinary pictures encode ZigZag (dx, dy) pan offsets before raster spans (count - 1) × 16 + opcode:
| Opcode | Payload | Reconstruction |
|---|---|---|
0 |
None | Skip unchanged pixels (delta only) |
1 |
1 pixel word | Fill span with constant pixel |
2 |
4 × count bytes |
Literal copy |
3 |
Compressed block (≤ 4,096 px) | Decompress LZ4 block into destination |
4 |
Compressed block | LZ4 decode u32 diffs, prefix-sum mod |
5 |
Compressed block | De-interleave 4 byte lanes |
6 |
Compressed block | De-interleave lanes + prefix-sum mod |
7 |
Compressed block | De-interleave lanes + add to translated surface (delta only) |
8 |
Residual block | Decode prefix-coded residuals from spatial/temporal predictors |
Prefix residuals (Opcode 8) select spatial/temporal predictors (0: left, 1: clamped gradient, 2: previous pixel, 3: temporal gradient), optional green coupling, per-channel zero masks, and bounded canonical prefix codes (max code length 9, 512-entry lookup) optionally bucketed by causal neighbor activity.
Adaptive outer framing & CBR/VBR budgeting (255)
Setting header byte 7 to 255 activates adaptive packets. Each packet prefixes a u32 physical length L and a u32 active body length U (), zero-padding any remainder. Residual tables reset before every nonempty adaptive picture. The first body byte selects:
| Body Tag | Representation |
|---|---|
0..4 |
Fixed-quantization picture within the adaptive stream |
5 |
Exact alpha + bilinearly interpolated color anchor grid |
6 |
Exact alpha + constant solid RGB word |
7 |
Exact alpha + unchanged RGB reference (delta only) |
8 |
Exact alpha + motion-compensated / intra cosine picture (Adaptive pictures) |
9 |
Exact alpha + piecewise planar regions & sparse mask corrections |
10 |
Shared materialized key reference + optional adaptive delta patch (group start only) |
Given frames at fps and target bitrate , total byte budget is . After reserving the 32-byte header and -byte seek table from remaining payload budget , strict CBR sets physical packet size to , while VBR allocates bytes globally across complex keyframes and motion cuts without stuffing.