encode

fun encode(input: ByteArray, k: Int, options: CcittOptions): ByteArray(source)

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.

decode with the same k and options returns input with its padding cleared. The other options set the framing, as PDF's CCITTFaxDecode names it:

  • CcittOptions.encodedByteAlign starts each row on a byte, its EOL included in Group 3. Group 4 pads after each row, and the end of block then starts on a byte too.

  • CcittOptions.endOfLine writes an EOL before each Group 3 row. T.6 has no EOL, so Group 4 refuses it.

  • CcittOptions.endOfBlock ends the data with EOFB in Group 4 and with RTC in Group 3, which lets a reader that is given no row count find the end.

The last byte is padded with zero bits.

Throws

if CcittOptions.columns is outside 1 to 65536, if CcittOptions.rows is negative or input holds fewer rows, or if k is negative and CcittOptions.endOfLine is set