Expand description
Pure-Rust DjVu decoder written from the DjVu v3 public specification.
This crate implements the full DjVu v3 document format in safe Rust, including IFF container parsing, JB2 bilevel decoding, IW44 wavelet decoding, BZZ decompression, text layer extraction, and annotation parsing. All algorithms are written from the public DjVu spec with no GPL code.
§Key public types
DjVuError— top-level error enum (wrapsIffError, etc.)IffError— errors from the IFF container parserPageInfo— page metadata parsed from the INFO chunkRotation— page rotation enum (None, Ccw90, Rot180, Cw90)DjVuDocument— high-level document model (IFF/BZZ/IW44 based)DjVuPage— lazy page handleDjVuBookmark— NAVM bookmark (table of contents)DocError— error type for the document modeldjvu_render::RenderOptions— render parametersdjvu_render::RenderError— render pipeline error typetext::TextLayer— text layer from TXTz/TXTa chunkstext::TextZone— a zone node in the text layer hierarchyannotation::Annotation— page-level annotationannotation::MapArea— clickable area with URL and shapePixmap— RGBA pixel buffer returned by render methodsBitmap— 1-bit bitmap for JB2 mask layersDocument— owned DjVu document (high-level std API, requires std feature)Page— a page within aDocument
§Quick start
use djvu_rs::Document;
let doc = Document::open("file.djvu").unwrap();
println!("{} pages", doc.page_count());
let page = doc.page(0).unwrap();
println!("{}x{} @ {} dpi", page.width(), page.height(), page.dpi());
let pixmap = page.render().unwrap();
// pixmap.data: RGBA bytes§IFF parser
use djvu_rs::iff::parse_form;
let data = std::fs::read("file.djvu").unwrap();
let form = parse_form(&data).unwrap();
println!("form type: {:?}", std::str::from_utf8(&form.form_type));Re-exports§
pub use bzz as bzz_new;pub use iw44 as iw44_new;pub use error::DjVuError;pub use djvu_document::ComponentDirectoryEntry;pub use djvu_document::ComponentId;pub use djvu_document::ComponentKind;pub use djvu_document::ComponentResolveError;pub use djvu_document::ComponentResolver;pub use djvu_document::DjVuBookmark;pub use djvu_document::DjVuDocument;pub use djvu_document::DjVuPage;pub use djvu_document::DocError;pub use editor::DocumentEditor;pub use editor::EDIT_SCHEMA_VERSION;pub use editor::EditError;pub use editor::EditOperation;pub use editor::EditOperationKind;pub use editor::EditPlan;pub use editor::EditRequest;pub use editor::EditTarget;pub use editor::PlannedEdit;pub use component_graph::ComponentGraph;pub use component_graph::ComponentNode;pub use component_graph::ComponentNodeKind;pub use component_graph::GraphError;pub use semantic_diff::PlaneDiff;pub use semantic_diff::PlaneStatus;pub use semantic_diff::SemanticDiff;pub use semantic_diff::semantic_diff;pub use resource_limits::DEFAULT_MAX_RENDER_PIXELS;pub use resource_limits::ParseOptions;pub use resource_limits::ResourceLimitAxis;pub use resource_limits::ResourceLimitExceeded;pub use resource_limits::ResourceLimits;pub use validate::Finding;pub use validate::Layer as ValidationLayer;pub use validate::ResourceEstimate;pub use validate::Severity;pub use validate::ValidateOptions;pub use validate::ValidationReport;pub use validate::ValidationSummary;pub use export_control::ExportObserver;pub use export_control::NoOpObserver;pub use text::TextLayer;pub use text::TextZone;pub use text::TextZoneKind;
Modules§
- annotation
- Annotation parser for DjVu ANTz/ANTa chunks — phase 4.
- bzz
- BZZ decompressor — clean-room implementation.
- bzz_
encode - BZZ compressor — encoding counterpart to
bzz. Backwards-compatible BZZ compressor module. - cbz
- DjVu to CBZ (comic book archive) exporter.
- chunk_
encode - Chunk-encoder seam — one
(id, payload)interface (chunk_encode::ChunkEncoder) over the per-chunk encoders, with a singlechunk_encode::EncodeErrordiscipline (no panic, no silent truncation). Chunk-encoder seam — one(id, payload)interface over the per-chunk encoders. - component_
graph - Validated dependency graph for bundled
FORM:DJVMcomponents. Validated dependency graph for bundledFORM:DJVMdocuments. - djvm
- DJVM document merge and split operations. DJVM document merge and split operations.
- djvu_
async - Async render surface for
DjVuPage— phase 5 extension. - djvu_
document - New document model — phase 3.
- djvu_
encode - High-level page encoder — composes the codec primitives into a
complete
FORM:DJVUpage. - djvu_
mut - In-place document mutation — byte-preserving rewrite primitive (PR1 of #222).
- djvu_
render - Rendering pipeline for
DjVuPage— phase 5. - djvu_
tile - Tile-first rendering API for viewer engines (#691).
- editor
- Versioned, typed document editing operations with validation and atomic output handoff. Typed, validated document editing operations.
- epub
- DjVu to EPUB 3 exporter.
- error
- Typed error hierarchy for the new implementation (phase 1).
- export_
async - Async adapters for the synchronous PDF and DJVM streaming writers. Async adapters for the synchronous streaming export writers.
- export_
control - Shared progress reporting and cooperative cancellation for export writers. Shared progress reporting and cooperative cancellation for export writers.
- ffi
- C FFI bindings for foreign language integration.
- fgbz_
encode - FGbz foreground-palette encoder — produces FGbz chunk payloads.
- iff
- IFF container parser (phase 1, written from spec). Backwards-compatible IFF module.
- image_
compat image::ImageDecoderintegration — allows DjVu pages to be used as first-class image sources in theimagecrate ecosystem.- ingest
- Encoder ingest policy — alpha, bit-depth down-conversion, and related knobs
(#694). See
docs/encoder-ingestion.mdfor the supported input matrix. Encoder input normalization policy (#694). - iw44
- IW44 wavelet image decoder — clean-room implementation (phase 2c).
- iw44_
encode - IW44 wavelet encoder — produces BG44/FG44/TH44 chunk payloads.
- jb2
- JB2 bilevel image decoder — clean-room implementation.
- jb2_
encode - JB2 bilevel image encoder — produces Sjbz chunk payloads.
- metadata
- Document metadata parser for METa/METz chunks — phase 4 extension.
- navm_
encode - NAVM bookmark encoder — serializes
djvu_document::DjVuBookmarktrees to BZZ-compressed binary. NAVM bookmark encoder. - ocr
- Pluggable OCR backend trait and error types.
- ocr_
neural - Experimental neural OCR placeholder (requires
ocr-neuralfeature). Experimental neural OCR placeholder (requiresocr-neuralfeature). - ocr_
onnx - Experimental ONNX OCR helper via tract (requires
ocr-onnxfeature). Experimental ONNX OCR via tract (requiresocr-onnxfeature). - ocr_
tesseract - Tesseract OCR backend (requires
ocr-tesseractfeature). Tesseract OCR backend (requiresocr-tesseractfeature). - optimizer
- High-level document optimization planning and safe structural cleanup. Document-level optimization planning, safe lossless cleanup and quality-aware archival re-encoding.
- DjVu to PDF converter — phase 6.
- png_io
- PNG file →
Pixmapdecoder. - quality
- Perceptual image-quality metrics (PSNR, SSIM) for render experiments.
- render_
cache - Process-wide ceiling for the page render caches (READ_CACHE_BOUNDED).
- resource_
limits - Shared configurable resource limits for parse, render, and validate. Configurable resource limits shared by validation, parse, and render entry points.
- segment
- Photometric foreground/background segmentation — splits an RGBA page into a bilevel ink mask and a sub-sampled background pixmap.
- semantic_
diff - Semantic comparison of two documents (#696): page properties, text, annotations, metadata, bookmarks, and the component graph. Semantic comparison of two DjVu documents (#696).
- smmr
- Smmr chunk codec — ITU-T G4 (MMR) bilevel image compression.
- text
- DjVu text layer — data model and parser.
- text_
encode - TXTa/TXTz text layer encoder — writes
text::TextLayerback to DjVu binary format. TXTa/TXTz text layer encoder. - text_
serialize - hOCR and ALTO XML serialization for the text layer.
- thumbnail
- TH44 thumbnail generation for multi-page bundles.
- tiff_
export - DjVu to TIFF exporter — phase 4 format extension.
- validate
- Layered, non-rendering DjVu document validation.
- wasm
- WebAssembly bindings for djvu-rs.
Structs§
- Bitmap
- A 1-bit-per-pixel packed bitmap image.
- Document
- A parsed DjVu document. Owns the parsed structure.
- Gray
Pixmap - An 8-bit grayscale image, 1 byte per pixel.
- Page
- A page within a DjVu document.
- Page
Info - Metadata from the INFO chunk of a DjVu page.
- Pixmap
- An RGBA pixel image, 4 bytes per pixel.
Enums§
- BzzError
- BZZ compression decoding errors.
- Error
- Original error type used by the legacy implementation.
- IffError
- Errors that can occur while parsing the IFF container.
- Iw44
Error - IW44 wavelet image decoding errors.
- Jb2Error
- JB2 bitonal image decoding errors.
- Pixmap
Error - Why
Pixmap::try_newrefused to allocate. - Rotation
- Page rotation encoded in INFO flags bits 0–1.
- Thumbnail
Strategy - Policy for
Document::thumbnails_with_strategy: how to source each page’s thumbnail.