1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
//! # Synthetic CCITT and JBIG2 codestreams for the bilevel adapters' tests
//!
//! **GENERATED FILE — do not hand-edit.** Regenerate with:
//!
//! ```text
//! python tools/gen-bilevel-fixtures.py
//! ```
//!
//! ## Provenance (docs/LEGAL.md §5)
//!
//! Every byte array below was produced on a developer machine by
//! `tools/gen-bilevel-fixtures.py` from a **16 x 4 pixel pattern authored
//! for this project**. Nothing here was downloaded. This matters more
//! than usual for these two codecs: the obvious sources — pdf.js's and
//! PDFBox's CCITT/JBIG2 regression suites, and the public JBIG2 test
//! streams — are all third-party files of unknown provenance, which
//! `LEGAL.md` §5 forbids outright. Generating them is not a convenience,
//! it is the only permitted route.
//!
//! - **CCITT**: encoded by **libtiff** (through Pillow 12.1.0's TIFF
//! writer, `compression='group3'`/`'group4'`) and lifted out of the
//! resulting file's strip. A TIFF strip compressed with tag 259 = 3 or
//! 4 *is* a CCITT Group 3/4 bit stream, so no transcoding happens.
//! - **JBIG2**: assembled segment by segment from T.88 clause 7's layout,
//! carrying the Group 4 payload above as an MMR generic region
//! (§6.2.6 defines MMR coding as T.6). There is no pure-Python JBIG2
//! encoder, and `hayro-jbig2` publishes no test vectors — its crate
//! package excludes `/tests/`.
//!
//! ## The polarity derivation these fixtures rest on
//!
//! libtiff's fax codec is purely bit-based: it codes runs of 0 bits as
//! T.4 "white" and runs of 1 bits as T.4 "black", irrespective of the
//! PhotometricInterpretation tag. Pillow packs a mode-`'1'` white pixel
//! as a 1 bit. So a T.4 white run corresponds to a Pillow **black**
//! pixel, and — since `/BlackIs1` defaults to false, making a T.4 white
//! run decode to sample 1 — the decoded PDF samples are the complement
//! of Pillow's raw bitmap. The generator therefore builds the source
//! image as the *visual complement* of the picture these fixtures
//! represent.
//!
//! That derivation is asserted, not assumed: [`BILEVEL_16X4_SAMPLES`] is
//! the byte-exact expected output and every fixture here is checked
//! against it.
//!
//! ## Why byte arrays rather than files
//!
//! Hermetic tests, exactly as in the sibling `fixtures` module: embedding
//! the bytes means the tests run identically from any working directory,
//! under `cargo test`, under `cargo fuzz`, and in a `wasm32` check.
// Shared by TWO test suites — `pdfcer-core`'s codec tests and
// `pdfcer-render`'s rasterizer tests (which pull this file in with
// `#[path]`) — and neither uses the whole set.
/// The expected decoded samples for every fixture in this file:
/// 16 x 4, one bit per sample, **PDF convention (0 = black)**, rows
/// padded to the 2-byte stride.
///
/// Table 11's `BlackIs1` describes 1-means-black as "the reverse of the
/// normal PDF convention for image data", and its default is **false** —
/// so with no `/BlackIs1` entry the filter must emit 0 for a black pixel.
/// With DeviceGray's default `Decode [0 1]` at 1 bit per component,
/// sample 0 maps to grey 0.0, which is black. This constant is that rule
/// made byte-exact.
///
/// All three CCITT fixtures and the JBIG2 fixture must decode to exactly
/// these bytes. That the two codecs agree is the point: CCITT reaches it
/// through `/BlackIs1` false -> `invert_black` false, JBIG2 through the
/// unconditional inverse of T.88's "1 is black", and the two routes have
/// nothing in common but the answer.
pub const BILEVEL_16X4_SAMPLES: & = &;
/// The same picture with **1 = ink**, i.e. the exact bitwise complement
/// of [`BILEVEL_16X4_SAMPLES`].
///
/// This is what `/BlackIs1 true` must produce — Table 11's "1 bits shall
/// be interpreted as black pixels" — so the pair pins the polarity from
/// both sides. A decoder with the flag wired backwards passes neither.
pub const BILEVEL_16X4_INK: & = &;
/// Group 4 (pure two-dimensional, T.6) — Table 11's **K < 0**.
///
/// Encoded by libtiff via Pillow (`compression='group4'`) and lifted out
/// of the TIFF strip; see `tools/gen-bilevel-fixtures.py` for the
/// polarity derivation that makes the source image the visual complement
/// of the decoded picture. libtiff terminates a Group 4 strip with EOFB,
/// so this fixture also exercises `EndOfBlock`'s default of **true**.
///
/// This same byte string is reused as the MMR payload of
/// [`JBIG2_MMR_16X4`], because T.88 §6.2.6 codes an MMR generic region
/// with exactly T.6.
pub const CCITT_G4_16X4: & = &;
/// Group 3 one-dimensional (T.4 §4.1) — Table 11's **K = 0**, the
/// default encoding scheme.
///
/// libtiff writes an EOL pattern before each line, so this fixture also
/// covers `EndOfLine`. Table 11 says the filter "shall always accept
/// end-of-line bit patterns" whatever the flag says, and `hayro-ccitt` is
/// unconditionally lenient about them — which is why the same bytes
/// decode identically with `/EndOfLine` absent, true, or false.
pub const CCITT_G3_1D_16X4: & = &;
/// Group 3 mixed one- and two-dimensional (T.4 §4.2) — Table 11's
/// **K > 0**.
///
/// Produced by setting TIFF tag 292 (T4Options) bit 0, libtiff's switch
/// for 2-D coding. Each line carries a tag bit saying whether it was
/// coded 1-D or 2-D, which is the structural difference from
/// [`CCITT_G3_1D_16X4`] and the reason `K` must be trichotomous rather
/// than boolean. Table 11 also forbids distinguishing between different
/// positive `K` values, so this fixture must decode identically for
/// `/K 1`, `/K 4` and `/K 40`.
pub const CCITT_G3_2D_16X4: & = &;
/// A complete **embedded** JBIG2 stream (T.88 Annex D.3): a page
/// information segment followed by an immediate generic region segment,
/// MMR-coded, with no `/JBIG2Globals` needed.
///
/// Assembled byte by byte in `tools/gen-bilevel-fixtures.py` from T.88
/// clause 7's segment layout, carrying [`CCITT_G4_16X4`] as its MMR
/// payload — legal because §6.2.6 defines MMR coding as T.6. There is no
/// pure-Python JBIG2 encoder and every available JBIG2 test corpus is
/// third-party (`docs/LEGAL.md` §5), so assembling one is not a shortcut
/// but the only permitted route.
///
/// It must decode to [`BILEVEL_16X4_SAMPLES`] — the same bytes the CCITT
/// fixtures produce. T.88 §6.2.6 fixes MMR black at bitmap value 1 and
/// PDF's convention is the opposite, so the adapter's unconditional
/// inversion is exactly what makes the two agree.
pub const JBIG2_MMR_16X4: & = &;
/// The page information segment of [`JBIG2_MMR_16X4`], **alone** — the
/// shape a `/JBIG2Globals` stream has (Table 12: "a stream containing the
/// JBIG2 global segments").
///
/// Paired with [`JBIG2_MMR_16X4_PAGE`]. Neither half decodes on its own:
/// the globals carry no region to draw, and the page carries no geometry
/// to draw it on. That is what makes the pair a real test of Table 12's
/// plumbing rather than a decoration — a decoder that silently ignored
/// `/JBIG2Globals` would fail with "missing page information" rather than
/// produce a wrong picture.
pub const JBIG2_MMR_16X4_GLOBALS: & = &;
/// The immediate generic region segment of [`JBIG2_MMR_16X4`], **alone**.
///
/// The image-stream half of the `/JBIG2Globals` pair. Decoding it without
/// [`JBIG2_MMR_16X4_GLOBALS`] must fail cleanly (no page information
/// segment); decoding it *with* them must produce
/// [`BILEVEL_16X4_SAMPLES`].
pub const JBIG2_MMR_16X4_PAGE: & = &;