justbig2
Pure Rust JBIG2 image decoder with no_std support.
Decodes JBIG2 (ITU T.88) compressed bi-level images used in PDF documents, fax transmissions, and document archival systems.
Features
- Full JBIG2 decoding — Generic, Text, Halftone, Refinement regions
- Arithmetic & MMR coding — QM arithmetic decoder + CCITT Group 4
- Symbol dictionaries — Glyph reuse across pages
- Streaming API — Feed data incrementally or all at once
no_stdcompatible — Usesalloconly, no OS dependencies- Zero unsafe code — Pure safe Rust
Quick Start
Add to your Cargo.toml:
[]
= "0.1"
Decode a JBIG2 file:
use ;
let data = read.unwrap;
let pages = decode.unwrap;
for page in &pages
API
One-shot decoding
// Full JBIG2 file (with file header)
let pages = decode?;
// Embedded stream (no file header, used in PDF)
let pages = decode_embedded?;
Streaming decoder
use Decoder;
let mut decoder = new;
// Feed data in chunks
decoder.write?;
decoder.write?;
// Retrieve completed pages
while let Some = decoder.page
Page struct
// Get individual pixel (0 = white, 1 = black)
let pixel = page.get_pixel;
Supported Segment Types
| Type | Segment | Status |
|---|---|---|
| 0 | Symbol Dictionary | Supported |
| 4, 6, 7 | Text Region | Supported (arithmetic) |
| 16 | Pattern Dictionary | Supported |
| 20, 22, 23 | Halftone Region | Supported |
| 38, 39 | Generic Region | Supported |
| 40, 42, 43 | Refinement Region | Supported |
| 48 | Page Information | Supported |
| 49, 50, 51 | End of Page/Stripe/File | Supported |
| 52 | Profile | Parsed (informational) |
| 53 | Code Table | Supported |
| 62 | Extension | Parsed (comments) |
Limitations
- Huffman-coded text regions — Only arithmetic coding path is implemented. Arithmetic coding is used by the vast majority of real-world JBIG2 files.
- Color Palette segments (type 54) — Not implemented. Defined in the spec but rarely used in practice.
- Intermediate Generic Region (type 36) — Not implemented. Not seen in real-world files.
- 12 adaptive template pixels (T.88 amendment 2) — Not supported.
- Colored region segments (T.88 amendment 3) — Not supported.
Minimum Supported Rust Version
The MSRV is 1.56.0 (Rust edition 2021).
no_std Usage
Disable the default std feature:
[]
= { = "0.1", = false }
The library uses alloc for Vec and String. The std::error::Error impl is only available with the std feature.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.