decode
fun decode(data: ByteArray, globals: ByteArray?, width: Int, height: Int, cancellationCheck: () -> Unit? = null): ByteArray?(source)
Decode data (the /JBIG2Decode stream) with optional globals into a 1bpp bitmap of width by height pixels. Rows are packed MSB first and padded to a whole byte, and a set bit is white.
Returns null when the stream is damaged or uses a feature this decoder lacks, and when width or height is not positive or the page would pass 2^28 pixels. The input size says little about the page, because a blank scanned page takes a few dozen bytes, so only the pixel ceiling applies.
cancellationCheck, when given, runs before each segment and every 64 rows of a generic region, and may throw to stop a decode whose result no longer matters; what it throws comes out of this call as it is.