Jbig2Decoder

A pure-Kotlin JBIG2 decoder (ITU-T T.88) covering the flavours PDFs use for scanned and OCR'd bilevel images. Produces a 1-bit-per-pixel bitmap. JBIG2 carries no magic bytes and no dimensions of its own, so it is not part of the KiteImage.decode sniff path; call this directly with the size the container declared.

Scope: the MQ arithmetic decoder (Annex E), arithmetic integer decoding (Annex A), generic region decoding (6.2, templates 0-3 + TPGDON), MMR-coded regions via the shared CCITT G4 core (6.2.6), generic refinement (6.3, templates 0/1 + TPGRON), symbol dictionary (6.5, arithmetic and Huffman, single-instance refinement/aggregation), text region (6.4, arithmetic and Huffman, with symbol refinement), pattern dictionary (6.7), halftone regions (6.6), the standard Huffman tables B.1-B.15 and custom code table segments (7.4.13). NOT handled: Huffman symbol dicts with refinement, and multi-instance aggregate coding, which emit blank symbols. Values here follow the T.88 reference tables.

Functions

Link copied to clipboard
fun decode(data: ByteArray, globals: ByteArray?, width: Int, height: Int): ByteArray?

Decode data (the /JBIG2Decode stream) with optional globals into a 1bpp bitmap.