CcittFax

CCITT fax decoding and encoding. Bilevel scan-world compression: there is no standalone container/magic for it, so this is a parameterized codec API, not part of io.github.yuroyami.imagekodec.ImageKodec.decode's sniffing.

A page is 1 bit per pixel, packed MSB-first, padded to a byte boundary per row; polarity follows CcittOptions.blackIs1. decode returns one and encode takes one.

Functions

Link copied to clipboard
fun decode(input: ByteArray, k: Int, options: CcittOptions): ByteArray

Decode with the mode selection PDF's /K uses: negative = pure 2D (Group 4, T.6), zero = pure 1D (Group 3, T.4), positive = mixed 1D/2D (Group 3, T.4). Positive values share the per-row mode-tag interpretation specified by PDF; their numerical cadence is not enforced.

Link copied to clipboard
fun encode(input: ByteArray, k: Int, options: CcittOptions): ByteArray

Encode input, a page laid out as decode returns one: rows of CcittOptions.columns pixels, packed MSB first and padded to a whole byte, a set bit black when CcittOptions.blackIs1 and white otherwise. The padding bits are ignored. CcittOptions.rows rows are written, or every whole row input holds when it is 0. k selects the coding as decode reads it: negative is Group 4 (T.6), zero is Group 3 one-dimensional (T.4 Modified Huffman), and a positive k is Group 3 two-dimensional, each 1D row followed by up to k - 1 rows coded against the row above.