Rust library for encoding DjVu documents with a modern builder API. 100% working as of 1/2026.
DjVuLibRust provides a thread-safe, coordinate-based API for creating multi-page DjVu documents from image data. It supports out-of-order page processing, automatic layer masking, and optional parallel encoding.
- Coordinate-based layers: Position image layers at specific coordinates with automatic JB2/IW44 masking
- Out-of-order processing: Add pages in any sequence, even in parallel
- Thread-safe: Safe concurrent access from multiple threads
- High performance: Optimized encoding with planned SIMD and assembly ZP coder support
- Memory efficient: Stream processing with minimal memory footprint
- Builder pattern: Intuitive API for complex document construction
use djvu_encoder::{DjvuBuilder, PageBuilder};
let doc = DjvuBuilder::new(10)
.with_dpi(300)
.with_quality(90)
.build();
// Add pages (out-of-order supported)
for i in 0..10 {
let page = PageBuilder::new(i, 2480, 3508) // A4 @ 300dpi
.with_background(load_pixmap(i))
.with_foreground(load_bitmap(i), 50, 100)
.build()?;
doc.add_page(page)?;
}
let djvu_bytes = doc.finalize()?;
std::fs::write("output.djvu", djvu_bytes)?;- Pixmap: RGB/grayscale images for IW44 background layers (photos, scans)
- Bitmap: Bilevel images for JB2 foreground layers (text, graphics)
- Rust 1.70+ (2024 edition)
- Cargo
cargo build --release# Enable parallel processing
cargo build --release --features rayon
# Enable SIMD optimizations (planned - not yet finalized)
cargo build --release --features portable_simd
# Enable assembly ZP coder (planned - x86_64 only, not yet finalized)
cargo build --release --features asm_zp
# Enable IW44 debug tracing
cargo build --release --features iw44-trace| Feature | Description | Default |
|---|---|---|
rayon |
Parallel encoding using Rayon | Disabled |
portable_simd |
SIMD optimizations for encoding (planned - not finalized) | Disabled |
asm_zp |
Assembly-optimized ZP arithmetic coder (planned - not finalized) | Disabled |
iw44-trace |
Verbose IW44 encoding debug output | Disabled |
dev_asm_cmp |
Assembly vs Rust ZP comparison tests | Disabled |
doc: Main builder API (DjvuBuilder,PageBuilder)encode: Core encodersiw44: Wavelet compression for color/grayscale imagesjb2: Bilevel compression for text/graphicszc: Arithmetic coding backend
iff: DjVu file format (IFF) handlingimage: Image types (Pixel,Pixmap,Bitmap) and operationsannotations: DjVu annotation supportutils: Error handling and utilities
- Parallel processing: Rayon-based multi-threading
- Memory efficient: Stream-based encoding with minimal allocations
- Planned optimizations: SIMD acceleration and assembly ZP coder (not yet finalized)
- Rust: 1.70+ (2024 edition)
- Platforms: Linux, macOS, Windows
- Architecture: x86_64, ARM64
Licensed under the GPL3 License. See LICENSE for details.
Contributions welcome! Please see CONTRIBUTING.md for guidelines.