@vaadin-component-factory/vcf-pdf-viewer 0.9.0 → 0.9.4

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 (174) hide show
  1. package/README.md +1 -1
  2. package/package.json +33 -18
  3. package/{src/display → pdfjs/dist}/display_utils.js +344 -139
  4. package/{src/display → pdfjs/dist}/fetch_stream.js +115 -97
  5. package/pdfjs/dist/get.js +1857 -0
  6. package/pdfjs/dist/index.js +767 -0
  7. package/pdfjs/dist/l10n_utils.js +140 -0
  8. package/{src/shared → pdfjs/dist}/message_handler.js +243 -259
  9. package/{src/display → pdfjs/dist}/network.js +149 -87
  10. package/{src/display/content_disposition.js → pdfjs/dist/network_utils.js} +167 -55
  11. package/{src/display → pdfjs/dist}/node_stream.js +133 -98
  12. package/pdfjs/dist/pdf.js +12778 -0
  13. package/pdfjs/dist/pdf_link_service.js +638 -0
  14. package/pdfjs/dist/pdf_rendering_queue.js +199 -0
  15. package/pdfjs/dist/pdf_thumbnail_viewer.js +819 -0
  16. package/pdfjs/dist/pdf_viewer.js +3598 -0
  17. package/pdfjs/dist/typeof.js +100 -0
  18. package/pdfjs/dist/ui_utils.js +1033 -0
  19. package/{src/shared → pdfjs/dist}/util.js +301 -287
  20. package/pdfjs/dist/worker.js +62813 -0
  21. package/src/vcf-pdf-viewer.js +77 -27
  22. package/theme/lumo/vcf-pdf-viewer-styles.js +1 -1
  23. package/theme/material/vcf-pdf-viewer.js +2 -2
  24. package/src/core/.eslintrc +0 -13
  25. package/src/core/annotation.js +0 -2948
  26. package/src/core/arithmetic_decoder.js +0 -182
  27. package/src/core/ascii_85_stream.js +0 -98
  28. package/src/core/ascii_hex_stream.js +0 -79
  29. package/src/core/base_stream.js +0 -110
  30. package/src/core/bidi.js +0 -438
  31. package/src/core/calibri_factors.js +0 -308
  32. package/src/core/catalog.js +0 -1459
  33. package/src/core/ccitt.js +0 -1062
  34. package/src/core/ccitt_stream.js +0 -60
  35. package/src/core/cff_font.js +0 -116
  36. package/src/core/cff_parser.js +0 -1949
  37. package/src/core/charsets.js +0 -119
  38. package/src/core/chunked_stream.js +0 -557
  39. package/src/core/cmap.js +0 -1039
  40. package/src/core/colorspace.js +0 -1533
  41. package/src/core/core_utils.js +0 -464
  42. package/src/core/crypto.js +0 -1900
  43. package/src/core/decode_stream.js +0 -170
  44. package/src/core/decrypt_stream.js +0 -59
  45. package/src/core/default_appearance.js +0 -99
  46. package/src/core/document.js +0 -1456
  47. package/src/core/encodings.js +0 -301
  48. package/src/core/evaluator.js +0 -4601
  49. package/src/core/file_spec.js +0 -108
  50. package/src/core/flate_stream.js +0 -402
  51. package/src/core/font_renderer.js +0 -882
  52. package/src/core/fonts.js +0 -3260
  53. package/src/core/fonts_utils.js +0 -221
  54. package/src/core/function.js +0 -1257
  55. package/src/core/glyf.js +0 -706
  56. package/src/core/glyphlist.js +0 -4558
  57. package/src/core/helvetica_factors.js +0 -353
  58. package/src/core/image.js +0 -802
  59. package/src/core/image_utils.js +0 -291
  60. package/src/core/jbig2.js +0 -2572
  61. package/src/core/jbig2_stream.js +0 -73
  62. package/src/core/jpeg_stream.js +0 -105
  63. package/src/core/jpg.js +0 -1416
  64. package/src/core/jpx.js +0 -2343
  65. package/src/core/jpx_stream.js +0 -87
  66. package/src/core/liberationsans_widths.js +0 -221
  67. package/src/core/lzw_stream.js +0 -150
  68. package/src/core/metadata_parser.js +0 -146
  69. package/src/core/metrics.js +0 -2970
  70. package/src/core/murmurhash3.js +0 -139
  71. package/src/core/myriadpro_factors.js +0 -290
  72. package/src/core/name_number_tree.js +0 -153
  73. package/src/core/object_loader.js +0 -149
  74. package/src/core/opentype_file_builder.js +0 -154
  75. package/src/core/operator_list.js +0 -734
  76. package/src/core/parser.js +0 -1416
  77. package/src/core/pattern.js +0 -985
  78. package/src/core/pdf_manager.js +0 -217
  79. package/src/core/predictor_stream.js +0 -238
  80. package/src/core/primitives.js +0 -402
  81. package/src/core/ps_parser.js +0 -272
  82. package/src/core/run_length_stream.js +0 -61
  83. package/src/core/segoeui_factors.js +0 -308
  84. package/src/core/standard_fonts.js +0 -817
  85. package/src/core/stream.js +0 -103
  86. package/src/core/struct_tree.js +0 -335
  87. package/src/core/to_unicode_map.js +0 -103
  88. package/src/core/type1_font.js +0 -421
  89. package/src/core/type1_parser.js +0 -776
  90. package/src/core/unicode.js +0 -1649
  91. package/src/core/worker.js +0 -848
  92. package/src/core/worker_stream.js +0 -135
  93. package/src/core/writer.js +0 -278
  94. package/src/core/xfa/bind.js +0 -652
  95. package/src/core/xfa/builder.js +0 -207
  96. package/src/core/xfa/config.js +0 -1926
  97. package/src/core/xfa/connection_set.js +0 -202
  98. package/src/core/xfa/data.js +0 -82
  99. package/src/core/xfa/datasets.js +0 -76
  100. package/src/core/xfa/factory.js +0 -111
  101. package/src/core/xfa/fonts.js +0 -181
  102. package/src/core/xfa/formcalc_lexer.js +0 -385
  103. package/src/core/xfa/formcalc_parser.js +0 -1340
  104. package/src/core/xfa/html_utils.js +0 -639
  105. package/src/core/xfa/layout.js +0 -383
  106. package/src/core/xfa/locale_set.js +0 -345
  107. package/src/core/xfa/namespaces.js +0 -81
  108. package/src/core/xfa/parser.js +0 -184
  109. package/src/core/xfa/setup.js +0 -38
  110. package/src/core/xfa/signature.js +0 -40
  111. package/src/core/xfa/som.js +0 -338
  112. package/src/core/xfa/stylesheet.js +0 -40
  113. package/src/core/xfa/template.js +0 -6260
  114. package/src/core/xfa/text.js +0 -290
  115. package/src/core/xfa/unknown.js +0 -29
  116. package/src/core/xfa/utils.js +0 -217
  117. package/src/core/xfa/xdp.js +0 -59
  118. package/src/core/xfa/xfa_object.js +0 -1130
  119. package/src/core/xfa/xhtml.js +0 -543
  120. package/src/core/xfa_fonts.js +0 -208
  121. package/src/core/xml_parser.js +0 -507
  122. package/src/core/xref.js +0 -899
  123. package/src/display/annotation_layer.js +0 -2107
  124. package/src/display/annotation_storage.js +0 -113
  125. package/src/display/api.js +0 -3292
  126. package/src/display/base_factory.js +0 -180
  127. package/src/display/canvas.js +0 -2828
  128. package/src/display/font_loader.js +0 -484
  129. package/src/display/metadata.js +0 -41
  130. package/src/display/network_utils.js +0 -100
  131. package/src/display/node_utils.js +0 -83
  132. package/src/display/optional_content_config.js +0 -189
  133. package/src/display/pattern_helper.js +0 -659
  134. package/src/display/svg.js +0 -1709
  135. package/src/display/text_layer.js +0 -847
  136. package/src/display/transport_stream.js +0 -303
  137. package/src/display/worker_options.js +0 -40
  138. package/src/display/xfa_layer.js +0 -204
  139. package/src/doc_helper.js +0 -25
  140. package/src/images/logo.svg +0 -41
  141. package/src/interfaces.js +0 -169
  142. package/src/license_header.js +0 -14
  143. package/src/license_header_libre.js +0 -21
  144. package/src/pdf.image_decoders.js +0 -46
  145. package/src/pdf.js +0 -146
  146. package/src/pdf.sandbox.external.js +0 -181
  147. package/src/pdf.sandbox.js +0 -151
  148. package/src/pdf.scripting.js +0 -25
  149. package/src/pdf.worker.entry.js +0 -19
  150. package/src/pdf.worker.js +0 -23
  151. package/src/scripting_api/aform.js +0 -608
  152. package/src/scripting_api/app.js +0 -621
  153. package/src/scripting_api/color.js +0 -129
  154. package/src/scripting_api/common.js +0 -58
  155. package/src/scripting_api/console.js +0 -38
  156. package/src/scripting_api/constants.js +0 -208
  157. package/src/scripting_api/doc.js +0 -1195
  158. package/src/scripting_api/error.js +0 -23
  159. package/src/scripting_api/event.js +0 -232
  160. package/src/scripting_api/field.js +0 -620
  161. package/src/scripting_api/fullscreen.js +0 -145
  162. package/src/scripting_api/initialization.js +0 -223
  163. package/src/scripting_api/pdf_object.js +0 -24
  164. package/src/scripting_api/print_params.js +0 -146
  165. package/src/scripting_api/proxy.js +0 -139
  166. package/src/scripting_api/thermometer.js +0 -69
  167. package/src/scripting_api/util.js +0 -581
  168. package/src/shared/.eslintrc +0 -13
  169. package/src/shared/cffStandardStrings.js +0 -311
  170. package/src/shared/compatibility.js +0 -114
  171. package/src/shared/fonts_utils.js +0 -429
  172. package/src/shared/is_node.js +0 -27
  173. package/src/shared/scripting_utils.js +0 -85
  174. package/src/worker_loader.js +0 -32
package/src/core/ccitt.js DELETED
@@ -1,1062 +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
- import { info } from "../shared/util.js";
23
-
24
- /**
25
- * @typedef {Object} CCITTFaxDecoderSource
26
- * @property {function} next - Method that return one byte of data for decoding,
27
- * or -1 when EOF is reached.
28
- */
29
-
30
- const ccittEOL = -2;
31
- const ccittEOF = -1;
32
- const twoDimPass = 0;
33
- const twoDimHoriz = 1;
34
- const twoDimVert0 = 2;
35
- const twoDimVertR1 = 3;
36
- const twoDimVertL1 = 4;
37
- const twoDimVertR2 = 5;
38
- const twoDimVertL2 = 6;
39
- const twoDimVertR3 = 7;
40
- const twoDimVertL3 = 8;
41
-
42
- // prettier-ignore
43
- const twoDimTable = [
44
- [-1, -1], [-1, -1], // 000000x
45
- [7, twoDimVertL3], // 0000010
46
- [7, twoDimVertR3], // 0000011
47
- [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
48
- [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
49
- [4, twoDimPass], [4, twoDimPass], // 0001xxx
50
- [4, twoDimPass], [4, twoDimPass],
51
- [4, twoDimPass], [4, twoDimPass],
52
- [4, twoDimPass], [4, twoDimPass],
53
- [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
54
- [3, twoDimHoriz], [3, twoDimHoriz],
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, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
62
- [3, twoDimVertL1], [3, twoDimVertL1],
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, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
70
- [3, twoDimVertR1], [3, twoDimVertR1],
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
- [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
78
- [1, twoDimVert0], [1, twoDimVert0],
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
- ];
110
-
111
- // prettier-ignore
112
- const whiteTable1 = [
113
- [-1, -1], // 00000
114
- [12, ccittEOL], // 00001
115
- [-1, -1], [-1, -1], // 0001x
116
- [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
117
- [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
118
- [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
119
- [11, 1792], [11, 1792], // 1000x
120
- [12, 1984], // 10010
121
- [12, 2048], // 10011
122
- [12, 2112], // 10100
123
- [12, 2176], // 10101
124
- [12, 2240], // 10110
125
- [12, 2304], // 10111
126
- [11, 1856], [11, 1856], // 1100x
127
- [11, 1920], [11, 1920], // 1101x
128
- [12, 2368], // 11100
129
- [12, 2432], // 11101
130
- [12, 2496], // 11110
131
- [12, 2560] // 11111
132
- ];
133
-
134
- // prettier-ignore
135
- const whiteTable2 = [
136
- [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
137
- [8, 29], [8, 29], // 00000010x
138
- [8, 30], [8, 30], // 00000011x
139
- [8, 45], [8, 45], // 00000100x
140
- [8, 46], [8, 46], // 00000101x
141
- [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
142
- [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
143
- [8, 47], [8, 47], // 00001010x
144
- [8, 48], [8, 48], // 00001011x
145
- [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
146
- [6, 13], [6, 13], [6, 13], [6, 13],
147
- [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
148
- [8, 33], [8, 33], // 00010010x
149
- [8, 34], [8, 34], // 00010011x
150
- [8, 35], [8, 35], // 00010100x
151
- [8, 36], [8, 36], // 00010101x
152
- [8, 37], [8, 37], // 00010110x
153
- [8, 38], [8, 38], // 00010111x
154
- [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
155
- [8, 31], [8, 31], // 00011010x
156
- [8, 32], [8, 32], // 00011011x
157
- [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
158
- [6, 1], [6, 1], [6, 1], [6, 1],
159
- [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
160
- [6, 12], [6, 12], [6, 12], [6, 12],
161
- [8, 53], [8, 53], // 00100100x
162
- [8, 54], [8, 54], // 00100101x
163
- [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
164
- [8, 39], [8, 39], // 00101000x
165
- [8, 40], [8, 40], // 00101001x
166
- [8, 41], [8, 41], // 00101010x
167
- [8, 42], [8, 42], // 00101011x
168
- [8, 43], [8, 43], // 00101100x
169
- [8, 44], [8, 44], // 00101101x
170
- [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
171
- [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
172
- [8, 61], [8, 61], // 00110010x
173
- [8, 62], [8, 62], // 00110011x
174
- [8, 63], [8, 63], // 00110100x
175
- [8, 0], [8, 0], // 00110101x
176
- [8, 320], [8, 320], // 00110110x
177
- [8, 384], [8, 384], // 00110111x
178
- [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
179
- [5, 10], [5, 10], [5, 10], [5, 10],
180
- [5, 10], [5, 10], [5, 10], [5, 10],
181
- [5, 10], [5, 10], [5, 10], [5, 10],
182
- [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
183
- [5, 11], [5, 11], [5, 11], [5, 11],
184
- [5, 11], [5, 11], [5, 11], [5, 11],
185
- [5, 11], [5, 11], [5, 11], [5, 11],
186
- [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
187
- [8, 59], [8, 59], // 01001010x
188
- [8, 60], [8, 60], // 01001011x
189
- [9, 1472], // 010011000
190
- [9, 1536], // 010011001
191
- [9, 1600], // 010011010
192
- [9, 1728], // 010011011
193
- [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
194
- [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
195
- [8, 49], [8, 49], // 01010010x
196
- [8, 50], [8, 50], // 01010011x
197
- [8, 51], [8, 51], // 01010100x
198
- [8, 52], [8, 52], // 01010101x
199
- [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
200
- [8, 55], [8, 55], // 01011000x
201
- [8, 56], [8, 56], // 01011001x
202
- [8, 57], [8, 57], // 01011010x
203
- [8, 58], [8, 58], // 01011011x
204
- [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
205
- [6, 192], [6, 192], [6, 192], [6, 192],
206
- [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
207
- [6, 1664], [6, 1664], [6, 1664], [6, 1664],
208
- [8, 448], [8, 448], // 01100100x
209
- [8, 512], [8, 512], // 01100101x
210
- [9, 704], // 011001100
211
- [9, 768], // 011001101
212
- [8, 640], [8, 640], // 01100111x
213
- [8, 576], [8, 576], // 01101000x
214
- [9, 832], // 011010010
215
- [9, 896], // 011010011
216
- [9, 960], // 011010100
217
- [9, 1024], // 011010101
218
- [9, 1088], // 011010110
219
- [9, 1152], // 011010111
220
- [9, 1216], // 011011000
221
- [9, 1280], // 011011001
222
- [9, 1344], // 011011010
223
- [9, 1408], // 011011011
224
- [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
225
- [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
226
- [4, 2], [4, 2], [4, 2], [4, 2],
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, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
234
- [4, 3], [4, 3], [4, 3], [4, 3],
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
- [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
242
- [5, 128], [5, 128], [5, 128], [5, 128],
243
- [5, 128], [5, 128], [5, 128], [5, 128],
244
- [5, 128], [5, 128], [5, 128], [5, 128],
245
- [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
246
- [5, 8], [5, 8], [5, 8], [5, 8],
247
- [5, 8], [5, 8], [5, 8], [5, 8],
248
- [5, 8], [5, 8], [5, 8], [5, 8],
249
- [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
250
- [5, 9], [5, 9], [5, 9], [5, 9],
251
- [5, 9], [5, 9], [5, 9], [5, 9],
252
- [5, 9], [5, 9], [5, 9], [5, 9],
253
- [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
254
- [6, 16], [6, 16], [6, 16], [6, 16],
255
- [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
256
- [6, 17], [6, 17], [6, 17], [6, 17],
257
- [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
258
- [4, 4], [4, 4], [4, 4], [4, 4],
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, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
266
- [4, 5], [4, 5], [4, 5], [4, 5],
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
- [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
274
- [6, 14], [6, 14], [6, 14], [6, 14],
275
- [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
276
- [6, 15], [6, 15], [6, 15], [6, 15],
277
- [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
278
- [5, 64], [5, 64], [5, 64], [5, 64],
279
- [5, 64], [5, 64], [5, 64], [5, 64],
280
- [5, 64], [5, 64], [5, 64], [5, 64],
281
- [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
282
- [4, 6], [4, 6], [4, 6], [4, 6],
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, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
290
- [4, 7], [4, 7], [4, 7], [4, 7],
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
- ];
298
-
299
- // prettier-ignore
300
- const blackTable1 = [
301
- [-1, -1], [-1, -1], // 000000000000x
302
- [12, ccittEOL], [12, ccittEOL], // 000000000001x
303
- [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
304
- [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
305
- [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
306
- [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
307
- [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
308
- [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
309
- [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
310
- [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
311
- [12, 1984], [12, 1984], // 000000010010x
312
- [12, 2048], [12, 2048], // 000000010011x
313
- [12, 2112], [12, 2112], // 000000010100x
314
- [12, 2176], [12, 2176], // 000000010101x
315
- [12, 2240], [12, 2240], // 000000010110x
316
- [12, 2304], [12, 2304], // 000000010111x
317
- [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
318
- [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
319
- [12, 2368], [12, 2368], // 000000011100x
320
- [12, 2432], [12, 2432], // 000000011101x
321
- [12, 2496], [12, 2496], // 000000011110x
322
- [12, 2560], [12, 2560], // 000000011111x
323
- [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
324
- [10, 18], [10, 18], [10, 18], [10, 18],
325
- [12, 52], [12, 52], // 000000100100x
326
- [13, 640], // 0000001001010
327
- [13, 704], // 0000001001011
328
- [13, 768], // 0000001001100
329
- [13, 832], // 0000001001101
330
- [12, 55], [12, 55], // 000000100111x
331
- [12, 56], [12, 56], // 000000101000x
332
- [13, 1280], // 0000001010010
333
- [13, 1344], // 0000001010011
334
- [13, 1408], // 0000001010100
335
- [13, 1472], // 0000001010101
336
- [12, 59], [12, 59], // 000000101011x
337
- [12, 60], [12, 60], // 000000101100x
338
- [13, 1536], // 0000001011010
339
- [13, 1600], // 0000001011011
340
- [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
341
- [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
342
- [13, 1664], // 0000001100100
343
- [13, 1728], // 0000001100101
344
- [12, 320], [12, 320], // 000000110011x
345
- [12, 384], [12, 384], // 000000110100x
346
- [12, 448], [12, 448], // 000000110101x
347
- [13, 512], // 0000001101100
348
- [13, 576], // 0000001101101
349
- [12, 53], [12, 53], // 000000110111x
350
- [12, 54], [12, 54], // 000000111000x
351
- [13, 896], // 0000001110010
352
- [13, 960], // 0000001110011
353
- [13, 1024], // 0000001110100
354
- [13, 1088], // 0000001110101
355
- [13, 1152], // 0000001110110
356
- [13, 1216], // 0000001110111
357
- [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
358
- [10, 64], [10, 64], [10, 64], [10, 64]
359
- ];
360
-
361
- // prettier-ignore
362
- const blackTable2 = [
363
- [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
364
- [8, 13], [8, 13], [8, 13], [8, 13],
365
- [8, 13], [8, 13], [8, 13], [8, 13],
366
- [8, 13], [8, 13], [8, 13], [8, 13],
367
- [11, 23], [11, 23], // 00000101000x
368
- [12, 50], // 000001010010
369
- [12, 51], // 000001010011
370
- [12, 44], // 000001010100
371
- [12, 45], // 000001010101
372
- [12, 46], // 000001010110
373
- [12, 47], // 000001010111
374
- [12, 57], // 000001011000
375
- [12, 58], // 000001011001
376
- [12, 61], // 000001011010
377
- [12, 256], // 000001011011
378
- [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
379
- [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
380
- [12, 48], // 000001100100
381
- [12, 49], // 000001100101
382
- [12, 62], // 000001100110
383
- [12, 63], // 000001100111
384
- [12, 30], // 000001101000
385
- [12, 31], // 000001101001
386
- [12, 32], // 000001101010
387
- [12, 33], // 000001101011
388
- [12, 40], // 000001101100
389
- [12, 41], // 000001101101
390
- [11, 22], [11, 22], // 00000110111x
391
- [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
392
- [8, 14], [8, 14], [8, 14], [8, 14],
393
- [8, 14], [8, 14], [8, 14], [8, 14],
394
- [8, 14], [8, 14], [8, 14], [8, 14],
395
- [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
396
- [7, 10], [7, 10], [7, 10], [7, 10],
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, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
404
- [7, 11], [7, 11], [7, 11], [7, 11],
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
- [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
412
- [9, 15], [9, 15], [9, 15], [9, 15],
413
- [12, 128], // 000011001000
414
- [12, 192], // 000011001001
415
- [12, 26], // 000011001010
416
- [12, 27], // 000011001011
417
- [12, 28], // 000011001100
418
- [12, 29], // 000011001101
419
- [11, 19], [11, 19], // 00001100111x
420
- [11, 20], [11, 20], // 00001101000x
421
- [12, 34], // 000011010010
422
- [12, 35], // 000011010011
423
- [12, 36], // 000011010100
424
- [12, 37], // 000011010101
425
- [12, 38], // 000011010110
426
- [12, 39], // 000011010111
427
- [11, 21], [11, 21], // 00001101100x
428
- [12, 42], // 000011011010
429
- [12, 43], // 000011011011
430
- [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
431
- [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
432
- [7, 12], [7, 12], [7, 12], [7, 12],
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
- ];
440
-
441
- // prettier-ignore
442
- const blackTable3 = [
443
- [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
444
- [6, 9], // 000100
445
- [6, 8], // 000101
446
- [5, 7], [5, 7], // 00011x
447
- [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
448
- [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
449
- [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
450
- [3, 1], [3, 1], [3, 1], [3, 1],
451
- [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
452
- [3, 4], [3, 4], [3, 4], [3, 4],
453
- [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
454
- [2, 3], [2, 3], [2, 3], [2, 3],
455
- [2, 3], [2, 3], [2, 3], [2, 3],
456
- [2, 3], [2, 3], [2, 3], [2, 3],
457
- [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
458
- [2, 2], [2, 2], [2, 2], [2, 2],
459
- [2, 2], [2, 2], [2, 2], [2, 2],
460
- [2, 2], [2, 2], [2, 2], [2, 2]
461
- ];
462
-
463
- /**
464
- * @param {CCITTFaxDecoderSource} source - The data which should be decoded.
465
- * @param {Object} [options] - Decoding options.
466
- */
467
- class CCITTFaxDecoder {
468
- constructor(source, options = {}) {
469
- if (!source || typeof source.next !== "function") {
470
- throw new Error('CCITTFaxDecoder - invalid "source" parameter.');
471
- }
472
- this.source = source;
473
- this.eof = false;
474
-
475
- this.encoding = options.K || 0;
476
- this.eoline = options.EndOfLine || false;
477
- this.byteAlign = options.EncodedByteAlign || false;
478
- this.columns = options.Columns || 1728;
479
- this.rows = options.Rows || 0;
480
- let eoblock = options.EndOfBlock;
481
- if (eoblock === null || eoblock === undefined) {
482
- eoblock = true;
483
- }
484
- this.eoblock = eoblock;
485
- this.black = options.BlackIs1 || false;
486
-
487
- this.codingLine = new Uint32Array(this.columns + 1);
488
- this.refLine = new Uint32Array(this.columns + 2);
489
-
490
- this.codingLine[0] = this.columns;
491
- this.codingPos = 0;
492
-
493
- this.row = 0;
494
- this.nextLine2D = this.encoding < 0;
495
- this.inputBits = 0;
496
- this.inputBuf = 0;
497
- this.outputBits = 0;
498
- this.rowsDone = false;
499
-
500
- let code1;
501
- while ((code1 = this._lookBits(12)) === 0) {
502
- this._eatBits(1);
503
- }
504
- if (code1 === 1) {
505
- this._eatBits(12);
506
- }
507
- if (this.encoding > 0) {
508
- this.nextLine2D = !this._lookBits(1);
509
- this._eatBits(1);
510
- }
511
- }
512
-
513
- readNextChar() {
514
- if (this.eof) {
515
- return -1;
516
- }
517
- const refLine = this.refLine;
518
- const codingLine = this.codingLine;
519
- const columns = this.columns;
520
-
521
- let refPos, blackPixels, bits, i;
522
-
523
- if (this.outputBits === 0) {
524
- if (this.rowsDone) {
525
- this.eof = true;
526
- }
527
- if (this.eof) {
528
- return -1;
529
- }
530
- this.err = false;
531
-
532
- let code1, code2, code3;
533
- if (this.nextLine2D) {
534
- for (i = 0; codingLine[i] < columns; ++i) {
535
- refLine[i] = codingLine[i];
536
- }
537
- refLine[i++] = columns;
538
- refLine[i] = columns;
539
- codingLine[0] = 0;
540
- this.codingPos = 0;
541
- refPos = 0;
542
- blackPixels = 0;
543
-
544
- while (codingLine[this.codingPos] < columns) {
545
- code1 = this._getTwoDimCode();
546
- switch (code1) {
547
- case twoDimPass:
548
- this._addPixels(refLine[refPos + 1], blackPixels);
549
- if (refLine[refPos + 1] < columns) {
550
- refPos += 2;
551
- }
552
- break;
553
- case twoDimHoriz:
554
- code1 = code2 = 0;
555
- if (blackPixels) {
556
- do {
557
- code1 += code3 = this._getBlackCode();
558
- } while (code3 >= 64);
559
- do {
560
- code2 += code3 = this._getWhiteCode();
561
- } while (code3 >= 64);
562
- } else {
563
- do {
564
- code1 += code3 = this._getWhiteCode();
565
- } while (code3 >= 64);
566
- do {
567
- code2 += code3 = this._getBlackCode();
568
- } while (code3 >= 64);
569
- }
570
- this._addPixels(codingLine[this.codingPos] + code1, blackPixels);
571
- if (codingLine[this.codingPos] < columns) {
572
- this._addPixels(
573
- codingLine[this.codingPos] + code2,
574
- blackPixels ^ 1
575
- );
576
- }
577
- while (
578
- refLine[refPos] <= codingLine[this.codingPos] &&
579
- refLine[refPos] < columns
580
- ) {
581
- refPos += 2;
582
- }
583
- break;
584
- case twoDimVertR3:
585
- this._addPixels(refLine[refPos] + 3, blackPixels);
586
- blackPixels ^= 1;
587
- if (codingLine[this.codingPos] < columns) {
588
- ++refPos;
589
- while (
590
- refLine[refPos] <= codingLine[this.codingPos] &&
591
- refLine[refPos] < columns
592
- ) {
593
- refPos += 2;
594
- }
595
- }
596
- break;
597
- case twoDimVertR2:
598
- this._addPixels(refLine[refPos] + 2, blackPixels);
599
- blackPixels ^= 1;
600
- if (codingLine[this.codingPos] < columns) {
601
- ++refPos;
602
- while (
603
- refLine[refPos] <= codingLine[this.codingPos] &&
604
- refLine[refPos] < columns
605
- ) {
606
- refPos += 2;
607
- }
608
- }
609
- break;
610
- case twoDimVertR1:
611
- this._addPixels(refLine[refPos] + 1, blackPixels);
612
- blackPixels ^= 1;
613
- if (codingLine[this.codingPos] < columns) {
614
- ++refPos;
615
- while (
616
- refLine[refPos] <= codingLine[this.codingPos] &&
617
- refLine[refPos] < columns
618
- ) {
619
- refPos += 2;
620
- }
621
- }
622
- break;
623
- case twoDimVert0:
624
- this._addPixels(refLine[refPos], blackPixels);
625
- blackPixels ^= 1;
626
- if (codingLine[this.codingPos] < columns) {
627
- ++refPos;
628
- while (
629
- refLine[refPos] <= codingLine[this.codingPos] &&
630
- refLine[refPos] < columns
631
- ) {
632
- refPos += 2;
633
- }
634
- }
635
- break;
636
- case twoDimVertL3:
637
- this._addPixelsNeg(refLine[refPos] - 3, blackPixels);
638
- blackPixels ^= 1;
639
- if (codingLine[this.codingPos] < columns) {
640
- if (refPos > 0) {
641
- --refPos;
642
- } else {
643
- ++refPos;
644
- }
645
- while (
646
- refLine[refPos] <= codingLine[this.codingPos] &&
647
- refLine[refPos] < columns
648
- ) {
649
- refPos += 2;
650
- }
651
- }
652
- break;
653
- case twoDimVertL2:
654
- this._addPixelsNeg(refLine[refPos] - 2, blackPixels);
655
- blackPixels ^= 1;
656
- if (codingLine[this.codingPos] < columns) {
657
- if (refPos > 0) {
658
- --refPos;
659
- } else {
660
- ++refPos;
661
- }
662
- while (
663
- refLine[refPos] <= codingLine[this.codingPos] &&
664
- refLine[refPos] < columns
665
- ) {
666
- refPos += 2;
667
- }
668
- }
669
- break;
670
- case twoDimVertL1:
671
- this._addPixelsNeg(refLine[refPos] - 1, blackPixels);
672
- blackPixels ^= 1;
673
- if (codingLine[this.codingPos] < columns) {
674
- if (refPos > 0) {
675
- --refPos;
676
- } else {
677
- ++refPos;
678
- }
679
- while (
680
- refLine[refPos] <= codingLine[this.codingPos] &&
681
- refLine[refPos] < columns
682
- ) {
683
- refPos += 2;
684
- }
685
- }
686
- break;
687
- case ccittEOF:
688
- this._addPixels(columns, 0);
689
- this.eof = true;
690
- break;
691
- default:
692
- info("bad 2d code");
693
- this._addPixels(columns, 0);
694
- this.err = true;
695
- }
696
- }
697
- } else {
698
- codingLine[0] = 0;
699
- this.codingPos = 0;
700
- blackPixels = 0;
701
- while (codingLine[this.codingPos] < columns) {
702
- code1 = 0;
703
- if (blackPixels) {
704
- do {
705
- code1 += code3 = this._getBlackCode();
706
- } while (code3 >= 64);
707
- } else {
708
- do {
709
- code1 += code3 = this._getWhiteCode();
710
- } while (code3 >= 64);
711
- }
712
- this._addPixels(codingLine[this.codingPos] + code1, blackPixels);
713
- blackPixels ^= 1;
714
- }
715
- }
716
-
717
- let gotEOL = false;
718
-
719
- if (this.byteAlign) {
720
- this.inputBits &= ~7;
721
- }
722
-
723
- if (!this.eoblock && this.row === this.rows - 1) {
724
- this.rowsDone = true;
725
- } else {
726
- code1 = this._lookBits(12);
727
- if (this.eoline) {
728
- while (code1 !== ccittEOF && code1 !== 1) {
729
- this._eatBits(1);
730
- code1 = this._lookBits(12);
731
- }
732
- } else {
733
- while (code1 === 0) {
734
- this._eatBits(1);
735
- code1 = this._lookBits(12);
736
- }
737
- }
738
- if (code1 === 1) {
739
- this._eatBits(12);
740
- gotEOL = true;
741
- } else if (code1 === ccittEOF) {
742
- this.eof = true;
743
- }
744
- }
745
-
746
- if (!this.eof && this.encoding > 0 && !this.rowsDone) {
747
- this.nextLine2D = !this._lookBits(1);
748
- this._eatBits(1);
749
- }
750
-
751
- if (this.eoblock && gotEOL && this.byteAlign) {
752
- code1 = this._lookBits(12);
753
- if (code1 === 1) {
754
- this._eatBits(12);
755
- if (this.encoding > 0) {
756
- this._lookBits(1);
757
- this._eatBits(1);
758
- }
759
- if (this.encoding >= 0) {
760
- for (i = 0; i < 4; ++i) {
761
- code1 = this._lookBits(12);
762
- if (code1 !== 1) {
763
- info("bad rtc code: " + code1);
764
- }
765
- this._eatBits(12);
766
- if (this.encoding > 0) {
767
- this._lookBits(1);
768
- this._eatBits(1);
769
- }
770
- }
771
- }
772
- this.eof = true;
773
- }
774
- } else if (this.err && this.eoline) {
775
- while (true) {
776
- code1 = this._lookBits(13);
777
- if (code1 === ccittEOF) {
778
- this.eof = true;
779
- return -1;
780
- }
781
- if (code1 >> 1 === 1) {
782
- break;
783
- }
784
- this._eatBits(1);
785
- }
786
- this._eatBits(12);
787
- if (this.encoding > 0) {
788
- this._eatBits(1);
789
- this.nextLine2D = !(code1 & 1);
790
- }
791
- }
792
-
793
- if (codingLine[0] > 0) {
794
- this.outputBits = codingLine[(this.codingPos = 0)];
795
- } else {
796
- this.outputBits = codingLine[(this.codingPos = 1)];
797
- }
798
- this.row++;
799
- }
800
-
801
- let c;
802
- if (this.outputBits >= 8) {
803
- c = this.codingPos & 1 ? 0 : 0xff;
804
- this.outputBits -= 8;
805
- if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
806
- this.codingPos++;
807
- this.outputBits =
808
- codingLine[this.codingPos] - codingLine[this.codingPos - 1];
809
- }
810
- } else {
811
- bits = 8;
812
- c = 0;
813
- do {
814
- if (this.outputBits > bits) {
815
- c <<= bits;
816
- if (!(this.codingPos & 1)) {
817
- c |= 0xff >> (8 - bits);
818
- }
819
- this.outputBits -= bits;
820
- bits = 0;
821
- } else {
822
- c <<= this.outputBits;
823
- if (!(this.codingPos & 1)) {
824
- c |= 0xff >> (8 - this.outputBits);
825
- }
826
- bits -= this.outputBits;
827
- this.outputBits = 0;
828
- if (codingLine[this.codingPos] < columns) {
829
- this.codingPos++;
830
- this.outputBits =
831
- codingLine[this.codingPos] - codingLine[this.codingPos - 1];
832
- } else if (bits > 0) {
833
- c <<= bits;
834
- bits = 0;
835
- }
836
- }
837
- } while (bits);
838
- }
839
- if (this.black) {
840
- c ^= 0xff;
841
- }
842
- return c;
843
- }
844
-
845
- /**
846
- * @private
847
- */
848
- _addPixels(a1, blackPixels) {
849
- const codingLine = this.codingLine;
850
- let codingPos = this.codingPos;
851
-
852
- if (a1 > codingLine[codingPos]) {
853
- if (a1 > this.columns) {
854
- info("row is wrong length");
855
- this.err = true;
856
- a1 = this.columns;
857
- }
858
- if ((codingPos & 1) ^ blackPixels) {
859
- ++codingPos;
860
- }
861
-
862
- codingLine[codingPos] = a1;
863
- }
864
- this.codingPos = codingPos;
865
- }
866
-
867
- /**
868
- * @private
869
- */
870
- _addPixelsNeg(a1, blackPixels) {
871
- const codingLine = this.codingLine;
872
- let codingPos = this.codingPos;
873
-
874
- if (a1 > codingLine[codingPos]) {
875
- if (a1 > this.columns) {
876
- info("row is wrong length");
877
- this.err = true;
878
- a1 = this.columns;
879
- }
880
- if ((codingPos & 1) ^ blackPixels) {
881
- ++codingPos;
882
- }
883
-
884
- codingLine[codingPos] = a1;
885
- } else if (a1 < codingLine[codingPos]) {
886
- if (a1 < 0) {
887
- info("invalid code");
888
- this.err = true;
889
- a1 = 0;
890
- }
891
- while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
892
- --codingPos;
893
- }
894
- codingLine[codingPos] = a1;
895
- }
896
-
897
- this.codingPos = codingPos;
898
- }
899
-
900
- /**
901
- * This function returns the code found from the table.
902
- * The start and end parameters set the boundaries for searching the table.
903
- * The limit parameter is optional. Function returns an array with three
904
- * values. The first array element indicates whether a valid code is being
905
- * returned. The second array element is the actual code. The third array
906
- * element indicates whether EOF was reached.
907
- * @private
908
- */
909
- _findTableCode(start, end, table, limit) {
910
- const limitValue = limit || 0;
911
- for (let i = start; i <= end; ++i) {
912
- let code = this._lookBits(i);
913
- if (code === ccittEOF) {
914
- return [true, 1, false];
915
- }
916
- if (i < end) {
917
- code <<= end - i;
918
- }
919
- if (!limitValue || code >= limitValue) {
920
- const p = table[code - limitValue];
921
- if (p[0] === i) {
922
- this._eatBits(i);
923
- return [true, p[1], true];
924
- }
925
- }
926
- }
927
- return [false, 0, false];
928
- }
929
-
930
- /**
931
- * @private
932
- */
933
- _getTwoDimCode() {
934
- let code = 0;
935
- let p;
936
- if (this.eoblock) {
937
- code = this._lookBits(7);
938
- p = twoDimTable[code];
939
- if (p && p[0] > 0) {
940
- this._eatBits(p[0]);
941
- return p[1];
942
- }
943
- } else {
944
- const result = this._findTableCode(1, 7, twoDimTable);
945
- if (result[0] && result[2]) {
946
- return result[1];
947
- }
948
- }
949
- info("Bad two dim code");
950
- return ccittEOF;
951
- }
952
-
953
- /**
954
- * @private
955
- */
956
- _getWhiteCode() {
957
- let code = 0;
958
- let p;
959
- if (this.eoblock) {
960
- code = this._lookBits(12);
961
- if (code === ccittEOF) {
962
- return 1;
963
- }
964
-
965
- if (code >> 5 === 0) {
966
- p = whiteTable1[code];
967
- } else {
968
- p = whiteTable2[code >> 3];
969
- }
970
-
971
- if (p[0] > 0) {
972
- this._eatBits(p[0]);
973
- return p[1];
974
- }
975
- } else {
976
- let result = this._findTableCode(1, 9, whiteTable2);
977
- if (result[0]) {
978
- return result[1];
979
- }
980
-
981
- result = this._findTableCode(11, 12, whiteTable1);
982
- if (result[0]) {
983
- return result[1];
984
- }
985
- }
986
- info("bad white code");
987
- this._eatBits(1);
988
- return 1;
989
- }
990
-
991
- /**
992
- * @private
993
- */
994
- _getBlackCode() {
995
- let code, p;
996
- if (this.eoblock) {
997
- code = this._lookBits(13);
998
- if (code === ccittEOF) {
999
- return 1;
1000
- }
1001
- if (code >> 7 === 0) {
1002
- p = blackTable1[code];
1003
- } else if (code >> 9 === 0 && code >> 7 !== 0) {
1004
- p = blackTable2[(code >> 1) - 64];
1005
- } else {
1006
- p = blackTable3[code >> 7];
1007
- }
1008
-
1009
- if (p[0] > 0) {
1010
- this._eatBits(p[0]);
1011
- return p[1];
1012
- }
1013
- } else {
1014
- let result = this._findTableCode(2, 6, blackTable3);
1015
- if (result[0]) {
1016
- return result[1];
1017
- }
1018
-
1019
- result = this._findTableCode(7, 12, blackTable2, 64);
1020
- if (result[0]) {
1021
- return result[1];
1022
- }
1023
-
1024
- result = this._findTableCode(10, 13, blackTable1);
1025
- if (result[0]) {
1026
- return result[1];
1027
- }
1028
- }
1029
- info("bad black code");
1030
- this._eatBits(1);
1031
- return 1;
1032
- }
1033
-
1034
- /**
1035
- * @private
1036
- */
1037
- _lookBits(n) {
1038
- let c;
1039
- while (this.inputBits < n) {
1040
- if ((c = this.source.next()) === -1) {
1041
- if (this.inputBits === 0) {
1042
- return ccittEOF;
1043
- }
1044
- return (this.inputBuf << (n - this.inputBits)) & (0xffff >> (16 - n));
1045
- }
1046
- this.inputBuf = (this.inputBuf << 8) | c;
1047
- this.inputBits += 8;
1048
- }
1049
- return (this.inputBuf >> (this.inputBits - n)) & (0xffff >> (16 - n));
1050
- }
1051
-
1052
- /**
1053
- * @private
1054
- */
1055
- _eatBits(n) {
1056
- if ((this.inputBits -= n) < 0) {
1057
- this.inputBits = 0;
1058
- }
1059
- }
1060
- }
1061
-
1062
- export { CCITTFaxDecoder };