img_jbig2#
JBIG2 decoder -- crate root lib/img_jbig2/src/lib.rs
img_jbig2 -- JBIG2 decoder (ITU-T T.88 | ISO/IEC 14492): bilevel images as PDF embeds them
(JBIG2Decode, with its JBIG2Globals) and JBIG2 files
decode_embedded(data, globals, &Options) -> Bitmap / Error PDF's JBIG2Decode: page 1
decode_file(data, &Options) -> Vec<Bitmap> / Error a .jb2 / .jbig2 file: every page
probe(data) -> bool the file header's id
Bitmap { width, height, stride, bits } 1 = black, MSB first, rows
padded to bytes
CODEC img_core's codec (page 1 as an
8-bit ARGB surface) for img_all
Modules: mq (the arithmetic decoder, integer decoding), huff (the Huffman tables), mmr (T.6),
bitmap (images and combination operators), generic (generic and refinement regions), symbol
(symbol dictionaries, text regions), halftone (pattern dictionaries, halftone regions).
What it decodes: every segment type of a page -- page information (striped pages, pages of
unknown height growing with their stripes, the default pixel and operator), end of stripe, end
of page, end of file, tables; symbol dictionaries (arithmetic and Huffman, refinement /
aggregate coding, collective bitmaps uncompressed or MMR, exports, contexts retained and used
again), text regions (arithmetic and Huffman, refinement, transposed, every reference corner and
combination operator), pattern dictionaries and halftone regions (MMR or arithmetic, skip,
grids at any angle), generic regions (MMR; templates 0 to 3 with adaptive pixels and TPGDON;
data of unknown length ended by its marker) and refinement regions (templates 0 and 1, TPGRON),
each intermediate, immediate or lossless; the combination operators OR, AND, XOR, XNOR and
REPLACE. The file organisations sequential and random-access.
Not here: colour (JBIG2 Amendment 3: colour palettes and coloured regions are ignored, the page
stays bilevel), extension segments. The segments are decoded once, in their order: the global
ones where they stand, a page's onto the page their association names (a file's pages may
interleave; PDF's embedded form has one page). A damaged segment ends its page with what was
decoded before it and that page's further segments are left out; the global ones and the other
pages go on. Limits (`Options::max_pixels`, symbol counts, the work of a stream: its pages' and
regions' pixels, at most four times `max_pixels` plus 2^22) refuse hostile files before they
cost memory or time, and symbol dictionaries and text regions stop where their arithmetic data
has run out (mq.rs).
img_jbig2 crate root#
enum Errorwhy a stream could not be decodedNotJbig2-- no JBIG2 file header (decode_file)Truncated-- the data ends earlyCorrupt-- a segment that breaks the standardUnsupported-- valid, but not decoded hereLimit-- larger than the limits allow (or than the memory the allocator gives)NoPage-- no page in the data
struct Optionswhat to decodemax_pixels: u64-- the largest width * height of the page and of any region
struct Bitmapa decoded page: 1 = black, MSB first,stridebytes a rowwidth: u32height: u32stride: usizebits: Vec<u8>
impl Bitmap
fn get(&self, x: u32, y: u32) -> boolthe pixel at (x, y): true for blackfn probe(d: &[u8]) -> boola JBIG2 file (its header's id)fn decode_embedded(data: &[u8], globals: Option<&[u8]>, opt: &Options) -> Result<Bitmap, Error>PDF's JBIG2Decode: the embedded segments (and those of JBIG2Globals) -> the first pagefn decode_file(data: &[u8], opt: &Options) -> Result<Vec<Bitmap>, Error>a JBIG2 file (sequential or random-access) -> its pages, in the order of their page information segments; one budget of work for the file (four timesOptions::max_pixelsplus 2^22): the pages past it are left outstatic CODEC: Codecjbig2_codec: the first page of a JBIG2 file as 8-bit ARGB (black on white)