Skip to main content

Crate jbig2enc

Crate jbig2enc 

Source
Expand description

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.

§Modules

§Usage

For single-page lossless encoding (generic region):

use jbig2enc::encoder::encode_generic;
use leptonica::io::read_image;

let pix = read_image("input.png").unwrap();
let data = encode_generic(&pix, true, 300, 300, false).unwrap();
std::fs::write("output.jbig2", &data).unwrap();

For multi-page symbol mode encoding:

use jbig2enc::encoder::Jbig2Context;
use leptonica::io::read_image;

let mut ctx = Jbig2Context::new(0.92, 0.5, 300, 300, true, -1).unwrap();
let page = read_image("page1.png").unwrap();
ctx.add_page(&page).unwrap();

let symbol_table = ctx.pages_complete().unwrap();
let page_data = ctx.produce_page(0, None, None).unwrap();

Modules§

arith
comparator
encoder
error
symbol
wire