jbig2enc
A Rust reimplementation of jbig2enc, a JBIG2 encoder for bi-level (1 bpp) images.
JBIG2 is a compression standard for bi-level images that achieves better compression ratios than G4 (CCITT Group 4) through symbol extraction and dictionary-based reuse. It is commonly used for embedding scanned document images into PDFs.
This crate provides both a library API and a command-line tool. Written entirely in Rust with no C/C++ dependencies -- the image processing foundation leptonica is also a pure Rust reimplementation, so the entire toolchain builds with cargo alone.
Installation
Library
[]
= "0.1"
To use only as a library without the CLI binary:
[]
= { = "0.1", = false }
CLI
Library Usage
Single-page lossless encoding (generic region):
use encode_generic;
use read_image;
let pix = read_image.unwrap;
let data = encode_generic.unwrap;
write.unwrap;
Multi-page symbol mode encoding:
use Jbig2Context;
use read_image;
let mut ctx = new.unwrap;
let page = read_image.unwrap;
ctx.add_page.unwrap;
let symbol_table = ctx.pages_complete.unwrap;
let page_data = ctx.produce_page.unwrap;
Modules
arith-- QM arithmetic coder, the core entropy coding enginecomparator-- Symbol template equivalence detectionencoder-- Multi-page compression context and generic region encodingerror-- Error typessymbol-- Symbol dictionary and text region encodingwire-- JBIG2 wire format structures
CLI Usage
# Single-page generic encoding (output to stdout)
# Symbol mode with PDF-ready output
# Multi-page symbol mode
# With duplicate line removal
# Custom threshold and DPI
Run jbig2enc --help for the full list of options.
Feature Flags
| Feature | Default | Description |
|---|---|---|
cli |
Yes | Builds the jbig2enc command-line binary (depends on clap) |
Minimum Supported Rust Version
Rust 2024 edition (1.87+).
License
This project is distributed under the Apache License 2.0, the same license as the original jbig2enc.
Acknowledgments
This project relies on the source code and design of the original C++ jbig2enc by Adam Langley. It also depends on leptonica as its image processing foundation, which in turn is a reimplementation of Leptonica by Dan Bloomberg.
How This Project Is Built
The porting work is carried out primarily by AI coding agents, including Claude Code. A human maintainer defines the overall architecture, process rules, and acceptance criteria, while the agents read the original C++ source, write Rust code, and run tests under those constraints. Every commit goes through CI and automated review before merging.