Encoder/decoder for Apple's deepmap2 image buffer compression format, written in Rust.
Supports gray/RGB/RGBA pixel formats and the None, Default (LZFSE), Lossless (YCC + LZFSE), and Palette compression modes. All 16-bit formats (0x11–0x14, half-float pixels — .car EDR icons) decode via both Lossless and Default; the decoder returns the rendition's native depth (little-endian u16 per channel), byte-identical to vImageDeepmap2Decode — downconverting to 8-bit is the caller's choice (Apple's CoreUI serves these renditions as 8-bit sRGB CGImages, ≈ clamp(half, 0, 1) * 255). The type-2 ENCODER replicates Apple's pipeline exactly (quantization, YCoCg lanes, logf-cost prediction-mode selection, residual coding, tiling — all formats, both qualities), and the LZFSE entropy stage is an in-tree port of Apple's compressor matching libcompression's variant of it. Together these make whole encoded streams byte-identical to vImageDeepmap2Encode for every tile that reaches the LZFSE path (≥ 4096 raw bytes); smaller tiles use raw LZVN, where the match finder still differs, so the compressed bytes differ but decode identically. The goal is a library bug-for-bug compatible with Apple's solution, independent of their system/software.
Implementation almost entirely autogenerated.
See deepmap2.md for the image format details.
use libdm2::{dm2_encode_auto, dm2_decode, ImageInfo, PixelFormat};
let info = ImageInfo { width: w, height: h, format: PixelFormat::Rgba8 };
let encoded = dm2_encode_auto(&pixels, &info)?;
let mut out = vec![0u8; (w * h * 4) as usize];
let mut info_out = info.clone();
dm2_decode(&encoded, &mut out, &mut info_out)?;A C ABI is also exported (dm2_encode, dm2_decode, dm2_encode_file, dm2_decode_file, dm2_free, …). Build with cargo build --release to produce both librlibdm2.a and the cdylib.
- Rust (edition 2021), no external dependencies. LZFSE and LZVN are implemented in-tree: the LZFSE container codec is a faithful port of Apple's open-source lzfse (byte-identical output, validated against the native library), LZVN is a compatible reimplementation.