@file-viewer/core 2.0.10 → 2.1.0

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 (114) hide show
  1. package/README.en.md +2 -2
  2. package/README.md +2 -2
  3. package/dist/config/options.d.ts +1 -1
  4. package/dist/config/options.js +1 -1
  5. package/dist/contracts/types.d.ts +71 -1
  6. package/dist/headless.d.ts +2 -2
  7. package/dist/headless.js +1 -1
  8. package/dist/index.d.ts +9 -6
  9. package/dist/index.js +105 -48
  10. package/dist/platform/assets.d.ts +3 -1
  11. package/dist/platform/assets.js +18 -2
  12. package/dist/registry/capabilities.d.ts +2 -2
  13. package/dist/registry/capabilities.js +2 -1
  14. package/dist/registry/formats.d.ts +20 -7
  15. package/dist/registry/formats.js +14 -5
  16. package/dist/registry/registry.d.ts +8 -1
  17. package/dist/registry/registry.js +29 -0
  18. package/dist/renderers/image.js +1 -10
  19. package/dist/renderers/index.d.ts +320 -2
  20. package/dist/renderers/index.js +27 -157
  21. package/dist/viewer/createViewer.js +86 -3
  22. package/package.json +17 -44
  23. package/dist/renderers/archive.d.ts +0 -2
  24. package/dist/renderers/archive.js +0 -547
  25. package/dist/renderers/archiveCache.d.ts +0 -10
  26. package/dist/renderers/archiveCache.js +0 -96
  27. package/dist/renderers/archiveFallback.d.ts +0 -7
  28. package/dist/renderers/archiveFallback.js +0 -166
  29. package/dist/renderers/archiveShared.d.ts +0 -23
  30. package/dist/renderers/archiveShared.js +0 -71
  31. package/dist/renderers/audio.d.ts +0 -8
  32. package/dist/renderers/audio.js +0 -219
  33. package/dist/renderers/cad.d.ts +0 -2
  34. package/dist/renderers/cad.js +0 -446
  35. package/dist/renderers/code.d.ts +0 -11
  36. package/dist/renderers/code.js +0 -233
  37. package/dist/renderers/data.d.ts +0 -7
  38. package/dist/renderers/data.js +0 -370
  39. package/dist/renderers/drawing.d.ts +0 -10
  40. package/dist/renderers/drawing.js +0 -882
  41. package/dist/renderers/eda.d.ts +0 -2
  42. package/dist/renderers/eda.js +0 -434
  43. package/dist/renderers/edaParser.d.ts +0 -77
  44. package/dist/renderers/edaParser.js +0 -569
  45. package/dist/renderers/email.d.ts +0 -2
  46. package/dist/renderers/email.js +0 -463
  47. package/dist/renderers/epub.d.ts +0 -2
  48. package/dist/renderers/epub.js +0 -331
  49. package/dist/renderers/geo.d.ts +0 -2
  50. package/dist/renderers/geo.js +0 -284
  51. package/dist/renderers/markdown.d.ts +0 -2
  52. package/dist/renderers/markdown.js +0 -83
  53. package/dist/renderers/model.d.ts +0 -2
  54. package/dist/renderers/model.js +0 -567
  55. package/dist/renderers/ofd.d.ts +0 -2
  56. package/dist/renderers/ofd.js +0 -256
  57. package/dist/renderers/openDocument.d.ts +0 -2
  58. package/dist/renderers/openDocument.js +0 -122
  59. package/dist/renderers/pdf.d.ts +0 -3
  60. package/dist/renderers/pdf.js +0 -1001
  61. package/dist/renderers/pdfStyles.d.ts +0 -1
  62. package/dist/renderers/pdfStyles.js +0 -1
  63. package/dist/renderers/pptx.d.ts +0 -2
  64. package/dist/renderers/pptx.js +0 -217
  65. package/dist/renderers/spreadsheet/state.d.ts +0 -80
  66. package/dist/renderers/spreadsheet/state.js +0 -96
  67. package/dist/renderers/spreadsheet/view.d.ts +0 -25
  68. package/dist/renderers/spreadsheet/view.js +0 -833
  69. package/dist/renderers/spreadsheet/worker/index.d.ts +0 -2
  70. package/dist/renderers/spreadsheet/worker/index.js +0 -1
  71. package/dist/renderers/spreadsheet/worker/sheetjs/SheetJsModel.d.ts +0 -73
  72. package/dist/renderers/spreadsheet/worker/sheetjs/SheetJsModel.js +0 -623
  73. package/dist/renderers/spreadsheet/worker/sheetjs/color.d.ts +0 -2
  74. package/dist/renderers/spreadsheet/worker/sheetjs/color.js +0 -73
  75. package/dist/renderers/spreadsheet/worker/sheetjs/index.d.ts +0 -1
  76. package/dist/renderers/spreadsheet/worker/sheetjs/index.js +0 -1
  77. package/dist/renderers/spreadsheet/worker/sheetjs/parser.d.ts +0 -18
  78. package/dist/renderers/spreadsheet/worker/sheetjs/parser.js +0 -106
  79. package/dist/renderers/spreadsheet/worker/sheetjs/sheet.worker.d.ts +0 -1
  80. package/dist/renderers/spreadsheet/worker/sheetjs/sheet.worker.js +0 -11
  81. package/dist/renderers/spreadsheet/worker/type.d.ts +0 -57
  82. package/dist/renderers/spreadsheet/worker/type.js +0 -1
  83. package/dist/renderers/spreadsheet.d.ts +0 -3
  84. package/dist/renderers/spreadsheet.js +0 -929
  85. package/dist/renderers/typst.d.ts +0 -8
  86. package/dist/renderers/typst.js +0 -547
  87. package/dist/renderers/umd/parser.d.ts +0 -30
  88. package/dist/renderers/umd/parser.js +0 -408
  89. package/dist/renderers/umd.d.ts +0 -2
  90. package/dist/renderers/umd.js +0 -297
  91. package/dist/renderers/video.d.ts +0 -8
  92. package/dist/renderers/video.js +0 -108
  93. package/dist/renderers/wordDoc.d.ts +0 -5
  94. package/dist/renderers/wordDoc.js +0 -284
  95. package/dist/renderers/wordDocx.d.ts +0 -5
  96. package/dist/renderers/wordDocx.js +0 -985
  97. package/dist/renderers/wordDocx.worker.d.ts +0 -1
  98. package/dist/renderers/wordDocx.worker.js +0 -96
  99. package/vendor/ofd/dltech/jbig2/arithmetic_decoder.js +0 -183
  100. package/vendor/ofd/dltech/jbig2/ccitt.js +0 -1070
  101. package/vendor/ofd/dltech/jbig2/compatibility.js +0 -12
  102. package/vendor/ofd/dltech/jbig2/core_utils.js +0 -180
  103. package/vendor/ofd/dltech/jbig2/is_node.js +0 -27
  104. package/vendor/ofd/dltech/jbig2/jbig2.js +0 -2589
  105. package/vendor/ofd/dltech/jbig2/jbig2_stream.js +0 -81
  106. package/vendor/ofd/dltech/jbig2/primitives.js +0 -387
  107. package/vendor/ofd/dltech/jbig2/stream.js +0 -1348
  108. package/vendor/ofd/dltech/jbig2/util.js +0 -972
  109. package/vendor/ofd/dltech/ofd/ofd.d.ts +0 -11
  110. package/vendor/ofd/dltech/ofd/ofd.js +0 -100
  111. package/vendor/ofd/dltech/ofd/ofd_parser.js +0 -395
  112. package/vendor/ofd/dltech/ofd/ofd_render.js +0 -473
  113. package/vendor/ofd/dltech/ofd/ofd_util.js +0 -350
  114. package/vendor/ofd/dltech/ofd/pipeline.js +0 -26
@@ -1,1070 +0,0 @@
1
- /* Copyright 2012 Mozilla Foundation
2
- *
3
- * Licensed under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License.
5
- * You may obtain a copy of the License at
6
- *
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software
10
- * distributed under the License is distributed on an "AS IS" BASIS,
11
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- * See the License for the specific language governing permissions and
13
- * limitations under the License.
14
- */
15
- /* Copyright 1996-2003 Glyph & Cog, LLC
16
- *
17
- * The CCITT stream implementation contained in this file is a JavaScript port
18
- * of XPDF's implementation, made available under the Apache 2.0 open source
19
- * license.
20
- */
21
-
22
- /**
23
- * @typedef {Object} CCITTFaxDecoderSource
24
- * @property {function} next - Method that return one byte of data for decoding,
25
- * or -1 when EOF is reached.
26
- */
27
-
28
- import { info } from "./util.js";
29
-
30
- const CCITTFaxDecoder = (function CCITTFaxDecoder() {
31
- const ccittEOL = -2;
32
- const ccittEOF = -1;
33
- const twoDimPass = 0;
34
- const twoDimHoriz = 1;
35
- const twoDimVert0 = 2;
36
- const twoDimVertR1 = 3;
37
- const twoDimVertL1 = 4;
38
- const twoDimVertR2 = 5;
39
- const twoDimVertL2 = 6;
40
- const twoDimVertR3 = 7;
41
- const twoDimVertL3 = 8;
42
-
43
- // prettier-ignore
44
- const twoDimTable = [
45
- [-1, -1], [-1, -1], // 000000x
46
- [7, twoDimVertL3], // 0000010
47
- [7, twoDimVertR3], // 0000011
48
- [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
49
- [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
50
- [4, twoDimPass], [4, twoDimPass], // 0001xxx
51
- [4, twoDimPass], [4, twoDimPass],
52
- [4, twoDimPass], [4, twoDimPass],
53
- [4, twoDimPass], [4, twoDimPass],
54
- [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
55
- [3, twoDimHoriz], [3, twoDimHoriz],
56
- [3, twoDimHoriz], [3, twoDimHoriz],
57
- [3, twoDimHoriz], [3, twoDimHoriz],
58
- [3, twoDimHoriz], [3, twoDimHoriz],
59
- [3, twoDimHoriz], [3, twoDimHoriz],
60
- [3, twoDimHoriz], [3, twoDimHoriz],
61
- [3, twoDimHoriz], [3, twoDimHoriz],
62
- [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
63
- [3, twoDimVertL1], [3, twoDimVertL1],
64
- [3, twoDimVertL1], [3, twoDimVertL1],
65
- [3, twoDimVertL1], [3, twoDimVertL1],
66
- [3, twoDimVertL1], [3, twoDimVertL1],
67
- [3, twoDimVertL1], [3, twoDimVertL1],
68
- [3, twoDimVertL1], [3, twoDimVertL1],
69
- [3, twoDimVertL1], [3, twoDimVertL1],
70
- [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
71
- [3, twoDimVertR1], [3, twoDimVertR1],
72
- [3, twoDimVertR1], [3, twoDimVertR1],
73
- [3, twoDimVertR1], [3, twoDimVertR1],
74
- [3, twoDimVertR1], [3, twoDimVertR1],
75
- [3, twoDimVertR1], [3, twoDimVertR1],
76
- [3, twoDimVertR1], [3, twoDimVertR1],
77
- [3, twoDimVertR1], [3, twoDimVertR1],
78
- [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
79
- [1, twoDimVert0], [1, twoDimVert0],
80
- [1, twoDimVert0], [1, twoDimVert0],
81
- [1, twoDimVert0], [1, twoDimVert0],
82
- [1, twoDimVert0], [1, twoDimVert0],
83
- [1, twoDimVert0], [1, twoDimVert0],
84
- [1, twoDimVert0], [1, twoDimVert0],
85
- [1, twoDimVert0], [1, twoDimVert0],
86
- [1, twoDimVert0], [1, twoDimVert0],
87
- [1, twoDimVert0], [1, twoDimVert0],
88
- [1, twoDimVert0], [1, twoDimVert0],
89
- [1, twoDimVert0], [1, twoDimVert0],
90
- [1, twoDimVert0], [1, twoDimVert0],
91
- [1, twoDimVert0], [1, twoDimVert0],
92
- [1, twoDimVert0], [1, twoDimVert0],
93
- [1, twoDimVert0], [1, twoDimVert0],
94
- [1, twoDimVert0], [1, twoDimVert0],
95
- [1, twoDimVert0], [1, twoDimVert0],
96
- [1, twoDimVert0], [1, twoDimVert0],
97
- [1, twoDimVert0], [1, twoDimVert0],
98
- [1, twoDimVert0], [1, twoDimVert0],
99
- [1, twoDimVert0], [1, twoDimVert0],
100
- [1, twoDimVert0], [1, twoDimVert0],
101
- [1, twoDimVert0], [1, twoDimVert0],
102
- [1, twoDimVert0], [1, twoDimVert0],
103
- [1, twoDimVert0], [1, twoDimVert0],
104
- [1, twoDimVert0], [1, twoDimVert0],
105
- [1, twoDimVert0], [1, twoDimVert0],
106
- [1, twoDimVert0], [1, twoDimVert0],
107
- [1, twoDimVert0], [1, twoDimVert0],
108
- [1, twoDimVert0], [1, twoDimVert0],
109
- [1, twoDimVert0], [1, twoDimVert0]
110
- ];
111
-
112
- // prettier-ignore
113
- const whiteTable1 = [
114
- [-1, -1], // 00000
115
- [12, ccittEOL], // 00001
116
- [-1, -1], [-1, -1], // 0001x
117
- [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
118
- [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
119
- [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
120
- [11, 1792], [11, 1792], // 1000x
121
- [12, 1984], // 10010
122
- [12, 2048], // 10011
123
- [12, 2112], // 10100
124
- [12, 2176], // 10101
125
- [12, 2240], // 10110
126
- [12, 2304], // 10111
127
- [11, 1856], [11, 1856], // 1100x
128
- [11, 1920], [11, 1920], // 1101x
129
- [12, 2368], // 11100
130
- [12, 2432], // 11101
131
- [12, 2496], // 11110
132
- [12, 2560] // 11111
133
- ];
134
-
135
- // prettier-ignore
136
- const whiteTable2 = [
137
- [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
138
- [8, 29], [8, 29], // 00000010x
139
- [8, 30], [8, 30], // 00000011x
140
- [8, 45], [8, 45], // 00000100x
141
- [8, 46], [8, 46], // 00000101x
142
- [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
143
- [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
144
- [8, 47], [8, 47], // 00001010x
145
- [8, 48], [8, 48], // 00001011x
146
- [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
147
- [6, 13], [6, 13], [6, 13], [6, 13],
148
- [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
149
- [8, 33], [8, 33], // 00010010x
150
- [8, 34], [8, 34], // 00010011x
151
- [8, 35], [8, 35], // 00010100x
152
- [8, 36], [8, 36], // 00010101x
153
- [8, 37], [8, 37], // 00010110x
154
- [8, 38], [8, 38], // 00010111x
155
- [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
156
- [8, 31], [8, 31], // 00011010x
157
- [8, 32], [8, 32], // 00011011x
158
- [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
159
- [6, 1], [6, 1], [6, 1], [6, 1],
160
- [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
161
- [6, 12], [6, 12], [6, 12], [6, 12],
162
- [8, 53], [8, 53], // 00100100x
163
- [8, 54], [8, 54], // 00100101x
164
- [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
165
- [8, 39], [8, 39], // 00101000x
166
- [8, 40], [8, 40], // 00101001x
167
- [8, 41], [8, 41], // 00101010x
168
- [8, 42], [8, 42], // 00101011x
169
- [8, 43], [8, 43], // 00101100x
170
- [8, 44], [8, 44], // 00101101x
171
- [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
172
- [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
173
- [8, 61], [8, 61], // 00110010x
174
- [8, 62], [8, 62], // 00110011x
175
- [8, 63], [8, 63], // 00110100x
176
- [8, 0], [8, 0], // 00110101x
177
- [8, 320], [8, 320], // 00110110x
178
- [8, 384], [8, 384], // 00110111x
179
- [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
180
- [5, 10], [5, 10], [5, 10], [5, 10],
181
- [5, 10], [5, 10], [5, 10], [5, 10],
182
- [5, 10], [5, 10], [5, 10], [5, 10],
183
- [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
184
- [5, 11], [5, 11], [5, 11], [5, 11],
185
- [5, 11], [5, 11], [5, 11], [5, 11],
186
- [5, 11], [5, 11], [5, 11], [5, 11],
187
- [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
188
- [8, 59], [8, 59], // 01001010x
189
- [8, 60], [8, 60], // 01001011x
190
- [9, 1472], // 010011000
191
- [9, 1536], // 010011001
192
- [9, 1600], // 010011010
193
- [9, 1728], // 010011011
194
- [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
195
- [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
196
- [8, 49], [8, 49], // 01010010x
197
- [8, 50], [8, 50], // 01010011x
198
- [8, 51], [8, 51], // 01010100x
199
- [8, 52], [8, 52], // 01010101x
200
- [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
201
- [8, 55], [8, 55], // 01011000x
202
- [8, 56], [8, 56], // 01011001x
203
- [8, 57], [8, 57], // 01011010x
204
- [8, 58], [8, 58], // 01011011x
205
- [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
206
- [6, 192], [6, 192], [6, 192], [6, 192],
207
- [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
208
- [6, 1664], [6, 1664], [6, 1664], [6, 1664],
209
- [8, 448], [8, 448], // 01100100x
210
- [8, 512], [8, 512], // 01100101x
211
- [9, 704], // 011001100
212
- [9, 768], // 011001101
213
- [8, 640], [8, 640], // 01100111x
214
- [8, 576], [8, 576], // 01101000x
215
- [9, 832], // 011010010
216
- [9, 896], // 011010011
217
- [9, 960], // 011010100
218
- [9, 1024], // 011010101
219
- [9, 1088], // 011010110
220
- [9, 1152], // 011010111
221
- [9, 1216], // 011011000
222
- [9, 1280], // 011011001
223
- [9, 1344], // 011011010
224
- [9, 1408], // 011011011
225
- [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
226
- [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
227
- [4, 2], [4, 2], [4, 2], [4, 2],
228
- [4, 2], [4, 2], [4, 2], [4, 2],
229
- [4, 2], [4, 2], [4, 2], [4, 2],
230
- [4, 2], [4, 2], [4, 2], [4, 2],
231
- [4, 2], [4, 2], [4, 2], [4, 2],
232
- [4, 2], [4, 2], [4, 2], [4, 2],
233
- [4, 2], [4, 2], [4, 2], [4, 2],
234
- [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
235
- [4, 3], [4, 3], [4, 3], [4, 3],
236
- [4, 3], [4, 3], [4, 3], [4, 3],
237
- [4, 3], [4, 3], [4, 3], [4, 3],
238
- [4, 3], [4, 3], [4, 3], [4, 3],
239
- [4, 3], [4, 3], [4, 3], [4, 3],
240
- [4, 3], [4, 3], [4, 3], [4, 3],
241
- [4, 3], [4, 3], [4, 3], [4, 3],
242
- [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
243
- [5, 128], [5, 128], [5, 128], [5, 128],
244
- [5, 128], [5, 128], [5, 128], [5, 128],
245
- [5, 128], [5, 128], [5, 128], [5, 128],
246
- [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
247
- [5, 8], [5, 8], [5, 8], [5, 8],
248
- [5, 8], [5, 8], [5, 8], [5, 8],
249
- [5, 8], [5, 8], [5, 8], [5, 8],
250
- [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
251
- [5, 9], [5, 9], [5, 9], [5, 9],
252
- [5, 9], [5, 9], [5, 9], [5, 9],
253
- [5, 9], [5, 9], [5, 9], [5, 9],
254
- [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
255
- [6, 16], [6, 16], [6, 16], [6, 16],
256
- [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
257
- [6, 17], [6, 17], [6, 17], [6, 17],
258
- [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
259
- [4, 4], [4, 4], [4, 4], [4, 4],
260
- [4, 4], [4, 4], [4, 4], [4, 4],
261
- [4, 4], [4, 4], [4, 4], [4, 4],
262
- [4, 4], [4, 4], [4, 4], [4, 4],
263
- [4, 4], [4, 4], [4, 4], [4, 4],
264
- [4, 4], [4, 4], [4, 4], [4, 4],
265
- [4, 4], [4, 4], [4, 4], [4, 4],
266
- [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
267
- [4, 5], [4, 5], [4, 5], [4, 5],
268
- [4, 5], [4, 5], [4, 5], [4, 5],
269
- [4, 5], [4, 5], [4, 5], [4, 5],
270
- [4, 5], [4, 5], [4, 5], [4, 5],
271
- [4, 5], [4, 5], [4, 5], [4, 5],
272
- [4, 5], [4, 5], [4, 5], [4, 5],
273
- [4, 5], [4, 5], [4, 5], [4, 5],
274
- [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
275
- [6, 14], [6, 14], [6, 14], [6, 14],
276
- [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
277
- [6, 15], [6, 15], [6, 15], [6, 15],
278
- [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
279
- [5, 64], [5, 64], [5, 64], [5, 64],
280
- [5, 64], [5, 64], [5, 64], [5, 64],
281
- [5, 64], [5, 64], [5, 64], [5, 64],
282
- [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
283
- [4, 6], [4, 6], [4, 6], [4, 6],
284
- [4, 6], [4, 6], [4, 6], [4, 6],
285
- [4, 6], [4, 6], [4, 6], [4, 6],
286
- [4, 6], [4, 6], [4, 6], [4, 6],
287
- [4, 6], [4, 6], [4, 6], [4, 6],
288
- [4, 6], [4, 6], [4, 6], [4, 6],
289
- [4, 6], [4, 6], [4, 6], [4, 6],
290
- [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
291
- [4, 7], [4, 7], [4, 7], [4, 7],
292
- [4, 7], [4, 7], [4, 7], [4, 7],
293
- [4, 7], [4, 7], [4, 7], [4, 7],
294
- [4, 7], [4, 7], [4, 7], [4, 7],
295
- [4, 7], [4, 7], [4, 7], [4, 7],
296
- [4, 7], [4, 7], [4, 7], [4, 7],
297
- [4, 7], [4, 7], [4, 7], [4, 7]
298
- ];
299
-
300
- // prettier-ignore
301
- const blackTable1 = [
302
- [-1, -1], [-1, -1], // 000000000000x
303
- [12, ccittEOL], [12, ccittEOL], // 000000000001x
304
- [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
305
- [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
306
- [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
307
- [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
308
- [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
309
- [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
310
- [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
311
- [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
312
- [12, 1984], [12, 1984], // 000000010010x
313
- [12, 2048], [12, 2048], // 000000010011x
314
- [12, 2112], [12, 2112], // 000000010100x
315
- [12, 2176], [12, 2176], // 000000010101x
316
- [12, 2240], [12, 2240], // 000000010110x
317
- [12, 2304], [12, 2304], // 000000010111x
318
- [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
319
- [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
320
- [12, 2368], [12, 2368], // 000000011100x
321
- [12, 2432], [12, 2432], // 000000011101x
322
- [12, 2496], [12, 2496], // 000000011110x
323
- [12, 2560], [12, 2560], // 000000011111x
324
- [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
325
- [10, 18], [10, 18], [10, 18], [10, 18],
326
- [12, 52], [12, 52], // 000000100100x
327
- [13, 640], // 0000001001010
328
- [13, 704], // 0000001001011
329
- [13, 768], // 0000001001100
330
- [13, 832], // 0000001001101
331
- [12, 55], [12, 55], // 000000100111x
332
- [12, 56], [12, 56], // 000000101000x
333
- [13, 1280], // 0000001010010
334
- [13, 1344], // 0000001010011
335
- [13, 1408], // 0000001010100
336
- [13, 1472], // 0000001010101
337
- [12, 59], [12, 59], // 000000101011x
338
- [12, 60], [12, 60], // 000000101100x
339
- [13, 1536], // 0000001011010
340
- [13, 1600], // 0000001011011
341
- [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
342
- [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
343
- [13, 1664], // 0000001100100
344
- [13, 1728], // 0000001100101
345
- [12, 320], [12, 320], // 000000110011x
346
- [12, 384], [12, 384], // 000000110100x
347
- [12, 448], [12, 448], // 000000110101x
348
- [13, 512], // 0000001101100
349
- [13, 576], // 0000001101101
350
- [12, 53], [12, 53], // 000000110111x
351
- [12, 54], [12, 54], // 000000111000x
352
- [13, 896], // 0000001110010
353
- [13, 960], // 0000001110011
354
- [13, 1024], // 0000001110100
355
- [13, 1088], // 0000001110101
356
- [13, 1152], // 0000001110110
357
- [13, 1216], // 0000001110111
358
- [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
359
- [10, 64], [10, 64], [10, 64], [10, 64]
360
- ];
361
-
362
- // prettier-ignore
363
- const blackTable2 = [
364
- [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
365
- [8, 13], [8, 13], [8, 13], [8, 13],
366
- [8, 13], [8, 13], [8, 13], [8, 13],
367
- [8, 13], [8, 13], [8, 13], [8, 13],
368
- [11, 23], [11, 23], // 00000101000x
369
- [12, 50], // 000001010010
370
- [12, 51], // 000001010011
371
- [12, 44], // 000001010100
372
- [12, 45], // 000001010101
373
- [12, 46], // 000001010110
374
- [12, 47], // 000001010111
375
- [12, 57], // 000001011000
376
- [12, 58], // 000001011001
377
- [12, 61], // 000001011010
378
- [12, 256], // 000001011011
379
- [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
380
- [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
381
- [12, 48], // 000001100100
382
- [12, 49], // 000001100101
383
- [12, 62], // 000001100110
384
- [12, 63], // 000001100111
385
- [12, 30], // 000001101000
386
- [12, 31], // 000001101001
387
- [12, 32], // 000001101010
388
- [12, 33], // 000001101011
389
- [12, 40], // 000001101100
390
- [12, 41], // 000001101101
391
- [11, 22], [11, 22], // 00000110111x
392
- [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
393
- [8, 14], [8, 14], [8, 14], [8, 14],
394
- [8, 14], [8, 14], [8, 14], [8, 14],
395
- [8, 14], [8, 14], [8, 14], [8, 14],
396
- [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
397
- [7, 10], [7, 10], [7, 10], [7, 10],
398
- [7, 10], [7, 10], [7, 10], [7, 10],
399
- [7, 10], [7, 10], [7, 10], [7, 10],
400
- [7, 10], [7, 10], [7, 10], [7, 10],
401
- [7, 10], [7, 10], [7, 10], [7, 10],
402
- [7, 10], [7, 10], [7, 10], [7, 10],
403
- [7, 10], [7, 10], [7, 10], [7, 10],
404
- [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
405
- [7, 11], [7, 11], [7, 11], [7, 11],
406
- [7, 11], [7, 11], [7, 11], [7, 11],
407
- [7, 11], [7, 11], [7, 11], [7, 11],
408
- [7, 11], [7, 11], [7, 11], [7, 11],
409
- [7, 11], [7, 11], [7, 11], [7, 11],
410
- [7, 11], [7, 11], [7, 11], [7, 11],
411
- [7, 11], [7, 11], [7, 11], [7, 11],
412
- [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
413
- [9, 15], [9, 15], [9, 15], [9, 15],
414
- [12, 128], // 000011001000
415
- [12, 192], // 000011001001
416
- [12, 26], // 000011001010
417
- [12, 27], // 000011001011
418
- [12, 28], // 000011001100
419
- [12, 29], // 000011001101
420
- [11, 19], [11, 19], // 00001100111x
421
- [11, 20], [11, 20], // 00001101000x
422
- [12, 34], // 000011010010
423
- [12, 35], // 000011010011
424
- [12, 36], // 000011010100
425
- [12, 37], // 000011010101
426
- [12, 38], // 000011010110
427
- [12, 39], // 000011010111
428
- [11, 21], [11, 21], // 00001101100x
429
- [12, 42], // 000011011010
430
- [12, 43], // 000011011011
431
- [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
432
- [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
433
- [7, 12], [7, 12], [7, 12], [7, 12],
434
- [7, 12], [7, 12], [7, 12], [7, 12],
435
- [7, 12], [7, 12], [7, 12], [7, 12],
436
- [7, 12], [7, 12], [7, 12], [7, 12],
437
- [7, 12], [7, 12], [7, 12], [7, 12],
438
- [7, 12], [7, 12], [7, 12], [7, 12],
439
- [7, 12], [7, 12], [7, 12], [7, 12]
440
- ];
441
-
442
- // prettier-ignore
443
- const blackTable3 = [
444
- [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
445
- [6, 9], // 000100
446
- [6, 8], // 000101
447
- [5, 7], [5, 7], // 00011x
448
- [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
449
- [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
450
- [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
451
- [3, 1], [3, 1], [3, 1], [3, 1],
452
- [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
453
- [3, 4], [3, 4], [3, 4], [3, 4],
454
- [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
455
- [2, 3], [2, 3], [2, 3], [2, 3],
456
- [2, 3], [2, 3], [2, 3], [2, 3],
457
- [2, 3], [2, 3], [2, 3], [2, 3],
458
- [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
459
- [2, 2], [2, 2], [2, 2], [2, 2],
460
- [2, 2], [2, 2], [2, 2], [2, 2],
461
- [2, 2], [2, 2], [2, 2], [2, 2]
462
- ];
463
-
464
- /**
465
- * @param {CCITTFaxDecoderSource} source - The data which should be decoded.
466
- * @param {Object} [options] - Decoding options.
467
- */
468
- // eslint-disable-next-line no-shadow
469
- function CCITTFaxDecoder(source, options = {}) {
470
- if (!source || typeof source.next !== "function") {
471
- throw new Error('CCITTFaxDecoder - invalid "source" parameter.');
472
- }
473
- this.source = source;
474
- this.eof = false;
475
-
476
- this.encoding = options.K || 0;
477
- this.eoline = options.EndOfLine || false;
478
- this.byteAlign = options.EncodedByteAlign || false;
479
- this.columns = options.Columns || 1728;
480
- this.rows = options.Rows || 0;
481
- let eoblock = options.EndOfBlock;
482
- if (eoblock === null || eoblock === undefined) {
483
- eoblock = true;
484
- }
485
- this.eoblock = eoblock;
486
- this.black = options.BlackIs1 || false;
487
-
488
- this.codingLine = new Uint32Array(this.columns + 1);
489
- this.refLine = new Uint32Array(this.columns + 2);
490
-
491
- this.codingLine[0] = this.columns;
492
- this.codingPos = 0;
493
-
494
- this.row = 0;
495
- this.nextLine2D = this.encoding < 0;
496
- this.inputBits = 0;
497
- this.inputBuf = 0;
498
- this.outputBits = 0;
499
- this.rowsDone = false;
500
-
501
- let code1;
502
- while ((code1 = this._lookBits(12)) === 0) {
503
- this._eatBits(1);
504
- }
505
- if (code1 === 1) {
506
- this._eatBits(12);
507
- }
508
- if (this.encoding > 0) {
509
- this.nextLine2D = !this._lookBits(1);
510
- this._eatBits(1);
511
- }
512
- }
513
-
514
- CCITTFaxDecoder.prototype = {
515
- readNextChar() {
516
- if (this.eof) {
517
- return -1;
518
- }
519
- const refLine = this.refLine;
520
- const codingLine = this.codingLine;
521
- const columns = this.columns;
522
-
523
- let refPos, blackPixels, bits, i;
524
-
525
- if (this.outputBits === 0) {
526
- if (this.rowsDone) {
527
- this.eof = true;
528
- }
529
- if (this.eof) {
530
- return -1;
531
- }
532
- this.err = false;
533
-
534
- let code1, code2, code3;
535
- if (this.nextLine2D) {
536
- for (i = 0; codingLine[i] < columns; ++i) {
537
- refLine[i] = codingLine[i];
538
- }
539
- refLine[i++] = columns;
540
- refLine[i] = columns;
541
- codingLine[0] = 0;
542
- this.codingPos = 0;
543
- refPos = 0;
544
- blackPixels = 0;
545
-
546
- while (codingLine[this.codingPos] < columns) {
547
- code1 = this._getTwoDimCode();
548
- switch (code1) {
549
- case twoDimPass:
550
- this._addPixels(refLine[refPos + 1], blackPixels);
551
- if (refLine[refPos + 1] < columns) {
552
- refPos += 2;
553
- }
554
- break;
555
- case twoDimHoriz:
556
- code1 = code2 = 0;
557
- if (blackPixels) {
558
- do {
559
- code1 += code3 = this._getBlackCode();
560
- } while (code3 >= 64);
561
- do {
562
- code2 += code3 = this._getWhiteCode();
563
- } while (code3 >= 64);
564
- } else {
565
- do {
566
- code1 += code3 = this._getWhiteCode();
567
- } while (code3 >= 64);
568
- do {
569
- code2 += code3 = this._getBlackCode();
570
- } while (code3 >= 64);
571
- }
572
- this._addPixels(
573
- codingLine[this.codingPos] + code1,
574
- blackPixels
575
- );
576
- if (codingLine[this.codingPos] < columns) {
577
- this._addPixels(
578
- codingLine[this.codingPos] + code2,
579
- blackPixels ^ 1
580
- );
581
- }
582
- while (
583
- refLine[refPos] <= codingLine[this.codingPos] &&
584
- refLine[refPos] < columns
585
- ) {
586
- refPos += 2;
587
- }
588
- break;
589
- case twoDimVertR3:
590
- this._addPixels(refLine[refPos] + 3, blackPixels);
591
- blackPixels ^= 1;
592
- if (codingLine[this.codingPos] < columns) {
593
- ++refPos;
594
- while (
595
- refLine[refPos] <= codingLine[this.codingPos] &&
596
- refLine[refPos] < columns
597
- ) {
598
- refPos += 2;
599
- }
600
- }
601
- break;
602
- case twoDimVertR2:
603
- this._addPixels(refLine[refPos] + 2, blackPixels);
604
- blackPixels ^= 1;
605
- if (codingLine[this.codingPos] < columns) {
606
- ++refPos;
607
- while (
608
- refLine[refPos] <= codingLine[this.codingPos] &&
609
- refLine[refPos] < columns
610
- ) {
611
- refPos += 2;
612
- }
613
- }
614
- break;
615
- case twoDimVertR1:
616
- this._addPixels(refLine[refPos] + 1, blackPixels);
617
- blackPixels ^= 1;
618
- if (codingLine[this.codingPos] < columns) {
619
- ++refPos;
620
- while (
621
- refLine[refPos] <= codingLine[this.codingPos] &&
622
- refLine[refPos] < columns
623
- ) {
624
- refPos += 2;
625
- }
626
- }
627
- break;
628
- case twoDimVert0:
629
- this._addPixels(refLine[refPos], blackPixels);
630
- blackPixels ^= 1;
631
- if (codingLine[this.codingPos] < columns) {
632
- ++refPos;
633
- while (
634
- refLine[refPos] <= codingLine[this.codingPos] &&
635
- refLine[refPos] < columns
636
- ) {
637
- refPos += 2;
638
- }
639
- }
640
- break;
641
- case twoDimVertL3:
642
- this._addPixelsNeg(refLine[refPos] - 3, blackPixels);
643
- blackPixels ^= 1;
644
- if (codingLine[this.codingPos] < columns) {
645
- if (refPos > 0) {
646
- --refPos;
647
- } else {
648
- ++refPos;
649
- }
650
- while (
651
- refLine[refPos] <= codingLine[this.codingPos] &&
652
- refLine[refPos] < columns
653
- ) {
654
- refPos += 2;
655
- }
656
- }
657
- break;
658
- case twoDimVertL2:
659
- this._addPixelsNeg(refLine[refPos] - 2, blackPixels);
660
- blackPixels ^= 1;
661
- if (codingLine[this.codingPos] < columns) {
662
- if (refPos > 0) {
663
- --refPos;
664
- } else {
665
- ++refPos;
666
- }
667
- while (
668
- refLine[refPos] <= codingLine[this.codingPos] &&
669
- refLine[refPos] < columns
670
- ) {
671
- refPos += 2;
672
- }
673
- }
674
- break;
675
- case twoDimVertL1:
676
- this._addPixelsNeg(refLine[refPos] - 1, blackPixels);
677
- blackPixels ^= 1;
678
- if (codingLine[this.codingPos] < columns) {
679
- if (refPos > 0) {
680
- --refPos;
681
- } else {
682
- ++refPos;
683
- }
684
- while (
685
- refLine[refPos] <= codingLine[this.codingPos] &&
686
- refLine[refPos] < columns
687
- ) {
688
- refPos += 2;
689
- }
690
- }
691
- break;
692
- case ccittEOF:
693
- this._addPixels(columns, 0);
694
- this.eof = true;
695
- break;
696
- default:
697
- info("bad 2d code");
698
- this._addPixels(columns, 0);
699
- this.err = true;
700
- }
701
- }
702
- } else {
703
- codingLine[0] = 0;
704
- this.codingPos = 0;
705
- blackPixels = 0;
706
- while (codingLine[this.codingPos] < columns) {
707
- code1 = 0;
708
- if (blackPixels) {
709
- do {
710
- code1 += code3 = this._getBlackCode();
711
- } while (code3 >= 64);
712
- } else {
713
- do {
714
- code1 += code3 = this._getWhiteCode();
715
- } while (code3 >= 64);
716
- }
717
- this._addPixels(codingLine[this.codingPos] + code1, blackPixels);
718
- blackPixels ^= 1;
719
- }
720
- }
721
-
722
- let gotEOL = false;
723
-
724
- if (this.byteAlign) {
725
- this.inputBits &= ~7;
726
- }
727
-
728
- if (!this.eoblock && this.row === this.rows - 1) {
729
- this.rowsDone = true;
730
- } else {
731
- code1 = this._lookBits(12);
732
- if (this.eoline) {
733
- while (code1 !== ccittEOF && code1 !== 1) {
734
- this._eatBits(1);
735
- code1 = this._lookBits(12);
736
- }
737
- } else {
738
- while (code1 === 0) {
739
- this._eatBits(1);
740
- code1 = this._lookBits(12);
741
- }
742
- }
743
- if (code1 === 1) {
744
- this._eatBits(12);
745
- gotEOL = true;
746
- } else if (code1 === ccittEOF) {
747
- this.eof = true;
748
- }
749
- }
750
-
751
- if (!this.eof && this.encoding > 0 && !this.rowsDone) {
752
- this.nextLine2D = !this._lookBits(1);
753
- this._eatBits(1);
754
- }
755
-
756
- if (this.eoblock && gotEOL && this.byteAlign) {
757
- code1 = this._lookBits(12);
758
- if (code1 === 1) {
759
- this._eatBits(12);
760
- if (this.encoding > 0) {
761
- this._lookBits(1);
762
- this._eatBits(1);
763
- }
764
- if (this.encoding >= 0) {
765
- for (i = 0; i < 4; ++i) {
766
- code1 = this._lookBits(12);
767
- if (code1 !== 1) {
768
- info("bad rtc code: " + code1);
769
- }
770
- this._eatBits(12);
771
- if (this.encoding > 0) {
772
- this._lookBits(1);
773
- this._eatBits(1);
774
- }
775
- }
776
- }
777
- this.eof = true;
778
- }
779
- } else if (this.err && this.eoline) {
780
- while (true) {
781
- code1 = this._lookBits(13);
782
- if (code1 === ccittEOF) {
783
- this.eof = true;
784
- return -1;
785
- }
786
- if (code1 >> 1 === 1) {
787
- break;
788
- }
789
- this._eatBits(1);
790
- }
791
- this._eatBits(12);
792
- if (this.encoding > 0) {
793
- this._eatBits(1);
794
- this.nextLine2D = !(code1 & 1);
795
- }
796
- }
797
-
798
- if (codingLine[0] > 0) {
799
- this.outputBits = codingLine[(this.codingPos = 0)];
800
- } else {
801
- this.outputBits = codingLine[(this.codingPos = 1)];
802
- }
803
- this.row++;
804
- }
805
-
806
- let c;
807
- if (this.outputBits >= 8) {
808
- c = this.codingPos & 1 ? 0 : 0xff;
809
- this.outputBits -= 8;
810
- if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
811
- this.codingPos++;
812
- this.outputBits =
813
- codingLine[this.codingPos] - codingLine[this.codingPos - 1];
814
- }
815
- } else {
816
- bits = 8;
817
- c = 0;
818
- do {
819
- if (this.outputBits > bits) {
820
- c <<= bits;
821
- if (!(this.codingPos & 1)) {
822
- c |= 0xff >> (8 - bits);
823
- }
824
- this.outputBits -= bits;
825
- bits = 0;
826
- } else {
827
- c <<= this.outputBits;
828
- if (!(this.codingPos & 1)) {
829
- c |= 0xff >> (8 - this.outputBits);
830
- }
831
- bits -= this.outputBits;
832
- this.outputBits = 0;
833
- if (codingLine[this.codingPos] < columns) {
834
- this.codingPos++;
835
- this.outputBits =
836
- codingLine[this.codingPos] - codingLine[this.codingPos - 1];
837
- } else if (bits > 0) {
838
- c <<= bits;
839
- bits = 0;
840
- }
841
- }
842
- } while (bits);
843
- }
844
- if (this.black) {
845
- c ^= 0xff;
846
- }
847
- return c;
848
- },
849
-
850
- /**
851
- * @private
852
- */
853
- _addPixels(a1, blackPixels) {
854
- const codingLine = this.codingLine;
855
- let codingPos = this.codingPos;
856
-
857
- if (a1 > codingLine[codingPos]) {
858
- if (a1 > this.columns) {
859
- info("row is wrong length");
860
- this.err = true;
861
- a1 = this.columns;
862
- }
863
- if ((codingPos & 1) ^ blackPixels) {
864
- ++codingPos;
865
- }
866
-
867
- codingLine[codingPos] = a1;
868
- }
869
- this.codingPos = codingPos;
870
- },
871
-
872
- /**
873
- * @private
874
- */
875
- _addPixelsNeg(a1, blackPixels) {
876
- const codingLine = this.codingLine;
877
- let codingPos = this.codingPos;
878
-
879
- if (a1 > codingLine[codingPos]) {
880
- if (a1 > this.columns) {
881
- info("row is wrong length");
882
- this.err = true;
883
- a1 = this.columns;
884
- }
885
- if ((codingPos & 1) ^ blackPixels) {
886
- ++codingPos;
887
- }
888
-
889
- codingLine[codingPos] = a1;
890
- } else if (a1 < codingLine[codingPos]) {
891
- if (a1 < 0) {
892
- info("invalid code");
893
- this.err = true;
894
- a1 = 0;
895
- }
896
- while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
897
- --codingPos;
898
- }
899
- codingLine[codingPos] = a1;
900
- }
901
-
902
- this.codingPos = codingPos;
903
- },
904
-
905
- /**
906
- * This function returns the code found from the table.
907
- * The start and end parameters set the boundaries for searching the table.
908
- * The limit parameter is optional. Function returns an array with three
909
- * values. The first array element indicates whether a valid code is being
910
- * returned. The second array element is the actual code. The third array
911
- * element indicates whether EOF was reached.
912
- * @private
913
- */
914
- _findTableCode(start, end, table, limit) {
915
- const limitValue = limit || 0;
916
- for (let i = start; i <= end; ++i) {
917
- let code = this._lookBits(i);
918
- if (code === ccittEOF) {
919
- return [true, 1, false];
920
- }
921
- if (i < end) {
922
- code <<= end - i;
923
- }
924
- if (!limitValue || code >= limitValue) {
925
- const p = table[code - limitValue];
926
- if (p[0] === i) {
927
- this._eatBits(i);
928
- return [true, p[1], true];
929
- }
930
- }
931
- }
932
- return [false, 0, false];
933
- },
934
-
935
- /**
936
- * @private
937
- */
938
- _getTwoDimCode() {
939
- let code = 0;
940
- let p;
941
- if (this.eoblock) {
942
- code = this._lookBits(7);
943
- p = twoDimTable[code];
944
- if (p && p[0] > 0) {
945
- this._eatBits(p[0]);
946
- return p[1];
947
- }
948
- } else {
949
- const result = this._findTableCode(1, 7, twoDimTable);
950
- if (result[0] && result[2]) {
951
- return result[1];
952
- }
953
- }
954
- info("Bad two dim code");
955
- return ccittEOF;
956
- },
957
-
958
- /**
959
- * @private
960
- */
961
- _getWhiteCode() {
962
- let code = 0;
963
- let p;
964
- if (this.eoblock) {
965
- code = this._lookBits(12);
966
- if (code === ccittEOF) {
967
- return 1;
968
- }
969
-
970
- if (code >> 5 === 0) {
971
- p = whiteTable1[code];
972
- } else {
973
- p = whiteTable2[code >> 3];
974
- }
975
-
976
- if (p[0] > 0) {
977
- this._eatBits(p[0]);
978
- return p[1];
979
- }
980
- } else {
981
- let result = this._findTableCode(1, 9, whiteTable2);
982
- if (result[0]) {
983
- return result[1];
984
- }
985
-
986
- result = this._findTableCode(11, 12, whiteTable1);
987
- if (result[0]) {
988
- return result[1];
989
- }
990
- }
991
- info("bad white code");
992
- this._eatBits(1);
993
- return 1;
994
- },
995
-
996
- /**
997
- * @private
998
- */
999
- _getBlackCode() {
1000
- let code, p;
1001
- if (this.eoblock) {
1002
- code = this._lookBits(13);
1003
- if (code === ccittEOF) {
1004
- return 1;
1005
- }
1006
- if (code >> 7 === 0) {
1007
- p = blackTable1[code];
1008
- } else if (code >> 9 === 0 && code >> 7 !== 0) {
1009
- p = blackTable2[(code >> 1) - 64];
1010
- } else {
1011
- p = blackTable3[code >> 7];
1012
- }
1013
-
1014
- if (p[0] > 0) {
1015
- this._eatBits(p[0]);
1016
- return p[1];
1017
- }
1018
- } else {
1019
- let result = this._findTableCode(2, 6, blackTable3);
1020
- if (result[0]) {
1021
- return result[1];
1022
- }
1023
-
1024
- result = this._findTableCode(7, 12, blackTable2, 64);
1025
- if (result[0]) {
1026
- return result[1];
1027
- }
1028
-
1029
- result = this._findTableCode(10, 13, blackTable1);
1030
- if (result[0]) {
1031
- return result[1];
1032
- }
1033
- }
1034
- info("bad black code");
1035
- this._eatBits(1);
1036
- return 1;
1037
- },
1038
-
1039
- /**
1040
- * @private
1041
- */
1042
- _lookBits(n) {
1043
- let c;
1044
- while (this.inputBits < n) {
1045
- if ((c = this.source.next()) === -1) {
1046
- if (this.inputBits === 0) {
1047
- return ccittEOF;
1048
- }
1049
- return (this.inputBuf << (n - this.inputBits)) & (0xffff >> (16 - n));
1050
- }
1051
- this.inputBuf = (this.inputBuf << 8) | c;
1052
- this.inputBits += 8;
1053
- }
1054
- return (this.inputBuf >> (this.inputBits - n)) & (0xffff >> (16 - n));
1055
- },
1056
-
1057
- /**
1058
- * @private
1059
- */
1060
- _eatBits(n) {
1061
- if ((this.inputBits -= n) < 0) {
1062
- this.inputBits = 0;
1063
- }
1064
- },
1065
- };
1066
-
1067
- return CCITTFaxDecoder;
1068
- })();
1069
-
1070
- export { CCITTFaxDecoder };