pdfjs-dist 2.0.943 → 2.4.456
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.
Potentially problematic release.
This version of pdfjs-dist might be problematic. Click here for more details.
- package/CODE_OF_CONDUCT.md +15 -0
- package/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +8286 -14230
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +22 -1
- package/build/pdf.worker.entry.js +5 -3
- package/build/pdf.worker.js +25500 -26628
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +25473 -0
- package/es5/build/pdf.js.map +1 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +57878 -0
- package/es5/build/pdf.worker.js.map +1 -0
- package/es5/web/images/annotation-check.svg +11 -0
- package/es5/web/images/annotation-comment.svg +16 -0
- package/es5/web/images/annotation-help.svg +26 -0
- package/es5/web/images/annotation-insert.svg +10 -0
- package/es5/web/images/annotation-key.svg +11 -0
- package/es5/web/images/annotation-newparagraph.svg +11 -0
- package/es5/web/images/annotation-noicon.svg +7 -0
- package/es5/web/images/annotation-note.svg +42 -0
- package/es5/web/images/annotation-paragraph.svg +16 -0
- package/es5/web/images/loading-icon.gif +0 -0
- package/es5/web/images/shadow.png +0 -0
- package/es5/web/images/texture.png +0 -0
- package/es5/web/pdf_viewer.css +407 -0
- package/es5/web/pdf_viewer.js +7757 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +2887 -4094
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +22 -1
- package/lib/README.md +7 -0
- package/lib/core/annotation.js +855 -778
- package/lib/core/arithmetic_decoder.js +325 -311
- package/lib/core/bidi.js +117 -50
- package/lib/core/ccitt.js +251 -89
- package/lib/core/ccitt_stream.js +26 -16
- package/lib/core/cff_parser.js +525 -197
- package/lib/core/charsets.js +6 -5
- package/lib/core/chunked_stream.js +541 -406
- package/lib/core/cmap.js +368 -253
- package/lib/core/colorspace.js +781 -800
- package/lib/core/core_utils.js +152 -0
- package/lib/core/crypto.js +609 -422
- package/lib/core/document.js +649 -481
- package/lib/core/encodings.js +33 -24
- package/lib/core/evaluator.js +1471 -736
- package/lib/core/font_renderer.js +289 -149
- package/lib/core/fonts.js +1067 -413
- package/lib/core/function.js +517 -287
- package/lib/core/glyphlist.js +4529 -4527
- package/lib/core/image.js +232 -114
- package/lib/core/image_utils.js +94 -0
- package/lib/core/jbig2.js +711 -342
- package/lib/core/jbig2_stream.js +31 -19
- package/lib/core/jpeg_stream.js +151 -26
- package/lib/core/jpg.js +433 -181
- package/lib/core/jpx.js +551 -143
- package/lib/core/jpx_stream.js +40 -28
- package/lib/core/metrics.js +2931 -2931
- package/lib/core/murmurhash3.js +104 -97
- package/lib/core/obj.js +1561 -1053
- package/lib/core/operator_list.js +192 -64
- package/lib/core/parser.js +1162 -864
- package/lib/core/pattern.js +224 -75
- package/lib/core/pdf_manager.js +154 -285
- package/lib/core/primitives.js +145 -69
- package/lib/core/ps_parser.js +212 -162
- package/lib/core/standard_fonts.js +245 -244
- package/lib/core/stream.js +353 -81
- package/lib/core/type1_parser.js +218 -68
- package/lib/core/unicode.js +1682 -1655
- package/lib/core/worker.js +233 -302
- package/lib/core/worker_stream.js +168 -0
- package/lib/display/annotation_layer.js +808 -862
- package/lib/display/api.js +1778 -1462
- package/lib/display/api_compatibility.js +14 -9
- package/lib/display/canvas.js +463 -140
- package/lib/display/content_disposition.js +86 -58
- package/lib/display/display_utils.js +524 -0
- package/lib/display/fetch_stream.js +202 -274
- package/lib/display/font_loader.js +311 -333
- package/lib/display/metadata.js +98 -88
- package/lib/display/network.js +343 -347
- package/lib/display/network_utils.js +46 -26
- package/lib/display/node_stream.js +326 -404
- package/lib/display/pattern_helper.js +168 -69
- package/lib/display/svg.js +1296 -885
- package/lib/display/text_layer.js +229 -103
- package/lib/display/transport_stream.js +290 -250
- package/lib/display/webgl.js +116 -83
- package/lib/display/worker_options.js +6 -5
- package/lib/display/xml_parser.js +358 -337
- package/lib/examples/node/domstubs.js +95 -39
- package/lib/pdf.js +49 -31
- package/lib/pdf.worker.js +7 -5
- package/lib/shared/compatibility.js +3 -145
- package/lib/shared/is_node.js +8 -7
- package/lib/shared/message_handler.js +367 -314
- package/lib/shared/util.js +421 -415
- package/lib/test/unit/annotation_spec.js +1570 -690
- package/lib/test/unit/api_spec.js +855 -493
- package/lib/test/unit/bidi_spec.js +12 -12
- package/lib/test/unit/cff_parser_spec.js +88 -61
- package/lib/test/unit/clitests_helper.js +9 -12
- package/lib/test/unit/cmap_spec.js +140 -88
- package/lib/test/unit/colorspace_spec.js +204 -152
- package/lib/test/unit/core_utils_spec.js +211 -0
- package/lib/test/unit/crypto_spec.js +194 -182
- package/lib/test/unit/custom_spec.js +50 -64
- package/lib/test/unit/display_svg_spec.js +53 -38
- package/lib/test/unit/display_utils_spec.js +263 -0
- package/lib/test/unit/document_spec.js +17 -22
- package/lib/test/unit/encodings_spec.js +15 -57
- package/lib/test/unit/evaluator_spec.js +90 -83
- package/lib/test/unit/fetch_stream_spec.js +111 -0
- package/lib/test/unit/function_spec.js +219 -205
- package/lib/test/unit/jasmine-boot.js +68 -39
- package/lib/test/unit/message_handler_spec.js +187 -160
- package/lib/test/unit/metadata_spec.js +87 -34
- package/lib/test/unit/murmurhash3_spec.js +13 -13
- package/lib/test/unit/network_spec.js +26 -59
- package/lib/test/unit/network_utils_spec.js +187 -121
- package/lib/test/unit/node_stream_spec.js +98 -90
- package/lib/test/unit/parser_spec.js +173 -131
- package/lib/test/unit/pdf_find_controller_spec.js +148 -67
- package/lib/test/unit/pdf_find_utils_spec.js +35 -34
- package/lib/test/unit/pdf_history_spec.js +45 -33
- package/lib/test/unit/primitives_spec.js +161 -126
- package/lib/test/unit/stream_spec.js +22 -15
- package/lib/test/unit/test_utils.js +149 -98
- package/lib/test/unit/testreporter.js +36 -18
- package/lib/test/unit/type1_parser_spec.js +46 -44
- package/lib/test/unit/ui_utils_spec.js +388 -372
- package/lib/test/unit/unicode_spec.js +49 -46
- package/lib/test/unit/util_spec.js +144 -248
- package/lib/web/annotation_layer_builder.js +75 -95
- package/lib/web/app.js +1538 -1147
- package/lib/web/app_options.js +116 -104
- package/lib/web/base_viewer.js +950 -775
- package/lib/web/chromecom.js +217 -225
- package/lib/web/debugger.js +236 -148
- package/lib/web/download_manager.js +50 -50
- package/lib/web/firefox_print_service.js +51 -33
- package/lib/web/firefoxcom.js +225 -352
- package/lib/web/genericcom.js +30 -93
- package/lib/web/genericl10n.js +26 -143
- package/lib/web/grab_to_pan.js +57 -33
- package/lib/web/interfaces.js +105 -232
- package/lib/web/overlay_manager.js +73 -227
- package/lib/web/password_prompt.js +44 -62
- package/lib/web/pdf_attachment_viewer.js +118 -123
- package/lib/web/pdf_cursor_tools.js +89 -93
- package/lib/web/pdf_document_properties.js +242 -281
- package/lib/web/pdf_find_bar.js +157 -163
- package/lib/web/pdf_find_controller.js +598 -454
- package/lib/web/pdf_find_utils.js +32 -16
- package/lib/web/pdf_history.js +481 -355
- package/lib/web/pdf_link_service.js +355 -323
- package/lib/web/pdf_outline_viewer.js +167 -152
- package/lib/web/pdf_page_view.js +511 -457
- package/lib/web/pdf_presentation_mode.js +347 -335
- package/lib/web/pdf_print_service.js +133 -103
- package/lib/web/pdf_rendering_queue.js +98 -100
- package/lib/web/pdf_sidebar.js +323 -299
- package/lib/web/pdf_sidebar_resizer.js +107 -108
- package/lib/web/pdf_single_page_viewer.js +94 -146
- package/lib/web/pdf_thumbnail_view.js +319 -269
- package/lib/web/pdf_thumbnail_viewer.js +219 -199
- package/lib/web/pdf_viewer.component.js +111 -32
- package/lib/web/pdf_viewer.js +61 -101
- package/lib/web/preferences.js +87 -272
- package/lib/web/secondary_toolbar.js +207 -220
- package/lib/web/text_layer_builder.js +322 -322
- package/lib/web/toolbar.js +227 -180
- package/lib/web/ui_utils.js +476 -421
- package/lib/web/view_history.js +59 -208
- package/lib/web/viewer_compatibility.js +9 -6
- package/package.json +2 -9
- package/web/pdf_viewer.css +36 -22
- package/web/pdf_viewer.js +4407 -4516
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +14 -5
- package/external/streams/streams-lib.js +0 -3962
- package/external/url/url-lib.js +0 -627
- package/lib/display/dom_utils.js +0 -441
- package/lib/shared/streams_polyfill.js +0 -39
- package/lib/shared/url_polyfill.js +0 -50
- package/lib/test/unit/dom_utils_spec.js +0 -89
- package/lib/web/dom_events.js +0 -140
package/lib/core/ccitt.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
* @licstart The following is the entire license notice for the
|
3
3
|
* Javascript code in this page
|
4
4
|
*
|
5
|
-
* Copyright
|
5
|
+
* Copyright 2020 Mozilla Foundation
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|
@@ -19,52 +19,54 @@
|
|
19
19
|
* @licend The above is the entire license notice for the
|
20
20
|
* Javascript code in this page
|
21
21
|
*/
|
22
|
-
|
22
|
+
"use strict";
|
23
23
|
|
24
24
|
Object.defineProperty(exports, "__esModule", {
|
25
25
|
value: true
|
26
26
|
});
|
27
|
-
exports.CCITTFaxDecoder =
|
28
|
-
|
29
|
-
var _util = require(
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
if (!source || typeof source.next !== 'function') {
|
27
|
+
exports.CCITTFaxDecoder = void 0;
|
28
|
+
|
29
|
+
var _util = require("../shared/util.js");
|
30
|
+
|
31
|
+
const CCITTFaxDecoder = function CCITTFaxDecoder() {
|
32
|
+
const ccittEOL = -2;
|
33
|
+
const ccittEOF = -1;
|
34
|
+
const twoDimPass = 0;
|
35
|
+
const twoDimHoriz = 1;
|
36
|
+
const twoDimVert0 = 2;
|
37
|
+
const twoDimVertR1 = 3;
|
38
|
+
const twoDimVertL1 = 4;
|
39
|
+
const twoDimVertR2 = 5;
|
40
|
+
const twoDimVertL2 = 6;
|
41
|
+
const twoDimVertR3 = 7;
|
42
|
+
const twoDimVertL3 = 8;
|
43
|
+
const twoDimTable = [[-1, -1], [-1, -1], [7, twoDimVertL3], [7, twoDimVertR3], [6, twoDimVertL2], [6, twoDimVertL2], [6, twoDimVertR2], [6, twoDimVertR2], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0]];
|
44
|
+
const whiteTable1 = [[-1, -1], [12, ccittEOL], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [11, 1792], [11, 1792], [12, 1984], [12, 2048], [12, 2112], [12, 2176], [12, 2240], [12, 2304], [11, 1856], [11, 1856], [11, 1920], [11, 1920], [12, 2368], [12, 2432], [12, 2496], [12, 2560]];
|
45
|
+
const whiteTable2 = [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [8, 29], [8, 29], [8, 30], [8, 30], [8, 45], [8, 45], [8, 46], [8, 46], [7, 22], [7, 22], [7, 22], [7, 22], [7, 23], [7, 23], [7, 23], [7, 23], [8, 47], [8, 47], [8, 48], [8, 48], [6, 13], [6, 13], [6, 13], [6, 13], [6, 13], [6, 13], [6, 13], [6, 13], [7, 20], [7, 20], [7, 20], [7, 20], [8, 33], [8, 33], [8, 34], [8, 34], [8, 35], [8, 35], [8, 36], [8, 36], [8, 37], [8, 37], [8, 38], [8, 38], [7, 19], [7, 19], [7, 19], [7, 19], [8, 31], [8, 31], [8, 32], [8, 32], [6, 1], [6, 1], [6, 1], [6, 1], [6, 1], [6, 1], [6, 1], [6, 1], [6, 12], [6, 12], [6, 12], [6, 12], [6, 12], [6, 12], [6, 12], [6, 12], [8, 53], [8, 53], [8, 54], [8, 54], [7, 26], [7, 26], [7, 26], [7, 26], [8, 39], [8, 39], [8, 40], [8, 40], [8, 41], [8, 41], [8, 42], [8, 42], [8, 43], [8, 43], [8, 44], [8, 44], [7, 21], [7, 21], [7, 21], [7, 21], [7, 28], [7, 28], [7, 28], [7, 28], [8, 61], [8, 61], [8, 62], [8, 62], [8, 63], [8, 63], [8, 0], [8, 0], [8, 320], [8, 320], [8, 384], [8, 384], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [7, 27], [7, 27], [7, 27], [7, 27], [8, 59], [8, 59], [8, 60], [8, 60], [9, 1472], [9, 1536], [9, 1600], [9, 1728], [7, 18], [7, 18], [7, 18], [7, 18], [7, 24], [7, 24], [7, 24], [7, 24], [8, 49], [8, 49], [8, 50], [8, 50], [8, 51], [8, 51], [8, 52], [8, 52], [7, 25], [7, 25], [7, 25], [7, 25], [8, 55], [8, 55], [8, 56], [8, 56], [8, 57], [8, 57], [8, 58], [8, 58], [6, 192], [6, 192], [6, 192], [6, 192], [6, 192], [6, 192], [6, 192], [6, 192], [6, 1664], [6, 1664], [6, 1664], [6, 1664], [6, 1664], [6, 1664], [6, 1664], [6, 1664], [8, 448], [8, 448], [8, 512], [8, 512], [9, 704], [9, 768], [8, 640], [8, 640], [8, 576], [8, 576], [9, 832], [9, 896], [9, 960], [9, 1024], [9, 1088], [9, 1152], [9, 1216], [9, 1280], [9, 1344], [9, 1408], [7, 256], [7, 256], [7, 256], [7, 256], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [6, 16], [6, 16], [6, 16], [6, 16], [6, 16], [6, 16], [6, 16], [6, 16], [6, 17], [6, 17], [6, 17], [6, 17], [6, 17], [6, 17], [6, 17], [6, 17], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [6, 14], [6, 14], [6, 14], [6, 14], [6, 14], [6, 14], [6, 14], [6, 14], [6, 15], [6, 15], [6, 15], [6, 15], [6, 15], [6, 15], [6, 15], [6, 15], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7]];
|
46
|
+
const blackTable1 = [[-1, -1], [-1, -1], [12, ccittEOL], [12, ccittEOL], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [11, 1792], [11, 1792], [11, 1792], [11, 1792], [12, 1984], [12, 1984], [12, 2048], [12, 2048], [12, 2112], [12, 2112], [12, 2176], [12, 2176], [12, 2240], [12, 2240], [12, 2304], [12, 2304], [11, 1856], [11, 1856], [11, 1856], [11, 1856], [11, 1920], [11, 1920], [11, 1920], [11, 1920], [12, 2368], [12, 2368], [12, 2432], [12, 2432], [12, 2496], [12, 2496], [12, 2560], [12, 2560], [10, 18], [10, 18], [10, 18], [10, 18], [10, 18], [10, 18], [10, 18], [10, 18], [12, 52], [12, 52], [13, 640], [13, 704], [13, 768], [13, 832], [12, 55], [12, 55], [12, 56], [12, 56], [13, 1280], [13, 1344], [13, 1408], [13, 1472], [12, 59], [12, 59], [12, 60], [12, 60], [13, 1536], [13, 1600], [11, 24], [11, 24], [11, 24], [11, 24], [11, 25], [11, 25], [11, 25], [11, 25], [13, 1664], [13, 1728], [12, 320], [12, 320], [12, 384], [12, 384], [12, 448], [12, 448], [13, 512], [13, 576], [12, 53], [12, 53], [12, 54], [12, 54], [13, 896], [13, 960], [13, 1024], [13, 1088], [13, 1152], [13, 1216], [10, 64], [10, 64], [10, 64], [10, 64], [10, 64], [10, 64], [10, 64], [10, 64]];
|
47
|
+
const blackTable2 = [[8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [11, 23], [11, 23], [12, 50], [12, 51], [12, 44], [12, 45], [12, 46], [12, 47], [12, 57], [12, 58], [12, 61], [12, 256], [10, 16], [10, 16], [10, 16], [10, 16], [10, 17], [10, 17], [10, 17], [10, 17], [12, 48], [12, 49], [12, 62], [12, 63], [12, 30], [12, 31], [12, 32], [12, 33], [12, 40], [12, 41], [11, 22], [11, 22], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [9, 15], [9, 15], [9, 15], [9, 15], [9, 15], [9, 15], [9, 15], [9, 15], [12, 128], [12, 192], [12, 26], [12, 27], [12, 28], [12, 29], [11, 19], [11, 19], [11, 20], [11, 20], [12, 34], [12, 35], [12, 36], [12, 37], [12, 38], [12, 39], [11, 21], [11, 21], [12, 42], [12, 43], [10, 0], [10, 0], [10, 0], [10, 0], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12]];
|
48
|
+
const blackTable3 = [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [6, 9], [6, 8], [5, 7], [5, 7], [4, 6], [4, 6], [4, 6], [4, 6], [4, 5], [4, 5], [4, 5], [4, 5], [3, 1], [3, 1], [3, 1], [3, 1], [3, 1], [3, 1], [3, 1], [3, 1], [3, 4], [3, 4], [3, 4], [3, 4], [3, 4], [3, 4], [3, 4], [3, 4], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2]];
|
49
|
+
|
50
|
+
function CCITTFaxDecoder(source, options = {}) {
|
51
|
+
if (!source || typeof source.next !== "function") {
|
53
52
|
throw new Error('CCITTFaxDecoder - invalid "source" parameter.');
|
54
53
|
}
|
54
|
+
|
55
55
|
this.source = source;
|
56
56
|
this.eof = false;
|
57
|
-
this.encoding = options[
|
58
|
-
this.eoline = options[
|
59
|
-
this.byteAlign = options[
|
60
|
-
this.columns = options[
|
61
|
-
this.rows = options[
|
62
|
-
|
57
|
+
this.encoding = options["K"] || 0;
|
58
|
+
this.eoline = options["EndOfLine"] || false;
|
59
|
+
this.byteAlign = options["EncodedByteAlign"] || false;
|
60
|
+
this.columns = options["Columns"] || 1728;
|
61
|
+
this.rows = options["Rows"] || 0;
|
62
|
+
let eoblock = options["EndOfBlock"];
|
63
|
+
|
63
64
|
if (eoblock === null || eoblock === undefined) {
|
64
65
|
eoblock = true;
|
65
66
|
}
|
67
|
+
|
66
68
|
this.eoblock = eoblock;
|
67
|
-
this.black = options[
|
69
|
+
this.black = options["BlackIs1"] || false;
|
68
70
|
this.codingLine = new Uint32Array(this.columns + 1);
|
69
71
|
this.refLine = new Uint32Array(this.columns + 2);
|
70
72
|
this.codingLine[0] = this.columns;
|
@@ -75,66 +77,79 @@ var CCITTFaxDecoder = function CCITTFaxDecoder() {
|
|
75
77
|
this.inputBuf = 0;
|
76
78
|
this.outputBits = 0;
|
77
79
|
this.rowsDone = false;
|
78
|
-
|
80
|
+
let code1;
|
81
|
+
|
79
82
|
while ((code1 = this._lookBits(12)) === 0) {
|
80
83
|
this._eatBits(1);
|
81
84
|
}
|
85
|
+
|
82
86
|
if (code1 === 1) {
|
83
87
|
this._eatBits(12);
|
84
88
|
}
|
89
|
+
|
85
90
|
if (this.encoding > 0) {
|
86
91
|
this.nextLine2D = !this._lookBits(1);
|
92
|
+
|
87
93
|
this._eatBits(1);
|
88
94
|
}
|
89
95
|
}
|
96
|
+
|
90
97
|
CCITTFaxDecoder.prototype = {
|
91
|
-
readNextChar
|
98
|
+
readNextChar() {
|
92
99
|
if (this.eof) {
|
93
100
|
return -1;
|
94
101
|
}
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
i = void 0;
|
102
|
+
|
103
|
+
const refLine = this.refLine;
|
104
|
+
const codingLine = this.codingLine;
|
105
|
+
const columns = this.columns;
|
106
|
+
let refPos, blackPixels, bits, i;
|
107
|
+
|
102
108
|
if (this.outputBits === 0) {
|
103
109
|
if (this.rowsDone) {
|
104
110
|
this.eof = true;
|
105
111
|
}
|
112
|
+
|
106
113
|
if (this.eof) {
|
107
114
|
return -1;
|
108
115
|
}
|
116
|
+
|
109
117
|
this.err = false;
|
110
|
-
|
111
|
-
|
112
|
-
code3 = void 0;
|
118
|
+
let code1, code2, code3;
|
119
|
+
|
113
120
|
if (this.nextLine2D) {
|
114
121
|
for (i = 0; codingLine[i] < columns; ++i) {
|
115
122
|
refLine[i] = codingLine[i];
|
116
123
|
}
|
124
|
+
|
117
125
|
refLine[i++] = columns;
|
118
126
|
refLine[i] = columns;
|
119
127
|
codingLine[0] = 0;
|
120
128
|
this.codingPos = 0;
|
121
129
|
refPos = 0;
|
122
130
|
blackPixels = 0;
|
131
|
+
|
123
132
|
while (codingLine[this.codingPos] < columns) {
|
124
133
|
code1 = this._getTwoDimCode();
|
134
|
+
|
125
135
|
switch (code1) {
|
126
136
|
case twoDimPass:
|
127
137
|
this._addPixels(refLine[refPos + 1], blackPixels);
|
138
|
+
|
128
139
|
if (refLine[refPos + 1] < columns) {
|
129
140
|
refPos += 2;
|
130
141
|
}
|
142
|
+
|
131
143
|
break;
|
144
|
+
|
132
145
|
case twoDimHoriz:
|
133
146
|
code1 = code2 = 0;
|
147
|
+
|
134
148
|
if (blackPixels) {
|
135
149
|
do {
|
136
150
|
code1 += code3 = this._getBlackCode();
|
137
151
|
} while (code3 >= 64);
|
152
|
+
|
138
153
|
do {
|
139
154
|
code2 += code3 = this._getWhiteCode();
|
140
155
|
} while (code3 >= 64);
|
@@ -142,107 +157,152 @@ var CCITTFaxDecoder = function CCITTFaxDecoder() {
|
|
142
157
|
do {
|
143
158
|
code1 += code3 = this._getWhiteCode();
|
144
159
|
} while (code3 >= 64);
|
160
|
+
|
145
161
|
do {
|
146
162
|
code2 += code3 = this._getBlackCode();
|
147
163
|
} while (code3 >= 64);
|
148
164
|
}
|
165
|
+
|
149
166
|
this._addPixels(codingLine[this.codingPos] + code1, blackPixels);
|
167
|
+
|
150
168
|
if (codingLine[this.codingPos] < columns) {
|
151
169
|
this._addPixels(codingLine[this.codingPos] + code2, blackPixels ^ 1);
|
152
170
|
}
|
171
|
+
|
153
172
|
while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
|
154
173
|
refPos += 2;
|
155
174
|
}
|
175
|
+
|
156
176
|
break;
|
177
|
+
|
157
178
|
case twoDimVertR3:
|
158
179
|
this._addPixels(refLine[refPos] + 3, blackPixels);
|
180
|
+
|
159
181
|
blackPixels ^= 1;
|
182
|
+
|
160
183
|
if (codingLine[this.codingPos] < columns) {
|
161
184
|
++refPos;
|
185
|
+
|
162
186
|
while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
|
163
187
|
refPos += 2;
|
164
188
|
}
|
165
189
|
}
|
190
|
+
|
166
191
|
break;
|
192
|
+
|
167
193
|
case twoDimVertR2:
|
168
194
|
this._addPixels(refLine[refPos] + 2, blackPixels);
|
195
|
+
|
169
196
|
blackPixels ^= 1;
|
197
|
+
|
170
198
|
if (codingLine[this.codingPos] < columns) {
|
171
199
|
++refPos;
|
200
|
+
|
172
201
|
while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
|
173
202
|
refPos += 2;
|
174
203
|
}
|
175
204
|
}
|
205
|
+
|
176
206
|
break;
|
207
|
+
|
177
208
|
case twoDimVertR1:
|
178
209
|
this._addPixels(refLine[refPos] + 1, blackPixels);
|
210
|
+
|
179
211
|
blackPixels ^= 1;
|
212
|
+
|
180
213
|
if (codingLine[this.codingPos] < columns) {
|
181
214
|
++refPos;
|
215
|
+
|
182
216
|
while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
|
183
217
|
refPos += 2;
|
184
218
|
}
|
185
219
|
}
|
220
|
+
|
186
221
|
break;
|
222
|
+
|
187
223
|
case twoDimVert0:
|
188
224
|
this._addPixels(refLine[refPos], blackPixels);
|
225
|
+
|
189
226
|
blackPixels ^= 1;
|
227
|
+
|
190
228
|
if (codingLine[this.codingPos] < columns) {
|
191
229
|
++refPos;
|
230
|
+
|
192
231
|
while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
|
193
232
|
refPos += 2;
|
194
233
|
}
|
195
234
|
}
|
235
|
+
|
196
236
|
break;
|
237
|
+
|
197
238
|
case twoDimVertL3:
|
198
239
|
this._addPixelsNeg(refLine[refPos] - 3, blackPixels);
|
240
|
+
|
199
241
|
blackPixels ^= 1;
|
242
|
+
|
200
243
|
if (codingLine[this.codingPos] < columns) {
|
201
244
|
if (refPos > 0) {
|
202
245
|
--refPos;
|
203
246
|
} else {
|
204
247
|
++refPos;
|
205
248
|
}
|
249
|
+
|
206
250
|
while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
|
207
251
|
refPos += 2;
|
208
252
|
}
|
209
253
|
}
|
254
|
+
|
210
255
|
break;
|
256
|
+
|
211
257
|
case twoDimVertL2:
|
212
258
|
this._addPixelsNeg(refLine[refPos] - 2, blackPixels);
|
259
|
+
|
213
260
|
blackPixels ^= 1;
|
261
|
+
|
214
262
|
if (codingLine[this.codingPos] < columns) {
|
215
263
|
if (refPos > 0) {
|
216
264
|
--refPos;
|
217
265
|
} else {
|
218
266
|
++refPos;
|
219
267
|
}
|
268
|
+
|
220
269
|
while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
|
221
270
|
refPos += 2;
|
222
271
|
}
|
223
272
|
}
|
273
|
+
|
224
274
|
break;
|
275
|
+
|
225
276
|
case twoDimVertL1:
|
226
277
|
this._addPixelsNeg(refLine[refPos] - 1, blackPixels);
|
278
|
+
|
227
279
|
blackPixels ^= 1;
|
280
|
+
|
228
281
|
if (codingLine[this.codingPos] < columns) {
|
229
282
|
if (refPos > 0) {
|
230
283
|
--refPos;
|
231
284
|
} else {
|
232
285
|
++refPos;
|
233
286
|
}
|
287
|
+
|
234
288
|
while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
|
235
289
|
refPos += 2;
|
236
290
|
}
|
237
291
|
}
|
292
|
+
|
238
293
|
break;
|
294
|
+
|
239
295
|
case ccittEOF:
|
240
296
|
this._addPixels(columns, 0);
|
297
|
+
|
241
298
|
this.eof = true;
|
242
299
|
break;
|
300
|
+
|
243
301
|
default:
|
244
|
-
(0, _util.info)(
|
302
|
+
(0, _util.info)("bad 2d code");
|
303
|
+
|
245
304
|
this._addPixels(columns, 0);
|
305
|
+
|
246
306
|
this.err = true;
|
247
307
|
}
|
248
308
|
}
|
@@ -250,8 +310,10 @@ var CCITTFaxDecoder = function CCITTFaxDecoder() {
|
|
250
310
|
codingLine[0] = 0;
|
251
311
|
this.codingPos = 0;
|
252
312
|
blackPixels = 0;
|
313
|
+
|
253
314
|
while (codingLine[this.codingPos] < columns) {
|
254
315
|
code1 = 0;
|
316
|
+
|
255
317
|
if (blackPixels) {
|
256
318
|
do {
|
257
319
|
code1 += code3 = this._getBlackCode();
|
@@ -261,92 +323,125 @@ var CCITTFaxDecoder = function CCITTFaxDecoder() {
|
|
261
323
|
code1 += code3 = this._getWhiteCode();
|
262
324
|
} while (code3 >= 64);
|
263
325
|
}
|
326
|
+
|
264
327
|
this._addPixels(codingLine[this.codingPos] + code1, blackPixels);
|
328
|
+
|
265
329
|
blackPixels ^= 1;
|
266
330
|
}
|
267
331
|
}
|
268
|
-
|
332
|
+
|
333
|
+
let gotEOL = false;
|
334
|
+
|
269
335
|
if (this.byteAlign) {
|
270
336
|
this.inputBits &= ~7;
|
271
337
|
}
|
338
|
+
|
272
339
|
if (!this.eoblock && this.row === this.rows - 1) {
|
273
340
|
this.rowsDone = true;
|
274
341
|
} else {
|
275
342
|
code1 = this._lookBits(12);
|
343
|
+
|
276
344
|
if (this.eoline) {
|
277
345
|
while (code1 !== ccittEOF && code1 !== 1) {
|
278
346
|
this._eatBits(1);
|
347
|
+
|
279
348
|
code1 = this._lookBits(12);
|
280
349
|
}
|
281
350
|
} else {
|
282
351
|
while (code1 === 0) {
|
283
352
|
this._eatBits(1);
|
353
|
+
|
284
354
|
code1 = this._lookBits(12);
|
285
355
|
}
|
286
356
|
}
|
357
|
+
|
287
358
|
if (code1 === 1) {
|
288
359
|
this._eatBits(12);
|
360
|
+
|
289
361
|
gotEOL = true;
|
290
362
|
} else if (code1 === ccittEOF) {
|
291
363
|
this.eof = true;
|
292
364
|
}
|
293
365
|
}
|
366
|
+
|
294
367
|
if (!this.eof && this.encoding > 0 && !this.rowsDone) {
|
295
368
|
this.nextLine2D = !this._lookBits(1);
|
369
|
+
|
296
370
|
this._eatBits(1);
|
297
371
|
}
|
372
|
+
|
298
373
|
if (this.eoblock && gotEOL && this.byteAlign) {
|
299
374
|
code1 = this._lookBits(12);
|
375
|
+
|
300
376
|
if (code1 === 1) {
|
301
377
|
this._eatBits(12);
|
378
|
+
|
302
379
|
if (this.encoding > 0) {
|
303
380
|
this._lookBits(1);
|
381
|
+
|
304
382
|
this._eatBits(1);
|
305
383
|
}
|
384
|
+
|
306
385
|
if (this.encoding >= 0) {
|
307
386
|
for (i = 0; i < 4; ++i) {
|
308
387
|
code1 = this._lookBits(12);
|
388
|
+
|
309
389
|
if (code1 !== 1) {
|
310
|
-
(0, _util.info)(
|
390
|
+
(0, _util.info)("bad rtc code: " + code1);
|
311
391
|
}
|
392
|
+
|
312
393
|
this._eatBits(12);
|
394
|
+
|
313
395
|
if (this.encoding > 0) {
|
314
396
|
this._lookBits(1);
|
397
|
+
|
315
398
|
this._eatBits(1);
|
316
399
|
}
|
317
400
|
}
|
318
401
|
}
|
402
|
+
|
319
403
|
this.eof = true;
|
320
404
|
}
|
321
405
|
} else if (this.err && this.eoline) {
|
322
406
|
while (true) {
|
323
407
|
code1 = this._lookBits(13);
|
408
|
+
|
324
409
|
if (code1 === ccittEOF) {
|
325
410
|
this.eof = true;
|
326
411
|
return -1;
|
327
412
|
}
|
413
|
+
|
328
414
|
if (code1 >> 1 === 1) {
|
329
415
|
break;
|
330
416
|
}
|
417
|
+
|
331
418
|
this._eatBits(1);
|
332
419
|
}
|
420
|
+
|
333
421
|
this._eatBits(12);
|
422
|
+
|
334
423
|
if (this.encoding > 0) {
|
335
424
|
this._eatBits(1);
|
425
|
+
|
336
426
|
this.nextLine2D = !(code1 & 1);
|
337
427
|
}
|
338
428
|
}
|
429
|
+
|
339
430
|
if (codingLine[0] > 0) {
|
340
431
|
this.outputBits = codingLine[this.codingPos = 0];
|
341
432
|
} else {
|
342
433
|
this.outputBits = codingLine[this.codingPos = 1];
|
343
434
|
}
|
435
|
+
|
344
436
|
this.row++;
|
345
437
|
}
|
346
|
-
|
438
|
+
|
439
|
+
let c;
|
440
|
+
|
347
441
|
if (this.outputBits >= 8) {
|
348
|
-
c = this.codingPos & 1 ? 0 :
|
442
|
+
c = this.codingPos & 1 ? 0 : 0xff;
|
349
443
|
this.outputBits -= 8;
|
444
|
+
|
350
445
|
if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
|
351
446
|
this.codingPos++;
|
352
447
|
this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1];
|
@@ -354,21 +449,27 @@ var CCITTFaxDecoder = function CCITTFaxDecoder() {
|
|
354
449
|
} else {
|
355
450
|
bits = 8;
|
356
451
|
c = 0;
|
452
|
+
|
357
453
|
do {
|
358
454
|
if (this.outputBits > bits) {
|
359
455
|
c <<= bits;
|
456
|
+
|
360
457
|
if (!(this.codingPos & 1)) {
|
361
|
-
c |=
|
458
|
+
c |= 0xff >> 8 - bits;
|
362
459
|
}
|
460
|
+
|
363
461
|
this.outputBits -= bits;
|
364
462
|
bits = 0;
|
365
463
|
} else {
|
366
464
|
c <<= this.outputBits;
|
465
|
+
|
367
466
|
if (!(this.codingPos & 1)) {
|
368
|
-
c |=
|
467
|
+
c |= 0xff >> 8 - this.outputBits;
|
369
468
|
}
|
469
|
+
|
370
470
|
bits -= this.outputBits;
|
371
471
|
this.outputBits = 0;
|
472
|
+
|
372
473
|
if (codingLine[this.codingPos] < columns) {
|
373
474
|
this.codingPos++;
|
374
475
|
this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1];
|
@@ -379,131 +480,174 @@ var CCITTFaxDecoder = function CCITTFaxDecoder() {
|
|
379
480
|
}
|
380
481
|
} while (bits);
|
381
482
|
}
|
483
|
+
|
382
484
|
if (this.black) {
|
383
|
-
c ^=
|
485
|
+
c ^= 0xff;
|
384
486
|
}
|
487
|
+
|
385
488
|
return c;
|
386
489
|
},
|
387
|
-
|
388
|
-
|
389
|
-
|
490
|
+
|
491
|
+
_addPixels(a1, blackPixels) {
|
492
|
+
const codingLine = this.codingLine;
|
493
|
+
let codingPos = this.codingPos;
|
494
|
+
|
390
495
|
if (a1 > codingLine[codingPos]) {
|
391
496
|
if (a1 > this.columns) {
|
392
|
-
(0, _util.info)(
|
497
|
+
(0, _util.info)("row is wrong length");
|
393
498
|
this.err = true;
|
394
499
|
a1 = this.columns;
|
395
500
|
}
|
501
|
+
|
396
502
|
if (codingPos & 1 ^ blackPixels) {
|
397
503
|
++codingPos;
|
398
504
|
}
|
505
|
+
|
399
506
|
codingLine[codingPos] = a1;
|
400
507
|
}
|
508
|
+
|
401
509
|
this.codingPos = codingPos;
|
402
510
|
},
|
403
|
-
|
404
|
-
|
405
|
-
|
511
|
+
|
512
|
+
_addPixelsNeg(a1, blackPixels) {
|
513
|
+
const codingLine = this.codingLine;
|
514
|
+
let codingPos = this.codingPos;
|
515
|
+
|
406
516
|
if (a1 > codingLine[codingPos]) {
|
407
517
|
if (a1 > this.columns) {
|
408
|
-
(0, _util.info)(
|
518
|
+
(0, _util.info)("row is wrong length");
|
409
519
|
this.err = true;
|
410
520
|
a1 = this.columns;
|
411
521
|
}
|
522
|
+
|
412
523
|
if (codingPos & 1 ^ blackPixels) {
|
413
524
|
++codingPos;
|
414
525
|
}
|
526
|
+
|
415
527
|
codingLine[codingPos] = a1;
|
416
528
|
} else if (a1 < codingLine[codingPos]) {
|
417
529
|
if (a1 < 0) {
|
418
|
-
(0, _util.info)(
|
530
|
+
(0, _util.info)("invalid code");
|
419
531
|
this.err = true;
|
420
532
|
a1 = 0;
|
421
533
|
}
|
534
|
+
|
422
535
|
while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
|
423
536
|
--codingPos;
|
424
537
|
}
|
538
|
+
|
425
539
|
codingLine[codingPos] = a1;
|
426
540
|
}
|
541
|
+
|
427
542
|
this.codingPos = codingPos;
|
428
543
|
},
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
544
|
+
|
545
|
+
_findTableCode(start, end, table, limit) {
|
546
|
+
const limitValue = limit || 0;
|
547
|
+
|
548
|
+
for (let i = start; i <= end; ++i) {
|
549
|
+
let code = this._lookBits(i);
|
550
|
+
|
433
551
|
if (code === ccittEOF) {
|
434
552
|
return [true, 1, false];
|
435
553
|
}
|
554
|
+
|
436
555
|
if (i < end) {
|
437
556
|
code <<= end - i;
|
438
557
|
}
|
558
|
+
|
439
559
|
if (!limitValue || code >= limitValue) {
|
440
|
-
|
560
|
+
const p = table[code - limitValue];
|
561
|
+
|
441
562
|
if (p[0] === i) {
|
442
563
|
this._eatBits(i);
|
564
|
+
|
443
565
|
return [true, p[1], true];
|
444
566
|
}
|
445
567
|
}
|
446
568
|
}
|
569
|
+
|
447
570
|
return [false, 0, false];
|
448
571
|
},
|
449
|
-
|
450
|
-
|
451
|
-
|
572
|
+
|
573
|
+
_getTwoDimCode() {
|
574
|
+
let code = 0;
|
575
|
+
let p;
|
576
|
+
|
452
577
|
if (this.eoblock) {
|
453
578
|
code = this._lookBits(7);
|
454
579
|
p = twoDimTable[code];
|
580
|
+
|
455
581
|
if (p && p[0] > 0) {
|
456
582
|
this._eatBits(p[0]);
|
583
|
+
|
457
584
|
return p[1];
|
458
585
|
}
|
459
586
|
} else {
|
460
|
-
|
587
|
+
const result = this._findTableCode(1, 7, twoDimTable);
|
588
|
+
|
461
589
|
if (result[0] && result[2]) {
|
462
590
|
return result[1];
|
463
591
|
}
|
464
592
|
}
|
465
|
-
|
593
|
+
|
594
|
+
(0, _util.info)("Bad two dim code");
|
466
595
|
return ccittEOF;
|
467
596
|
},
|
468
|
-
|
469
|
-
|
470
|
-
|
597
|
+
|
598
|
+
_getWhiteCode() {
|
599
|
+
let code = 0;
|
600
|
+
let p;
|
601
|
+
|
471
602
|
if (this.eoblock) {
|
472
603
|
code = this._lookBits(12);
|
604
|
+
|
473
605
|
if (code === ccittEOF) {
|
474
606
|
return 1;
|
475
607
|
}
|
608
|
+
|
476
609
|
if (code >> 5 === 0) {
|
477
610
|
p = whiteTable1[code];
|
478
611
|
} else {
|
479
612
|
p = whiteTable2[code >> 3];
|
480
613
|
}
|
614
|
+
|
481
615
|
if (p[0] > 0) {
|
482
616
|
this._eatBits(p[0]);
|
617
|
+
|
483
618
|
return p[1];
|
484
619
|
}
|
485
620
|
} else {
|
486
|
-
|
621
|
+
let result = this._findTableCode(1, 9, whiteTable2);
|
622
|
+
|
487
623
|
if (result[0]) {
|
488
624
|
return result[1];
|
489
625
|
}
|
626
|
+
|
490
627
|
result = this._findTableCode(11, 12, whiteTable1);
|
628
|
+
|
491
629
|
if (result[0]) {
|
492
630
|
return result[1];
|
493
631
|
}
|
494
632
|
}
|
495
|
-
|
633
|
+
|
634
|
+
(0, _util.info)("bad white code");
|
635
|
+
|
496
636
|
this._eatBits(1);
|
637
|
+
|
497
638
|
return 1;
|
498
639
|
},
|
499
|
-
|
500
|
-
|
501
|
-
|
640
|
+
|
641
|
+
_getBlackCode() {
|
642
|
+
let code, p;
|
643
|
+
|
502
644
|
if (this.eoblock) {
|
503
645
|
code = this._lookBits(13);
|
646
|
+
|
504
647
|
if (code === ccittEOF) {
|
505
648
|
return 1;
|
506
649
|
}
|
650
|
+
|
507
651
|
if (code >> 7 === 0) {
|
508
652
|
p = blackTable1[code];
|
509
653
|
} else if (code >> 9 === 0 && code >> 7 !== 0) {
|
@@ -511,48 +655,66 @@ var CCITTFaxDecoder = function CCITTFaxDecoder() {
|
|
511
655
|
} else {
|
512
656
|
p = blackTable3[code >> 7];
|
513
657
|
}
|
658
|
+
|
514
659
|
if (p[0] > 0) {
|
515
660
|
this._eatBits(p[0]);
|
661
|
+
|
516
662
|
return p[1];
|
517
663
|
}
|
518
664
|
} else {
|
519
|
-
|
665
|
+
let result = this._findTableCode(2, 6, blackTable3);
|
666
|
+
|
520
667
|
if (result[0]) {
|
521
668
|
return result[1];
|
522
669
|
}
|
670
|
+
|
523
671
|
result = this._findTableCode(7, 12, blackTable2, 64);
|
672
|
+
|
524
673
|
if (result[0]) {
|
525
674
|
return result[1];
|
526
675
|
}
|
676
|
+
|
527
677
|
result = this._findTableCode(10, 13, blackTable1);
|
678
|
+
|
528
679
|
if (result[0]) {
|
529
680
|
return result[1];
|
530
681
|
}
|
531
682
|
}
|
532
|
-
|
683
|
+
|
684
|
+
(0, _util.info)("bad black code");
|
685
|
+
|
533
686
|
this._eatBits(1);
|
687
|
+
|
534
688
|
return 1;
|
535
689
|
},
|
536
|
-
|
537
|
-
|
690
|
+
|
691
|
+
_lookBits(n) {
|
692
|
+
let c;
|
693
|
+
|
538
694
|
while (this.inputBits < n) {
|
539
695
|
if ((c = this.source.next()) === -1) {
|
540
696
|
if (this.inputBits === 0) {
|
541
697
|
return ccittEOF;
|
542
698
|
}
|
543
|
-
|
699
|
+
|
700
|
+
return this.inputBuf << n - this.inputBits & 0xffff >> 16 - n;
|
544
701
|
}
|
702
|
+
|
545
703
|
this.inputBuf = this.inputBuf << 8 | c;
|
546
704
|
this.inputBits += 8;
|
547
705
|
}
|
548
|
-
|
706
|
+
|
707
|
+
return this.inputBuf >> this.inputBits - n & 0xffff >> 16 - n;
|
549
708
|
},
|
550
|
-
|
709
|
+
|
710
|
+
_eatBits(n) {
|
551
711
|
if ((this.inputBits -= n) < 0) {
|
552
712
|
this.inputBits = 0;
|
553
713
|
}
|
554
714
|
}
|
715
|
+
|
555
716
|
};
|
556
717
|
return CCITTFaxDecoder;
|
557
718
|
}();
|
719
|
+
|
558
720
|
exports.CCITTFaxDecoder = CCITTFaxDecoder;
|