pdfjs-dist 2.0.943 → 2.1.266

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 (159) hide show
  1. package/bower.json +1 -1
  2. package/build/pdf.js +15329 -11095
  3. package/build/pdf.js.map +1 -1
  4. package/build/pdf.min.js +1 -1
  5. package/build/pdf.worker.js +12497 -4184
  6. package/build/pdf.worker.js.map +1 -1
  7. package/build/pdf.worker.min.js +1 -1
  8. package/image_decoders/pdf.image_decoders.js +3438 -1209
  9. package/image_decoders/pdf.image_decoders.js.map +1 -1
  10. package/image_decoders/pdf.image_decoders.min.js +1 -1
  11. package/lib/core/annotation.js +335 -109
  12. package/lib/core/arithmetic_decoder.js +274 -244
  13. package/lib/core/bidi.js +64 -5
  14. package/lib/core/ccitt.js +172 -17
  15. package/lib/core/ccitt_stream.js +14 -5
  16. package/lib/core/cff_parser.js +304 -28
  17. package/lib/core/charsets.js +4 -3
  18. package/lib/core/chunked_stream.js +379 -149
  19. package/lib/core/cmap.js +210 -40
  20. package/lib/core/colorspace.js +332 -187
  21. package/lib/core/crypto.js +289 -44
  22. package/lib/core/document.js +508 -249
  23. package/lib/core/encodings.js +18 -9
  24. package/lib/core/evaluator.js +657 -119
  25. package/lib/core/font_renderer.js +217 -34
  26. package/lib/core/fonts.js +632 -41
  27. package/lib/core/function.js +252 -26
  28. package/lib/core/glyphlist.js +2 -1
  29. package/lib/core/image.js +124 -27
  30. package/lib/core/jbig2.js +425 -65
  31. package/lib/core/jbig2_stream.js +18 -7
  32. package/lib/core/jpeg_stream.js +24 -8
  33. package/lib/core/jpg.js +208 -16
  34. package/lib/core/jpx.js +395 -5
  35. package/lib/core/jpx_stream.js +17 -5
  36. package/lib/core/metrics.js +3 -3
  37. package/lib/core/murmurhash3.js +23 -5
  38. package/lib/core/obj.js +625 -132
  39. package/lib/core/operator_list.js +104 -3
  40. package/lib/core/parser.js +262 -25
  41. package/lib/core/pattern.js +144 -12
  42. package/lib/core/pdf_manager.js +104 -70
  43. package/lib/core/primitives.js +74 -21
  44. package/lib/core/ps_parser.js +133 -44
  45. package/lib/core/standard_fonts.js +9 -9
  46. package/lib/core/stream.js +283 -31
  47. package/lib/core/type1_parser.js +138 -6
  48. package/lib/core/unicode.js +28 -1
  49. package/lib/core/worker.js +192 -57
  50. package/lib/display/annotation_layer.js +303 -123
  51. package/lib/display/api.js +1073 -574
  52. package/lib/display/api_compatibility.js +4 -1
  53. package/lib/display/canvas.js +314 -18
  54. package/lib/display/content_disposition.js +70 -23
  55. package/lib/display/dom_utils.js +112 -59
  56. package/lib/display/fetch_stream.js +95 -50
  57. package/lib/display/font_loader.js +250 -132
  58. package/lib/display/metadata.js +37 -15
  59. package/lib/display/network.js +123 -34
  60. package/lib/display/network_utils.js +23 -10
  61. package/lib/display/node_stream.js +162 -65
  62. package/lib/display/pattern_helper.js +57 -6
  63. package/lib/display/svg.js +194 -18
  64. package/lib/display/text_layer.js +128 -14
  65. package/lib/display/transport_stream.js +83 -27
  66. package/lib/display/webgl.js +63 -17
  67. package/lib/display/worker_options.js +4 -3
  68. package/lib/display/xml_parser.js +162 -52
  69. package/lib/examples/node/domstubs.js +56 -3
  70. package/lib/pdf.js +15 -2
  71. package/lib/pdf.worker.js +4 -2
  72. package/lib/shared/compatibility.js +129 -26
  73. package/lib/shared/global_scope.js +1 -1
  74. package/lib/shared/is_node.js +3 -3
  75. package/lib/shared/message_handler.js +103 -45
  76. package/lib/shared/streams_polyfill.js +20 -16
  77. package/lib/shared/url_polyfill.js +8 -2
  78. package/lib/shared/util.js +246 -84
  79. package/lib/test/unit/annotation_spec.js +99 -73
  80. package/lib/test/unit/api_spec.js +347 -113
  81. package/lib/test/unit/bidi_spec.js +6 -6
  82. package/lib/test/unit/cff_parser_spec.js +17 -5
  83. package/lib/test/unit/clitests_helper.js +7 -8
  84. package/lib/test/unit/cmap_spec.js +79 -25
  85. package/lib/test/unit/colorspace_spec.js +65 -18
  86. package/lib/test/unit/crypto_spec.js +16 -4
  87. package/lib/test/unit/custom_spec.js +40 -52
  88. package/lib/test/unit/display_svg_spec.js +32 -16
  89. package/lib/test/unit/document_spec.js +2 -2
  90. package/lib/test/unit/dom_utils_spec.js +8 -8
  91. package/lib/test/unit/encodings_spec.js +24 -44
  92. package/lib/test/unit/evaluator_spec.js +15 -8
  93. package/lib/test/unit/function_spec.js +16 -4
  94. package/lib/test/unit/jasmine-boot.js +29 -16
  95. package/lib/test/unit/message_handler_spec.js +19 -6
  96. package/lib/test/unit/metadata_spec.js +64 -11
  97. package/lib/test/unit/murmurhash3_spec.js +2 -2
  98. package/lib/test/unit/network_spec.js +19 -4
  99. package/lib/test/unit/network_utils_spec.js +6 -4
  100. package/lib/test/unit/node_stream_spec.js +50 -26
  101. package/lib/test/unit/parser_spec.js +13 -29
  102. package/lib/test/unit/pdf_find_controller_spec.js +144 -32
  103. package/lib/test/unit/pdf_find_utils_spec.js +10 -9
  104. package/lib/test/unit/pdf_history_spec.js +20 -8
  105. package/lib/test/unit/primitives_spec.js +23 -3
  106. package/lib/test/unit/stream_spec.js +8 -3
  107. package/lib/test/unit/test_utils.js +89 -26
  108. package/lib/test/unit/testreporter.js +19 -1
  109. package/lib/test/unit/type1_parser_spec.js +7 -5
  110. package/lib/test/unit/ui_utils_spec.js +162 -38
  111. package/lib/test/unit/unicode_spec.js +13 -10
  112. package/lib/test/unit/util_spec.js +89 -9
  113. package/lib/web/annotation_layer_builder.js +38 -21
  114. package/lib/web/app.js +610 -245
  115. package/lib/web/app_options.js +54 -34
  116. package/lib/web/base_viewer.js +359 -162
  117. package/lib/web/chromecom.js +159 -80
  118. package/lib/web/debugger.js +161 -17
  119. package/lib/web/download_manager.js +29 -11
  120. package/lib/web/firefox_print_service.js +16 -8
  121. package/lib/web/firefoxcom.js +127 -91
  122. package/lib/web/genericcom.js +50 -31
  123. package/lib/web/genericl10n.js +46 -34
  124. package/lib/web/grab_to_pan.js +25 -3
  125. package/lib/web/interfaces.js +108 -61
  126. package/lib/web/overlay_manager.js +67 -45
  127. package/lib/web/password_prompt.js +20 -12
  128. package/lib/web/pdf_attachment_viewer.js +37 -17
  129. package/lib/web/pdf_cursor_tools.js +38 -15
  130. package/lib/web/pdf_document_properties.js +65 -24
  131. package/lib/web/pdf_find_bar.js +48 -20
  132. package/lib/web/pdf_find_controller.js +290 -89
  133. package/lib/web/pdf_find_utils.js +19 -3
  134. package/lib/web/pdf_history.js +186 -49
  135. package/lib/web/pdf_link_service.js +127 -52
  136. package/lib/web/pdf_outline_viewer.js +71 -21
  137. package/lib/web/pdf_page_view.js +188 -63
  138. package/lib/web/pdf_presentation_mode.js +98 -33
  139. package/lib/web/pdf_print_service.js +54 -10
  140. package/lib/web/pdf_rendering_queue.js +26 -4
  141. package/lib/web/pdf_sidebar.js +116 -62
  142. package/lib/web/pdf_sidebar_resizer.js +41 -15
  143. package/lib/web/pdf_single_page_viewer.js +65 -68
  144. package/lib/web/pdf_thumbnail_view.js +102 -31
  145. package/lib/web/pdf_thumbnail_viewer.js +62 -22
  146. package/lib/web/pdf_viewer.component.js +111 -31
  147. package/lib/web/pdf_viewer.js +80 -60
  148. package/lib/web/preferences.js +61 -39
  149. package/lib/web/secondary_toolbar.js +101 -82
  150. package/lib/web/text_layer_builder.js +124 -69
  151. package/lib/web/toolbar.js +67 -27
  152. package/lib/web/ui_utils.js +284 -128
  153. package/lib/web/view_history.js +75 -51
  154. package/lib/web/viewer_compatibility.js +2 -1
  155. package/package.json +1 -1
  156. package/web/pdf_viewer.css +1 -1
  157. package/web/pdf_viewer.js +2200 -973
  158. package/web/pdf_viewer.js.map +1 -1
  159. package/lib/web/dom_events.js +0 -140
@@ -19,18 +19,24 @@
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.LZWStream = exports.StringStream = exports.StreamsSequenceStream = exports.Stream = exports.RunLengthStream = exports.PredictorStream = exports.NullStream = exports.FlateStream = exports.DecodeStream = exports.DecryptStream = exports.AsciiHexStream = exports.Ascii85Stream = undefined;
27
+ exports.LZWStream = exports.StringStream = exports.StreamsSequenceStream = exports.Stream = exports.RunLengthStream = exports.PredictorStream = exports.NullStream = exports.FlateStream = exports.DecodeStream = exports.DecryptStream = exports.AsciiHexStream = exports.Ascii85Stream = void 0;
28
28
 
29
- var _util = require('../shared/util');
29
+ var _util = require("../shared/util");
30
30
 
31
- var _primitives = require('./primitives');
31
+ var _primitives = require("./primitives");
32
32
 
33
- function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
33
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
34
+
35
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
36
+
37
+ function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
38
+
39
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
34
40
 
35
41
  var Stream = function StreamClosure() {
36
42
  function Stream(arrayBuffer, start, length, dict) {
@@ -40,25 +46,31 @@ var Stream = function StreamClosure() {
40
46
  this.end = start + length || this.bytes.length;
41
47
  this.dict = dict;
42
48
  }
49
+
43
50
  Stream.prototype = {
44
51
  get length() {
45
52
  return this.end - this.start;
46
53
  },
54
+
47
55
  get isEmpty() {
48
56
  return this.length === 0;
49
57
  },
58
+
50
59
  getByte: function Stream_getByte() {
51
60
  if (this.pos >= this.end) {
52
61
  return -1;
53
62
  }
63
+
54
64
  return this.bytes[this.pos++];
55
65
  },
56
66
  getUint16: function Stream_getUint16() {
57
67
  var b0 = this.getByte();
58
68
  var b1 = this.getByte();
69
+
59
70
  if (b0 === -1 || b1 === -1) {
60
71
  return -1;
61
72
  }
73
+
62
74
  return (b0 << 8) + b1;
63
75
  },
64
76
  getInt32: function Stream_getInt32() {
@@ -70,23 +82,26 @@ var Stream = function StreamClosure() {
70
82
  },
71
83
  getBytes: function getBytes(length) {
72
84
  var forceClamped = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
73
-
74
85
  var bytes = this.bytes;
75
86
  var pos = this.pos;
76
87
  var strEnd = this.end;
88
+
77
89
  if (!length) {
78
90
  var _subarray = bytes.subarray(pos, strEnd);
91
+
79
92
  return forceClamped ? new Uint8ClampedArray(_subarray) : _subarray;
80
93
  }
94
+
81
95
  var end = pos + length;
96
+
82
97
  if (end > strEnd) {
83
98
  end = strEnd;
84
99
  }
100
+
85
101
  this.pos = end;
86
102
  var subarray = bytes.subarray(pos, end);
87
103
  return forceClamped ? new Uint8ClampedArray(subarray) : subarray;
88
104
  },
89
-
90
105
  peekByte: function Stream_peekByte() {
91
106
  var peekedByte = this.getByte();
92
107
  this.pos--;
@@ -94,16 +109,15 @@ var Stream = function StreamClosure() {
94
109
  },
95
110
  peekBytes: function peekBytes(length) {
96
111
  var forceClamped = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
97
-
98
112
  var bytes = this.getBytes(length, forceClamped);
99
113
  this.pos -= bytes.length;
100
114
  return bytes;
101
115
  },
102
-
103
116
  skip: function Stream_skip(n) {
104
117
  if (!n) {
105
118
  n = 1;
106
119
  }
120
+
107
121
  this.pos += n;
108
122
  },
109
123
  reset: function Stream_reset() {
@@ -118,16 +132,24 @@ var Stream = function StreamClosure() {
118
132
  };
119
133
  return Stream;
120
134
  }();
135
+
136
+ exports.Stream = Stream;
137
+
121
138
  var StringStream = function StringStreamClosure() {
122
139
  function StringStream(str) {
123
140
  var bytes = (0, _util.stringToBytes)(str);
124
141
  Stream.call(this, bytes);
125
142
  }
143
+
126
144
  StringStream.prototype = Stream.prototype;
127
145
  return StringStream;
128
146
  }();
147
+
148
+ exports.StringStream = StringStream;
149
+
129
150
  var DecodeStream = function DecodeStreamClosure() {
130
151
  var emptyBuffer = new Uint8Array(0);
152
+
131
153
  function DecodeStream(maybeMinBufferLength) {
132
154
  this._rawMinBufferLength = maybeMinBufferLength || 0;
133
155
  this.pos = 0;
@@ -135,48 +157,61 @@ var DecodeStream = function DecodeStreamClosure() {
135
157
  this.eof = false;
136
158
  this.buffer = emptyBuffer;
137
159
  this.minBufferLength = 512;
160
+
138
161
  if (maybeMinBufferLength) {
139
162
  while (this.minBufferLength < maybeMinBufferLength) {
140
163
  this.minBufferLength *= 2;
141
164
  }
142
165
  }
143
166
  }
167
+
144
168
  DecodeStream.prototype = {
145
169
  get isEmpty() {
146
170
  while (!this.eof && this.bufferLength === 0) {
147
171
  this.readBlock();
148
172
  }
173
+
149
174
  return this.bufferLength === 0;
150
175
  },
176
+
151
177
  ensureBuffer: function DecodeStream_ensureBuffer(requested) {
152
178
  var buffer = this.buffer;
179
+
153
180
  if (requested <= buffer.byteLength) {
154
181
  return buffer;
155
182
  }
183
+
156
184
  var size = this.minBufferLength;
185
+
157
186
  while (size < requested) {
158
187
  size *= 2;
159
188
  }
189
+
160
190
  var buffer2 = new Uint8Array(size);
161
191
  buffer2.set(buffer);
162
192
  return this.buffer = buffer2;
163
193
  },
164
194
  getByte: function DecodeStream_getByte() {
165
195
  var pos = this.pos;
196
+
166
197
  while (this.bufferLength <= pos) {
167
198
  if (this.eof) {
168
199
  return -1;
169
200
  }
201
+
170
202
  this.readBlock();
171
203
  }
204
+
172
205
  return this.buffer[this.pos++];
173
206
  },
174
207
  getUint16: function DecodeStream_getUint16() {
175
208
  var b0 = this.getByte();
176
209
  var b1 = this.getByte();
210
+
177
211
  if (b0 === -1 || b1 === -1) {
178
212
  return -1;
179
213
  }
214
+
180
215
  return (b0 << 8) + b1;
181
216
  },
182
217
  getInt32: function DecodeStream_getInt32() {
@@ -188,16 +223,19 @@ var DecodeStream = function DecodeStreamClosure() {
188
223
  },
189
224
  getBytes: function getBytes(length) {
190
225
  var forceClamped = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
191
-
192
226
  var end,
193
227
  pos = this.pos;
228
+
194
229
  if (length) {
195
230
  this.ensureBuffer(pos + length);
196
231
  end = pos + length;
232
+
197
233
  while (!this.eof && this.bufferLength < end) {
198
234
  this.readBlock();
199
235
  }
236
+
200
237
  var bufEnd = this.bufferLength;
238
+
201
239
  if (end > bufEnd) {
202
240
  end = bufEnd;
203
241
  }
@@ -205,13 +243,14 @@ var DecodeStream = function DecodeStreamClosure() {
205
243
  while (!this.eof) {
206
244
  this.readBlock();
207
245
  }
246
+
208
247
  end = this.bufferLength;
209
248
  }
249
+
210
250
  this.pos = end;
211
251
  var subarray = this.buffer.subarray(pos, end);
212
252
  return forceClamped && !(subarray instanceof Uint8ClampedArray) ? new Uint8ClampedArray(subarray) : subarray;
213
253
  },
214
-
215
254
  peekByte: function DecodeStream_peekByte() {
216
255
  var peekedByte = this.getByte();
217
256
  this.pos--;
@@ -219,23 +258,24 @@ var DecodeStream = function DecodeStreamClosure() {
219
258
  },
220
259
  peekBytes: function peekBytes(length) {
221
260
  var forceClamped = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
222
-
223
261
  var bytes = this.getBytes(length, forceClamped);
224
262
  this.pos -= bytes.length;
225
263
  return bytes;
226
264
  },
227
-
228
265
  makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
229
266
  var end = start + length;
267
+
230
268
  while (this.bufferLength <= end && !this.eof) {
231
269
  this.readBlock();
232
270
  }
271
+
233
272
  return new Stream(this.buffer, start, length, dict);
234
273
  },
235
274
  skip: function DecodeStream_skip(n) {
236
275
  if (!n) {
237
276
  n = 1;
238
277
  }
278
+
239
279
  this.pos += n;
240
280
  },
241
281
  reset: function DecodeStream_reset() {
@@ -245,32 +285,43 @@ var DecodeStream = function DecodeStreamClosure() {
245
285
  if (this.str && this.str.getBaseStreams) {
246
286
  return this.str.getBaseStreams();
247
287
  }
288
+
248
289
  return [];
249
290
  }
250
291
  };
251
292
  return DecodeStream;
252
293
  }();
294
+
295
+ exports.DecodeStream = DecodeStream;
296
+
253
297
  var StreamsSequenceStream = function StreamsSequenceStreamClosure() {
254
298
  function StreamsSequenceStream(streams) {
255
299
  this.streams = streams;
256
300
  var maybeLength = 0;
301
+
257
302
  for (var i = 0, ii = streams.length; i < ii; i++) {
258
303
  var stream = streams[i];
304
+
259
305
  if (stream instanceof DecodeStream) {
260
306
  maybeLength += stream._rawMinBufferLength;
261
307
  } else {
262
308
  maybeLength += stream.length;
263
309
  }
264
310
  }
311
+
265
312
  DecodeStream.call(this, maybeLength);
266
313
  }
314
+
267
315
  StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
316
+
268
317
  StreamsSequenceStream.prototype.readBlock = function streamSequenceStreamReadBlock() {
269
318
  var streams = this.streams;
319
+
270
320
  if (streams.length === 0) {
271
321
  this.eof = true;
272
322
  return;
273
323
  }
324
+
274
325
  var stream = streams.shift();
275
326
  var chunk = stream.getBytes();
276
327
  var bufferLength = this.bufferLength;
@@ -279,63 +330,83 @@ var StreamsSequenceStream = function StreamsSequenceStreamClosure() {
279
330
  buffer.set(chunk, bufferLength);
280
331
  this.bufferLength = newLength;
281
332
  };
333
+
282
334
  StreamsSequenceStream.prototype.getBaseStreams = function StreamsSequenceStream_getBaseStreams() {
283
335
  var baseStreams = [];
336
+
284
337
  for (var i = 0, ii = this.streams.length; i < ii; i++) {
285
338
  var stream = this.streams[i];
339
+
286
340
  if (stream.getBaseStreams) {
287
341
  baseStreams.push.apply(baseStreams, _toConsumableArray(stream.getBaseStreams()));
288
342
  }
289
343
  }
344
+
290
345
  return baseStreams;
291
346
  };
347
+
292
348
  return StreamsSequenceStream;
293
349
  }();
350
+
351
+ exports.StreamsSequenceStream = StreamsSequenceStream;
352
+
294
353
  var FlateStream = function FlateStreamClosure() {
295
354
  var codeLenCodeMap = new Int32Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
296
355
  var lengthDecode = new Int32Array([0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a, 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f, 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073, 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102]);
297
356
  var distDecode = new Int32Array([0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d, 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1, 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01, 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001]);
298
357
  var fixedLitCodeTab = [new Int32Array([0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0, 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0, 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0, 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0, 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8, 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8, 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8, 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8, 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4, 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4, 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4, 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4, 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc, 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec, 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc, 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc, 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2, 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2, 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2, 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2, 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca, 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea, 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da, 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa, 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6, 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6, 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6, 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6, 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce, 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee, 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de, 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe, 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1, 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1, 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1, 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1, 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9, 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9, 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9, 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9, 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5, 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5, 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5, 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5, 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd, 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed, 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd, 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd, 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3, 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3, 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3, 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3, 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb, 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb, 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db, 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb, 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7, 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7, 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7, 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7, 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf, 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef, 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df, 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff]), 9];
299
358
  var fixedDistCodeTab = [new Int32Array([0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c, 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000, 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d, 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000]), 5];
359
+
300
360
  function FlateStream(str, maybeLength) {
301
361
  this.str = str;
302
362
  this.dict = str.dict;
303
363
  var cmf = str.getByte();
304
364
  var flg = str.getByte();
365
+
305
366
  if (cmf === -1 || flg === -1) {
306
- throw new _util.FormatError('Invalid header in flate stream: ' + cmf + ', ' + flg);
367
+ throw new _util.FormatError("Invalid header in flate stream: ".concat(cmf, ", ").concat(flg));
307
368
  }
369
+
308
370
  if ((cmf & 0x0f) !== 0x08) {
309
- throw new _util.FormatError('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
371
+ throw new _util.FormatError("Unknown compression method in flate stream: ".concat(cmf, ", ").concat(flg));
310
372
  }
373
+
311
374
  if (((cmf << 8) + flg) % 31 !== 0) {
312
- throw new _util.FormatError('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
375
+ throw new _util.FormatError("Bad FCHECK in flate stream: ".concat(cmf, ", ").concat(flg));
313
376
  }
377
+
314
378
  if (flg & 0x20) {
315
- throw new _util.FormatError('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
379
+ throw new _util.FormatError("FDICT bit set in flate stream: ".concat(cmf, ", ").concat(flg));
316
380
  }
381
+
317
382
  this.codeSize = 0;
318
383
  this.codeBuf = 0;
319
384
  DecodeStream.call(this, maybeLength);
320
385
  }
386
+
321
387
  FlateStream.prototype = Object.create(DecodeStream.prototype);
388
+
322
389
  FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
323
390
  var str = this.str;
324
391
  var codeSize = this.codeSize;
325
392
  var codeBuf = this.codeBuf;
326
393
  var b;
394
+
327
395
  while (codeSize < bits) {
328
396
  if ((b = str.getByte()) === -1) {
329
397
  throw new _util.FormatError('Bad encoding in flate stream');
330
398
  }
399
+
331
400
  codeBuf |= b << codeSize;
332
401
  codeSize += 8;
333
402
  }
403
+
334
404
  b = codeBuf & (1 << bits) - 1;
335
405
  this.codeBuf = codeBuf >> bits;
336
406
  this.codeSize = codeSize -= bits;
337
407
  return b;
338
408
  };
409
+
339
410
  FlateStream.prototype.getCode = function FlateStream_getCode(table) {
340
411
  var str = this.str;
341
412
  var codes = table[0];
@@ -343,87 +414,115 @@ var FlateStream = function FlateStreamClosure() {
343
414
  var codeSize = this.codeSize;
344
415
  var codeBuf = this.codeBuf;
345
416
  var b;
417
+
346
418
  while (codeSize < maxLen) {
347
419
  if ((b = str.getByte()) === -1) {
348
420
  break;
349
421
  }
422
+
350
423
  codeBuf |= b << codeSize;
351
424
  codeSize += 8;
352
425
  }
426
+
353
427
  var code = codes[codeBuf & (1 << maxLen) - 1];
354
428
  var codeLen = code >> 16;
355
429
  var codeVal = code & 0xffff;
430
+
356
431
  if (codeLen < 1 || codeSize < codeLen) {
357
432
  throw new _util.FormatError('Bad encoding in flate stream');
358
433
  }
434
+
359
435
  this.codeBuf = codeBuf >> codeLen;
360
436
  this.codeSize = codeSize - codeLen;
361
437
  return codeVal;
362
438
  };
439
+
363
440
  FlateStream.prototype.generateHuffmanTable = function flateStreamGenerateHuffmanTable(lengths) {
364
441
  var n = lengths.length;
365
442
  var maxLen = 0;
366
443
  var i;
444
+
367
445
  for (i = 0; i < n; ++i) {
368
446
  if (lengths[i] > maxLen) {
369
447
  maxLen = lengths[i];
370
448
  }
371
449
  }
450
+
372
451
  var size = 1 << maxLen;
373
452
  var codes = new Int32Array(size);
453
+
374
454
  for (var len = 1, code = 0, skip = 2; len <= maxLen; ++len, code <<= 1, skip <<= 1) {
375
455
  for (var val = 0; val < n; ++val) {
376
456
  if (lengths[val] === len) {
377
457
  var code2 = 0;
378
458
  var t = code;
459
+
379
460
  for (i = 0; i < len; ++i) {
380
461
  code2 = code2 << 1 | t & 1;
381
462
  t >>= 1;
382
463
  }
464
+
383
465
  for (i = code2; i < size; i += skip) {
384
466
  codes[i] = len << 16 | val;
385
467
  }
468
+
386
469
  ++code;
387
470
  }
388
471
  }
389
472
  }
473
+
390
474
  return [codes, maxLen];
391
475
  };
476
+
392
477
  FlateStream.prototype.readBlock = function FlateStream_readBlock() {
393
478
  var buffer, len;
394
479
  var str = this.str;
395
480
  var hdr = this.getBits(3);
481
+
396
482
  if (hdr & 1) {
397
483
  this.eof = true;
398
484
  }
485
+
399
486
  hdr >>= 1;
487
+
400
488
  if (hdr === 0) {
401
489
  var b;
490
+
402
491
  if ((b = str.getByte()) === -1) {
403
492
  throw new _util.FormatError('Bad block header in flate stream');
404
493
  }
494
+
405
495
  var blockLen = b;
496
+
406
497
  if ((b = str.getByte()) === -1) {
407
498
  throw new _util.FormatError('Bad block header in flate stream');
408
499
  }
500
+
409
501
  blockLen |= b << 8;
502
+
410
503
  if ((b = str.getByte()) === -1) {
411
504
  throw new _util.FormatError('Bad block header in flate stream');
412
505
  }
506
+
413
507
  var check = b;
508
+
414
509
  if ((b = str.getByte()) === -1) {
415
510
  throw new _util.FormatError('Bad block header in flate stream');
416
511
  }
512
+
417
513
  check |= b << 8;
514
+
418
515
  if (check !== (~blockLen & 0xffff) && (blockLen !== 0 || check !== 0)) {
419
516
  throw new _util.FormatError('Bad uncompressed block length in flate stream');
420
517
  }
518
+
421
519
  this.codeBuf = 0;
422
520
  this.codeSize = 0;
423
521
  var bufferLength = this.bufferLength;
424
522
  buffer = this.ensureBuffer(bufferLength + blockLen);
425
523
  var end = bufferLength + blockLen;
426
524
  this.bufferLength = end;
525
+
427
526
  if (blockLen === 0) {
428
527
  if (str.peekByte() === -1) {
429
528
  this.eof = true;
@@ -434,13 +533,17 @@ var FlateStream = function FlateStreamClosure() {
434
533
  this.eof = true;
435
534
  break;
436
535
  }
536
+
437
537
  buffer[n] = b;
438
538
  }
439
539
  }
540
+
440
541
  return;
441
542
  }
543
+
442
544
  var litCodeTable;
443
545
  var distCodeTable;
546
+
444
547
  if (hdr === 1) {
445
548
  litCodeTable = fixedLitCodeTab;
446
549
  distCodeTable = fixedDistCodeTab;
@@ -450,17 +553,21 @@ var FlateStream = function FlateStreamClosure() {
450
553
  var numCodeLenCodes = this.getBits(4) + 4;
451
554
  var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
452
555
  var i;
556
+
453
557
  for (i = 0; i < numCodeLenCodes; ++i) {
454
558
  codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
455
559
  }
560
+
456
561
  var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
457
562
  len = 0;
458
563
  i = 0;
459
564
  var codes = numLitCodes + numDistCodes;
460
565
  var codeLengths = new Uint8Array(codes);
461
566
  var bitsLength, bitsOffset, what;
567
+
462
568
  while (i < codes) {
463
569
  var code = this.getCode(codeLenCodeTab);
570
+
464
571
  if (code === 16) {
465
572
  bitsLength = 2;
466
573
  bitsOffset = 3;
@@ -477,75 +584,99 @@ var FlateStream = function FlateStreamClosure() {
477
584
  codeLengths[i++] = len = code;
478
585
  continue;
479
586
  }
587
+
480
588
  var repeatLength = this.getBits(bitsLength) + bitsOffset;
589
+
481
590
  while (repeatLength-- > 0) {
482
591
  codeLengths[i++] = what;
483
592
  }
484
593
  }
594
+
485
595
  litCodeTable = this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
486
596
  distCodeTable = this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
487
597
  } else {
488
598
  throw new _util.FormatError('Unknown block type in flate stream');
489
599
  }
600
+
490
601
  buffer = this.buffer;
491
602
  var limit = buffer ? buffer.length : 0;
492
603
  var pos = this.bufferLength;
604
+
493
605
  while (true) {
494
606
  var code1 = this.getCode(litCodeTable);
607
+
495
608
  if (code1 < 256) {
496
609
  if (pos + 1 >= limit) {
497
610
  buffer = this.ensureBuffer(pos + 1);
498
611
  limit = buffer.length;
499
612
  }
613
+
500
614
  buffer[pos++] = code1;
501
615
  continue;
502
616
  }
617
+
503
618
  if (code1 === 256) {
504
619
  this.bufferLength = pos;
505
620
  return;
506
621
  }
622
+
507
623
  code1 -= 257;
508
624
  code1 = lengthDecode[code1];
509
625
  var code2 = code1 >> 16;
626
+
510
627
  if (code2 > 0) {
511
628
  code2 = this.getBits(code2);
512
629
  }
630
+
513
631
  len = (code1 & 0xffff) + code2;
514
632
  code1 = this.getCode(distCodeTable);
515
633
  code1 = distDecode[code1];
516
634
  code2 = code1 >> 16;
635
+
517
636
  if (code2 > 0) {
518
637
  code2 = this.getBits(code2);
519
638
  }
639
+
520
640
  var dist = (code1 & 0xffff) + code2;
641
+
521
642
  if (pos + len >= limit) {
522
643
  buffer = this.ensureBuffer(pos + len);
523
644
  limit = buffer.length;
524
645
  }
646
+
525
647
  for (var k = 0; k < len; ++k, ++pos) {
526
648
  buffer[pos] = buffer[pos - dist];
527
649
  }
528
650
  }
529
651
  };
652
+
530
653
  return FlateStream;
531
654
  }();
655
+
656
+ exports.FlateStream = FlateStream;
657
+
532
658
  var PredictorStream = function PredictorStreamClosure() {
533
659
  function PredictorStream(str, maybeLength, params) {
534
660
  if (!(0, _primitives.isDict)(params)) {
535
661
  return str;
536
662
  }
663
+
537
664
  var predictor = this.predictor = params.get('Predictor') || 1;
665
+
538
666
  if (predictor <= 1) {
539
667
  return str;
540
668
  }
669
+
541
670
  if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
542
- throw new _util.FormatError('Unsupported predictor: ' + predictor);
671
+ throw new _util.FormatError("Unsupported predictor: ".concat(predictor));
543
672
  }
673
+
544
674
  if (predictor === 2) {
545
675
  this.readBlock = this.readBlockTiff;
546
676
  } else {
547
677
  this.readBlock = this.readBlockPng;
548
678
  }
679
+
549
680
  this.str = str;
550
681
  this.dict = str.dict;
551
682
  var colors = this.colors = params.get('Colors') || 1;
@@ -556,7 +687,9 @@ var PredictorStream = function PredictorStreamClosure() {
556
687
  DecodeStream.call(this, maybeLength);
557
688
  return this;
558
689
  }
690
+
559
691
  PredictorStream.prototype = Object.create(DecodeStream.prototype);
692
+
560
693
  PredictorStream.prototype.readBlockTiff = function predictorStreamReadBlockTiff() {
561
694
  var rowBytes = this.rowBytes;
562
695
  var bufferLength = this.bufferLength;
@@ -565,15 +698,18 @@ var PredictorStream = function PredictorStreamClosure() {
565
698
  var colors = this.colors;
566
699
  var rawBytes = this.str.getBytes(rowBytes);
567
700
  this.eof = !rawBytes.length;
701
+
568
702
  if (this.eof) {
569
703
  return;
570
704
  }
705
+
571
706
  var inbuf = 0,
572
707
  outbuf = 0;
573
708
  var inbits = 0,
574
709
  outbits = 0;
575
710
  var pos = bufferLength;
576
711
  var i;
712
+
577
713
  if (bits === 1 && colors === 1) {
578
714
  for (i = 0; i < rowBytes; ++i) {
579
715
  var c = rawBytes[i] ^ inbuf;
@@ -587,15 +723,18 @@ var PredictorStream = function PredictorStreamClosure() {
587
723
  for (i = 0; i < colors; ++i) {
588
724
  buffer[pos++] = rawBytes[i];
589
725
  }
726
+
590
727
  for (; i < rowBytes; ++i) {
591
728
  buffer[pos] = buffer[pos - colors] + rawBytes[i];
592
729
  pos++;
593
730
  }
594
731
  } else if (bits === 16) {
595
732
  var bytesPerPixel = colors * 2;
733
+
596
734
  for (i = 0; i < bytesPerPixel; ++i) {
597
735
  buffer[pos++] = rawBytes[i];
598
736
  }
737
+
599
738
  for (; i < rowBytes; i += 2) {
600
739
  var sum = ((rawBytes[i] & 0xFF) << 8) + (rawBytes[i + 1] & 0xFF) + ((buffer[pos - bytesPerPixel] & 0xFF) << 8) + (buffer[pos - bytesPerPixel + 1] & 0xFF);
601
740
  buffer[pos++] = sum >> 8 & 0xFF;
@@ -607,100 +746,129 @@ var PredictorStream = function PredictorStreamClosure() {
607
746
  var j = 0,
608
747
  k = bufferLength;
609
748
  var columns = this.columns;
749
+
610
750
  for (i = 0; i < columns; ++i) {
611
751
  for (var kk = 0; kk < colors; ++kk) {
612
752
  if (inbits < bits) {
613
753
  inbuf = inbuf << 8 | rawBytes[j++] & 0xFF;
614
754
  inbits += 8;
615
755
  }
756
+
616
757
  compArray[kk] = compArray[kk] + (inbuf >> inbits - bits) & bitMask;
617
758
  inbits -= bits;
618
759
  outbuf = outbuf << bits | compArray[kk];
619
760
  outbits += bits;
761
+
620
762
  if (outbits >= 8) {
621
763
  buffer[k++] = outbuf >> outbits - 8 & 0xFF;
622
764
  outbits -= 8;
623
765
  }
624
766
  }
625
767
  }
768
+
626
769
  if (outbits > 0) {
627
770
  buffer[k++] = (outbuf << 8 - outbits) + (inbuf & (1 << 8 - outbits) - 1);
628
771
  }
629
772
  }
773
+
630
774
  this.bufferLength += rowBytes;
631
775
  };
776
+
632
777
  PredictorStream.prototype.readBlockPng = function predictorStreamReadBlockPng() {
633
778
  var rowBytes = this.rowBytes;
634
779
  var pixBytes = this.pixBytes;
635
780
  var predictor = this.str.getByte();
636
781
  var rawBytes = this.str.getBytes(rowBytes);
637
782
  this.eof = !rawBytes.length;
783
+
638
784
  if (this.eof) {
639
785
  return;
640
786
  }
787
+
641
788
  var bufferLength = this.bufferLength;
642
789
  var buffer = this.ensureBuffer(bufferLength + rowBytes);
643
790
  var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
791
+
644
792
  if (prevRow.length === 0) {
645
793
  prevRow = new Uint8Array(rowBytes);
646
794
  }
795
+
647
796
  var i,
648
797
  j = bufferLength,
649
798
  up,
650
799
  c;
800
+
651
801
  switch (predictor) {
652
802
  case 0:
653
803
  for (i = 0; i < rowBytes; ++i) {
654
804
  buffer[j++] = rawBytes[i];
655
805
  }
806
+
656
807
  break;
808
+
657
809
  case 1:
658
810
  for (i = 0; i < pixBytes; ++i) {
659
811
  buffer[j++] = rawBytes[i];
660
812
  }
813
+
661
814
  for (; i < rowBytes; ++i) {
662
815
  buffer[j] = buffer[j - pixBytes] + rawBytes[i] & 0xFF;
663
816
  j++;
664
817
  }
818
+
665
819
  break;
820
+
666
821
  case 2:
667
822
  for (i = 0; i < rowBytes; ++i) {
668
823
  buffer[j++] = prevRow[i] + rawBytes[i] & 0xFF;
669
824
  }
825
+
670
826
  break;
827
+
671
828
  case 3:
672
829
  for (i = 0; i < pixBytes; ++i) {
673
830
  buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
674
831
  }
832
+
675
833
  for (; i < rowBytes; ++i) {
676
834
  buffer[j] = (prevRow[i] + buffer[j - pixBytes] >> 1) + rawBytes[i] & 0xFF;
677
835
  j++;
678
836
  }
837
+
679
838
  break;
839
+
680
840
  case 4:
681
841
  for (i = 0; i < pixBytes; ++i) {
682
842
  up = prevRow[i];
683
843
  c = rawBytes[i];
684
844
  buffer[j++] = up + c;
685
845
  }
846
+
686
847
  for (; i < rowBytes; ++i) {
687
848
  up = prevRow[i];
688
849
  var upLeft = prevRow[i - pixBytes];
689
850
  var left = buffer[j - pixBytes];
690
851
  var p = left + up - upLeft;
691
852
  var pa = p - left;
853
+
692
854
  if (pa < 0) {
693
855
  pa = -pa;
694
856
  }
857
+
695
858
  var pb = p - up;
859
+
696
860
  if (pb < 0) {
697
861
  pb = -pb;
698
862
  }
863
+
699
864
  var pc = p - upLeft;
865
+
700
866
  if (pc < 0) {
701
867
  pc = -pc;
702
868
  }
869
+
703
870
  c = rawBytes[i];
871
+
704
872
  if (pa <= pb && pa <= pc) {
705
873
  buffer[j++] = left + c;
706
874
  } else if (pb <= pc) {
@@ -709,14 +877,21 @@ var PredictorStream = function PredictorStreamClosure() {
709
877
  buffer[j++] = upLeft + c;
710
878
  }
711
879
  }
880
+
712
881
  break;
882
+
713
883
  default:
714
- throw new _util.FormatError('Unsupported predictor: ' + predictor);
884
+ throw new _util.FormatError("Unsupported predictor: ".concat(predictor));
715
885
  }
886
+
716
887
  this.bufferLength += rowBytes;
717
888
  };
889
+
718
890
  return PredictorStream;
719
891
  }();
892
+
893
+ exports.PredictorStream = PredictorStream;
894
+
720
895
  var DecryptStream = function DecryptStreamClosure() {
721
896
  function DecryptStream(str, maybeLength, decrypt) {
722
897
  this.str = str;
@@ -726,20 +901,25 @@ var DecryptStream = function DecryptStreamClosure() {
726
901
  this.initialized = false;
727
902
  DecodeStream.call(this, maybeLength);
728
903
  }
904
+
729
905
  var chunkSize = 512;
730
906
  DecryptStream.prototype = Object.create(DecodeStream.prototype);
907
+
731
908
  DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
732
909
  var chunk;
910
+
733
911
  if (this.initialized) {
734
912
  chunk = this.nextChunk;
735
913
  } else {
736
914
  chunk = this.str.getBytes(chunkSize);
737
915
  this.initialized = true;
738
916
  }
917
+
739
918
  if (!chunk || chunk.length === 0) {
740
919
  this.eof = true;
741
920
  return;
742
921
  }
922
+
743
923
  this.nextChunk = this.str.getBytes(chunkSize);
744
924
  var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
745
925
  var decrypt = this.decrypt;
@@ -748,104 +928,142 @@ var DecryptStream = function DecryptStreamClosure() {
748
928
  var i,
749
929
  n = chunk.length;
750
930
  var buffer = this.ensureBuffer(bufferLength + n);
931
+
751
932
  for (i = 0; i < n; i++) {
752
933
  buffer[bufferLength++] = chunk[i];
753
934
  }
935
+
754
936
  this.bufferLength = bufferLength;
755
937
  };
938
+
756
939
  return DecryptStream;
757
940
  }();
941
+
942
+ exports.DecryptStream = DecryptStream;
943
+
758
944
  var Ascii85Stream = function Ascii85StreamClosure() {
759
945
  function Ascii85Stream(str, maybeLength) {
760
946
  this.str = str;
761
947
  this.dict = str.dict;
762
948
  this.input = new Uint8Array(5);
949
+
763
950
  if (maybeLength) {
764
951
  maybeLength = 0.8 * maybeLength;
765
952
  }
953
+
766
954
  DecodeStream.call(this, maybeLength);
767
955
  }
956
+
768
957
  Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
958
+
769
959
  Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
770
960
  var TILDA_CHAR = 0x7E;
771
961
  var Z_LOWER_CHAR = 0x7A;
772
962
  var EOF = -1;
773
963
  var str = this.str;
774
964
  var c = str.getByte();
965
+
775
966
  while ((0, _util.isSpace)(c)) {
776
967
  c = str.getByte();
777
968
  }
969
+
778
970
  if (c === EOF || c === TILDA_CHAR) {
779
971
  this.eof = true;
780
972
  return;
781
973
  }
974
+
782
975
  var bufferLength = this.bufferLength,
783
976
  buffer;
784
977
  var i;
978
+
785
979
  if (c === Z_LOWER_CHAR) {
786
980
  buffer = this.ensureBuffer(bufferLength + 4);
981
+
787
982
  for (i = 0; i < 4; ++i) {
788
983
  buffer[bufferLength + i] = 0;
789
984
  }
985
+
790
986
  this.bufferLength += 4;
791
987
  } else {
792
988
  var input = this.input;
793
989
  input[0] = c;
990
+
794
991
  for (i = 1; i < 5; ++i) {
795
992
  c = str.getByte();
993
+
796
994
  while ((0, _util.isSpace)(c)) {
797
995
  c = str.getByte();
798
996
  }
997
+
799
998
  input[i] = c;
999
+
800
1000
  if (c === EOF || c === TILDA_CHAR) {
801
1001
  break;
802
1002
  }
803
1003
  }
1004
+
804
1005
  buffer = this.ensureBuffer(bufferLength + i - 1);
805
1006
  this.bufferLength += i - 1;
1007
+
806
1008
  if (i < 5) {
807
1009
  for (; i < 5; ++i) {
808
1010
  input[i] = 0x21 + 84;
809
1011
  }
1012
+
810
1013
  this.eof = true;
811
1014
  }
1015
+
812
1016
  var t = 0;
1017
+
813
1018
  for (i = 0; i < 5; ++i) {
814
1019
  t = t * 85 + (input[i] - 0x21);
815
1020
  }
1021
+
816
1022
  for (i = 3; i >= 0; --i) {
817
1023
  buffer[bufferLength + i] = t & 0xFF;
818
1024
  t >>= 8;
819
1025
  }
820
1026
  }
821
1027
  };
1028
+
822
1029
  return Ascii85Stream;
823
1030
  }();
1031
+
1032
+ exports.Ascii85Stream = Ascii85Stream;
1033
+
824
1034
  var AsciiHexStream = function AsciiHexStreamClosure() {
825
1035
  function AsciiHexStream(str, maybeLength) {
826
1036
  this.str = str;
827
1037
  this.dict = str.dict;
828
1038
  this.firstDigit = -1;
1039
+
829
1040
  if (maybeLength) {
830
1041
  maybeLength = 0.5 * maybeLength;
831
1042
  }
1043
+
832
1044
  DecodeStream.call(this, maybeLength);
833
1045
  }
1046
+
834
1047
  AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
1048
+
835
1049
  AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
836
1050
  var UPSTREAM_BLOCK_SIZE = 8000;
837
1051
  var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
1052
+
838
1053
  if (!bytes.length) {
839
1054
  this.eof = true;
840
1055
  return;
841
1056
  }
1057
+
842
1058
  var maxDecodeLength = bytes.length + 1 >> 1;
843
1059
  var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
844
1060
  var bufferLength = this.bufferLength;
845
1061
  var firstDigit = this.firstDigit;
1062
+
846
1063
  for (var i = 0, ii = bytes.length; i < ii; i++) {
847
1064
  var ch = bytes[i],
848
1065
  digit;
1066
+
849
1067
  if (ch >= 0x30 && ch <= 0x39) {
850
1068
  digit = ch & 0x0F;
851
1069
  } else if (ch >= 0x41 && ch <= 0x46 || ch >= 0x61 && ch <= 0x66) {
@@ -856,6 +1074,7 @@ var AsciiHexStream = function AsciiHexStreamClosure() {
856
1074
  } else {
857
1075
  continue;
858
1076
  }
1077
+
859
1078
  if (firstDigit < 0) {
860
1079
  firstDigit = digit;
861
1080
  } else {
@@ -863,34 +1082,46 @@ var AsciiHexStream = function AsciiHexStreamClosure() {
863
1082
  firstDigit = -1;
864
1083
  }
865
1084
  }
1085
+
866
1086
  if (firstDigit >= 0 && this.eof) {
867
1087
  buffer[bufferLength++] = firstDigit << 4;
868
1088
  firstDigit = -1;
869
1089
  }
1090
+
870
1091
  this.firstDigit = firstDigit;
871
1092
  this.bufferLength = bufferLength;
872
1093
  };
1094
+
873
1095
  return AsciiHexStream;
874
1096
  }();
1097
+
1098
+ exports.AsciiHexStream = AsciiHexStream;
1099
+
875
1100
  var RunLengthStream = function RunLengthStreamClosure() {
876
1101
  function RunLengthStream(str, maybeLength) {
877
1102
  this.str = str;
878
1103
  this.dict = str.dict;
879
1104
  DecodeStream.call(this, maybeLength);
880
1105
  }
1106
+
881
1107
  RunLengthStream.prototype = Object.create(DecodeStream.prototype);
1108
+
882
1109
  RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
883
1110
  var repeatHeader = this.str.getBytes(2);
1111
+
884
1112
  if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
885
1113
  this.eof = true;
886
1114
  return;
887
1115
  }
1116
+
888
1117
  var buffer;
889
1118
  var bufferLength = this.bufferLength;
890
1119
  var n = repeatHeader[0];
1120
+
891
1121
  if (n < 128) {
892
1122
  buffer = this.ensureBuffer(bufferLength + n + 1);
893
1123
  buffer[bufferLength++] = repeatHeader[1];
1124
+
894
1125
  if (n > 0) {
895
1126
  var source = this.str.getBytes(n);
896
1127
  buffer.set(source, bufferLength);
@@ -900,14 +1131,20 @@ var RunLengthStream = function RunLengthStreamClosure() {
900
1131
  n = 257 - n;
901
1132
  var b = repeatHeader[1];
902
1133
  buffer = this.ensureBuffer(bufferLength + n + 1);
1134
+
903
1135
  for (var i = 0; i < n; i++) {
904
1136
  buffer[bufferLength++] = b;
905
1137
  }
906
1138
  }
1139
+
907
1140
  this.bufferLength = bufferLength;
908
1141
  };
1142
+
909
1143
  return RunLengthStream;
910
1144
  }();
1145
+
1146
+ exports.RunLengthStream = RunLengthStream;
1147
+
911
1148
  var LZWStream = function LZWStreamClosure() {
912
1149
  function LZWStream(str, maybeLength, earlyChange) {
913
1150
  this.str = str;
@@ -925,40 +1162,51 @@ var LZWStream = function LZWStreamClosure() {
925
1162
  currentSequence: new Uint8Array(maxLzwDictionarySize),
926
1163
  currentSequenceLength: 0
927
1164
  };
1165
+
928
1166
  for (var i = 0; i < 256; ++i) {
929
1167
  lzwState.dictionaryValues[i] = i;
930
1168
  lzwState.dictionaryLengths[i] = 1;
931
1169
  }
1170
+
932
1171
  this.lzwState = lzwState;
933
1172
  DecodeStream.call(this, maybeLength);
934
1173
  }
1174
+
935
1175
  LZWStream.prototype = Object.create(DecodeStream.prototype);
1176
+
936
1177
  LZWStream.prototype.readBits = function LZWStream_readBits(n) {
937
1178
  var bitsCached = this.bitsCached;
938
1179
  var cachedData = this.cachedData;
1180
+
939
1181
  while (bitsCached < n) {
940
1182
  var c = this.str.getByte();
1183
+
941
1184
  if (c === -1) {
942
1185
  this.eof = true;
943
1186
  return null;
944
1187
  }
1188
+
945
1189
  cachedData = cachedData << 8 | c;
946
1190
  bitsCached += 8;
947
1191
  }
1192
+
948
1193
  this.bitsCached = bitsCached -= n;
949
1194
  this.cachedData = cachedData;
950
1195
  this.lastCode = null;
951
1196
  return cachedData >>> bitsCached & (1 << n) - 1;
952
1197
  };
1198
+
953
1199
  LZWStream.prototype.readBlock = function LZWStream_readBlock() {
954
1200
  var blockSize = 512;
955
1201
  var estimatedDecodedSize = blockSize * 2,
956
1202
  decodedSizeDelta = blockSize;
957
1203
  var i, j, q;
958
1204
  var lzwState = this.lzwState;
1205
+
959
1206
  if (!lzwState) {
960
1207
  return;
961
1208
  }
1209
+
962
1210
  var earlyChange = lzwState.earlyChange;
963
1211
  var nextCode = lzwState.nextCode;
964
1212
  var dictionaryValues = lzwState.dictionaryValues;
@@ -971,15 +1219,18 @@ var LZWStream = function LZWStreamClosure() {
971
1219
  var decodedLength = 0;
972
1220
  var currentBufferLength = this.bufferLength;
973
1221
  var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
1222
+
974
1223
  for (i = 0; i < blockSize; i++) {
975
1224
  var code = this.readBits(codeLength);
976
1225
  var hasPrev = currentSequenceLength > 0;
1226
+
977
1227
  if (code < 256) {
978
1228
  currentSequence[0] = code;
979
1229
  currentSequenceLength = 1;
980
1230
  } else if (code >= 258) {
981
1231
  if (code < nextCode) {
982
1232
  currentSequenceLength = dictionaryLengths[code];
1233
+
983
1234
  for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
984
1235
  currentSequence[j] = dictionaryValues[q];
985
1236
  q = dictionaryPrevCodes[q];
@@ -997,6 +1248,7 @@ var LZWStream = function LZWStreamClosure() {
997
1248
  delete this.lzwState;
998
1249
  break;
999
1250
  }
1251
+
1000
1252
  if (hasPrev) {
1001
1253
  dictionaryPrevCodes[nextCode] = prevCode;
1002
1254
  dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
@@ -1004,42 +1256,42 @@ var LZWStream = function LZWStreamClosure() {
1004
1256
  nextCode++;
1005
1257
  codeLength = nextCode + earlyChange & nextCode + earlyChange - 1 ? codeLength : Math.min(Math.log(nextCode + earlyChange) / 0.6931471805599453 + 1, 12) | 0;
1006
1258
  }
1259
+
1007
1260
  prevCode = code;
1008
1261
  decodedLength += currentSequenceLength;
1262
+
1009
1263
  if (estimatedDecodedSize < decodedLength) {
1010
1264
  do {
1011
1265
  estimatedDecodedSize += decodedSizeDelta;
1012
1266
  } while (estimatedDecodedSize < decodedLength);
1267
+
1013
1268
  buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
1014
1269
  }
1270
+
1015
1271
  for (j = 0; j < currentSequenceLength; j++) {
1016
1272
  buffer[currentBufferLength++] = currentSequence[j];
1017
1273
  }
1018
1274
  }
1275
+
1019
1276
  lzwState.nextCode = nextCode;
1020
1277
  lzwState.codeLength = codeLength;
1021
1278
  lzwState.prevCode = prevCode;
1022
1279
  lzwState.currentSequenceLength = currentSequenceLength;
1023
1280
  this.bufferLength = currentBufferLength;
1024
1281
  };
1282
+
1025
1283
  return LZWStream;
1026
1284
  }();
1285
+
1286
+ exports.LZWStream = LZWStream;
1287
+
1027
1288
  var NullStream = function NullStreamClosure() {
1028
1289
  function NullStream() {
1029
1290
  Stream.call(this, new Uint8Array(0));
1030
1291
  }
1292
+
1031
1293
  NullStream.prototype = Stream.prototype;
1032
1294
  return NullStream;
1033
1295
  }();
1034
- exports.Ascii85Stream = Ascii85Stream;
1035
- exports.AsciiHexStream = AsciiHexStream;
1036
- exports.DecryptStream = DecryptStream;
1037
- exports.DecodeStream = DecodeStream;
1038
- exports.FlateStream = FlateStream;
1039
- exports.NullStream = NullStream;
1040
- exports.PredictorStream = PredictorStream;
1041
- exports.RunLengthStream = RunLengthStream;
1042
- exports.Stream = Stream;
1043
- exports.StreamsSequenceStream = StreamsSequenceStream;
1044
- exports.StringStream = StringStream;
1045
- exports.LZWStream = LZWStream;
1296
+
1297
+ exports.NullStream = NullStream;