Developed by: Greg Lamberson, Lamco Development (https://www.lamco.ai/) Contact: greg@lamco.io
This is a reference implementation of JPEG XL (ISO/IEC 18181) in Rust, based on the official libjxl C++ implementation (v0.11.1).
Reference Repository: https://github.com/libjxl/libjxl This Repository: https://github.com/lamco-admin/jxl-rust-reference
The implementation is structured as a Cargo workspace with the following crates:
- Purpose: Fundamental types and error handling
- Key Components:
JxlErrorandJxlResulttypesImageandImageBufferstructures- Color encoding types (
ColorEncoding,ColorChannels) - Pixel types (
PixelType,Sampletrait) - Image metadata structures
- Constants and configuration
- Purpose: Bitstream reading/writing and entropy coding
- Key Components:
BitReaderandBitWriterfor bit-level I/O- ANS (Asymmetric Numeral Systems) encoder/decoder
- Huffman coding support
- Algorithms: Implements the ANS entropy coding used in JPEG XL for efficient compression
- Purpose: Color space transformations
- Key Components:
- XYB color space (JPEG XL's perceptual color space)
- sRGB ↔ Linear RGB conversions
- Color correlation transforms (YCoCg)
- Details: XYB is a perceptual color space designed to be more uniform than RGB
- Purpose: Image transformations
- Key Components:
- DCT (Discrete Cosine Transform) - 8x8 blocks
- Prediction modes (Left, Top, Average, Paeth, Gradient)
- Quantization for lossy compression
- Algorithms: Implements DCT-II (forward) and DCT-III (inverse)
- Purpose: Header parsing and generation
- Key Components:
JxlHeaderstructure- Bitstream signature validation
- Metadata parsing
- Purpose: JPEG XL decoding pipeline
- Key Components:
JxlDecodermain API- Frame decoding
- Integration with all transform and color components
- Process:
- Parse header
- Decode entropy-coded bitstream (ANS)
- Dequantize coefficients
- Apply inverse DCT
- Convert from XYB to RGB color space
- Purpose: JPEG XL encoding pipeline
- Key Components:
JxlEncodermain APIEncoderOptionsfor quality/effort control- Frame encoding
- Process:
- Convert RGB to XYB color space
- Apply DCT transformation
- Quantize coefficients (lossy mode)
- Entropy encode using ANS
- Write header and bitstream
- Purpose: High-level API
- Exports: All public types and functions from sub-crates
- Documentation: Main entry point with examples
┌─────────────────────┐
│ Signature (0x0AFF)│
├─────────────────────┤
│ Size Header │
├─────────────────────┤
│ Image Header │
├─────────────────────┤
│ Frame Data │
│ - DC Groups │
│ - AC Groups │
└─────────────────────┘
-
Bitstream Format:
- Variable-length encoding for dimensions
- Bit depth support (8, 10, 12, 16, 32-bit)
- Multiple channel support (1-4 channels)
-
Color Spaces:
- sRGB (with gamma correction)
- Linear sRGB
- XYB (perceptual color space)
-
Compression:
- ANS entropy coding
- DCT transformation (8x8 blocks)
- Quantization with quality parameter
- Prediction modes
-
Image Features:
- Multiple pixel types (u8, u16, f32)
- Orientation metadata
- Animation support (structure in place)
- ✅ Core types and error handling
- ✅ Bitstream reader/writer
- ✅ ANS entropy coding
- ✅ Huffman coding
- ✅ XYB color space transforms
- ✅ sRGB transforms
- ✅ Color correlation
- ✅ DCT (8x8)
- ✅ Prediction modes
- ✅ Quantization
- ✅ Header parsing/writing
- ✅ Basic encoder/decoder framework
⚠️ Frame decoding (simplified for reference)⚠️ DC/AC group processing (basic implementation)⚠️ Parallel processing hooks (rayon dependency in place)
- ❌ Full DC group processing (2048x2048 regions)
- ❌ Full AC group processing (256x256 regions)
- ❌ Adaptive quantization
- ❌ Noise synthesis
- ❌ Patches
- ❌ Splines
- ❌ Progressive decoding
- ❌ Animation playback
- ❌ JPEG reconstruction mode
- ❌ Full ICC profile support
- ❌ EXIF/XMP metadata handling
- Parallelism: Uses Rayon for potential multi-threading
- Memory: Zero-copy where possible
- SIMD: Could be added for DCT and color transforms
Run tests with:
cargo test --allBuild examples:
cargo build --examplesRun example:
cargo run --example encode_decode- JPEG XL Official Site
- libjxl Reference Implementation
- ISO/IEC 18181:2022 Standard
- JPEG XL Whitepaper
BSD 3-Clause License (matching libjxl)