pdf-parser.js 5.2.27 → 5.2.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/dist/{afm-widths-BYiX2L9D.cjs → afm-widths-BHD2HZIL.cjs} +553 -642
  2. package/dist/{afm-widths-blUDDjlI.js → afm-widths-B_IGbGky.js} +553 -642
  3. package/dist/afm-widths.cjs +1 -1
  4. package/dist/afm-widths.js +1 -1
  5. package/dist/annotations.cjs +5 -3
  6. package/dist/annotations.js +5 -3
  7. package/dist/builtin-encoding.cjs +17 -6
  8. package/dist/builtin-encoding.js +17 -6
  9. package/dist/bytes/crc32.cjs +5 -3
  10. package/dist/bytes/crc32.js +5 -3
  11. package/dist/bytes/flate.cjs +0 -1
  12. package/dist/bytes/flate.js +0 -1
  13. package/dist/cff-bounds.cjs +42 -24
  14. package/dist/cff-bounds.js +42 -24
  15. package/dist/cff.cjs +13 -6
  16. package/dist/cff.js +13 -6
  17. package/dist/cmap-table.cjs +54 -26
  18. package/dist/cmap-table.js +54 -26
  19. package/dist/cmap.cjs +5 -3
  20. package/dist/cmap.js +5 -3
  21. package/dist/content-write.cjs +3 -2
  22. package/dist/content-write.js +3 -2
  23. package/dist/crypto/aes.cjs +76 -55
  24. package/dist/crypto/aes.js +76 -55
  25. package/dist/crypto/md5.cjs +345 -149
  26. package/dist/crypto/md5.js +345 -149
  27. package/dist/crypto/rc4.cjs +5 -4
  28. package/dist/crypto/rc4.js +5 -4
  29. package/dist/crypto/sha2.cjs +92 -43
  30. package/dist/crypto/sha2.js +92 -43
  31. package/dist/embedded-font.cjs +4 -2
  32. package/dist/embedded-font.js +4 -2
  33. package/dist/encoding.cjs +1 -1
  34. package/dist/encoding.js +1 -1
  35. package/dist/encrypt-write.cjs +25 -21
  36. package/dist/encrypt-write.js +25 -21
  37. package/dist/encrypt.cjs +43 -64
  38. package/dist/encrypt.js +43 -64
  39. package/dist/filters.cjs +40 -20
  40. package/dist/filters.js +40 -20
  41. package/dist/font-face.cjs +2 -1
  42. package/dist/font-face.js +2 -1
  43. package/dist/font-read.cjs +12 -6
  44. package/dist/font-read.js +12 -6
  45. package/dist/font-tables.cjs +55 -28
  46. package/dist/font-tables.js +55 -28
  47. package/dist/gdef-table.cjs +6 -3
  48. package/dist/gdef-table.js +6 -3
  49. package/dist/glyf-contours.cjs +3 -1
  50. package/dist/glyf-contours.js +3 -1
  51. package/dist/glyf.cjs +22 -11
  52. package/dist/glyf.js +22 -11
  53. package/dist/gpos-table.cjs +37 -19
  54. package/dist/gpos-table.js +37 -19
  55. package/dist/gsub-table.cjs +28 -17
  56. package/dist/gsub-table.js +28 -17
  57. package/dist/hmtx-table.cjs +5 -3
  58. package/dist/hmtx-table.js +5 -3
  59. package/dist/image/ccitt-encode.cjs +8 -5
  60. package/dist/image/ccitt-encode.js +8 -5
  61. package/dist/image/ccitt.cjs +801 -209
  62. package/dist/image/ccitt.js +801 -209
  63. package/dist/image/jbig2-arith.cjs +340 -306
  64. package/dist/image/jbig2-arith.js +340 -306
  65. package/dist/image/jbig2-bitmap.cjs +8 -5
  66. package/dist/image/jbig2-bitmap.js +8 -5
  67. package/dist/image/jbig2-generic.cjs +240 -69
  68. package/dist/image/jbig2-generic.js +240 -69
  69. package/dist/image/jbig2-text.cjs +4 -2
  70. package/dist/image/jbig2-text.js +4 -2
  71. package/dist/image/jbig2.cjs +69 -31
  72. package/dist/image/jbig2.js +69 -31
  73. package/dist/image/jp2-boxes.cjs +52 -27
  74. package/dist/image/jp2-boxes.js +52 -27
  75. package/dist/image/jpeg-info.cjs +29 -24
  76. package/dist/image/jpeg-info.js +29 -24
  77. package/dist/image/jpeg2000-codestream.cjs +44 -24
  78. package/dist/image/jpeg2000-codestream.js +44 -24
  79. package/dist/image/jpeg2000-dwt.cjs +2 -1
  80. package/dist/image/jpeg2000-dwt.js +2 -1
  81. package/dist/image/jpeg2000-t1.cjs +21 -11
  82. package/dist/image/jpeg2000-t1.js +21 -11
  83. package/dist/image/jpeg2000-t2.cjs +12 -5
  84. package/dist/image/jpeg2000-t2.js +12 -5
  85. package/dist/image/jpeg2000-tagtree.cjs +8 -4
  86. package/dist/image/jpeg2000-tagtree.js +8 -4
  87. package/dist/image/jpeg2000.cjs +11 -6
  88. package/dist/image/jpeg2000.js +11 -6
  89. package/dist/image/png-decode.cjs +62 -39
  90. package/dist/image/png-decode.d.cts +3 -2
  91. package/dist/image/png-decode.d.ts +3 -2
  92. package/dist/image/png-decode.js +62 -39
  93. package/dist/image/png-filter.cjs +23 -15
  94. package/dist/image/png-filter.js +23 -15
  95. package/dist/images-read.cjs +41 -36
  96. package/dist/images-read.js +41 -36
  97. package/dist/index.cjs +1 -1
  98. package/dist/index.js +1 -1
  99. package/dist/interpret.cjs +39 -24
  100. package/dist/interpret.js +39 -24
  101. package/dist/lexer.cjs +86 -51
  102. package/dist/lexer.js +86 -51
  103. package/dist/math-content-write.cjs +9 -5
  104. package/dist/math-content-write.js +9 -5
  105. package/dist/math-font-write.cjs +2 -1
  106. package/dist/math-font-write.js +2 -1
  107. package/dist/math-font.cjs +16 -7
  108. package/dist/math-font.js +16 -7
  109. package/dist/math-table.cjs +25 -13
  110. package/dist/math-table.js +25 -13
  111. package/dist/matrix.cjs +3 -2
  112. package/dist/matrix.js +3 -2
  113. package/dist/measure.cjs +1 -1
  114. package/dist/measure.js +1 -1
  115. package/dist/navigation.cjs +10 -5
  116. package/dist/navigation.js +10 -5
  117. package/dist/ot-layout-common.cjs +4 -2
  118. package/dist/ot-layout-common.js +4 -2
  119. package/dist/parse.cjs +7 -5
  120. package/dist/parse.js +7 -5
  121. package/dist/pdf-text.cjs +5 -2
  122. package/dist/pdf-text.js +5 -2
  123. package/dist/predictors.cjs +14 -9
  124. package/dist/predictors.js +14 -9
  125. package/dist/raster.cjs +30 -19
  126. package/dist/raster.js +30 -19
  127. package/dist/read.cjs +17 -8
  128. package/dist/read.js +17 -8
  129. package/dist/serialize.cjs +6 -2
  130. package/dist/serialize.js +6 -2
  131. package/dist/sfnt-subset.cjs +25 -13
  132. package/dist/sfnt-subset.js +25 -13
  133. package/dist/sfnt.cjs +20 -10
  134. package/dist/sfnt.js +20 -10
  135. package/dist/text-group.cjs +0 -1
  136. package/dist/text-group.js +0 -1
  137. package/dist/tounicode.cjs +4 -2
  138. package/dist/tounicode.js +4 -2
  139. package/dist/winansi.cjs +1 -1
  140. package/dist/winansi.js +1 -1
  141. package/dist/write.cjs +20 -12
  142. package/dist/write.js +20 -12
  143. package/dist/xref.cjs +5 -2
  144. package/dist/xref.js +5 -2
  145. package/package.json +1 -1
@@ -1,76 +1,252 @@
1
1
  import { Jbig2UnsupportedError } from "./jbig2-errors.js";
2
2
  import { createBitmap, getPixel } from "./jbig2-bitmap.js";
3
3
  //#region src/image/jbig2-generic.ts
4
- function fixed(dx, dy) {
5
- return {
6
- kind: "fixed",
7
- dx,
8
- dy
9
- };
10
- }
11
- function at(index) {
12
- return {
13
- kind: "at",
14
- index
15
- };
16
- }
17
4
  const GENERIC_TEMPLATES = [
18
5
  [
19
- at(3),
20
- fixed(-1, -2),
21
- fixed(0, -2),
22
- fixed(1, -2),
23
- at(2),
24
- at(1),
25
- fixed(-2, -1),
26
- fixed(-1, -1),
27
- fixed(0, -1),
28
- fixed(1, -1),
29
- fixed(2, -1),
30
- at(0),
31
- fixed(-4, 0),
32
- fixed(-3, 0),
33
- fixed(-2, 0),
34
- fixed(-1, 0)
6
+ {
7
+ kind: "at",
8
+ index: 3
9
+ },
10
+ {
11
+ kind: "fixed",
12
+ dx: -1,
13
+ dy: -2
14
+ },
15
+ {
16
+ kind: "fixed",
17
+ dx: 0,
18
+ dy: -2
19
+ },
20
+ {
21
+ kind: "fixed",
22
+ dx: 1,
23
+ dy: -2
24
+ },
25
+ {
26
+ kind: "at",
27
+ index: 2
28
+ },
29
+ {
30
+ kind: "at",
31
+ index: 1
32
+ },
33
+ {
34
+ kind: "fixed",
35
+ dx: -2,
36
+ dy: -1
37
+ },
38
+ {
39
+ kind: "fixed",
40
+ dx: -1,
41
+ dy: -1
42
+ },
43
+ {
44
+ kind: "fixed",
45
+ dx: 0,
46
+ dy: -1
47
+ },
48
+ {
49
+ kind: "fixed",
50
+ dx: 1,
51
+ dy: -1
52
+ },
53
+ {
54
+ kind: "fixed",
55
+ dx: 2,
56
+ dy: -1
57
+ },
58
+ {
59
+ kind: "at",
60
+ index: 0
61
+ },
62
+ {
63
+ kind: "fixed",
64
+ dx: -4,
65
+ dy: 0
66
+ },
67
+ {
68
+ kind: "fixed",
69
+ dx: -3,
70
+ dy: 0
71
+ },
72
+ {
73
+ kind: "fixed",
74
+ dx: -2,
75
+ dy: 0
76
+ },
77
+ {
78
+ kind: "fixed",
79
+ dx: -1,
80
+ dy: 0
81
+ }
35
82
  ],
36
83
  [
37
- fixed(-1, -2),
38
- fixed(0, -2),
39
- fixed(1, -2),
40
- fixed(2, -2),
41
- fixed(-2, -1),
42
- fixed(-1, -1),
43
- fixed(0, -1),
44
- fixed(1, -1),
45
- fixed(2, -1),
46
- at(0),
47
- fixed(-3, 0),
48
- fixed(-2, 0),
49
- fixed(-1, 0)
84
+ {
85
+ kind: "fixed",
86
+ dx: -1,
87
+ dy: -2
88
+ },
89
+ {
90
+ kind: "fixed",
91
+ dx: 0,
92
+ dy: -2
93
+ },
94
+ {
95
+ kind: "fixed",
96
+ dx: 1,
97
+ dy: -2
98
+ },
99
+ {
100
+ kind: "fixed",
101
+ dx: 2,
102
+ dy: -2
103
+ },
104
+ {
105
+ kind: "fixed",
106
+ dx: -2,
107
+ dy: -1
108
+ },
109
+ {
110
+ kind: "fixed",
111
+ dx: -1,
112
+ dy: -1
113
+ },
114
+ {
115
+ kind: "fixed",
116
+ dx: 0,
117
+ dy: -1
118
+ },
119
+ {
120
+ kind: "fixed",
121
+ dx: 1,
122
+ dy: -1
123
+ },
124
+ {
125
+ kind: "fixed",
126
+ dx: 2,
127
+ dy: -1
128
+ },
129
+ {
130
+ kind: "at",
131
+ index: 0
132
+ },
133
+ {
134
+ kind: "fixed",
135
+ dx: -3,
136
+ dy: 0
137
+ },
138
+ {
139
+ kind: "fixed",
140
+ dx: -2,
141
+ dy: 0
142
+ },
143
+ {
144
+ kind: "fixed",
145
+ dx: -1,
146
+ dy: 0
147
+ }
50
148
  ],
51
149
  [
52
- fixed(-1, -2),
53
- fixed(0, -2),
54
- fixed(1, -2),
55
- fixed(-2, -1),
56
- fixed(-1, -1),
57
- fixed(0, -1),
58
- fixed(1, -1),
59
- at(0),
60
- fixed(-2, 0),
61
- fixed(-1, 0)
150
+ {
151
+ kind: "fixed",
152
+ dx: -1,
153
+ dy: -2
154
+ },
155
+ {
156
+ kind: "fixed",
157
+ dx: 0,
158
+ dy: -2
159
+ },
160
+ {
161
+ kind: "fixed",
162
+ dx: 1,
163
+ dy: -2
164
+ },
165
+ {
166
+ kind: "fixed",
167
+ dx: -2,
168
+ dy: -1
169
+ },
170
+ {
171
+ kind: "fixed",
172
+ dx: -1,
173
+ dy: -1
174
+ },
175
+ {
176
+ kind: "fixed",
177
+ dx: 0,
178
+ dy: -1
179
+ },
180
+ {
181
+ kind: "fixed",
182
+ dx: 1,
183
+ dy: -1
184
+ },
185
+ {
186
+ kind: "at",
187
+ index: 0
188
+ },
189
+ {
190
+ kind: "fixed",
191
+ dx: -2,
192
+ dy: 0
193
+ },
194
+ {
195
+ kind: "fixed",
196
+ dx: -1,
197
+ dy: 0
198
+ }
62
199
  ],
63
200
  [
64
- fixed(-3, -1),
65
- fixed(-2, -1),
66
- fixed(-1, -1),
67
- fixed(0, -1),
68
- fixed(1, -1),
69
- at(0),
70
- fixed(-4, 0),
71
- fixed(-3, 0),
72
- fixed(-2, 0),
73
- fixed(-1, 0)
201
+ {
202
+ kind: "fixed",
203
+ dx: -3,
204
+ dy: -1
205
+ },
206
+ {
207
+ kind: "fixed",
208
+ dx: -2,
209
+ dy: -1
210
+ },
211
+ {
212
+ kind: "fixed",
213
+ dx: -1,
214
+ dy: -1
215
+ },
216
+ {
217
+ kind: "fixed",
218
+ dx: 0,
219
+ dy: -1
220
+ },
221
+ {
222
+ kind: "fixed",
223
+ dx: 1,
224
+ dy: -1
225
+ },
226
+ {
227
+ kind: "at",
228
+ index: 0
229
+ },
230
+ {
231
+ kind: "fixed",
232
+ dx: -4,
233
+ dy: 0
234
+ },
235
+ {
236
+ kind: "fixed",
237
+ dx: -3,
238
+ dy: 0
239
+ },
240
+ {
241
+ kind: "fixed",
242
+ dx: -2,
243
+ dy: 0
244
+ },
245
+ {
246
+ kind: "fixed",
247
+ dx: -1,
248
+ dy: 0
249
+ }
74
250
  ]
75
251
  ];
76
252
  const GENERIC_SLTP_CONTEXT = [
@@ -79,12 +255,7 @@ const GENERIC_SLTP_CONTEXT = [
79
255
  229,
80
256
  405
81
257
  ];
82
- const GENERIC_CONTEXT_BITS = [
83
- 16,
84
- 13,
85
- 10,
86
- 10
87
- ];
258
+ const GENERIC_CONTEXT_BITS = GENERIC_TEMPLATES.map((positions) => positions.length);
88
259
  function resolveTemplate(template) {
89
260
  const positions = GENERIC_TEMPLATES[template];
90
261
  if (positions === void 0) throw new Jbig2UnsupportedError(`generic region declares GBTEMPLATE ${String(template)}, which is outside the 0-3 range T.88 6.2.5.3 defines`);
@@ -199,7 +370,7 @@ const REFINEMENT_TEMPLATES = [[
199
370
  reference(1, 1)
200
371
  ]];
201
372
  const TPGRON_UNSUPPORTED = "JBIG2 refinement region sets TPGRON (typical prediction, T.88 6.3.5.6), whose per-template pseudo-context constants this decoder has no way to verify against a real encoder; refusing rather than risking a silently wrong bitmap";
202
- const REFINEMENT_CONTEXT_BITS = [13, 10];
373
+ const REFINEMENT_CONTEXT_BITS = REFINEMENT_TEMPLATES.map((positions) => positions.length);
203
374
  const NOMINAL_REFINEMENT_AT = [{
204
375
  x: -1,
205
376
  y: -1
@@ -4,6 +4,8 @@ const require_image_jbig2_errors = require("./jbig2-errors.cjs");
4
4
  const require_image_jbig2_bitmap = require("./jbig2-bitmap.cjs");
5
5
  const require_image_jbig2_generic = require("./jbig2-generic.cjs");
6
6
  //#region src/image/jbig2-text.ts
7
+ const GENERIC_TEMPLATE_0_CONTEXT_BITS = 16;
8
+ const REFINEMENT_TEMPLATE_0_CONTEXT_BITS = 13;
7
9
  const REFERENCE_CORNERS = [
8
10
  {
9
11
  right: false,
@@ -46,8 +48,8 @@ function createTextArithContexts(genericTemplate, refinementTemplate, symbolIdBi
46
48
  iardx: require_image_jbig2_arith.createIntegerContexts(),
47
49
  iardy: require_image_jbig2_arith.createIntegerContexts(),
48
50
  iaid: require_image_jbig2_arith.createSymbolIdContexts(symbolIdBits),
49
- generic: require_image_jbig2_arith.createArithContexts(require_image_jbig2_generic.GENERIC_CONTEXT_BITS[genericTemplate] ?? 16),
50
- refinement: require_image_jbig2_arith.createArithContexts(require_image_jbig2_generic.REFINEMENT_CONTEXT_BITS[refinementTemplate] ?? 13)
51
+ generic: require_image_jbig2_arith.createArithContexts(require_image_jbig2_generic.GENERIC_CONTEXT_BITS[genericTemplate] ?? GENERIC_TEMPLATE_0_CONTEXT_BITS),
52
+ refinement: require_image_jbig2_arith.createArithContexts(require_image_jbig2_generic.REFINEMENT_CONTEXT_BITS[refinementTemplate] ?? REFINEMENT_TEMPLATE_0_CONTEXT_BITS)
51
53
  };
52
54
  }
53
55
  function instanceTopLeft(s, t, width, height, corner, transposed) {
@@ -3,6 +3,8 @@ import { Jbig2ParseError, Jbig2UnsupportedError } from "./jbig2-errors.js";
3
3
  import { combineBitmap, createBitmap } from "./jbig2-bitmap.js";
4
4
  import { GENERIC_CONTEXT_BITS, REFINEMENT_CONTEXT_BITS, decodeGenericRegion, decodeRefinementRegion } from "./jbig2-generic.js";
5
5
  //#region src/image/jbig2-text.ts
6
+ const GENERIC_TEMPLATE_0_CONTEXT_BITS = 16;
7
+ const REFINEMENT_TEMPLATE_0_CONTEXT_BITS = 13;
6
8
  const REFERENCE_CORNERS = [
7
9
  {
8
10
  right: false,
@@ -45,8 +47,8 @@ function createTextArithContexts(genericTemplate, refinementTemplate, symbolIdBi
45
47
  iardx: createIntegerContexts(),
46
48
  iardy: createIntegerContexts(),
47
49
  iaid: createSymbolIdContexts(symbolIdBits),
48
- generic: createArithContexts(GENERIC_CONTEXT_BITS[genericTemplate] ?? 16),
49
- refinement: createArithContexts(REFINEMENT_CONTEXT_BITS[refinementTemplate] ?? 13)
50
+ generic: createArithContexts(GENERIC_CONTEXT_BITS[genericTemplate] ?? GENERIC_TEMPLATE_0_CONTEXT_BITS),
51
+ refinement: createArithContexts(REFINEMENT_CONTEXT_BITS[refinementTemplate] ?? REFINEMENT_TEMPLATE_0_CONTEXT_BITS)
50
52
  };
51
53
  }
52
54
  function instanceTopLeft(s, t, width, height, corner, transposed) {
@@ -29,6 +29,44 @@ const SEGMENT_TABLES = 53;
29
29
  const SEGMENT_EXTENSION = 62;
30
30
  const UNKNOWN_DATA_LENGTH = 4294967295;
31
31
  const UNKNOWN_PAGE_HEIGHT = 4294967295;
32
+ const BITS_PER_BYTE = 8;
33
+ const UINT8_MODULUS = 256;
34
+ const INT8_MAX = UINT8_MODULUS / 2 - 1;
35
+ const UINT32_BYTE_2_SHIFT = 16;
36
+ const UINT32_BYTE_3_SHIFT = 24;
37
+ const SEGMENT_TYPE_MASK = 63;
38
+ const PAGE_ASSOCIATION_SIZE_FLAG = 64;
39
+ const REFERRED_COUNT_SHORT_SHIFT = 5;
40
+ const REFERRED_COUNT_LONG_FORM_SENTINEL = 7;
41
+ const REFERRED_COUNT_LONG_MASK = 536870911;
42
+ const SEGMENT_NUMBER_1BYTE_LIMIT = 256;
43
+ const SEGMENT_NUMBER_2BYTE_LIMIT = 65536;
44
+ const REFERRED_NUMBER_SIZE_4_BYTES = 4;
45
+ const REGION_COMBOP_MASK = 7;
46
+ const PAGE_DEFAULT_COMBOP_SHIFT = 3;
47
+ const PAGE_DEFAULT_COMBOP_MASK = 3;
48
+ const PAGE_COMBOP_OVERRIDE_FLAG = 64;
49
+ const GENERIC_CODING_AT_PIXEL_COUNT_TEMPLATE_0 = 4;
50
+ const GENERIC_TEMPLATE_0_CONTEXT_BITS = 16;
51
+ const REFINEMENT_TEMPLATE_0_CONTEXT_BITS = 13;
52
+ const GENERIC_REGION_TEMPLATE_MASK = 3;
53
+ const GENERIC_REGION_TPGDON_FLAG = 8;
54
+ const GENERIC_REGION_EXTTEMPLATE_FLAG = 16;
55
+ const SYMBOL_DICT_BITMAP_CODING_CONTEXT_USED = 256;
56
+ const SYMBOL_DICT_BITMAP_CODING_CONTEXT_RETAINED = 512;
57
+ const SYMBOL_DICT_TEMPLATE_SHIFT = 10;
58
+ const SYMBOL_DICT_TEMPLATE_MASK = 3;
59
+ const SYMBOL_DICT_REFINEMENT_TEMPLATE_SHIFT = 12;
60
+ const TEXT_REGION_STRIP_SIZE_LOG_MASK = 3;
61
+ const TEXT_REGION_REFCORNER_SHIFT = 4;
62
+ const TEXT_REGION_REFCORNER_MASK = 3;
63
+ const TEXT_REGION_TRANSPOSED_FLAG = 64;
64
+ const TEXT_REGION_SBCOMBOP_SHIFT = 7;
65
+ const TEXT_REGION_SBCOMBOP_MASK = 3;
66
+ const TEXT_REGION_DEFAULT_PIXEL_SHIFT = 9;
67
+ const TEXT_REGION_REFINEMENT_TEMPLATE_SHIFT = 15;
68
+ const SBDSOFFSET_SIGN_EXTEND_LEFT_SHIFT = 17;
69
+ const SBDSOFFSET_SIGN_EXTEND_RIGHT_SHIFT = 27;
32
70
  var ByteCursor = class {
33
71
  data;
34
72
  position;
@@ -46,28 +84,28 @@ var ByteCursor = class {
46
84
  return value;
47
85
  }
48
86
  uint16() {
49
- return this.uint8() << 8 | this.uint8();
87
+ return this.uint8() << BITS_PER_BYTE | this.uint8();
50
88
  }
51
89
  uint32() {
52
- return (this.uint8() << 24 | this.uint8() << 16 | this.uint8() << 8 | this.uint8()) >>> 0;
90
+ return (this.uint8() << UINT32_BYTE_3_SHIFT | this.uint8() << UINT32_BYTE_2_SHIFT | this.uint8() << BITS_PER_BYTE | this.uint8()) >>> 0;
53
91
  }
54
92
  int8() {
55
93
  const value = this.uint8();
56
- return value > 127 ? value - 256 : value;
94
+ return value > INT8_MAX ? value - UINT8_MODULUS : value;
57
95
  }
58
96
  };
59
97
  function readSegmentHeader(cursor, dataLength) {
60
98
  const number = cursor.uint32();
61
99
  const flags = cursor.uint8();
62
- const type = flags & 63;
63
- const pageAssociationIsLong = (flags & 64) !== 0;
64
- let referredCount = cursor.uint8() >> 5;
65
- if (referredCount === 7) {
100
+ const type = flags & SEGMENT_TYPE_MASK;
101
+ const pageAssociationIsLong = (flags & PAGE_ASSOCIATION_SIZE_FLAG) !== 0;
102
+ let referredCount = cursor.uint8() >> REFERRED_COUNT_SHORT_SHIFT;
103
+ if (referredCount === REFERRED_COUNT_LONG_FORM_SENTINEL) {
66
104
  cursor.position -= 1;
67
- referredCount = cursor.uint32() & 536870911;
68
- cursor.position += Math.ceil((referredCount + 1) / 8);
105
+ referredCount = cursor.uint32() & REFERRED_COUNT_LONG_MASK;
106
+ cursor.position += Math.ceil((referredCount + 1) / BITS_PER_BYTE);
69
107
  }
70
- const referredSize = number <= 256 ? 1 : number <= 65536 ? 2 : 4;
108
+ const referredSize = number <= SEGMENT_NUMBER_1BYTE_LIMIT ? 1 : number <= SEGMENT_NUMBER_2BYTE_LIMIT ? 2 : REFERRED_NUMBER_SIZE_4_BYTES;
71
109
  const referredTo = [];
72
110
  for (let i = 0; i < referredCount; i++) referredTo.push(referredSize === 1 ? cursor.uint8() : referredSize === 2 ? cursor.uint16() : cursor.uint32());
73
111
  const pageAssociation = pageAssociationIsLong ? cursor.uint32() : cursor.uint8();
@@ -91,8 +129,8 @@ function readRegionInfo(cursor) {
91
129
  const x = cursor.uint32();
92
130
  const y = cursor.uint32();
93
131
  const flags = cursor.uint8();
94
- const combinationOperator = require_image_jbig2_bitmap.combinationOperatorFromCode(flags & 7);
95
- if (combinationOperator === void 0) throw new require_image_jbig2_errors.Jbig2ParseError(`JBIG2 region declares external combination operator ${String(flags & 7)}, outside the 0-4 range T.88 Table 12 defines`);
132
+ const combinationOperator = require_image_jbig2_bitmap.combinationOperatorFromCode(flags & REGION_COMBOP_MASK);
133
+ if (combinationOperator === void 0) throw new require_image_jbig2_errors.Jbig2ParseError(`JBIG2 region declares external combination operator ${String(flags & REGION_COMBOP_MASK)}, outside the 0-4 range T.88 Table 12 defines`);
96
134
  return {
97
135
  width,
98
136
  height,
@@ -175,12 +213,12 @@ var Jbig2Decoder = class {
175
213
  const declaredOrHintedHeight = declaredHeight === UNKNOWN_PAGE_HEIGHT ? this.options.height : this.options.height ?? declaredHeight;
176
214
  if (declaredOrHintedHeight === void 0) throw new require_image_jbig2_errors.Jbig2UnsupportedError("JBIG2 page information declares an unknown height and the caller supplied none; a striped page with no known height is not resolvable from the page segments alone");
177
215
  const defaultPixel = flags >> 2 & 1;
178
- const defaultCombinationOperator = require_image_jbig2_bitmap.combinationOperatorFromCode(flags >> 3 & 3);
216
+ const defaultCombinationOperator = require_image_jbig2_bitmap.combinationOperatorFromCode(flags >> PAGE_DEFAULT_COMBOP_SHIFT & PAGE_DEFAULT_COMBOP_MASK);
179
217
  if (defaultCombinationOperator === void 0) throw new require_image_jbig2_errors.Jbig2ParseError("JBIG2 page information declares an unrecognised default combination operator");
180
218
  this.page = {
181
219
  bitmap: require_image_jbig2_bitmap.createBitmap(width, declaredOrHintedHeight, defaultPixel),
182
220
  defaultCombinationOperator,
183
- combinationOperatorOverridden: (flags & 64) !== 0
221
+ combinationOperatorOverridden: (flags & PAGE_COMBOP_OVERRIDE_FLAG) !== 0
184
222
  };
185
223
  }
186
224
  requirePage() {
@@ -195,10 +233,10 @@ var Jbig2Decoder = class {
195
233
  const region = readRegionInfo(cursor);
196
234
  const flags = cursor.uint8();
197
235
  const mmr = (flags & 1) !== 0;
198
- const template = flags >> 1 & 3;
199
- const tpgdon = (flags & 8) !== 0;
200
- if ((flags & 16) !== 0) throw new require_image_jbig2_errors.Jbig2UnsupportedError("JBIG2 generic region sets EXTTEMPLATE, the twelve-adaptive-pixel template of T.88 Amendment 2, which is not implemented");
201
- const at = mmr ? [] : readAtPixels(cursor, template === 0 ? 4 : 1);
236
+ const template = flags >> 1 & GENERIC_REGION_TEMPLATE_MASK;
237
+ const tpgdon = (flags & GENERIC_REGION_TPGDON_FLAG) !== 0;
238
+ if ((flags & GENERIC_REGION_EXTTEMPLATE_FLAG) !== 0) throw new require_image_jbig2_errors.Jbig2UnsupportedError("JBIG2 generic region sets EXTTEMPLATE, the twelve-adaptive-pixel template of T.88 Amendment 2, which is not implemented");
239
+ const at = mmr ? [] : readAtPixels(cursor, template === 0 ? GENERIC_CODING_AT_PIXEL_COUNT_TEMPLATE_0 : 1);
202
240
  const payload = cursor.position;
203
241
  if (mmr) {
204
242
  const fax = require_image_ccitt.decodeCcittFax(cursor.data.subarray(payload, dataEnd), {
@@ -214,7 +252,7 @@ var Jbig2Decoder = class {
214
252
  return;
215
253
  }
216
254
  const mq = new require_image_jbig2_arith.MqDecoder(cursor.data, payload, dataEnd);
217
- const contexts = require_image_jbig2_arith.createArithContexts(require_image_jbig2_generic.GENERIC_CONTEXT_BITS[template] ?? 16);
255
+ const contexts = require_image_jbig2_arith.createArithContexts(require_image_jbig2_generic.GENERIC_CONTEXT_BITS[template] ?? GENERIC_TEMPLATE_0_CONTEXT_BITS);
218
256
  this.compose(region, require_image_jbig2_generic.decodeGenericRegion(region.width, region.height, {
219
257
  template,
220
258
  tpgdon,
@@ -231,7 +269,7 @@ var Jbig2Decoder = class {
231
269
  const reference = require_image_jbig2_bitmap.createBitmap(region.width, region.height);
232
270
  for (let y = 0; y < region.height; y++) for (let x = 0; x < region.width; x++) reference.data[y * region.width + x] = require_image_jbig2_bitmap.getPixel(page.bitmap, region.x + x, region.y + y);
233
271
  const mq = new require_image_jbig2_arith.MqDecoder(cursor.data, cursor.position, dataEnd);
234
- const contexts = require_image_jbig2_arith.createArithContexts(require_image_jbig2_generic.REFINEMENT_CONTEXT_BITS[template] ?? 13);
272
+ const contexts = require_image_jbig2_arith.createArithContexts(require_image_jbig2_generic.REFINEMENT_CONTEXT_BITS[template] ?? REFINEMENT_TEMPLATE_0_CONTEXT_BITS);
235
273
  const refined = require_image_jbig2_generic.decodeRefinementRegion(region.width, region.height, {
236
274
  template,
237
275
  tpgron,
@@ -245,11 +283,11 @@ var Jbig2Decoder = class {
245
283
  readSymbolDictionary(header, cursor) {
246
284
  const flags = cursor.uint16();
247
285
  if ((flags & 1) !== 0) throw new require_image_jbig2_errors.Jbig2UnsupportedError("JBIG2 symbol dictionary is Huffman-coded (SDHUFF = 1); only the arithmetic form is implemented");
248
- if ((flags & 256) !== 0 || (flags & 512) !== 0) throw new require_image_jbig2_errors.Jbig2UnsupportedError("JBIG2 symbol dictionary uses or retains a shared bitmap coding context (T.88 7.4.3.1.1 bits 8-9), which is not implemented");
286
+ if ((flags & SYMBOL_DICT_BITMAP_CODING_CONTEXT_USED) !== 0 || (flags & SYMBOL_DICT_BITMAP_CODING_CONTEXT_RETAINED) !== 0) throw new require_image_jbig2_errors.Jbig2UnsupportedError("JBIG2 symbol dictionary uses or retains a shared bitmap coding context (T.88 7.4.3.1.1 bits 8-9), which is not implemented");
249
287
  const refinementAggregate = (flags & 2) !== 0;
250
- const template = flags >> 10 & 3;
251
- const refinementTemplate = flags >> 12 & 1;
252
- const at = readAtPixels(cursor, template === 0 ? 4 : 1);
288
+ const template = flags >> SYMBOL_DICT_TEMPLATE_SHIFT & SYMBOL_DICT_TEMPLATE_MASK;
289
+ const refinementTemplate = flags >> SYMBOL_DICT_REFINEMENT_TEMPLATE_SHIFT & 1;
290
+ const at = readAtPixels(cursor, template === 0 ? GENERIC_CODING_AT_PIXEL_COUNT_TEMPLATE_0 : 1);
253
291
  const refinementAt = refinementAggregate && refinementTemplate === 0 ? readAtPixels(cursor, 2) : [...require_image_jbig2_generic.NOMINAL_REFINEMENT_AT];
254
292
  const exportedSymbolCount = cursor.uint32();
255
293
  const newSymbolCount = cursor.uint32();
@@ -273,15 +311,15 @@ var Jbig2Decoder = class {
273
311
  const flags = cursor.uint16();
274
312
  if ((flags & 1) !== 0) throw new require_image_jbig2_errors.Jbig2UnsupportedError("JBIG2 text region is Huffman-coded (SBHUFF = 1); only the arithmetic form is implemented");
275
313
  const refine = (flags & 2) !== 0;
276
- const stripSize = 1 << (flags >> 2 & 3);
277
- const referenceCorner = require_image_jbig2_text.referenceCornerFromCode(flags >> 4 & 3);
314
+ const stripSize = 1 << (flags >> 2 & TEXT_REGION_STRIP_SIZE_LOG_MASK);
315
+ const referenceCorner = require_image_jbig2_text.referenceCornerFromCode(flags >> TEXT_REGION_REFCORNER_SHIFT & TEXT_REGION_REFCORNER_MASK);
278
316
  if (referenceCorner === void 0) throw new require_image_jbig2_errors.Jbig2ParseError("JBIG2 text region declares an unrecognised REFCORNER");
279
- const transposed = (flags & 64) !== 0;
280
- const combinationOperator = require_image_jbig2_bitmap.combinationOperatorFromCode(flags >> 7 & 3);
317
+ const transposed = (flags & TEXT_REGION_TRANSPOSED_FLAG) !== 0;
318
+ const combinationOperator = require_image_jbig2_bitmap.combinationOperatorFromCode(flags >> TEXT_REGION_SBCOMBOP_SHIFT & TEXT_REGION_SBCOMBOP_MASK);
281
319
  if (combinationOperator === void 0) throw new require_image_jbig2_errors.Jbig2ParseError("JBIG2 text region declares an unrecognised SBCOMBOP");
282
- const defaultPixel = flags >> 9 & 1;
283
- const dsOffset = flags << 17 >> 27 | 0;
284
- const refinementTemplate = flags >> 15 & 1;
320
+ const defaultPixel = flags >> TEXT_REGION_DEFAULT_PIXEL_SHIFT & 1;
321
+ const dsOffset = flags << SBDSOFFSET_SIGN_EXTEND_LEFT_SHIFT >> SBDSOFFSET_SIGN_EXTEND_RIGHT_SHIFT | 0;
322
+ const refinementTemplate = flags >> TEXT_REGION_REFINEMENT_TEMPLATE_SHIFT & 1;
285
323
  const refinementAt = refine && refinementTemplate === 0 ? readAtPixels(cursor, 2) : [...require_image_jbig2_generic.NOMINAL_REFINEMENT_AT];
286
324
  const instanceCount = cursor.uint32();
287
325
  const symbols = this.gatherSymbols(header.referredTo);