comparison mupdf-source/thirdparty/jbig2dec/jbig2_hufftab.c @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 /* Copyright (C) 2001-2023 Artifex Software, Inc.
2 All Rights Reserved.
3
4 This software is provided AS-IS with no warranty, either express or
5 implied.
6
7 This software is distributed under license and may not be copied,
8 modified or distributed except as expressly authorized under the terms
9 of the license contained in the file LICENSE in this distribution.
10
11 Refer to licensing information at http://www.artifex.com or contact
12 Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
13 CA 94129, USA, for further information.
14 */
15
16 /*
17 jbig2dec
18 */
19
20 /* predefined Huffman table definitions
21 -- See Annex B of the JBIG2 specification */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26 #include "os_types.h"
27
28 #include <stdlib.h>
29
30 #include "jbig2.h"
31 #include "jbig2_priv.h"
32 #include "jbig2_huffman.h"
33 #include "jbig2_hufftab.h"
34
35 #define JBIG2_COUNTOF(x) (sizeof((x)) / sizeof((x)[0]))
36
37 /* Table B.1 */
38 static const Jbig2HuffmanLine jbig2_huffman_lines_A[] = {
39 {1, 4, 0},
40 {2, 8, 16},
41 {3, 16, 272},
42 {0, 32, -1}, /* low */
43 {3, 32, 65808} /* high */
44 };
45
46 const Jbig2HuffmanParams jbig2_huffman_params_A = { FALSE, JBIG2_COUNTOF(jbig2_huffman_lines_A), jbig2_huffman_lines_A };
47
48 /* Table B.2 */
49 static const Jbig2HuffmanLine jbig2_huffman_lines_B[] = {
50 {1, 0, 0},
51 {2, 0, 1},
52 {3, 0, 2},
53 {4, 3, 3},
54 {5, 6, 11},
55 {0, 32, -1}, /* low */
56 {6, 32, 75}, /* high */
57 {6, 0, 0} /* OOB */
58 };
59
60 const Jbig2HuffmanParams jbig2_huffman_params_B = { TRUE, JBIG2_COUNTOF(jbig2_huffman_lines_B), jbig2_huffman_lines_B };
61
62 /* Table B.3 */
63 static const Jbig2HuffmanLine jbig2_huffman_lines_C[] = {
64 {8, 8, -256},
65 {1, 0, 0},
66 {2, 0, 1},
67 {3, 0, 2},
68 {4, 3, 3},
69 {5, 6, 11},
70 {8, 32, -257}, /* low */
71 {7, 32, 75}, /* high */
72 {6, 0, 0} /* OOB */
73 };
74
75 const Jbig2HuffmanParams jbig2_huffman_params_C = { TRUE, JBIG2_COUNTOF(jbig2_huffman_lines_C), jbig2_huffman_lines_C };
76
77 /* Table B.4 */
78 static const Jbig2HuffmanLine jbig2_huffman_lines_D[] = {
79 {1, 0, 1},
80 {2, 0, 2},
81 {3, 0, 3},
82 {4, 3, 4},
83 {5, 6, 12},
84 {0, 32, -1}, /* low */
85 {5, 32, 76}, /* high */
86 };
87
88 const Jbig2HuffmanParams jbig2_huffman_params_D = { FALSE, JBIG2_COUNTOF(jbig2_huffman_lines_D), jbig2_huffman_lines_D };
89
90 /* Table B.5 */
91 static const Jbig2HuffmanLine jbig2_huffman_lines_E[] = {
92 {7, 8, -255},
93 {1, 0, 1},
94 {2, 0, 2},
95 {3, 0, 3},
96 {4, 3, 4},
97 {5, 6, 12},
98 {7, 32, -256}, /* low */
99 {6, 32, 76} /* high */
100 };
101
102 const Jbig2HuffmanParams jbig2_huffman_params_E = { FALSE, JBIG2_COUNTOF(jbig2_huffman_lines_E), jbig2_huffman_lines_E };
103
104 /* Table B.6 */
105 static const Jbig2HuffmanLine jbig2_huffman_lines_F[] = {
106 {5, 10, -2048},
107 {4, 9, -1024},
108 {4, 8, -512},
109 {4, 7, -256},
110 {5, 6, -128},
111 {5, 5, -64},
112 {4, 5, -32},
113 {2, 7, 0},
114 {3, 7, 128},
115 {3, 8, 256},
116 {4, 9, 512},
117 {4, 10, 1024},
118 {6, 32, -2049}, /* low */
119 {6, 32, 2048} /* high */
120 };
121
122 const Jbig2HuffmanParams jbig2_huffman_params_F = { FALSE, JBIG2_COUNTOF(jbig2_huffman_lines_F), jbig2_huffman_lines_F };
123
124 /* Table B.7 */
125 static const Jbig2HuffmanLine jbig2_huffman_lines_G[] = {
126 {4, 9, -1024},
127 {3, 8, -512},
128 {4, 7, -256},
129 {5, 6, -128},
130 {5, 5, -64},
131 {4, 5, -32},
132 {4, 5, 0},
133 {5, 5, 32},
134 {5, 6, 64},
135 {4, 7, 128},
136 {3, 8, 256},
137 {3, 9, 512},
138 {3, 10, 1024},
139 {5, 32, -1025}, /* low */
140 {5, 32, 2048} /* high */
141 };
142
143 const Jbig2HuffmanParams jbig2_huffman_params_G = { FALSE, JBIG2_COUNTOF(jbig2_huffman_lines_G), jbig2_huffman_lines_G };
144
145 /* Table B.8 */
146 static const Jbig2HuffmanLine jbig2_huffman_lines_H[] = {
147 {8, 3, -15},
148 {9, 1, -7},
149 {8, 1, -5},
150 {9, 0, -3},
151 {7, 0, -2},
152 {4, 0, -1},
153 {2, 1, 0},
154 {5, 0, 2},
155 {6, 0, 3},
156 {3, 4, 4},
157 {6, 1, 20},
158 {4, 4, 22},
159 {4, 5, 38},
160 {5, 6, 70},
161 {5, 7, 134},
162 {6, 7, 262},
163 {7, 8, 390},
164 {6, 10, 646},
165 {9, 32, -16}, /* low */
166 {9, 32, 1670}, /* high */
167 {2, 0, 0} /* OOB */
168 };
169
170 const Jbig2HuffmanParams jbig2_huffman_params_H = { TRUE, JBIG2_COUNTOF(jbig2_huffman_lines_H), jbig2_huffman_lines_H };
171
172 /* Table B.9 */
173 static const Jbig2HuffmanLine jbig2_huffman_lines_I[] = {
174 {8, 4, -31},
175 {9, 2, -15},
176 {8, 2, -11},
177 {9, 1, -7},
178 {7, 1, -5},
179 {4, 1, -3},
180 {3, 1, -1},
181 {3, 1, 1},
182 {5, 1, 3},
183 {6, 1, 5},
184 {3, 5, 7},
185 {6, 2, 39},
186 {4, 5, 43},
187 {4, 6, 75},
188 {5, 7, 139},
189 {5, 8, 267},
190 {6, 8, 523},
191 {7, 9, 779},
192 {6, 11, 1291},
193 {9, 32, -32}, /* low */
194 {9, 32, 3339}, /* high */
195 {2, 0, 0} /* OOB */
196 };
197
198 const Jbig2HuffmanParams jbig2_huffman_params_I = { TRUE, JBIG2_COUNTOF(jbig2_huffman_lines_I), jbig2_huffman_lines_I };
199
200 /* Table B.10 */
201 static const Jbig2HuffmanLine jbig2_huffman_lines_J[] = {
202 {7, 4, -21},
203 {8, 0, -5},
204 {7, 0, -4},
205 {5, 0, -3},
206 {2, 2, -2},
207 {5, 0, 2},
208 {6, 0, 3},
209 {7, 0, 4},
210 {8, 0, 5},
211 {2, 6, 6},
212 {5, 5, 70},
213 {6, 5, 102},
214 {6, 6, 134},
215 {6, 7, 198},
216 {6, 8, 326},
217 {6, 9, 582},
218 {6, 10, 1094},
219 {7, 11, 2118},
220 {8, 32, -22}, /* low */
221 {8, 32, 4166}, /* high */
222 {2, 0, 0} /* OOB */
223 };
224
225 const Jbig2HuffmanParams jbig2_huffman_params_J = { TRUE, JBIG2_COUNTOF(jbig2_huffman_lines_J), jbig2_huffman_lines_J };
226
227 /* Table B.11 */
228 static const Jbig2HuffmanLine jbig2_huffman_lines_K[] = {
229 {1, 0, 1},
230 {2, 1, 2},
231 {4, 0, 4},
232 {4, 1, 5},
233 {5, 1, 7},
234 {5, 2, 9},
235 {6, 2, 13},
236 {7, 2, 17},
237 {7, 3, 21},
238 {7, 4, 29},
239 {7, 5, 45},
240 {7, 6, 77},
241 {0, 32, -1}, /* low */
242 {7, 32, 141} /* high */
243 };
244
245 const Jbig2HuffmanParams jbig2_huffman_params_K = { FALSE, JBIG2_COUNTOF(jbig2_huffman_lines_K), jbig2_huffman_lines_K };
246
247 /* Table B.12 */
248 static const Jbig2HuffmanLine jbig2_huffman_lines_L[] = {
249 {1, 0, 1},
250 {2, 0, 2},
251 {3, 1, 3},
252 {5, 0, 5},
253 {5, 1, 6},
254 {6, 1, 8},
255 {7, 0, 10},
256 {7, 1, 11},
257 {7, 2, 13},
258 {7, 3, 17},
259 {7, 4, 25},
260 {8, 5, 41},
261 {8, 32, 73},
262 {0, 32, -1}, /* low */
263 {0, 32, 0} /* high */
264 };
265
266 const Jbig2HuffmanParams jbig2_huffman_params_L = { FALSE, JBIG2_COUNTOF(jbig2_huffman_lines_L), jbig2_huffman_lines_L };
267
268 /* Table B.13 */
269 static const Jbig2HuffmanLine jbig2_huffman_lines_M[] = {
270 {1, 0, 1},
271 {3, 0, 2},
272 {4, 0, 3},
273 {5, 0, 4},
274 {4, 1, 5},
275 {3, 3, 7},
276 {6, 1, 15},
277 {6, 2, 17},
278 {6, 3, 21},
279 {6, 4, 29},
280 {6, 5, 45},
281 {7, 6, 77},
282 {0, 32, -1}, /* low */
283 {7, 32, 141} /* high */
284 };
285
286 const Jbig2HuffmanParams jbig2_huffman_params_M = { FALSE, JBIG2_COUNTOF(jbig2_huffman_lines_M), jbig2_huffman_lines_M };
287
288 /* Table B.14 */
289 static const Jbig2HuffmanLine jbig2_huffman_lines_N[] = {
290 {3, 0, -2},
291 {3, 0, -1},
292 {1, 0, 0},
293 {3, 0, 1},
294 {3, 0, 2},
295 {0, 32, -1}, /* low */
296 {0, 32, 3}, /* high */
297 };
298
299 const Jbig2HuffmanParams jbig2_huffman_params_N = { FALSE, JBIG2_COUNTOF(jbig2_huffman_lines_N), jbig2_huffman_lines_N };
300
301 /* Table B.15 */
302 static const Jbig2HuffmanLine jbig2_huffman_lines_O[] = {
303 {7, 4, -24},
304 {6, 2, -8},
305 {5, 1, -4},
306 {4, 0, -2},
307 {3, 0, -1},
308 {1, 0, 0},
309 {3, 0, 1},
310 {4, 0, 2},
311 {5, 1, 3},
312 {6, 2, 5},
313 {7, 4, 9},
314 {7, 32, -25}, /* low */
315 {7, 32, 25} /* high */
316 };
317
318 const Jbig2HuffmanParams jbig2_huffman_params_O = { FALSE, JBIG2_COUNTOF(jbig2_huffman_lines_O), jbig2_huffman_lines_O };