Skip to content

Commit dc83595

Browse files
committed
Tests/LibGfx: Add JBIG2 test with > 4 referred-to segments
Up to four referred-to segments use a single byte to store referred-to segment count and retained bits. Five or more referred-to segments cause a u32 for the count to be written (with the topmost 3 bits masked out), and then one bit per referred-to segment. This adds a test case for that "five or more" case. There's a few places where this can happen, but the most natural seems like a text segment referring to a bunch of symbol segments, so the test is that. The json file is basically bitmap-symbol-symhuff-texthuff.json, but with huffman coding disabled, superfluous flags removed, and with one dedicated symbol region per symbol. This jbig2 file, when run through Meta/jbig2_to_pdf.py, decodes fine in Preview.app and Acrobat Reader (I only checked on mobile). PDFium, pdf.js, and mutool all can't decode it.
1 parent 96b3b0b commit dc83595

File tree

3 files changed

+244
-0
lines changed

3 files changed

+244
-0
lines changed

Tests/LibGfx/TestImageDecoder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ TEST_CASE(test_jbig2_decode)
374374
TEST_INPUT("jbig2/bitmap-halftone-10bpp.jbig2"sv),
375375
TEST_INPUT("jbig2/bitmap-halftone-10bpp-mmr.jbig2"sv),
376376
TEST_INPUT("jbig2/bitmap-symbol.jbig2"sv),
377+
TEST_INPUT("jbig2/bitmap-symbol-manyrefs.jbig2"sv),
377378
TEST_INPUT("jbig2/bitmap-symbol-negative-sbdsoffset.jbig2"sv),
378379
TEST_INPUT("jbig2/bitmap-symbol-symhuff-texthuff.jbig2"sv),
379380
TEST_INPUT("jbig2/bitmap-symbol-symhuffB5B3-texthuffB7B9B12.jbig2"sv),
586 Bytes
Binary file not shown.
Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
{
2+
"global_header": {
3+
"organization": "sequential",
4+
"number_of_pages": 1
5+
},
6+
"segments": [
7+
{
8+
"segment_number": 0,
9+
"type": "page_information",
10+
"page_association": 1,
11+
"data": {
12+
"page_width": 399,
13+
"page_height": 400,
14+
"flags": {
15+
"is_eventually_lossless": true
16+
}
17+
}
18+
},
19+
20+
{
21+
"segment_number": 1,
22+
"type": "symbol_dictionary",
23+
"page_association": 1,
24+
"retained": true,
25+
"data": {
26+
"height_classes": [
27+
{
28+
"symbols": [
29+
{
30+
"image_data": {
31+
"from_file": "bitmap.bmp",
32+
"crop": {
33+
"x": 60,
34+
"y": 265,
35+
"width": 10,
36+
"height": 30
37+
}
38+
}
39+
}
40+
]
41+
}
42+
]
43+
}
44+
},
45+
46+
{
47+
"segment_number": 2,
48+
"type": "symbol_dictionary",
49+
"page_association": 1,
50+
"retained": true,
51+
"data": {
52+
"height_classes": [
53+
{
54+
"symbols": [
55+
{
56+
"image_data": {
57+
"from_file": "bitmap.bmp",
58+
"crop": {
59+
"x": 70,
60+
"y": 265,
61+
"width": 20,
62+
"height": 30
63+
}
64+
}
65+
}
66+
]
67+
}
68+
]
69+
}
70+
},
71+
72+
{
73+
"segment_number": 3,
74+
"type": "symbol_dictionary",
75+
"page_association": 1,
76+
"retained": true,
77+
"data": {
78+
"height_classes": [
79+
{
80+
"symbols": [
81+
{
82+
"image_data": {
83+
"from_file": "bitmap.bmp",
84+
"crop": {
85+
"x": 50,
86+
"y": 108,
87+
"width": 30,
88+
"height": 30
89+
}
90+
}
91+
}
92+
]
93+
}
94+
]
95+
}
96+
},
97+
98+
{
99+
"segment_number": 4,
100+
"type": "symbol_dictionary",
101+
"page_association": 1,
102+
"retained": true,
103+
"data": {
104+
"height_classes": [
105+
{
106+
"symbols": [
107+
{
108+
"image_data": {
109+
"from_file": "bitmap.bmp",
110+
"crop": {
111+
"x": 135,
112+
"y": 100,
113+
"width": 100,
114+
"height": 100
115+
}
116+
}
117+
}
118+
]
119+
}
120+
]
121+
}
122+
},
123+
124+
{
125+
"segment_number": 5,
126+
"type": "symbol_dictionary",
127+
"page_association": 1,
128+
"retained": true,
129+
"data": {
130+
"height_classes": [
131+
{
132+
"symbols": [
133+
{
134+
"image_data": {
135+
"from_file": "bitmap.bmp",
136+
"crop": {
137+
"x": 232,
138+
"y": 70,
139+
"width": 120,
140+
"height": 250
141+
}
142+
}
143+
}
144+
]
145+
}
146+
]
147+
}
148+
},
149+
150+
{
151+
"segment_number": 6,
152+
"type": "text_region",
153+
"page_association": 1,
154+
"referred_to_segments": [
155+
{
156+
"segment_number": 1,
157+
"retained": false
158+
},
159+
{
160+
"segment_number": 2,
161+
"retained": false
162+
},
163+
{
164+
"segment_number": 3,
165+
"retained": false
166+
},
167+
{
168+
"segment_number": 4,
169+
"retained": false
170+
},
171+
{
172+
"segment_number": 5,
173+
"retained": false
174+
}
175+
],
176+
"data": {
177+
"region_segment_information": {
178+
"width": 399,
179+
"height": 400
180+
},
181+
"flags": {
182+
"strip_size": 2,
183+
"reference_corner": "top_left"
184+
},
185+
186+
"initial_strip_t": -2,
187+
"strips": [
188+
{
189+
"strip_t": 70,
190+
"instances": [
191+
{
192+
"instance_s": 232,
193+
"instance_t": 70,
194+
"symbol_id": 4
195+
}
196+
]
197+
},
198+
{
199+
"strip_t": 100,
200+
"instances": [
201+
{
202+
"instance_s": 135,
203+
"instance_t": 100,
204+
"symbol_id": 3
205+
}
206+
]
207+
},
208+
{
209+
"strip_t": 108,
210+
"instances": [
211+
{
212+
"instance_s": 50,
213+
"instance_t": 108,
214+
"symbol_id": 2
215+
}
216+
]
217+
},
218+
{
219+
"strip_t": 264,
220+
"instances": [
221+
{
222+
"instance_s": 60,
223+
"instance_t": 265,
224+
"symbol_id": 0
225+
},
226+
{
227+
"instance_s": 70,
228+
"instance_t": 265,
229+
"symbol_id": 1
230+
}
231+
]
232+
}
233+
]
234+
}
235+
},
236+
237+
{
238+
"segment_number": 7,
239+
"type": "end_of_page",
240+
"page_association": 1
241+
}
242+
]
243+
}

0 commit comments

Comments
 (0)