Skip to main content

encode_generic

Function encode_generic 

Source
pub fn encode_generic(samples: &[u8], width: u32, height: u32) -> Vec<u8> ⓘ
Expand description

Encodes 1-bit samples as a lossless JBIG2 generic region.

samples holds height rows of width pixels, one bit per pixel, MSB first, each row padded to a whole byte (the PDF image sample layout, ISO 32000-2 §8.9.3). Bits past the end of samples read as 0.

The output is a complete /JBIG2Decode stream in the embedded organisation (T.88 Annex D.3): a page-information segment for a width x height page, then one immediate lossless generic-region segment covering it (template 0, typical prediction on, nominal AT pixels, MQ coding). It needs no /JBIG2Globals, so no /DecodeParms. A PDF sample 1 is coded as a JBIG2 0 (white), so the decoded samples equal samples and the image keeps its /Decode. The image needs /BitsPerComponent 1 and /Width and /Height equal to width and height, and must be an XObject: §7.4.7 does not allow the filter on an inline image.

§Examples

use pdfcer_image_codec::jbig2::encode_generic;

let stream = encode_generic(&[0xFF, 0x00], 8, 2);
// Segment 0 is the page information, type 48.
assert_eq!(&stream[..5], &[0, 0, 0, 0, 48]);
assert!(stream.ends_with(&[0xFF, 0xAC]));