pdfjs-dist 2.0.550 → 2.3.200

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.

Files changed (168) hide show
  1. package/CODE_OF_CONDUCT.md +15 -0
  2. package/bower.json +1 -1
  3. package/build/pdf.js +21618 -14369
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +1 -1
  6. package/build/pdf.worker.js +22758 -11399
  7. package/build/pdf.worker.js.map +1 -1
  8. package/build/pdf.worker.min.js +1 -1
  9. package/image_decoders/pdf.image_decoders.js +11500 -0
  10. package/image_decoders/pdf.image_decoders.js.map +1 -0
  11. package/image_decoders/pdf.image_decoders.min.js +1 -0
  12. package/lib/core/annotation.js +767 -258
  13. package/lib/core/arithmetic_decoder.js +275 -245
  14. package/lib/core/bidi.js +65 -6
  15. package/lib/core/ccitt.js +173 -18
  16. package/lib/core/ccitt_stream.js +15 -6
  17. package/lib/core/cff_parser.js +433 -61
  18. package/lib/core/charsets.js +5 -4
  19. package/lib/core/chunked_stream.js +428 -157
  20. package/lib/core/cmap.js +326 -87
  21. package/lib/core/colorspace.js +874 -594
  22. package/lib/core/core_utils.js +173 -0
  23. package/lib/core/crypto.js +290 -45
  24. package/lib/core/document.js +575 -272
  25. package/lib/core/encodings.js +19 -10
  26. package/lib/core/evaluator.js +1032 -351
  27. package/lib/core/font_renderer.js +331 -97
  28. package/lib/core/fonts.js +813 -196
  29. package/lib/core/function.js +253 -27
  30. package/lib/core/glyphlist.js +5 -3
  31. package/lib/core/image.js +169 -62
  32. package/lib/core/image_utils.js +111 -0
  33. package/lib/core/jbig2.js +502 -72
  34. package/lib/core/jbig2_stream.js +19 -8
  35. package/lib/core/jpeg_stream.js +38 -13
  36. package/lib/core/jpg.js +293 -52
  37. package/lib/core/jpx.js +419 -12
  38. package/lib/core/jpx_stream.js +18 -6
  39. package/lib/core/metrics.js +15 -15
  40. package/lib/core/murmurhash3.js +56 -34
  41. package/lib/core/obj.js +1368 -500
  42. package/lib/core/operator_list.js +159 -43
  43. package/lib/core/parser.js +544 -199
  44. package/lib/core/pattern.js +170 -21
  45. package/lib/core/pdf_manager.js +324 -134
  46. package/lib/core/primitives.js +169 -61
  47. package/lib/core/ps_parser.js +134 -45
  48. package/lib/core/standard_fonts.js +17 -17
  49. package/lib/core/stream.js +327 -34
  50. package/lib/core/type1_parser.js +148 -8
  51. package/lib/core/unicode.js +32 -5
  52. package/lib/core/worker.js +215 -229
  53. package/lib/core/worker_stream.js +277 -0
  54. package/lib/display/annotation_layer.js +618 -192
  55. package/lib/display/api.js +1798 -882
  56. package/lib/display/api_compatibility.js +5 -10
  57. package/lib/display/canvas.js +366 -45
  58. package/lib/display/content_disposition.js +71 -24
  59. package/lib/display/display_utils.js +777 -0
  60. package/lib/display/fetch_stream.js +205 -87
  61. package/lib/display/font_loader.js +468 -236
  62. package/lib/display/metadata.js +38 -16
  63. package/lib/display/network.js +635 -428
  64. package/lib/display/network_utils.js +38 -19
  65. package/lib/display/node_stream.js +367 -175
  66. package/lib/display/pattern_helper.js +103 -36
  67. package/lib/display/svg.js +1232 -519
  68. package/lib/display/text_layer.js +208 -75
  69. package/lib/display/transport_stream.js +345 -94
  70. package/lib/display/webgl.js +64 -18
  71. package/lib/display/worker_options.js +5 -4
  72. package/lib/display/xml_parser.js +166 -53
  73. package/lib/examples/node/domstubs.js +60 -4
  74. package/lib/pdf.js +35 -14
  75. package/lib/pdf.worker.js +5 -3
  76. package/lib/shared/compatibility.js +170 -572
  77. package/lib/shared/global_scope.js +2 -2
  78. package/lib/shared/is_node.js +4 -4
  79. package/lib/shared/message_handler.js +216 -163
  80. package/lib/shared/streams_polyfill.js +21 -17
  81. package/lib/shared/util.js +495 -385
  82. package/lib/test/unit/annotation_spec.js +1464 -401
  83. package/lib/test/unit/api_spec.js +718 -361
  84. package/lib/test/unit/bidi_spec.js +7 -7
  85. package/lib/test/unit/cff_parser_spec.js +54 -11
  86. package/lib/test/unit/clitests_helper.js +9 -10
  87. package/lib/test/unit/cmap_spec.js +95 -41
  88. package/lib/test/unit/colorspace_spec.js +115 -63
  89. package/lib/test/unit/core_utils_spec.js +191 -0
  90. package/lib/test/unit/crypto_spec.js +17 -5
  91. package/lib/test/unit/custom_spec.js +43 -55
  92. package/lib/test/unit/display_svg_spec.js +34 -18
  93. package/lib/test/unit/display_utils_spec.js +273 -0
  94. package/lib/test/unit/document_spec.js +8 -13
  95. package/lib/test/unit/encodings_spec.js +25 -45
  96. package/lib/test/unit/evaluator_spec.js +59 -20
  97. package/lib/test/unit/fetch_stream_spec.js +111 -0
  98. package/lib/test/unit/function_spec.js +17 -5
  99. package/lib/test/unit/jasmine-boot.js +33 -20
  100. package/lib/test/unit/message_handler_spec.js +30 -13
  101. package/lib/test/unit/metadata_spec.js +71 -11
  102. package/lib/test/unit/murmurhash3_spec.js +3 -3
  103. package/lib/test/unit/network_spec.js +22 -55
  104. package/lib/test/unit/network_utils_spec.js +105 -14
  105. package/lib/test/unit/node_stream_spec.js +58 -34
  106. package/lib/test/unit/parser_spec.js +162 -71
  107. package/lib/test/unit/pdf_find_controller_spec.js +230 -0
  108. package/lib/test/unit/pdf_find_utils_spec.js +63 -0
  109. package/lib/test/unit/pdf_history_spec.js +21 -9
  110. package/lib/test/unit/primitives_spec.js +55 -22
  111. package/lib/test/unit/stream_spec.js +12 -4
  112. package/lib/test/unit/test_utils.js +273 -56
  113. package/lib/test/unit/testreporter.js +21 -3
  114. package/lib/test/unit/type1_parser_spec.js +9 -7
  115. package/lib/test/unit/ui_utils_spec.js +236 -36
  116. package/lib/test/unit/unicode_spec.js +18 -15
  117. package/lib/test/unit/util_spec.js +87 -128
  118. package/lib/web/annotation_layer_builder.js +39 -22
  119. package/lib/web/app.js +1252 -609
  120. package/lib/web/app_options.js +103 -65
  121. package/lib/web/base_viewer.js +522 -242
  122. package/lib/web/chromecom.js +259 -117
  123. package/lib/web/debugger.js +166 -22
  124. package/lib/web/download_manager.js +31 -12
  125. package/lib/web/firefox_print_service.js +27 -14
  126. package/lib/web/firefoxcom.js +318 -78
  127. package/lib/web/genericcom.js +89 -30
  128. package/lib/web/genericl10n.js +142 -30
  129. package/lib/web/grab_to_pan.js +28 -4
  130. package/lib/web/interfaces.js +174 -47
  131. package/lib/web/overlay_manager.js +235 -85
  132. package/lib/web/password_prompt.js +22 -14
  133. package/lib/web/pdf_attachment_viewer.js +38 -18
  134. package/lib/web/pdf_cursor_tools.js +39 -16
  135. package/lib/web/pdf_document_properties.js +255 -136
  136. package/lib/web/pdf_find_bar.js +84 -40
  137. package/lib/web/pdf_find_controller.js +495 -184
  138. package/lib/web/pdf_find_utils.js +111 -0
  139. package/lib/web/pdf_history.js +190 -53
  140. package/lib/web/pdf_link_service.js +144 -79
  141. package/lib/web/pdf_outline_viewer.js +124 -47
  142. package/lib/web/pdf_page_view.js +194 -74
  143. package/lib/web/pdf_presentation_mode.js +99 -34
  144. package/lib/web/pdf_print_service.js +59 -13
  145. package/lib/web/pdf_rendering_queue.js +28 -9
  146. package/lib/web/pdf_sidebar.js +144 -81
  147. package/lib/web/pdf_sidebar_resizer.js +42 -16
  148. package/lib/web/pdf_single_page_viewer.js +74 -66
  149. package/lib/web/pdf_thumbnail_view.js +104 -33
  150. package/lib/web/pdf_thumbnail_viewer.js +66 -26
  151. package/lib/web/pdf_viewer.component.js +112 -32
  152. package/lib/web/pdf_viewer.js +82 -87
  153. package/lib/web/preferences.js +284 -91
  154. package/lib/web/secondary_toolbar.js +132 -59
  155. package/lib/web/text_layer_builder.js +134 -59
  156. package/lib/web/toolbar.js +80 -43
  157. package/lib/web/ui_utils.js +400 -134
  158. package/lib/web/view_history.js +215 -67
  159. package/lib/web/viewer_compatibility.js +3 -8
  160. package/package.json +3 -2
  161. package/web/pdf_viewer.css +23 -15
  162. package/web/pdf_viewer.js +3429 -1245
  163. package/web/pdf_viewer.js.map +1 -1
  164. package/external/streams/streams-lib.js +0 -3962
  165. package/lib/display/dom_utils.js +0 -429
  166. package/lib/test/unit/dom_utils_spec.js +0 -89
  167. package/lib/test/unit/fonts_spec.js +0 -81
  168. package/lib/web/dom_events.js +0 -137
package/lib/core/jbig2.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 2017 Mozilla Foundation
5
+ * Copyright 2019 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,81 +19,116 @@
19
19
  * @licend The above is the entire license notice for the
20
20
  * Javascript code in this page
21
21
  */
22
- 'use strict';
22
+ "use strict";
23
23
 
24
24
  Object.defineProperty(exports, "__esModule", {
25
25
  value: true
26
26
  });
27
- exports.Jbig2Image = undefined;
27
+ exports.Jbig2Image = void 0;
28
28
 
29
- var _util = require('../shared/util');
29
+ var _util = require("../shared/util");
30
30
 
31
- var _arithmetic_decoder = require('./arithmetic_decoder');
31
+ var _arithmetic_decoder = require("./arithmetic_decoder");
32
32
 
33
- var _ccitt = require('./ccitt');
33
+ var _ccitt = require("./ccitt");
34
+
35
+ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
36
+
37
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
38
+
39
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
40
+
41
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
42
+
43
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
44
+
45
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
46
+
47
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
48
+
49
+ var Jbig2Error =
50
+ /*#__PURE__*/
51
+ function (_BaseException) {
52
+ _inherits(Jbig2Error, _BaseException);
34
53
 
35
- var Jbig2Error = function Jbig2ErrorClosure() {
36
54
  function Jbig2Error(msg) {
37
- this.message = 'JBIG2 error: ' + msg;
55
+ _classCallCheck(this, Jbig2Error);
56
+
57
+ return _possibleConstructorReturn(this, _getPrototypeOf(Jbig2Error).call(this, "JBIG2 error: ".concat(msg)));
38
58
  }
39
- Jbig2Error.prototype = new Error();
40
- Jbig2Error.prototype.name = 'Jbig2Error';
41
- Jbig2Error.constructor = Jbig2Error;
59
+
42
60
  return Jbig2Error;
43
- }();
61
+ }(_util.BaseException);
62
+
44
63
  var Jbig2Image = function Jbig2ImageClosure() {
45
64
  function ContextCache() {}
65
+
46
66
  ContextCache.prototype = {
47
67
  getContexts: function getContexts(id) {
48
68
  if (id in this) {
49
69
  return this[id];
50
70
  }
71
+
51
72
  return this[id] = new Int8Array(1 << 16);
52
73
  }
53
74
  };
75
+
54
76
  function DecodingContext(data, start, end) {
55
77
  this.data = data;
56
78
  this.start = start;
57
79
  this.end = end;
58
80
  }
81
+
59
82
  DecodingContext.prototype = {
60
83
  get decoder() {
61
84
  var decoder = new _arithmetic_decoder.ArithmeticDecoder(this.data, this.start, this.end);
62
85
  return (0, _util.shadow)(this, 'decoder', decoder);
63
86
  },
87
+
64
88
  get contextCache() {
65
89
  var cache = new ContextCache();
66
90
  return (0, _util.shadow)(this, 'contextCache', cache);
67
91
  }
92
+
68
93
  };
94
+
69
95
  function decodeInteger(contextCache, procedure, decoder) {
70
96
  var contexts = contextCache.getContexts(procedure);
71
97
  var prev = 1;
98
+
72
99
  function readBits(length) {
73
100
  var v = 0;
101
+
74
102
  for (var i = 0; i < length; i++) {
75
103
  var bit = decoder.readBit(contexts, prev);
76
104
  prev = prev < 256 ? prev << 1 | bit : (prev << 1 | bit) & 511 | 256;
77
105
  v = v << 1 | bit;
78
106
  }
107
+
79
108
  return v >>> 0;
80
109
  }
110
+
81
111
  var sign = readBits(1);
82
112
  var value = readBits(1) ? readBits(1) ? readBits(1) ? readBits(1) ? readBits(1) ? readBits(32) + 4436 : readBits(12) + 340 : readBits(8) + 84 : readBits(6) + 20 : readBits(4) + 4 : readBits(2);
83
113
  return sign === 0 ? value : value > 0 ? -value : null;
84
114
  }
115
+
85
116
  function decodeIAID(contextCache, decoder, codeLength) {
86
117
  var contexts = contextCache.getContexts('IAID');
87
118
  var prev = 1;
119
+
88
120
  for (var i = 0; i < codeLength; i++) {
89
121
  var bit = decoder.readBit(contexts, prev);
90
122
  prev = prev << 1 | bit;
91
123
  }
124
+
92
125
  if (codeLength < 31) {
93
126
  return prev & (1 << codeLength) - 1;
94
127
  }
128
+
95
129
  return prev & 0x7FFFFFFF;
96
130
  }
131
+
97
132
  var SegmentTypes = ['SymbolDictionary', null, null, null, 'IntermediateTextRegion', null, 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null, null, null, null, null, null, 'PatternDictionary', null, null, null, 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion', 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null, null, null, null, null, null, 'IntermediateGenericRegion', null, 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion', 'IntermediateGenericRefinementRegion', null, 'ImmediateGenericRefinementRegion', 'ImmediateLosslessGenericRefinementRegion', null, null, null, null, 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles', 'Tables', null, null, null, null, null, null, null, null, 'Extension'];
98
133
  var CodingTemplates = [[{
99
134
  x: -1,
@@ -294,6 +329,7 @@ var Jbig2Image = function Jbig2ImageClosure() {
294
329
  }];
295
330
  var ReusedContexts = [0x9B25, 0x0795, 0x00E5, 0x0195];
296
331
  var RefinementReusedContexts = [0x0020, 0x0008];
332
+
297
333
  function decodeBitmapTemplate0(width, height, decodingContext) {
298
334
  var decoder = decodingContext.decoder;
299
335
  var contexts = decodingContext.contextCache.getContexts('GB');
@@ -306,26 +342,32 @@ var Jbig2Image = function Jbig2ImageClosure() {
306
342
  row2,
307
343
  bitmap = [];
308
344
  var OLD_PIXEL_MASK = 0x7BF7;
345
+
309
346
  for (i = 0; i < height; i++) {
310
347
  row = bitmap[i] = new Uint8Array(width);
311
348
  row1 = i < 1 ? row : bitmap[i - 1];
312
349
  row2 = i < 2 ? row : bitmap[i - 2];
313
350
  contextLabel = row2[0] << 13 | row2[1] << 12 | row2[2] << 11 | row1[0] << 7 | row1[1] << 6 | row1[2] << 5 | row1[3] << 4;
351
+
314
352
  for (j = 0; j < width; j++) {
315
353
  row[j] = pixel = decoder.readBit(contexts, contextLabel);
316
354
  contextLabel = (contextLabel & OLD_PIXEL_MASK) << 1 | (j + 3 < width ? row2[j + 3] << 11 : 0) | (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
317
355
  }
318
356
  }
357
+
319
358
  return bitmap;
320
359
  }
360
+
321
361
  function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at, decodingContext) {
322
362
  if (mmr) {
323
363
  var input = new Reader(decodingContext.data, decodingContext.start, decodingContext.end);
324
364
  return decodeMMRBitmap(input, width, height, false);
325
365
  }
366
+
326
367
  if (templateIndex === 0 && !skip && !prediction && at.length === 4 && at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 && at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
327
368
  return decodeBitmapTemplate0(width, height, decodingContext);
328
369
  }
370
+
329
371
  var useskip = !!skip;
330
372
  var template = CodingTemplates[templateIndex].concat(at);
331
373
  template.sort(function (a, b) {
@@ -340,28 +382,33 @@ var Jbig2Image = function Jbig2ImageClosure() {
340
382
  maxX = 0,
341
383
  minY = 0;
342
384
  var c, k;
385
+
343
386
  for (k = 0; k < templateLength; k++) {
344
387
  templateX[k] = template[k].x;
345
388
  templateY[k] = template[k].y;
346
389
  minX = Math.min(minX, template[k].x);
347
390
  maxX = Math.max(maxX, template[k].x);
348
391
  minY = Math.min(minY, template[k].y);
392
+
349
393
  if (k < templateLength - 1 && template[k].y === template[k + 1].y && template[k].x === template[k + 1].x - 1) {
350
394
  reuseMask |= 1 << templateLength - 1 - k;
351
395
  } else {
352
396
  changingTemplateEntries.push(k);
353
397
  }
354
398
  }
399
+
355
400
  var changingEntriesLength = changingTemplateEntries.length;
356
401
  var changingTemplateX = new Int8Array(changingEntriesLength);
357
402
  var changingTemplateY = new Int8Array(changingEntriesLength);
358
403
  var changingTemplateBit = new Uint16Array(changingEntriesLength);
404
+
359
405
  for (c = 0; c < changingEntriesLength; c++) {
360
406
  k = changingTemplateEntries[c];
361
407
  changingTemplateX[c] = template[k].x;
362
408
  changingTemplateY[c] = template[k].y;
363
409
  changingTemplateBit[c] = 1 << templateLength - 1 - k;
364
410
  }
411
+
365
412
  var sbb_left = -minX;
366
413
  var sbb_top = -minY;
367
414
  var sbb_right = width - maxX;
@@ -377,28 +424,35 @@ var Jbig2Image = function Jbig2ImageClosure() {
377
424
  contextLabel = 0,
378
425
  bit,
379
426
  shift;
427
+
380
428
  for (var i = 0; i < height; i++) {
381
429
  if (prediction) {
382
430
  var sltp = decoder.readBit(contexts, pseudoPixelContext);
383
431
  ltp ^= sltp;
432
+
384
433
  if (ltp) {
385
434
  bitmap.push(row);
386
435
  continue;
387
436
  }
388
437
  }
438
+
389
439
  row = new Uint8Array(row);
390
440
  bitmap.push(row);
441
+
391
442
  for (j = 0; j < width; j++) {
392
443
  if (useskip && skip[i][j]) {
393
444
  row[j] = 0;
394
445
  continue;
395
446
  }
447
+
396
448
  if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
397
449
  contextLabel = contextLabel << 1 & reuseMask;
450
+
398
451
  for (k = 0; k < changingEntriesLength; k++) {
399
452
  i0 = i + changingTemplateY[k];
400
453
  j0 = j + changingTemplateX[k];
401
454
  bit = bitmap[i0][j0];
455
+
402
456
  if (bit) {
403
457
  bit = changingTemplateBit[k];
404
458
  contextLabel |= bit;
@@ -407,12 +461,16 @@ var Jbig2Image = function Jbig2ImageClosure() {
407
461
  } else {
408
462
  contextLabel = 0;
409
463
  shift = templateLength - 1;
464
+
410
465
  for (k = 0; k < templateLength; k++, shift--) {
411
466
  j0 = j + templateX[k];
467
+
412
468
  if (j0 >= 0 && j0 < width) {
413
469
  i0 = i + templateY[k];
470
+
414
471
  if (i0 >= 0) {
415
472
  bit = bitmap[i0][j0];
473
+
416
474
  if (bit) {
417
475
  contextLabel |= bit << shift;
418
476
  }
@@ -420,36 +478,47 @@ var Jbig2Image = function Jbig2ImageClosure() {
420
478
  }
421
479
  }
422
480
  }
481
+
423
482
  var pixel = decoder.readBit(contexts, contextLabel);
424
483
  row[j] = pixel;
425
484
  }
426
485
  }
486
+
427
487
  return bitmap;
428
488
  }
489
+
429
490
  function decodeRefinement(width, height, templateIndex, referenceBitmap, offsetX, offsetY, prediction, at, decodingContext) {
430
491
  var codingTemplate = RefinementTemplates[templateIndex].coding;
492
+
431
493
  if (templateIndex === 0) {
432
494
  codingTemplate = codingTemplate.concat([at[0]]);
433
495
  }
496
+
434
497
  var codingTemplateLength = codingTemplate.length;
435
498
  var codingTemplateX = new Int32Array(codingTemplateLength);
436
499
  var codingTemplateY = new Int32Array(codingTemplateLength);
437
500
  var k;
501
+
438
502
  for (k = 0; k < codingTemplateLength; k++) {
439
503
  codingTemplateX[k] = codingTemplate[k].x;
440
504
  codingTemplateY[k] = codingTemplate[k].y;
441
505
  }
506
+
442
507
  var referenceTemplate = RefinementTemplates[templateIndex].reference;
508
+
443
509
  if (templateIndex === 0) {
444
510
  referenceTemplate = referenceTemplate.concat([at[1]]);
445
511
  }
512
+
446
513
  var referenceTemplateLength = referenceTemplate.length;
447
514
  var referenceTemplateX = new Int32Array(referenceTemplateLength);
448
515
  var referenceTemplateY = new Int32Array(referenceTemplateLength);
516
+
449
517
  for (k = 0; k < referenceTemplateLength; k++) {
450
518
  referenceTemplateX[k] = referenceTemplate[k].x;
451
519
  referenceTemplateY[k] = referenceTemplate[k].y;
452
520
  }
521
+
453
522
  var referenceWidth = referenceBitmap[0].length;
454
523
  var referenceHeight = referenceBitmap.length;
455
524
  var pseudoPixelContext = RefinementReusedContexts[templateIndex];
@@ -457,75 +526,93 @@ var Jbig2Image = function Jbig2ImageClosure() {
457
526
  var decoder = decodingContext.decoder;
458
527
  var contexts = decodingContext.contextCache.getContexts('GR');
459
528
  var ltp = 0;
529
+
460
530
  for (var i = 0; i < height; i++) {
461
531
  if (prediction) {
462
532
  var sltp = decoder.readBit(contexts, pseudoPixelContext);
463
533
  ltp ^= sltp;
534
+
464
535
  if (ltp) {
465
536
  throw new Jbig2Error('prediction is not supported');
466
537
  }
467
538
  }
539
+
468
540
  var row = new Uint8Array(width);
469
541
  bitmap.push(row);
542
+
470
543
  for (var j = 0; j < width; j++) {
471
544
  var i0, j0;
472
545
  var contextLabel = 0;
546
+
473
547
  for (k = 0; k < codingTemplateLength; k++) {
474
548
  i0 = i + codingTemplateY[k];
475
549
  j0 = j + codingTemplateX[k];
550
+
476
551
  if (i0 < 0 || j0 < 0 || j0 >= width) {
477
552
  contextLabel <<= 1;
478
553
  } else {
479
554
  contextLabel = contextLabel << 1 | bitmap[i0][j0];
480
555
  }
481
556
  }
557
+
482
558
  for (k = 0; k < referenceTemplateLength; k++) {
483
559
  i0 = i + referenceTemplateY[k] - offsetY;
484
560
  j0 = j + referenceTemplateX[k] - offsetX;
561
+
485
562
  if (i0 < 0 || i0 >= referenceHeight || j0 < 0 || j0 >= referenceWidth) {
486
563
  contextLabel <<= 1;
487
564
  } else {
488
565
  contextLabel = contextLabel << 1 | referenceBitmap[i0][j0];
489
566
  }
490
567
  }
568
+
491
569
  var pixel = decoder.readBit(contexts, contextLabel);
492
570
  row[j] = pixel;
493
571
  }
494
572
  }
573
+
495
574
  return bitmap;
496
575
  }
576
+
497
577
  function decodeSymbolDictionary(huffman, refinement, symbols, numberOfNewSymbols, numberOfExportedSymbols, huffmanTables, templateIndex, at, refinementTemplateIndex, refinementAt, decodingContext, huffmanInput) {
498
578
  if (huffman && refinement) {
499
579
  throw new Jbig2Error('symbol refinement with Huffman is not supported');
500
580
  }
581
+
501
582
  var newSymbols = [];
502
583
  var currentHeight = 0;
503
584
  var symbolCodeLength = (0, _util.log2)(symbols.length + numberOfNewSymbols);
504
585
  var decoder = decodingContext.decoder;
505
586
  var contextCache = decodingContext.contextCache;
506
- var tableB1 = void 0,
507
- symbolWidths = void 0;
587
+ var tableB1, symbolWidths;
588
+
508
589
  if (huffman) {
509
590
  tableB1 = getStandardTable(1);
510
591
  symbolWidths = [];
511
592
  symbolCodeLength = Math.max(symbolCodeLength, 1);
512
593
  }
594
+
513
595
  while (newSymbols.length < numberOfNewSymbols) {
514
596
  var deltaHeight = huffman ? huffmanTables.tableDeltaHeight.decode(huffmanInput) : decodeInteger(contextCache, 'IADH', decoder);
515
597
  currentHeight += deltaHeight;
516
598
  var currentWidth = 0,
517
599
  totalWidth = 0;
518
600
  var firstSymbol = huffman ? symbolWidths.length : 0;
601
+
519
602
  while (true) {
520
603
  var deltaWidth = huffman ? huffmanTables.tableDeltaWidth.decode(huffmanInput) : decodeInteger(contextCache, 'IADW', decoder);
604
+
521
605
  if (deltaWidth === null) {
522
606
  break;
523
607
  }
608
+
524
609
  currentWidth += deltaWidth;
525
610
  totalWidth += currentWidth;
526
611
  var bitmap;
612
+
527
613
  if (refinement) {
528
614
  var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
615
+
529
616
  if (numberOfInstances > 1) {
530
617
  bitmap = decodeTextRegion(huffman, refinement, currentWidth, currentHeight, 0, numberOfInstances, 1, symbols.concat(newSymbols), symbolCodeLength, 0, 0, 1, 0, huffmanTables, refinementTemplateIndex, refinementAt, decodingContext, 0, huffmanInput);
531
618
  } else {
@@ -535,6 +622,7 @@ var Jbig2Image = function Jbig2ImageClosure() {
535
622
  var symbol = symbolId < symbols.length ? symbols[symbolId] : newSymbols[symbolId - symbols.length];
536
623
  bitmap = decodeRefinement(currentWidth, currentHeight, refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt, decodingContext);
537
624
  }
625
+
538
626
  newSymbols.push(bitmap);
539
627
  } else if (huffman) {
540
628
  symbolWidths.push(currentWidth);
@@ -543,10 +631,12 @@ var Jbig2Image = function Jbig2ImageClosure() {
543
631
  newSymbols.push(bitmap);
544
632
  }
545
633
  }
634
+
546
635
  if (huffman && !refinement) {
547
636
  var bitmapSize = huffmanTables.tableBitmapSize.decode(huffmanInput);
548
637
  huffmanInput.byteAlign();
549
638
  var collectiveBitmap = void 0;
639
+
550
640
  if (bitmapSize === 0) {
551
641
  collectiveBitmap = readUncompressedBitmap(huffmanInput, totalWidth, currentHeight);
552
642
  } else {
@@ -557,7 +647,9 @@ var Jbig2Image = function Jbig2ImageClosure() {
557
647
  huffmanInput.end = originalEnd;
558
648
  huffmanInput.position = bitmapEnd;
559
649
  }
650
+
560
651
  var numberOfSymbolsDecoded = symbolWidths.length;
652
+
561
653
  if (firstSymbol === numberOfSymbolsDecoded - 1) {
562
654
  newSymbols.push(collectiveBitmap);
563
655
  } else {
@@ -567,79 +659,100 @@ var Jbig2Image = function Jbig2ImageClosure() {
567
659
  xMax = void 0,
568
660
  bitmapWidth = void 0,
569
661
  symbolBitmap = void 0;
662
+
570
663
  for (_i = firstSymbol; _i < numberOfSymbolsDecoded; _i++) {
571
664
  bitmapWidth = symbolWidths[_i];
572
665
  xMax = xMin + bitmapWidth;
573
666
  symbolBitmap = [];
667
+
574
668
  for (y = 0; y < currentHeight; y++) {
575
669
  symbolBitmap.push(collectiveBitmap[y].subarray(xMin, xMax));
576
670
  }
671
+
577
672
  newSymbols.push(symbolBitmap);
578
673
  xMin = xMax;
579
674
  }
580
675
  }
581
676
  }
582
677
  }
678
+
583
679
  var exportedSymbols = [];
584
680
  var flags = [],
585
681
  currentFlag = false;
586
682
  var totalSymbolsLength = symbols.length + numberOfNewSymbols;
683
+
587
684
  while (flags.length < totalSymbolsLength) {
588
685
  var runLength = huffman ? tableB1.decode(huffmanInput) : decodeInteger(contextCache, 'IAEX', decoder);
686
+
589
687
  while (runLength--) {
590
688
  flags.push(currentFlag);
591
689
  }
690
+
592
691
  currentFlag = !currentFlag;
593
692
  }
693
+
594
694
  for (var i = 0, ii = symbols.length; i < ii; i++) {
595
695
  if (flags[i]) {
596
696
  exportedSymbols.push(symbols[i]);
597
697
  }
598
698
  }
699
+
599
700
  for (var j = 0; j < numberOfNewSymbols; i++, j++) {
600
701
  if (flags[i]) {
601
702
  exportedSymbols.push(newSymbols[j]);
602
703
  }
603
704
  }
705
+
604
706
  return exportedSymbols;
605
707
  }
708
+
606
709
  function decodeTextRegion(huffman, refinement, width, height, defaultPixelValue, numberOfSymbolInstances, stripSize, inputSymbols, symbolCodeLength, transposed, dsOffset, referenceCorner, combinationOperator, huffmanTables, refinementTemplateIndex, refinementAt, decodingContext, logStripSize, huffmanInput) {
607
710
  if (huffman && refinement) {
608
711
  throw new Jbig2Error('refinement with Huffman is not supported');
609
712
  }
713
+
610
714
  var bitmap = [];
611
715
  var i, row;
716
+
612
717
  for (i = 0; i < height; i++) {
613
718
  row = new Uint8Array(width);
719
+
614
720
  if (defaultPixelValue) {
615
721
  for (var j = 0; j < width; j++) {
616
722
  row[j] = defaultPixelValue;
617
723
  }
618
724
  }
725
+
619
726
  bitmap.push(row);
620
727
  }
728
+
621
729
  var decoder = decodingContext.decoder;
622
730
  var contextCache = decodingContext.contextCache;
623
731
  var stripT = huffman ? -huffmanTables.tableDeltaT.decode(huffmanInput) : -decodeInteger(contextCache, 'IADT', decoder);
624
732
  var firstS = 0;
625
733
  i = 0;
734
+
626
735
  while (i < numberOfSymbolInstances) {
627
736
  var deltaT = huffman ? huffmanTables.tableDeltaT.decode(huffmanInput) : decodeInteger(contextCache, 'IADT', decoder);
628
737
  stripT += deltaT;
629
738
  var deltaFirstS = huffman ? huffmanTables.tableFirstS.decode(huffmanInput) : decodeInteger(contextCache, 'IAFS', decoder);
630
739
  firstS += deltaFirstS;
631
740
  var currentS = firstS;
741
+
632
742
  do {
633
743
  var currentT = 0;
744
+
634
745
  if (stripSize > 1) {
635
746
  currentT = huffman ? huffmanInput.readBits(logStripSize) : decodeInteger(contextCache, 'IAIT', decoder);
636
747
  }
748
+
637
749
  var t = stripSize * stripT + currentT;
638
750
  var symbolId = huffman ? huffmanTables.symbolIDTable.decode(huffmanInput) : decodeIAID(contextCache, decoder, symbolCodeLength);
639
751
  var applyRefinement = refinement && (huffman ? huffmanInput.readBit() : decodeInteger(contextCache, 'IARI', decoder));
640
752
  var symbolBitmap = inputSymbols[symbolId];
641
753
  var symbolWidth = symbolBitmap[0].length;
642
754
  var symbolHeight = symbolBitmap.length;
755
+
643
756
  if (applyRefinement) {
644
757
  var rdw = decodeInteger(contextCache, 'IARDW', decoder);
645
758
  var rdh = decodeInteger(contextCache, 'IARDH', decoder);
@@ -649,74 +762,99 @@ var Jbig2Image = function Jbig2ImageClosure() {
649
762
  symbolHeight += rdh;
650
763
  symbolBitmap = decodeRefinement(symbolWidth, symbolHeight, refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx, (rdh >> 1) + rdy, false, refinementAt, decodingContext);
651
764
  }
765
+
652
766
  var offsetT = t - (referenceCorner & 1 ? 0 : symbolHeight - 1);
653
767
  var offsetS = currentS - (referenceCorner & 2 ? symbolWidth - 1 : 0);
654
768
  var s2, t2, symbolRow;
769
+
655
770
  if (transposed) {
656
771
  for (s2 = 0; s2 < symbolHeight; s2++) {
657
772
  row = bitmap[offsetS + s2];
773
+
658
774
  if (!row) {
659
775
  continue;
660
776
  }
777
+
661
778
  symbolRow = symbolBitmap[s2];
662
779
  var maxWidth = Math.min(width - offsetT, symbolWidth);
780
+
663
781
  switch (combinationOperator) {
664
782
  case 0:
665
783
  for (t2 = 0; t2 < maxWidth; t2++) {
666
784
  row[offsetT + t2] |= symbolRow[t2];
667
785
  }
786
+
668
787
  break;
788
+
669
789
  case 2:
670
790
  for (t2 = 0; t2 < maxWidth; t2++) {
671
791
  row[offsetT + t2] ^= symbolRow[t2];
672
792
  }
793
+
673
794
  break;
795
+
674
796
  default:
675
- throw new Jbig2Error('operator ' + combinationOperator + ' is not supported');
797
+ throw new Jbig2Error("operator ".concat(combinationOperator, " is not supported"));
676
798
  }
677
799
  }
800
+
678
801
  currentS += symbolHeight - 1;
679
802
  } else {
680
803
  for (t2 = 0; t2 < symbolHeight; t2++) {
681
804
  row = bitmap[offsetT + t2];
805
+
682
806
  if (!row) {
683
807
  continue;
684
808
  }
809
+
685
810
  symbolRow = symbolBitmap[t2];
811
+
686
812
  switch (combinationOperator) {
687
813
  case 0:
688
814
  for (s2 = 0; s2 < symbolWidth; s2++) {
689
815
  row[offsetS + s2] |= symbolRow[s2];
690
816
  }
817
+
691
818
  break;
819
+
692
820
  case 2:
693
821
  for (s2 = 0; s2 < symbolWidth; s2++) {
694
822
  row[offsetS + s2] ^= symbolRow[s2];
695
823
  }
824
+
696
825
  break;
826
+
697
827
  default:
698
- throw new Jbig2Error('operator ' + combinationOperator + ' is not supported');
828
+ throw new Jbig2Error("operator ".concat(combinationOperator, " is not supported"));
699
829
  }
700
830
  }
831
+
701
832
  currentS += symbolWidth - 1;
702
833
  }
834
+
703
835
  i++;
704
836
  var deltaS = huffman ? huffmanTables.tableDeltaS.decode(huffmanInput) : decodeInteger(contextCache, 'IADS', decoder);
837
+
705
838
  if (deltaS === null) {
706
839
  break;
707
840
  }
841
+
708
842
  currentS += deltaS + dsOffset;
709
843
  } while (true);
710
844
  }
845
+
711
846
  return bitmap;
712
847
  }
848
+
713
849
  function decodePatternDictionary(mmr, patternWidth, patternHeight, maxPatternIndex, template, decodingContext) {
714
850
  var at = [];
851
+
715
852
  if (!mmr) {
716
853
  at.push({
717
854
  x: -patternWidth,
718
855
  y: 0
719
856
  });
857
+
720
858
  if (template === 0) {
721
859
  at.push({
722
860
  x: -3,
@@ -732,58 +870,71 @@ var Jbig2Image = function Jbig2ImageClosure() {
732
870
  });
733
871
  }
734
872
  }
873
+
735
874
  var collectiveWidth = (maxPatternIndex + 1) * patternWidth;
736
875
  var collectiveBitmap = decodeBitmap(mmr, collectiveWidth, patternHeight, template, false, null, at, decodingContext);
737
876
  var patterns = [],
738
877
  i = 0,
739
- patternBitmap = void 0,
740
- xMin = void 0,
741
- xMax = void 0,
742
- y = void 0;
878
+ patternBitmap,
879
+ xMin,
880
+ xMax,
881
+ y;
882
+
743
883
  while (i <= maxPatternIndex) {
744
884
  patternBitmap = [];
745
885
  xMin = patternWidth * i;
746
886
  xMax = xMin + patternWidth;
887
+
747
888
  for (y = 0; y < patternHeight; y++) {
748
889
  patternBitmap.push(collectiveBitmap[y].subarray(xMin, xMax));
749
890
  }
891
+
750
892
  patterns.push(patternBitmap);
751
893
  i++;
752
894
  }
895
+
753
896
  return patterns;
754
897
  }
898
+
755
899
  function decodeHalftoneRegion(mmr, patterns, template, regionWidth, regionHeight, defaultPixelValue, enableSkip, combinationOperator, gridWidth, gridHeight, gridOffsetX, gridOffsetY, gridVectorX, gridVectorY, decodingContext) {
756
900
  var skip = null;
901
+
757
902
  if (enableSkip) {
758
903
  throw new Jbig2Error('skip is not supported');
759
904
  }
905
+
760
906
  if (combinationOperator !== 0) {
761
907
  throw new Jbig2Error('operator ' + combinationOperator + ' is not supported in halftone region');
762
908
  }
909
+
763
910
  var regionBitmap = [];
764
- var i = void 0,
765
- j = void 0,
766
- row = void 0;
911
+ var i, j, row;
912
+
767
913
  for (i = 0; i < regionHeight; i++) {
768
914
  row = new Uint8Array(regionWidth);
915
+
769
916
  if (defaultPixelValue) {
770
917
  for (j = 0; j < regionWidth; j++) {
771
918
  row[j] = defaultPixelValue;
772
919
  }
773
920
  }
921
+
774
922
  regionBitmap.push(row);
775
923
  }
924
+
776
925
  var numberOfPatterns = patterns.length;
777
926
  var pattern0 = patterns[0];
778
927
  var patternWidth = pattern0[0].length,
779
928
  patternHeight = pattern0.length;
780
929
  var bitsPerValue = (0, _util.log2)(numberOfPatterns);
781
930
  var at = [];
931
+
782
932
  if (!mmr) {
783
933
  at.push({
784
934
  x: template <= 1 ? 3 : 2,
785
935
  y: -1
786
936
  });
937
+
787
938
  if (template === 0) {
788
939
  at.push({
789
940
  x: -3,
@@ -799,44 +950,46 @@ var Jbig2Image = function Jbig2ImageClosure() {
799
950
  });
800
951
  }
801
952
  }
953
+
802
954
  var grayScaleBitPlanes = [],
803
- mmrInput = void 0,
804
- bitmap = void 0;
955
+ mmrInput,
956
+ bitmap;
957
+
805
958
  if (mmr) {
806
959
  mmrInput = new Reader(decodingContext.data, decodingContext.start, decodingContext.end);
807
960
  }
961
+
808
962
  for (i = bitsPerValue - 1; i >= 0; i--) {
809
963
  if (mmr) {
810
964
  bitmap = decodeMMRBitmap(mmrInput, gridWidth, gridHeight, true);
811
965
  } else {
812
966
  bitmap = decodeBitmap(false, gridWidth, gridHeight, template, false, skip, at, decodingContext);
813
967
  }
968
+
814
969
  grayScaleBitPlanes[i] = bitmap;
815
970
  }
816
- var mg = void 0,
817
- ng = void 0,
818
- bit = void 0,
819
- patternIndex = void 0,
820
- patternBitmap = void 0,
821
- x = void 0,
822
- y = void 0,
823
- patternRow = void 0,
824
- regionRow = void 0;
971
+
972
+ var mg, ng, bit, patternIndex, patternBitmap, x, y, patternRow, regionRow;
973
+
825
974
  for (mg = 0; mg < gridHeight; mg++) {
826
975
  for (ng = 0; ng < gridWidth; ng++) {
827
976
  bit = 0;
828
977
  patternIndex = 0;
978
+
829
979
  for (j = bitsPerValue - 1; j >= 0; j--) {
830
980
  bit = grayScaleBitPlanes[j][mg][ng] ^ bit;
831
981
  patternIndex |= bit << j;
832
982
  }
983
+
833
984
  patternBitmap = patterns[patternIndex];
834
985
  x = gridOffsetX + mg * gridVectorY + ng * gridVectorX >> 8;
835
986
  y = gridOffsetY + mg * gridVectorX - ng * gridVectorY >> 8;
987
+
836
988
  if (x >= 0 && x + patternWidth <= regionWidth && y >= 0 && y + patternHeight <= regionHeight) {
837
989
  for (i = 0; i < patternHeight; i++) {
838
990
  regionRow = regionBitmap[y + i];
839
991
  patternRow = patternBitmap[i];
992
+
840
993
  for (j = 0; j < patternWidth; j++) {
841
994
  regionRow[x + j] |= patternRow[j];
842
995
  }
@@ -844,15 +997,20 @@ var Jbig2Image = function Jbig2ImageClosure() {
844
997
  } else {
845
998
  var regionX = void 0,
846
999
  regionY = void 0;
1000
+
847
1001
  for (i = 0; i < patternHeight; i++) {
848
1002
  regionY = y + i;
1003
+
849
1004
  if (regionY < 0 || regionY >= regionHeight) {
850
1005
  continue;
851
1006
  }
1007
+
852
1008
  regionRow = regionBitmap[regionY];
853
1009
  patternRow = patternBitmap[i];
1010
+
854
1011
  for (j = 0; j < patternWidth; j++) {
855
1012
  regionX = x + j;
1013
+
856
1014
  if (regionX >= 0 && regionX < regionWidth) {
857
1015
  regionRow[regionX] |= patternRow[j];
858
1016
  }
@@ -861,16 +1019,20 @@ var Jbig2Image = function Jbig2ImageClosure() {
861
1019
  }
862
1020
  }
863
1021
  }
1022
+
864
1023
  return regionBitmap;
865
1024
  }
1025
+
866
1026
  function readSegmentHeader(data, start) {
867
1027
  var segmentHeader = {};
868
1028
  segmentHeader.number = (0, _util.readUint32)(data, start);
869
1029
  var flags = data[start + 4];
870
1030
  var segmentType = flags & 0x3F;
1031
+
871
1032
  if (!SegmentTypes[segmentType]) {
872
1033
  throw new Jbig2Error('invalid segment type: ' + segmentType);
873
1034
  }
1035
+
874
1036
  segmentHeader.type = segmentType;
875
1037
  segmentHeader.typeName = SegmentTypes[segmentType];
876
1038
  segmentHeader.deferredNonRetain = !!(flags & 0x80);
@@ -879,35 +1041,43 @@ var Jbig2Image = function Jbig2ImageClosure() {
879
1041
  var referredToCount = referredFlags >> 5 & 7;
880
1042
  var retainBits = [referredFlags & 31];
881
1043
  var position = start + 6;
1044
+
882
1045
  if (referredFlags === 7) {
883
1046
  referredToCount = (0, _util.readUint32)(data, position - 1) & 0x1FFFFFFF;
884
1047
  position += 3;
885
1048
  var bytes = referredToCount + 7 >> 3;
886
1049
  retainBits[0] = data[position++];
1050
+
887
1051
  while (--bytes > 0) {
888
1052
  retainBits.push(data[position++]);
889
1053
  }
890
1054
  } else if (referredFlags === 5 || referredFlags === 6) {
891
1055
  throw new Jbig2Error('invalid referred-to flags');
892
1056
  }
1057
+
893
1058
  segmentHeader.retainBits = retainBits;
894
1059
  var referredToSegmentNumberSize = segmentHeader.number <= 256 ? 1 : segmentHeader.number <= 65536 ? 2 : 4;
895
1060
  var referredTo = [];
896
1061
  var i, ii;
1062
+
897
1063
  for (i = 0; i < referredToCount; i++) {
898
1064
  var number = referredToSegmentNumberSize === 1 ? data[position] : referredToSegmentNumberSize === 2 ? (0, _util.readUint16)(data, position) : (0, _util.readUint32)(data, position);
899
1065
  referredTo.push(number);
900
1066
  position += referredToSegmentNumberSize;
901
1067
  }
1068
+
902
1069
  segmentHeader.referredTo = referredTo;
1070
+
903
1071
  if (!pageAssociationFieldSize) {
904
1072
  segmentHeader.pageAssociation = data[position++];
905
1073
  } else {
906
1074
  segmentHeader.pageAssociation = (0, _util.readUint32)(data, position);
907
1075
  position += 4;
908
1076
  }
1077
+
909
1078
  segmentHeader.length = (0, _util.readUint32)(data, position);
910
1079
  position += 4;
1080
+
911
1081
  if (segmentHeader.length === 0xFFFFFFFF) {
912
1082
  if (segmentType === 38) {
913
1083
  var genericRegionInfo = readRegionSegmentInformation(data, position);
@@ -915,24 +1085,30 @@ var Jbig2Image = function Jbig2ImageClosure() {
915
1085
  var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
916
1086
  var searchPatternLength = 6;
917
1087
  var searchPattern = new Uint8Array(searchPatternLength);
1088
+
918
1089
  if (!genericRegionMmr) {
919
1090
  searchPattern[0] = 0xFF;
920
1091
  searchPattern[1] = 0xAC;
921
1092
  }
1093
+
922
1094
  searchPattern[2] = genericRegionInfo.height >>> 24 & 0xFF;
923
1095
  searchPattern[3] = genericRegionInfo.height >> 16 & 0xFF;
924
1096
  searchPattern[4] = genericRegionInfo.height >> 8 & 0xFF;
925
1097
  searchPattern[5] = genericRegionInfo.height & 0xFF;
1098
+
926
1099
  for (i = position, ii = data.length; i < ii; i++) {
927
1100
  var j = 0;
1101
+
928
1102
  while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
929
1103
  j++;
930
1104
  }
1105
+
931
1106
  if (j === searchPatternLength) {
932
1107
  segmentHeader.length = i + searchPatternLength;
933
1108
  break;
934
1109
  }
935
1110
  }
1111
+
936
1112
  if (segmentHeader.length === 0xFFFFFFFF) {
937
1113
  throw new Jbig2Error('segment end was not found');
938
1114
  }
@@ -940,12 +1116,15 @@ var Jbig2Image = function Jbig2ImageClosure() {
940
1116
  throw new Jbig2Error('invalid unknown segment length');
941
1117
  }
942
1118
  }
1119
+
943
1120
  segmentHeader.headerEnd = position;
944
1121
  return segmentHeader;
945
1122
  }
1123
+
946
1124
  function readSegments(header, data, start, end) {
947
1125
  var segments = [];
948
1126
  var position = start;
1127
+
949
1128
  while (position < end) {
950
1129
  var segmentHeader = readSegmentHeader(data, position);
951
1130
  position = segmentHeader.headerEnd;
@@ -953,16 +1132,20 @@ var Jbig2Image = function Jbig2ImageClosure() {
953
1132
  header: segmentHeader,
954
1133
  data: data
955
1134
  };
1135
+
956
1136
  if (!header.randomAccess) {
957
1137
  segment.start = position;
958
1138
  position += segmentHeader.length;
959
1139
  segment.end = position;
960
1140
  }
1141
+
961
1142
  segments.push(segment);
1143
+
962
1144
  if (segmentHeader.type === 51) {
963
1145
  break;
964
1146
  }
965
1147
  }
1148
+
966
1149
  if (header.randomAccess) {
967
1150
  for (var i = 0, ii = segments.length; i < ii; i++) {
968
1151
  segments[i].start = position;
@@ -970,8 +1153,10 @@ var Jbig2Image = function Jbig2ImageClosure() {
970
1153
  segments[i].end = position;
971
1154
  }
972
1155
  }
1156
+
973
1157
  return segments;
974
1158
  }
1159
+
975
1160
  function readRegionSegmentInformation(data, start) {
976
1161
  return {
977
1162
  width: (0, _util.readUint32)(data, start),
@@ -981,13 +1166,16 @@ var Jbig2Image = function Jbig2ImageClosure() {
981
1166
  combinationOperator: data[start + 16] & 7
982
1167
  };
983
1168
  }
1169
+
984
1170
  var RegionSegmentInformationFieldLength = 17;
1171
+
985
1172
  function processSegment(segment, visitor) {
986
1173
  var header = segment.header;
987
1174
  var data = segment.data,
988
1175
  position = segment.start,
989
1176
  end = segment.end;
990
1177
  var args, at, i, atLength;
1178
+
991
1179
  switch (header.type) {
992
1180
  case 0:
993
1181
  var dictionary = {};
@@ -1003,9 +1191,11 @@ var Jbig2Image = function Jbig2ImageClosure() {
1003
1191
  dictionary.template = dictionaryFlags >> 10 & 3;
1004
1192
  dictionary.refinementTemplate = dictionaryFlags >> 12 & 1;
1005
1193
  position += 2;
1194
+
1006
1195
  if (!dictionary.huffman) {
1007
1196
  atLength = dictionary.template === 0 ? 4 : 1;
1008
1197
  at = [];
1198
+
1009
1199
  for (i = 0; i < atLength; i++) {
1010
1200
  at.push({
1011
1201
  x: (0, _util.readInt8)(data, position),
@@ -1013,10 +1203,13 @@ var Jbig2Image = function Jbig2ImageClosure() {
1013
1203
  });
1014
1204
  position += 2;
1015
1205
  }
1206
+
1016
1207
  dictionary.at = at;
1017
1208
  }
1209
+
1018
1210
  if (dictionary.refinement && !dictionary.refinementTemplate) {
1019
1211
  at = [];
1212
+
1020
1213
  for (i = 0; i < 2; i++) {
1021
1214
  at.push({
1022
1215
  x: (0, _util.readInt8)(data, position),
@@ -1024,14 +1217,17 @@ var Jbig2Image = function Jbig2ImageClosure() {
1024
1217
  });
1025
1218
  position += 2;
1026
1219
  }
1220
+
1027
1221
  dictionary.refinementAt = at;
1028
1222
  }
1223
+
1029
1224
  dictionary.numberOfExportedSymbols = (0, _util.readUint32)(data, position);
1030
1225
  position += 4;
1031
1226
  dictionary.numberOfNewSymbols = (0, _util.readUint32)(data, position);
1032
1227
  position += 4;
1033
1228
  args = [dictionary, header.number, header.referredTo, data, position, end];
1034
1229
  break;
1230
+
1035
1231
  case 6:
1036
1232
  case 7:
1037
1233
  var textRegion = {};
@@ -1049,6 +1245,7 @@ var Jbig2Image = function Jbig2ImageClosure() {
1049
1245
  textRegion.defaultPixelValue = textRegionSegmentFlags >> 9 & 1;
1050
1246
  textRegion.dsOffset = textRegionSegmentFlags << 17 >> 27;
1051
1247
  textRegion.refinementTemplate = textRegionSegmentFlags >> 15 & 1;
1248
+
1052
1249
  if (textRegion.huffman) {
1053
1250
  var textRegionHuffmanFlags = (0, _util.readUint16)(data, position);
1054
1251
  position += 2;
@@ -1061,8 +1258,10 @@ var Jbig2Image = function Jbig2ImageClosure() {
1061
1258
  textRegion.huffmanRefinementDY = textRegionHuffmanFlags >> 12 & 3;
1062
1259
  textRegion.huffmanRefinementSizeSelector = !!(textRegionHuffmanFlags & 0x4000);
1063
1260
  }
1261
+
1064
1262
  if (textRegion.refinement && !textRegion.refinementTemplate) {
1065
1263
  at = [];
1264
+
1066
1265
  for (i = 0; i < 2; i++) {
1067
1266
  at.push({
1068
1267
  x: (0, _util.readInt8)(data, position),
@@ -1070,12 +1269,15 @@ var Jbig2Image = function Jbig2ImageClosure() {
1070
1269
  });
1071
1270
  position += 2;
1072
1271
  }
1272
+
1073
1273
  textRegion.refinementAt = at;
1074
1274
  }
1275
+
1075
1276
  textRegion.numberOfSymbolInstances = (0, _util.readUint32)(data, position);
1076
1277
  position += 4;
1077
1278
  args = [textRegion, header.referredTo, data, position, end];
1078
1279
  break;
1280
+
1079
1281
  case 16:
1080
1282
  var patternDictionary = {};
1081
1283
  var patternDictionaryFlags = data[position++];
@@ -1087,6 +1289,7 @@ var Jbig2Image = function Jbig2ImageClosure() {
1087
1289
  position += 4;
1088
1290
  args = [patternDictionary, header.number, data, position, end];
1089
1291
  break;
1292
+
1090
1293
  case 22:
1091
1294
  case 23:
1092
1295
  var halftoneRegion = {};
@@ -1112,6 +1315,7 @@ var Jbig2Image = function Jbig2ImageClosure() {
1112
1315
  position += 2;
1113
1316
  args = [halftoneRegion, header.referredTo, data, position, end];
1114
1317
  break;
1318
+
1115
1319
  case 38:
1116
1320
  case 39:
1117
1321
  var genericRegion = {};
@@ -1121,9 +1325,11 @@ var Jbig2Image = function Jbig2ImageClosure() {
1121
1325
  genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
1122
1326
  genericRegion.template = genericRegionSegmentFlags >> 1 & 3;
1123
1327
  genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
1328
+
1124
1329
  if (!genericRegion.mmr) {
1125
1330
  atLength = genericRegion.template === 0 ? 4 : 1;
1126
1331
  at = [];
1332
+
1127
1333
  for (i = 0; i < atLength; i++) {
1128
1334
  at.push({
1129
1335
  x: (0, _util.readInt8)(data, position),
@@ -1131,10 +1337,13 @@ var Jbig2Image = function Jbig2ImageClosure() {
1131
1337
  });
1132
1338
  position += 2;
1133
1339
  }
1340
+
1134
1341
  genericRegion.at = at;
1135
1342
  }
1343
+
1136
1344
  args = [genericRegion, data, position, end];
1137
1345
  break;
1346
+
1138
1347
  case 48:
1139
1348
  var pageInfo = {
1140
1349
  width: (0, _util.readUint32)(data, position),
@@ -1142,9 +1351,11 @@ var Jbig2Image = function Jbig2ImageClosure() {
1142
1351
  resolutionX: (0, _util.readUint32)(data, position + 8),
1143
1352
  resolutionY: (0, _util.readUint32)(data, position + 12)
1144
1353
  };
1354
+
1145
1355
  if (pageInfo.height === 0xFFFFFFFF) {
1146
1356
  delete pageInfo.height;
1147
1357
  }
1358
+
1148
1359
  var pageSegmentFlags = data[position + 16];
1149
1360
  (0, _util.readUint16)(data, position + 17);
1150
1361
  pageInfo.lossless = !!(pageSegmentFlags & 1);
@@ -1155,50 +1366,117 @@ var Jbig2Image = function Jbig2ImageClosure() {
1155
1366
  pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
1156
1367
  args = [pageInfo];
1157
1368
  break;
1369
+
1158
1370
  case 49:
1159
1371
  break;
1372
+
1160
1373
  case 50:
1161
1374
  break;
1375
+
1162
1376
  case 51:
1163
1377
  break;
1378
+
1164
1379
  case 53:
1165
1380
  args = [header.number, data, position, end];
1166
1381
  break;
1382
+
1167
1383
  case 62:
1168
1384
  break;
1385
+
1169
1386
  default:
1170
- throw new Jbig2Error('segment type ' + header.typeName + '(' + header.type + ')' + ' is not implemented');
1387
+ throw new Jbig2Error("segment type ".concat(header.typeName, "(").concat(header.type, ")") + ' is not implemented');
1171
1388
  }
1389
+
1172
1390
  var callbackName = 'on' + header.typeName;
1391
+
1173
1392
  if (callbackName in visitor) {
1174
1393
  visitor[callbackName].apply(visitor, args);
1175
1394
  }
1176
1395
  }
1396
+
1177
1397
  function processSegments(segments, visitor) {
1178
1398
  for (var i = 0, ii = segments.length; i < ii; i++) {
1179
1399
  processSegment(segments[i], visitor);
1180
1400
  }
1181
1401
  }
1402
+
1182
1403
  function parseJbig2Chunks(chunks) {
1183
1404
  var visitor = new SimpleSegmentVisitor();
1405
+
1184
1406
  for (var i = 0, ii = chunks.length; i < ii; i++) {
1185
1407
  var chunk = chunks[i];
1186
1408
  var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
1187
1409
  processSegments(segments, visitor);
1188
1410
  }
1411
+
1189
1412
  return visitor.buffer;
1190
1413
  }
1414
+
1415
+ function parseJbig2(data) {
1416
+ var position = 0,
1417
+ end = data.length;
1418
+
1419
+ if (data[position] !== 0x97 || data[position + 1] !== 0x4A || data[position + 2] !== 0x42 || data[position + 3] !== 0x32 || data[position + 4] !== 0x0D || data[position + 5] !== 0x0A || data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
1420
+ throw new Jbig2Error('parseJbig2 - invalid header.');
1421
+ }
1422
+
1423
+ var header = Object.create(null);
1424
+ position += 8;
1425
+ var flags = data[position++];
1426
+ header.randomAccess = !(flags & 1);
1427
+
1428
+ if (!(flags & 2)) {
1429
+ header.numberOfPages = (0, _util.readUint32)(data, position);
1430
+ position += 4;
1431
+ }
1432
+
1433
+ var segments = readSegments(header, data, position, end);
1434
+ var visitor = new SimpleSegmentVisitor();
1435
+ processSegments(segments, visitor);
1436
+ var _visitor$currentPageI = visitor.currentPageInfo,
1437
+ width = _visitor$currentPageI.width,
1438
+ height = _visitor$currentPageI.height;
1439
+ var bitPacked = visitor.buffer;
1440
+ var imgData = new Uint8ClampedArray(width * height);
1441
+ var q = 0,
1442
+ k = 0;
1443
+
1444
+ for (var i = 0; i < height; i++) {
1445
+ var mask = 0,
1446
+ buffer = void 0;
1447
+
1448
+ for (var j = 0; j < width; j++) {
1449
+ if (!mask) {
1450
+ mask = 128;
1451
+ buffer = bitPacked[k++];
1452
+ }
1453
+
1454
+ imgData[q++] = buffer & mask ? 0 : 255;
1455
+ mask >>= 1;
1456
+ }
1457
+ }
1458
+
1459
+ return {
1460
+ imgData: imgData,
1461
+ width: width,
1462
+ height: height
1463
+ };
1464
+ }
1465
+
1191
1466
  function SimpleSegmentVisitor() {}
1467
+
1192
1468
  SimpleSegmentVisitor.prototype = {
1193
1469
  onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
1194
1470
  this.currentPageInfo = info;
1195
1471
  var rowSize = info.width + 7 >> 3;
1196
1472
  var buffer = new Uint8ClampedArray(rowSize * info.height);
1473
+
1197
1474
  if (info.defaultPixelValue) {
1198
1475
  for (var i = 0, ii = buffer.length; i < ii; i++) {
1199
1476
  buffer[i] = 0xFF;
1200
1477
  }
1201
1478
  }
1479
+
1202
1480
  this.buffer = buffer;
1203
1481
  },
1204
1482
  drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
@@ -1211,43 +1489,56 @@ var Jbig2Image = function Jbig2ImageClosure() {
1211
1489
  var mask0 = 128 >> (regionInfo.x & 7);
1212
1490
  var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
1213
1491
  var i, j, mask, offset;
1492
+
1214
1493
  switch (combinationOperator) {
1215
1494
  case 0:
1216
1495
  for (i = 0; i < height; i++) {
1217
1496
  mask = mask0;
1218
1497
  offset = offset0;
1498
+
1219
1499
  for (j = 0; j < width; j++) {
1220
1500
  if (bitmap[i][j]) {
1221
1501
  buffer[offset] |= mask;
1222
1502
  }
1503
+
1223
1504
  mask >>= 1;
1505
+
1224
1506
  if (!mask) {
1225
1507
  mask = 128;
1226
1508
  offset++;
1227
1509
  }
1228
1510
  }
1511
+
1229
1512
  offset0 += rowSize;
1230
1513
  }
1514
+
1231
1515
  break;
1516
+
1232
1517
  case 2:
1233
1518
  for (i = 0; i < height; i++) {
1234
1519
  mask = mask0;
1235
1520
  offset = offset0;
1521
+
1236
1522
  for (j = 0; j < width; j++) {
1237
1523
  if (bitmap[i][j]) {
1238
1524
  buffer[offset] ^= mask;
1239
1525
  }
1526
+
1240
1527
  mask >>= 1;
1528
+
1241
1529
  if (!mask) {
1242
1530
  mask = 128;
1243
1531
  offset++;
1244
1532
  }
1245
1533
  }
1534
+
1246
1535
  offset0 += rowSize;
1247
1536
  }
1537
+
1248
1538
  break;
1539
+
1249
1540
  default:
1250
- throw new Jbig2Error('operator ' + combinationOperator + ' is not supported');
1541
+ throw new Jbig2Error("operator ".concat(combinationOperator, " is not supported"));
1251
1542
  }
1252
1543
  },
1253
1544
  onImmediateGenericRegion: function SimpleSegmentVisitor_onImmediateGenericRegion(region, data, start, end) {
@@ -1260,43 +1551,53 @@ var Jbig2Image = function Jbig2ImageClosure() {
1260
1551
  this.onImmediateGenericRegion.apply(this, arguments);
1261
1552
  },
1262
1553
  onSymbolDictionary: function SimpleSegmentVisitor_onSymbolDictionary(dictionary, currentSegment, referredSegments, data, start, end) {
1263
- var huffmanTables = void 0,
1264
- huffmanInput = void 0;
1554
+ var huffmanTables, huffmanInput;
1555
+
1265
1556
  if (dictionary.huffman) {
1266
1557
  huffmanTables = getSymbolDictionaryHuffmanTables(dictionary, referredSegments, this.customTables);
1267
1558
  huffmanInput = new Reader(data, start, end);
1268
1559
  }
1560
+
1269
1561
  var symbols = this.symbols;
1562
+
1270
1563
  if (!symbols) {
1271
1564
  this.symbols = symbols = {};
1272
1565
  }
1566
+
1273
1567
  var inputSymbols = [];
1568
+
1274
1569
  for (var i = 0, ii = referredSegments.length; i < ii; i++) {
1275
1570
  var referredSymbols = symbols[referredSegments[i]];
1571
+
1276
1572
  if (referredSymbols) {
1277
1573
  inputSymbols = inputSymbols.concat(referredSymbols);
1278
1574
  }
1279
1575
  }
1576
+
1280
1577
  var decodingContext = new DecodingContext(data, start, end);
1281
1578
  symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman, dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols, dictionary.numberOfExportedSymbols, huffmanTables, dictionary.template, dictionary.at, dictionary.refinementTemplate, dictionary.refinementAt, decodingContext, huffmanInput);
1282
1579
  },
1283
1580
  onImmediateTextRegion: function SimpleSegmentVisitor_onImmediateTextRegion(region, referredSegments, data, start, end) {
1284
1581
  var regionInfo = region.info;
1285
- var huffmanTables = void 0,
1286
- huffmanInput = void 0;
1582
+ var huffmanTables, huffmanInput;
1287
1583
  var symbols = this.symbols;
1288
1584
  var inputSymbols = [];
1585
+
1289
1586
  for (var i = 0, ii = referredSegments.length; i < ii; i++) {
1290
1587
  var referredSymbols = symbols[referredSegments[i]];
1588
+
1291
1589
  if (referredSymbols) {
1292
1590
  inputSymbols = inputSymbols.concat(referredSymbols);
1293
1591
  }
1294
1592
  }
1593
+
1295
1594
  var symbolCodeLength = (0, _util.log2)(inputSymbols.length);
1595
+
1296
1596
  if (region.huffman) {
1297
1597
  huffmanInput = new Reader(data, start, end);
1298
1598
  huffmanTables = getTextRegionHuffmanTables(region, referredSegments, this.customTables, inputSymbols.length, huffmanInput);
1299
1599
  }
1600
+
1300
1601
  var decodingContext = new DecodingContext(data, start, end);
1301
1602
  var bitmap = decodeTextRegion(region.huffman, region.refinement, regionInfo.width, regionInfo.height, region.defaultPixelValue, region.numberOfSymbolInstances, region.stripSize, inputSymbols, symbolCodeLength, region.transposed, region.dsOffset, region.referenceCorner, region.combinationOperator, huffmanTables, region.refinementTemplate, region.refinementAt, decodingContext, region.logStripSize, huffmanInput);
1302
1603
  this.drawBitmap(regionInfo, bitmap);
@@ -1306,9 +1607,11 @@ var Jbig2Image = function Jbig2ImageClosure() {
1306
1607
  },
1307
1608
  onPatternDictionary: function onPatternDictionary(dictionary, currentSegment, data, start, end) {
1308
1609
  var patterns = this.patterns;
1610
+
1309
1611
  if (!patterns) {
1310
1612
  this.patterns = patterns = {};
1311
1613
  }
1614
+
1312
1615
  var decodingContext = new DecodingContext(data, start, end);
1313
1616
  patterns[currentSegment] = decodePatternDictionary(dictionary.mmr, dictionary.patternWidth, dictionary.patternHeight, dictionary.maxPatternIndex, dictionary.template, decodingContext);
1314
1617
  },
@@ -1324,12 +1627,15 @@ var Jbig2Image = function Jbig2ImageClosure() {
1324
1627
  },
1325
1628
  onTables: function onTables(currentSegment, data, start, end) {
1326
1629
  var customTables = this.customTables;
1630
+
1327
1631
  if (!customTables) {
1328
1632
  this.customTables = customTables = {};
1329
1633
  }
1634
+
1330
1635
  customTables[currentSegment] = decodeTablesSegment(data, start, end);
1331
1636
  }
1332
1637
  };
1638
+
1333
1639
  function HuffmanLine(lineData) {
1334
1640
  if (lineData.length === 2) {
1335
1641
  this.isOOB = true;
@@ -1347,8 +1653,10 @@ var Jbig2Image = function Jbig2ImageClosure() {
1347
1653
  this.isLowerRange = lineData[4] === 'lower';
1348
1654
  }
1349
1655
  }
1656
+
1350
1657
  function HuffmanTreeNode(line) {
1351
1658
  this.children = [];
1659
+
1352
1660
  if (line) {
1353
1661
  this.isLeaf = true;
1354
1662
  this.rangeLength = line.rangeLength;
@@ -1359,16 +1667,20 @@ var Jbig2Image = function Jbig2ImageClosure() {
1359
1667
  this.isLeaf = false;
1360
1668
  }
1361
1669
  }
1670
+
1362
1671
  HuffmanTreeNode.prototype = {
1363
1672
  buildTree: function buildTree(line, shift) {
1364
1673
  var bit = line.prefixCode >> shift & 1;
1674
+
1365
1675
  if (shift <= 0) {
1366
1676
  this.children[bit] = new HuffmanTreeNode(line);
1367
1677
  } else {
1368
1678
  var node = this.children[bit];
1679
+
1369
1680
  if (!node) {
1370
1681
  this.children[bit] = node = new HuffmanTreeNode(null);
1371
1682
  }
1683
+
1372
1684
  node.buildTree(line, shift - 1);
1373
1685
  }
1374
1686
  },
@@ -1377,31 +1689,40 @@ var Jbig2Image = function Jbig2ImageClosure() {
1377
1689
  if (this.isOOB) {
1378
1690
  return null;
1379
1691
  }
1692
+
1380
1693
  var htOffset = reader.readBits(this.rangeLength);
1381
1694
  return this.rangeLow + (this.isLowerRange ? -htOffset : htOffset);
1382
1695
  }
1696
+
1383
1697
  var node = this.children[reader.readBit()];
1698
+
1384
1699
  if (!node) {
1385
1700
  throw new Jbig2Error('invalid Huffman data');
1386
1701
  }
1702
+
1387
1703
  return node.decodeNode(reader);
1388
1704
  }
1389
1705
  };
1706
+
1390
1707
  function HuffmanTable(lines, prefixCodesDone) {
1391
1708
  if (!prefixCodesDone) {
1392
1709
  this.assignPrefixCodes(lines);
1393
1710
  }
1711
+
1394
1712
  this.rootNode = new HuffmanTreeNode(null);
1395
- var i = void 0,
1713
+ var i,
1396
1714
  ii = lines.length,
1397
- line = void 0;
1715
+ line;
1716
+
1398
1717
  for (i = 0; i < ii; i++) {
1399
1718
  line = lines[i];
1719
+
1400
1720
  if (line.prefixLength > 0) {
1401
1721
  this.rootNode.buildTree(line, line.prefixLength - 1);
1402
1722
  }
1403
1723
  }
1404
1724
  }
1725
+
1405
1726
  HuffmanTable.prototype = {
1406
1727
  decode: function decode(reader) {
1407
1728
  return this.rootNode.decodeNode(reader);
@@ -1409,36 +1730,46 @@ var Jbig2Image = function Jbig2ImageClosure() {
1409
1730
  assignPrefixCodes: function assignPrefixCodes(lines) {
1410
1731
  var linesLength = lines.length,
1411
1732
  prefixLengthMax = 0,
1412
- i = void 0;
1733
+ i;
1734
+
1413
1735
  for (i = 0; i < linesLength; i++) {
1414
1736
  prefixLengthMax = Math.max(prefixLengthMax, lines[i].prefixLength);
1415
1737
  }
1738
+
1416
1739
  var histogram = new Uint32Array(prefixLengthMax + 1);
1740
+
1417
1741
  for (i = 0; i < linesLength; i++) {
1418
1742
  histogram[lines[i].prefixLength]++;
1419
1743
  }
1744
+
1420
1745
  var currentLength = 1,
1421
1746
  firstCode = 0,
1422
- currentCode = void 0,
1423
- currentTemp = void 0,
1424
- line = void 0;
1747
+ currentCode,
1748
+ currentTemp,
1749
+ line;
1425
1750
  histogram[0] = 0;
1751
+
1426
1752
  while (currentLength <= prefixLengthMax) {
1427
1753
  firstCode = firstCode + histogram[currentLength - 1] << 1;
1428
1754
  currentCode = firstCode;
1429
1755
  currentTemp = 0;
1756
+
1430
1757
  while (currentTemp < linesLength) {
1431
1758
  line = lines[currentTemp];
1759
+
1432
1760
  if (line.prefixLength === currentLength) {
1433
1761
  line.prefixCode = currentCode;
1434
1762
  currentCode++;
1435
1763
  }
1764
+
1436
1765
  currentTemp++;
1437
1766
  }
1767
+
1438
1768
  currentLength++;
1439
1769
  }
1440
1770
  }
1441
1771
  };
1772
+
1442
1773
  function decodeTablesSegment(data, start, end) {
1443
1774
  var flags = data[start];
1444
1775
  var lowestValue = (0, _util.readUint32)(data, start + 1) & 0xFFFFFFFF;
@@ -1447,90 +1778,118 @@ var Jbig2Image = function Jbig2ImageClosure() {
1447
1778
  var prefixSizeBits = (flags >> 1 & 7) + 1;
1448
1779
  var rangeSizeBits = (flags >> 4 & 7) + 1;
1449
1780
  var lines = [];
1450
- var prefixLength = void 0,
1451
- rangeLength = void 0,
1781
+ var prefixLength,
1782
+ rangeLength,
1452
1783
  currentRangeLow = lowestValue;
1784
+
1453
1785
  do {
1454
1786
  prefixLength = reader.readBits(prefixSizeBits);
1455
1787
  rangeLength = reader.readBits(rangeSizeBits);
1456
1788
  lines.push(new HuffmanLine([currentRangeLow, prefixLength, rangeLength, 0]));
1457
1789
  currentRangeLow += 1 << rangeLength;
1458
1790
  } while (currentRangeLow < highestValue);
1791
+
1459
1792
  prefixLength = reader.readBits(prefixSizeBits);
1460
1793
  lines.push(new HuffmanLine([lowestValue - 1, prefixLength, 32, 0, 'lower']));
1461
1794
  prefixLength = reader.readBits(prefixSizeBits);
1462
1795
  lines.push(new HuffmanLine([highestValue, prefixLength, 32, 0]));
1796
+
1463
1797
  if (flags & 1) {
1464
1798
  prefixLength = reader.readBits(prefixSizeBits);
1465
1799
  lines.push(new HuffmanLine([prefixLength, 0]));
1466
1800
  }
1801
+
1467
1802
  return new HuffmanTable(lines, false);
1468
1803
  }
1804
+
1469
1805
  var standardTablesCache = {};
1806
+
1470
1807
  function getStandardTable(number) {
1471
1808
  var table = standardTablesCache[number];
1809
+
1472
1810
  if (table) {
1473
1811
  return table;
1474
1812
  }
1475
- var lines = void 0;
1813
+
1814
+ var lines;
1815
+
1476
1816
  switch (number) {
1477
1817
  case 1:
1478
1818
  lines = [[0, 1, 4, 0x0], [16, 2, 8, 0x2], [272, 3, 16, 0x6], [65808, 3, 32, 0x7]];
1479
1819
  break;
1820
+
1480
1821
  case 2:
1481
1822
  lines = [[0, 1, 0, 0x0], [1, 2, 0, 0x2], [2, 3, 0, 0x6], [3, 4, 3, 0xE], [11, 5, 6, 0x1E], [75, 6, 32, 0x3E], [6, 0x3F]];
1482
1823
  break;
1824
+
1483
1825
  case 3:
1484
1826
  lines = [[-256, 8, 8, 0xFE], [0, 1, 0, 0x0], [1, 2, 0, 0x2], [2, 3, 0, 0x6], [3, 4, 3, 0xE], [11, 5, 6, 0x1E], [-257, 8, 32, 0xFF, 'lower'], [75, 7, 32, 0x7E], [6, 0x3E]];
1485
1827
  break;
1828
+
1486
1829
  case 4:
1487
1830
  lines = [[1, 1, 0, 0x0], [2, 2, 0, 0x2], [3, 3, 0, 0x6], [4, 4, 3, 0xE], [12, 5, 6, 0x1E], [76, 5, 32, 0x1F]];
1488
1831
  break;
1832
+
1489
1833
  case 5:
1490
1834
  lines = [[-255, 7, 8, 0x7E], [1, 1, 0, 0x0], [2, 2, 0, 0x2], [3, 3, 0, 0x6], [4, 4, 3, 0xE], [12, 5, 6, 0x1E], [-256, 7, 32, 0x7F, 'lower'], [76, 6, 32, 0x3E]];
1491
1835
  break;
1836
+
1492
1837
  case 6:
1493
1838
  lines = [[-2048, 5, 10, 0x1C], [-1024, 4, 9, 0x8], [-512, 4, 8, 0x9], [-256, 4, 7, 0xA], [-128, 5, 6, 0x1D], [-64, 5, 5, 0x1E], [-32, 4, 5, 0xB], [0, 2, 7, 0x0], [128, 3, 7, 0x2], [256, 3, 8, 0x3], [512, 4, 9, 0xC], [1024, 4, 10, 0xD], [-2049, 6, 32, 0x3E, 'lower'], [2048, 6, 32, 0x3F]];
1494
1839
  break;
1840
+
1495
1841
  case 7:
1496
1842
  lines = [[-1024, 4, 9, 0x8], [-512, 3, 8, 0x0], [-256, 4, 7, 0x9], [-128, 5, 6, 0x1A], [-64, 5, 5, 0x1B], [-32, 4, 5, 0xA], [0, 4, 5, 0xB], [32, 5, 5, 0x1C], [64, 5, 6, 0x1D], [128, 4, 7, 0xC], [256, 3, 8, 0x1], [512, 3, 9, 0x2], [1024, 3, 10, 0x3], [-1025, 5, 32, 0x1E, 'lower'], [2048, 5, 32, 0x1F]];
1497
1843
  break;
1844
+
1498
1845
  case 8:
1499
1846
  lines = [[-15, 8, 3, 0xFC], [-7, 9, 1, 0x1FC], [-5, 8, 1, 0xFD], [-3, 9, 0, 0x1FD], [-2, 7, 0, 0x7C], [-1, 4, 0, 0xA], [0, 2, 1, 0x0], [2, 5, 0, 0x1A], [3, 6, 0, 0x3A], [4, 3, 4, 0x4], [20, 6, 1, 0x3B], [22, 4, 4, 0xB], [38, 4, 5, 0xC], [70, 5, 6, 0x1B], [134, 5, 7, 0x1C], [262, 6, 7, 0x3C], [390, 7, 8, 0x7D], [646, 6, 10, 0x3D], [-16, 9, 32, 0x1FE, 'lower'], [1670, 9, 32, 0x1FF], [2, 0x1]];
1500
1847
  break;
1848
+
1501
1849
  case 9:
1502
1850
  lines = [[-31, 8, 4, 0xFC], [-15, 9, 2, 0x1FC], [-11, 8, 2, 0xFD], [-7, 9, 1, 0x1FD], [-5, 7, 1, 0x7C], [-3, 4, 1, 0xA], [-1, 3, 1, 0x2], [1, 3, 1, 0x3], [3, 5, 1, 0x1A], [5, 6, 1, 0x3A], [7, 3, 5, 0x4], [39, 6, 2, 0x3B], [43, 4, 5, 0xB], [75, 4, 6, 0xC], [139, 5, 7, 0x1B], [267, 5, 8, 0x1C], [523, 6, 8, 0x3C], [779, 7, 9, 0x7D], [1291, 6, 11, 0x3D], [-32, 9, 32, 0x1FE, 'lower'], [3339, 9, 32, 0x1FF], [2, 0x0]];
1503
1851
  break;
1852
+
1504
1853
  case 10:
1505
1854
  lines = [[-21, 7, 4, 0x7A], [-5, 8, 0, 0xFC], [-4, 7, 0, 0x7B], [-3, 5, 0, 0x18], [-2, 2, 2, 0x0], [2, 5, 0, 0x19], [3, 6, 0, 0x36], [4, 7, 0, 0x7C], [5, 8, 0, 0xFD], [6, 2, 6, 0x1], [70, 5, 5, 0x1A], [102, 6, 5, 0x37], [134, 6, 6, 0x38], [198, 6, 7, 0x39], [326, 6, 8, 0x3A], [582, 6, 9, 0x3B], [1094, 6, 10, 0x3C], [2118, 7, 11, 0x7D], [-22, 8, 32, 0xFE, 'lower'], [4166, 8, 32, 0xFF], [2, 0x2]];
1506
1855
  break;
1856
+
1507
1857
  case 11:
1508
1858
  lines = [[1, 1, 0, 0x0], [2, 2, 1, 0x2], [4, 4, 0, 0xC], [5, 4, 1, 0xD], [7, 5, 1, 0x1C], [9, 5, 2, 0x1D], [13, 6, 2, 0x3C], [17, 7, 2, 0x7A], [21, 7, 3, 0x7B], [29, 7, 4, 0x7C], [45, 7, 5, 0x7D], [77, 7, 6, 0x7E], [141, 7, 32, 0x7F]];
1509
1859
  break;
1860
+
1510
1861
  case 12:
1511
1862
  lines = [[1, 1, 0, 0x0], [2, 2, 0, 0x2], [3, 3, 1, 0x6], [5, 5, 0, 0x1C], [6, 5, 1, 0x1D], [8, 6, 1, 0x3C], [10, 7, 0, 0x7A], [11, 7, 1, 0x7B], [13, 7, 2, 0x7C], [17, 7, 3, 0x7D], [25, 7, 4, 0x7E], [41, 8, 5, 0xFE], [73, 8, 32, 0xFF]];
1512
1863
  break;
1864
+
1513
1865
  case 13:
1514
1866
  lines = [[1, 1, 0, 0x0], [2, 3, 0, 0x4], [3, 4, 0, 0xC], [4, 5, 0, 0x1C], [5, 4, 1, 0xD], [7, 3, 3, 0x5], [15, 6, 1, 0x3A], [17, 6, 2, 0x3B], [21, 6, 3, 0x3C], [29, 6, 4, 0x3D], [45, 6, 5, 0x3E], [77, 7, 6, 0x7E], [141, 7, 32, 0x7F]];
1515
1867
  break;
1868
+
1516
1869
  case 14:
1517
1870
  lines = [[-2, 3, 0, 0x4], [-1, 3, 0, 0x5], [0, 1, 0, 0x0], [1, 3, 0, 0x6], [2, 3, 0, 0x7]];
1518
1871
  break;
1872
+
1519
1873
  case 15:
1520
1874
  lines = [[-24, 7, 4, 0x7C], [-8, 6, 2, 0x3C], [-4, 5, 1, 0x1C], [-2, 4, 0, 0xC], [-1, 3, 0, 0x4], [0, 1, 0, 0x0], [1, 3, 0, 0x5], [2, 4, 0, 0xD], [3, 5, 1, 0x1D], [5, 6, 2, 0x3D], [9, 7, 4, 0x7D], [-25, 7, 32, 0x7E, 'lower'], [25, 7, 32, 0x7F]];
1521
1875
  break;
1876
+
1522
1877
  default:
1523
- throw new Jbig2Error('standard table B.' + number + ' does not exist');
1878
+ throw new Jbig2Error("standard table B.".concat(number, " does not exist"));
1524
1879
  }
1880
+
1525
1881
  var length = lines.length,
1526
- i = void 0;
1882
+ i;
1883
+
1527
1884
  for (i = 0; i < length; i++) {
1528
1885
  lines[i] = new HuffmanLine(lines[i]);
1529
1886
  }
1887
+
1530
1888
  table = new HuffmanTable(lines, true);
1531
1889
  standardTablesCache[number] = table;
1532
1890
  return table;
1533
1891
  }
1892
+
1534
1893
  function Reader(data, start, end) {
1535
1894
  this.data = data;
1536
1895
  this.start = start;
@@ -1539,25 +1898,30 @@ var Jbig2Image = function Jbig2ImageClosure() {
1539
1898
  this.shift = -1;
1540
1899
  this.currentByte = 0;
1541
1900
  }
1901
+
1542
1902
  Reader.prototype = {
1543
1903
  readBit: function readBit() {
1544
1904
  if (this.shift < 0) {
1545
1905
  if (this.position >= this.end) {
1546
1906
  throw new Jbig2Error('end of data while reading bit');
1547
1907
  }
1908
+
1548
1909
  this.currentByte = this.data[this.position++];
1549
1910
  this.shift = 7;
1550
1911
  }
1912
+
1551
1913
  var bit = this.currentByte >> this.shift & 1;
1552
1914
  this.shift--;
1553
1915
  return bit;
1554
1916
  },
1555
1917
  readBits: function readBits(numBits) {
1556
1918
  var result = 0,
1557
- i = void 0;
1919
+ i;
1920
+
1558
1921
  for (i = numBits - 1; i >= 0; i--) {
1559
1922
  result |= this.readBit() << i;
1560
1923
  }
1924
+
1561
1925
  return result;
1562
1926
  },
1563
1927
  byteAlign: function byteAlign() {
@@ -1567,60 +1931,77 @@ var Jbig2Image = function Jbig2ImageClosure() {
1567
1931
  if (this.position >= this.end) {
1568
1932
  return -1;
1569
1933
  }
1934
+
1570
1935
  return this.data[this.position++];
1571
1936
  }
1572
1937
  };
1938
+
1573
1939
  function getCustomHuffmanTable(index, referredTo, customTables) {
1574
1940
  var currentIndex = 0,
1575
- i = void 0,
1941
+ i,
1576
1942
  ii = referredTo.length,
1577
- table = void 0;
1943
+ table;
1944
+
1578
1945
  for (i = 0; i < ii; i++) {
1579
1946
  table = customTables[referredTo[i]];
1947
+
1580
1948
  if (table) {
1581
1949
  if (index === currentIndex) {
1582
1950
  return table;
1583
1951
  }
1952
+
1584
1953
  currentIndex++;
1585
1954
  }
1586
1955
  }
1956
+
1587
1957
  throw new Jbig2Error('can\'t find custom Huffman table');
1588
1958
  }
1959
+
1589
1960
  function getTextRegionHuffmanTables(textRegion, referredTo, customTables, numberOfSymbols, reader) {
1590
1961
  var codes = [],
1591
- i = void 0,
1592
- codeLength = void 0;
1962
+ i,
1963
+ codeLength;
1964
+
1593
1965
  for (i = 0; i <= 34; i++) {
1594
1966
  codeLength = reader.readBits(4);
1595
1967
  codes.push(new HuffmanLine([i, codeLength, 0, 0]));
1596
1968
  }
1969
+
1597
1970
  var runCodesTable = new HuffmanTable(codes, false);
1598
1971
  codes.length = 0;
1972
+
1599
1973
  for (i = 0; i < numberOfSymbols;) {
1600
1974
  codeLength = runCodesTable.decode(reader);
1975
+
1601
1976
  if (codeLength >= 32) {
1602
1977
  var repeatedLength = void 0,
1603
1978
  numberOfRepeats = void 0,
1604
1979
  j = void 0;
1980
+
1605
1981
  switch (codeLength) {
1606
1982
  case 32:
1607
1983
  if (i === 0) {
1608
1984
  throw new Jbig2Error('no previous value in symbol ID table');
1609
1985
  }
1986
+
1610
1987
  numberOfRepeats = reader.readBits(2) + 3;
1611
1988
  repeatedLength = codes[i - 1].prefixLength;
1612
1989
  break;
1990
+
1613
1991
  case 33:
1614
1992
  numberOfRepeats = reader.readBits(3) + 3;
1615
1993
  repeatedLength = 0;
1616
1994
  break;
1995
+
1617
1996
  case 34:
1618
1997
  numberOfRepeats = reader.readBits(7) + 11;
1619
1998
  repeatedLength = 0;
1620
1999
  break;
2000
+
1621
2001
  default:
1622
2002
  throw new Jbig2Error('invalid code length in symbol ID table');
1623
2003
  }
2004
+
1624
2005
  for (j = 0; j < numberOfRepeats; j++) {
1625
2006
  codes.push(new HuffmanLine([i, repeatedLength, 0, 0]));
1626
2007
  i++;
@@ -1630,53 +2011,65 @@ var Jbig2Image = function Jbig2ImageClosure() {
1630
2011
  i++;
1631
2012
  }
1632
2013
  }
2014
+
1633
2015
  reader.byteAlign();
1634
2016
  var symbolIDTable = new HuffmanTable(codes, false);
1635
2017
  var customIndex = 0,
1636
- tableFirstS = void 0,
1637
- tableDeltaS = void 0,
1638
- tableDeltaT = void 0;
2018
+ tableFirstS,
2019
+ tableDeltaS,
2020
+ tableDeltaT;
2021
+
1639
2022
  switch (textRegion.huffmanFS) {
1640
2023
  case 0:
1641
2024
  case 1:
1642
2025
  tableFirstS = getStandardTable(textRegion.huffmanFS + 6);
1643
2026
  break;
2027
+
1644
2028
  case 3:
1645
2029
  tableFirstS = getCustomHuffmanTable(customIndex, referredTo, customTables);
1646
2030
  customIndex++;
1647
2031
  break;
2032
+
1648
2033
  default:
1649
2034
  throw new Jbig2Error('invalid Huffman FS selector');
1650
2035
  }
2036
+
1651
2037
  switch (textRegion.huffmanDS) {
1652
2038
  case 0:
1653
2039
  case 1:
1654
2040
  case 2:
1655
2041
  tableDeltaS = getStandardTable(textRegion.huffmanDS + 8);
1656
2042
  break;
2043
+
1657
2044
  case 3:
1658
2045
  tableDeltaS = getCustomHuffmanTable(customIndex, referredTo, customTables);
1659
2046
  customIndex++;
1660
2047
  break;
2048
+
1661
2049
  default:
1662
2050
  throw new Jbig2Error('invalid Huffman DS selector');
1663
2051
  }
2052
+
1664
2053
  switch (textRegion.huffmanDT) {
1665
2054
  case 0:
1666
2055
  case 1:
1667
2056
  case 2:
1668
2057
  tableDeltaT = getStandardTable(textRegion.huffmanDT + 11);
1669
2058
  break;
2059
+
1670
2060
  case 3:
1671
2061
  tableDeltaT = getCustomHuffmanTable(customIndex, referredTo, customTables);
1672
2062
  customIndex++;
1673
2063
  break;
2064
+
1674
2065
  default:
1675
2066
  throw new Jbig2Error('invalid Huffman DT selector');
1676
2067
  }
2068
+
1677
2069
  if (textRegion.refinement) {
1678
2070
  throw new Jbig2Error('refinement with Huffman is not supported');
1679
2071
  }
2072
+
1680
2073
  return {
1681
2074
  symbolIDTable: symbolIDTable,
1682
2075
  tableFirstS: tableFirstS,
@@ -1684,47 +2077,57 @@ var Jbig2Image = function Jbig2ImageClosure() {
1684
2077
  tableDeltaT: tableDeltaT
1685
2078
  };
1686
2079
  }
2080
+
1687
2081
  function getSymbolDictionaryHuffmanTables(dictionary, referredTo, customTables) {
1688
2082
  var customIndex = 0,
1689
- tableDeltaHeight = void 0,
1690
- tableDeltaWidth = void 0;
2083
+ tableDeltaHeight,
2084
+ tableDeltaWidth;
2085
+
1691
2086
  switch (dictionary.huffmanDHSelector) {
1692
2087
  case 0:
1693
2088
  case 1:
1694
2089
  tableDeltaHeight = getStandardTable(dictionary.huffmanDHSelector + 4);
1695
2090
  break;
2091
+
1696
2092
  case 3:
1697
2093
  tableDeltaHeight = getCustomHuffmanTable(customIndex, referredTo, customTables);
1698
2094
  customIndex++;
1699
2095
  break;
2096
+
1700
2097
  default:
1701
2098
  throw new Jbig2Error('invalid Huffman DH selector');
1702
2099
  }
2100
+
1703
2101
  switch (dictionary.huffmanDWSelector) {
1704
2102
  case 0:
1705
2103
  case 1:
1706
2104
  tableDeltaWidth = getStandardTable(dictionary.huffmanDWSelector + 2);
1707
2105
  break;
2106
+
1708
2107
  case 3:
1709
2108
  tableDeltaWidth = getCustomHuffmanTable(customIndex, referredTo, customTables);
1710
2109
  customIndex++;
1711
2110
  break;
2111
+
1712
2112
  default:
1713
2113
  throw new Jbig2Error('invalid Huffman DW selector');
1714
2114
  }
1715
- var tableBitmapSize = void 0,
1716
- tableAggregateInstances = void 0;
2115
+
2116
+ var tableBitmapSize, tableAggregateInstances;
2117
+
1717
2118
  if (dictionary.bitmapSizeSelector) {
1718
2119
  tableBitmapSize = getCustomHuffmanTable(customIndex, referredTo, customTables);
1719
2120
  customIndex++;
1720
2121
  } else {
1721
2122
  tableBitmapSize = getStandardTable(1);
1722
2123
  }
2124
+
1723
2125
  if (dictionary.aggregationInstancesSelector) {
1724
2126
  tableAggregateInstances = getCustomHuffmanTable(customIndex, referredTo, customTables);
1725
2127
  } else {
1726
2128
  tableAggregateInstances = getStandardTable(1);
1727
2129
  }
2130
+
1728
2131
  return {
1729
2132
  tableDeltaHeight: tableDeltaHeight,
1730
2133
  tableDeltaWidth: tableDeltaWidth,
@@ -1732,21 +2135,27 @@ var Jbig2Image = function Jbig2ImageClosure() {
1732
2135
  tableAggregateInstances: tableAggregateInstances
1733
2136
  };
1734
2137
  }
2138
+
1735
2139
  function readUncompressedBitmap(reader, width, height) {
1736
2140
  var bitmap = [],
1737
- x = void 0,
1738
- y = void 0,
1739
- row = void 0;
2141
+ x,
2142
+ y,
2143
+ row;
2144
+
1740
2145
  for (y = 0; y < height; y++) {
1741
2146
  row = new Uint8Array(width);
1742
2147
  bitmap.push(row);
2148
+
1743
2149
  for (x = 0; x < width; x++) {
1744
2150
  row[x] = reader.readBit();
1745
2151
  }
2152
+
1746
2153
  reader.byteAlign();
1747
2154
  }
2155
+
1748
2156
  return bitmap;
1749
2157
  }
2158
+
1750
2159
  function decodeMMRBitmap(input, width, height, endOfBlock) {
1751
2160
  var params = {
1752
2161
  K: -1,
@@ -1757,45 +2166,66 @@ var Jbig2Image = function Jbig2ImageClosure() {
1757
2166
  };
1758
2167
  var decoder = new _ccitt.CCITTFaxDecoder(input, params);
1759
2168
  var bitmap = [],
1760
- x = void 0,
1761
- y = void 0,
1762
- row = void 0,
1763
- currentByte = void 0,
1764
- shift = void 0,
2169
+ x,
2170
+ y,
2171
+ row,
2172
+ currentByte,
2173
+ shift,
1765
2174
  eof = false;
2175
+
1766
2176
  for (y = 0; y < height; y++) {
1767
2177
  row = new Uint8Array(width);
1768
2178
  bitmap.push(row);
1769
2179
  shift = -1;
2180
+
1770
2181
  for (x = 0; x < width; x++) {
1771
2182
  if (shift < 0) {
1772
2183
  currentByte = decoder.readNextChar();
2184
+
1773
2185
  if (currentByte === -1) {
1774
2186
  currentByte = 0;
1775
2187
  eof = true;
1776
2188
  }
2189
+
1777
2190
  shift = 7;
1778
2191
  }
2192
+
1779
2193
  row[x] = currentByte >> shift & 1;
1780
2194
  shift--;
1781
2195
  }
1782
2196
  }
2197
+
1783
2198
  if (endOfBlock && !eof) {
1784
2199
  var lookForEOFLimit = 5;
2200
+
1785
2201
  for (var i = 0; i < lookForEOFLimit; i++) {
1786
2202
  if (decoder.readNextChar() === -1) {
1787
2203
  break;
1788
2204
  }
1789
2205
  }
1790
2206
  }
2207
+
1791
2208
  return bitmap;
1792
2209
  }
2210
+
1793
2211
  function Jbig2Image() {}
2212
+
1794
2213
  Jbig2Image.prototype = {
1795
- parseChunks: function Jbig2Image_parseChunks(chunks) {
2214
+ parseChunks: function parseChunks(chunks) {
1796
2215
  return parseJbig2Chunks(chunks);
2216
+ },
2217
+ parse: function parse(data) {
2218
+ var _parseJbig = parseJbig2(data),
2219
+ imgData = _parseJbig.imgData,
2220
+ width = _parseJbig.width,
2221
+ height = _parseJbig.height;
2222
+
2223
+ this.width = width;
2224
+ this.height = height;
2225
+ return imgData;
1797
2226
  }
1798
2227
  };
1799
2228
  return Jbig2Image;
1800
2229
  }();
2230
+
1801
2231
  exports.Jbig2Image = Jbig2Image;