pdfjs-dist 2.0.489 → 2.2.228

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 (169) hide show
  1. package/CODE_OF_CONDUCT.md +15 -0
  2. package/bower.json +1 -1
  3. package/build/pdf.js +18515 -11402
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +1 -1
  6. package/build/pdf.worker.js +48266 -37137
  7. package/build/pdf.worker.js.map +1 -1
  8. package/build/pdf.worker.min.js +1 -1
  9. package/external/url/url-lib.js +627 -0
  10. package/image_decoders/pdf.image_decoders.js +11350 -0
  11. package/image_decoders/pdf.image_decoders.js.map +1 -0
  12. package/image_decoders/pdf.image_decoders.min.js +1 -0
  13. package/lib/core/annotation.js +587 -242
  14. package/lib/core/arithmetic_decoder.js +275 -245
  15. package/lib/core/bidi.js +65 -6
  16. package/lib/core/ccitt.js +173 -18
  17. package/lib/core/ccitt_stream.js +15 -6
  18. package/lib/core/cff_parser.js +433 -61
  19. package/lib/core/charsets.js +5 -4
  20. package/lib/core/chunked_stream.js +400 -152
  21. package/lib/core/cmap.js +326 -87
  22. package/lib/core/colorspace.js +874 -594
  23. package/lib/core/core_utils.js +147 -0
  24. package/lib/core/crypto.js +290 -45
  25. package/lib/core/document.js +560 -268
  26. package/lib/core/encodings.js +19 -10
  27. package/lib/core/evaluator.js +1005 -360
  28. package/lib/core/font_renderer.js +331 -97
  29. package/lib/core/fonts.js +812 -195
  30. package/lib/core/function.js +284 -71
  31. package/lib/core/glyphlist.js +4 -3
  32. package/lib/core/image.js +169 -62
  33. package/lib/core/image_utils.js +111 -0
  34. package/lib/core/jbig2.js +479 -66
  35. package/lib/core/jbig2_stream.js +19 -8
  36. package/lib/core/jpeg_stream.js +38 -13
  37. package/lib/core/jpg.js +253 -29
  38. package/lib/core/jpx.js +396 -6
  39. package/lib/core/jpx_stream.js +18 -6
  40. package/lib/core/metrics.js +15 -15
  41. package/lib/core/murmurhash3.js +56 -34
  42. package/lib/core/obj.js +1354 -488
  43. package/lib/core/operator_list.js +144 -31
  44. package/lib/core/parser.js +539 -191
  45. package/lib/core/pattern.js +148 -14
  46. package/lib/core/pdf_manager.js +323 -133
  47. package/lib/core/primitives.js +111 -24
  48. package/lib/core/ps_parser.js +134 -45
  49. package/lib/core/standard_fonts.js +17 -17
  50. package/lib/core/stream.js +313 -34
  51. package/lib/core/type1_parser.js +143 -13
  52. package/lib/core/unicode.js +32 -5
  53. package/lib/core/worker.js +217 -190
  54. package/lib/core/worker_stream.js +277 -0
  55. package/lib/display/annotation_layer.js +450 -133
  56. package/lib/display/api.js +1597 -784
  57. package/lib/display/api_compatibility.js +11 -13
  58. package/lib/display/canvas.js +360 -44
  59. package/lib/display/content_disposition.js +83 -32
  60. package/lib/display/display_utils.js +747 -0
  61. package/lib/display/fetch_stream.js +221 -90
  62. package/lib/display/font_loader.js +468 -236
  63. package/lib/display/metadata.js +38 -16
  64. package/lib/display/network.js +635 -428
  65. package/lib/display/network_utils.js +32 -19
  66. package/lib/display/node_stream.js +367 -175
  67. package/lib/display/pattern_helper.js +81 -31
  68. package/lib/display/svg.js +1235 -519
  69. package/lib/display/text_layer.js +153 -29
  70. package/lib/display/transport_stream.js +345 -94
  71. package/lib/display/webgl.js +64 -18
  72. package/lib/display/worker_options.js +5 -4
  73. package/lib/display/xml_parser.js +166 -53
  74. package/lib/examples/node/domstubs.js +60 -4
  75. package/lib/pdf.js +36 -14
  76. package/lib/pdf.worker.js +5 -3
  77. package/lib/shared/compatibility.js +158 -564
  78. package/lib/shared/global_scope.js +2 -2
  79. package/lib/shared/is_node.js +4 -4
  80. package/lib/shared/message_handler.js +521 -0
  81. package/lib/shared/streams_polyfill.js +21 -17
  82. package/lib/shared/url_polyfill.js +56 -0
  83. package/lib/shared/util.js +243 -710
  84. package/lib/test/unit/annotation_spec.js +870 -401
  85. package/lib/test/unit/api_spec.js +657 -345
  86. package/lib/test/unit/bidi_spec.js +7 -7
  87. package/lib/test/unit/cff_parser_spec.js +54 -11
  88. package/lib/test/unit/clitests_helper.js +10 -8
  89. package/lib/test/unit/cmap_spec.js +95 -41
  90. package/lib/test/unit/colorspace_spec.js +115 -63
  91. package/lib/test/unit/core_utils_spec.js +191 -0
  92. package/lib/test/unit/crypto_spec.js +17 -5
  93. package/lib/test/unit/custom_spec.js +43 -55
  94. package/lib/test/unit/display_svg_spec.js +34 -18
  95. package/lib/test/unit/display_utils_spec.js +273 -0
  96. package/lib/test/unit/document_spec.js +8 -13
  97. package/lib/test/unit/encodings_spec.js +25 -45
  98. package/lib/test/unit/evaluator_spec.js +38 -15
  99. package/lib/test/unit/fetch_stream_spec.js +109 -0
  100. package/lib/test/unit/function_spec.js +17 -5
  101. package/lib/test/unit/jasmine-boot.js +33 -20
  102. package/lib/test/unit/{util_stream_spec.js → message_handler_spec.js} +41 -69
  103. package/lib/test/unit/metadata_spec.js +71 -11
  104. package/lib/test/unit/murmurhash3_spec.js +3 -3
  105. package/lib/test/unit/network_spec.js +19 -54
  106. package/lib/test/unit/network_utils_spec.js +91 -14
  107. package/lib/test/unit/node_stream_spec.js +56 -32
  108. package/lib/test/unit/parser_spec.js +162 -71
  109. package/lib/test/unit/pdf_find_controller_spec.js +230 -0
  110. package/lib/test/unit/pdf_find_utils_spec.js +63 -0
  111. package/lib/test/unit/pdf_history_spec.js +21 -9
  112. package/lib/test/unit/primitives_spec.js +53 -20
  113. package/lib/test/unit/stream_spec.js +12 -4
  114. package/lib/test/unit/test_utils.js +273 -56
  115. package/lib/test/unit/testreporter.js +21 -3
  116. package/lib/test/unit/type1_parser_spec.js +8 -6
  117. package/lib/test/unit/ui_utils_spec.js +454 -16
  118. package/lib/test/unit/unicode_spec.js +18 -15
  119. package/lib/test/unit/util_spec.js +87 -128
  120. package/lib/web/annotation_layer_builder.js +39 -22
  121. package/lib/web/app.js +1290 -588
  122. package/lib/web/app_options.js +100 -62
  123. package/lib/web/base_viewer.js +511 -182
  124. package/lib/web/chromecom.js +261 -117
  125. package/lib/web/debugger.js +166 -22
  126. package/lib/web/download_manager.js +32 -13
  127. package/lib/web/firefox_print_service.js +20 -10
  128. package/lib/web/firefoxcom.js +315 -80
  129. package/lib/web/genericcom.js +89 -30
  130. package/lib/web/genericl10n.js +142 -30
  131. package/lib/web/grab_to_pan.js +28 -4
  132. package/lib/web/interfaces.js +170 -47
  133. package/lib/web/overlay_manager.js +235 -85
  134. package/lib/web/password_prompt.js +22 -14
  135. package/lib/web/pdf_attachment_viewer.js +38 -18
  136. package/lib/web/pdf_cursor_tools.js +39 -16
  137. package/lib/web/pdf_document_properties.js +255 -136
  138. package/lib/web/pdf_find_bar.js +84 -40
  139. package/lib/web/pdf_find_controller.js +495 -184
  140. package/lib/web/pdf_find_utils.js +111 -0
  141. package/lib/web/pdf_history.js +190 -53
  142. package/lib/web/pdf_link_service.js +138 -77
  143. package/lib/web/pdf_outline_viewer.js +122 -46
  144. package/lib/web/pdf_page_view.js +191 -67
  145. package/lib/web/pdf_presentation_mode.js +99 -34
  146. package/lib/web/pdf_print_service.js +61 -13
  147. package/lib/web/pdf_rendering_queue.js +28 -9
  148. package/lib/web/pdf_sidebar.js +141 -81
  149. package/lib/web/pdf_sidebar_resizer.js +42 -16
  150. package/lib/web/pdf_single_page_viewer.js +74 -66
  151. package/lib/web/pdf_thumbnail_view.js +104 -33
  152. package/lib/web/pdf_thumbnail_viewer.js +66 -26
  153. package/lib/web/pdf_viewer.component.js +112 -32
  154. package/lib/web/pdf_viewer.js +91 -52
  155. package/lib/web/preferences.js +284 -89
  156. package/lib/web/secondary_toolbar.js +165 -40
  157. package/lib/web/text_layer_builder.js +134 -59
  158. package/lib/web/toolbar.js +78 -43
  159. package/lib/web/ui_utils.js +462 -136
  160. package/lib/web/view_history.js +215 -67
  161. package/lib/web/viewer_compatibility.js +4 -13
  162. package/package.json +5 -4
  163. package/web/pdf_viewer.css +79 -11
  164. package/web/pdf_viewer.js +6107 -3748
  165. package/web/pdf_viewer.js.map +1 -1
  166. package/lib/display/dom_utils.js +0 -309
  167. package/lib/test/unit/dom_utils_spec.js +0 -89
  168. package/lib/test/unit/fonts_spec.js +0 -81
  169. package/lib/web/dom_events.js +0 -137
@@ -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,16 +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
+
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; } }
32
40
 
33
41
  var Stream = function StreamClosure() {
34
42
  function Stream(arrayBuffer, start, length, dict) {
@@ -38,25 +46,31 @@ var Stream = function StreamClosure() {
38
46
  this.end = start + length || this.bytes.length;
39
47
  this.dict = dict;
40
48
  }
49
+
41
50
  Stream.prototype = {
42
51
  get length() {
43
52
  return this.end - this.start;
44
53
  },
54
+
45
55
  get isEmpty() {
46
56
  return this.length === 0;
47
57
  },
58
+
48
59
  getByte: function Stream_getByte() {
49
60
  if (this.pos >= this.end) {
50
61
  return -1;
51
62
  }
63
+
52
64
  return this.bytes[this.pos++];
53
65
  },
54
66
  getUint16: function Stream_getUint16() {
55
67
  var b0 = this.getByte();
56
68
  var b1 = this.getByte();
69
+
57
70
  if (b0 === -1 || b1 === -1) {
58
71
  return -1;
59
72
  }
73
+
60
74
  return (b0 << 8) + b1;
61
75
  },
62
76
  getInt32: function Stream_getInt32() {
@@ -66,27 +80,36 @@ var Stream = function StreamClosure() {
66
80
  var b3 = this.getByte();
67
81
  return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
68
82
  },
69
- getBytes: function Stream_getBytes(length) {
83
+ getBytes: function getBytes(length) {
84
+ var forceClamped = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
70
85
  var bytes = this.bytes;
71
86
  var pos = this.pos;
72
87
  var strEnd = this.end;
88
+
73
89
  if (!length) {
74
- return bytes.subarray(pos, strEnd);
90
+ var _subarray = bytes.subarray(pos, strEnd);
91
+
92
+ return forceClamped ? new Uint8ClampedArray(_subarray) : _subarray;
75
93
  }
94
+
76
95
  var end = pos + length;
96
+
77
97
  if (end > strEnd) {
78
98
  end = strEnd;
79
99
  }
100
+
80
101
  this.pos = end;
81
- return bytes.subarray(pos, end);
102
+ var subarray = bytes.subarray(pos, end);
103
+ return forceClamped ? new Uint8ClampedArray(subarray) : subarray;
82
104
  },
83
105
  peekByte: function Stream_peekByte() {
84
106
  var peekedByte = this.getByte();
85
107
  this.pos--;
86
108
  return peekedByte;
87
109
  },
88
- peekBytes: function Stream_peekBytes(length) {
89
- var bytes = this.getBytes(length);
110
+ peekBytes: function peekBytes(length) {
111
+ var forceClamped = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
112
+ var bytes = this.getBytes(length, forceClamped);
90
113
  this.pos -= bytes.length;
91
114
  return bytes;
92
115
  },
@@ -94,6 +117,7 @@ var Stream = function StreamClosure() {
94
117
  if (!n) {
95
118
  n = 1;
96
119
  }
120
+
97
121
  this.pos += n;
98
122
  },
99
123
  reset: function Stream_reset() {
@@ -108,64 +132,86 @@ var Stream = function StreamClosure() {
108
132
  };
109
133
  return Stream;
110
134
  }();
135
+
136
+ exports.Stream = Stream;
137
+
111
138
  var StringStream = function StringStreamClosure() {
112
139
  function StringStream(str) {
113
140
  var bytes = (0, _util.stringToBytes)(str);
114
141
  Stream.call(this, bytes);
115
142
  }
143
+
116
144
  StringStream.prototype = Stream.prototype;
117
145
  return StringStream;
118
146
  }();
147
+
148
+ exports.StringStream = StringStream;
149
+
119
150
  var DecodeStream = function DecodeStreamClosure() {
120
151
  var emptyBuffer = new Uint8Array(0);
152
+
121
153
  function DecodeStream(maybeMinBufferLength) {
154
+ this._rawMinBufferLength = maybeMinBufferLength || 0;
122
155
  this.pos = 0;
123
156
  this.bufferLength = 0;
124
157
  this.eof = false;
125
158
  this.buffer = emptyBuffer;
126
159
  this.minBufferLength = 512;
160
+
127
161
  if (maybeMinBufferLength) {
128
162
  while (this.minBufferLength < maybeMinBufferLength) {
129
163
  this.minBufferLength *= 2;
130
164
  }
131
165
  }
132
166
  }
167
+
133
168
  DecodeStream.prototype = {
134
169
  get isEmpty() {
135
170
  while (!this.eof && this.bufferLength === 0) {
136
171
  this.readBlock();
137
172
  }
173
+
138
174
  return this.bufferLength === 0;
139
175
  },
176
+
140
177
  ensureBuffer: function DecodeStream_ensureBuffer(requested) {
141
178
  var buffer = this.buffer;
179
+
142
180
  if (requested <= buffer.byteLength) {
143
181
  return buffer;
144
182
  }
183
+
145
184
  var size = this.minBufferLength;
185
+
146
186
  while (size < requested) {
147
187
  size *= 2;
148
188
  }
189
+
149
190
  var buffer2 = new Uint8Array(size);
150
191
  buffer2.set(buffer);
151
192
  return this.buffer = buffer2;
152
193
  },
153
194
  getByte: function DecodeStream_getByte() {
154
195
  var pos = this.pos;
196
+
155
197
  while (this.bufferLength <= pos) {
156
198
  if (this.eof) {
157
199
  return -1;
158
200
  }
201
+
159
202
  this.readBlock();
160
203
  }
204
+
161
205
  return this.buffer[this.pos++];
162
206
  },
163
207
  getUint16: function DecodeStream_getUint16() {
164
208
  var b0 = this.getByte();
165
209
  var b1 = this.getByte();
210
+
166
211
  if (b0 === -1 || b1 === -1) {
167
212
  return -1;
168
213
  }
214
+
169
215
  return (b0 << 8) + b1;
170
216
  },
171
217
  getInt32: function DecodeStream_getInt32() {
@@ -175,16 +221,21 @@ var DecodeStream = function DecodeStreamClosure() {
175
221
  var b3 = this.getByte();
176
222
  return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
177
223
  },
178
- getBytes: function DecodeStream_getBytes(length) {
224
+ getBytes: function getBytes(length) {
225
+ var forceClamped = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
179
226
  var end,
180
227
  pos = this.pos;
228
+
181
229
  if (length) {
182
230
  this.ensureBuffer(pos + length);
183
231
  end = pos + length;
232
+
184
233
  while (!this.eof && this.bufferLength < end) {
185
234
  this.readBlock();
186
235
  }
236
+
187
237
  var bufEnd = this.bufferLength;
238
+
188
239
  if (end > bufEnd) {
189
240
  end = bufEnd;
190
241
  }
@@ -192,32 +243,39 @@ var DecodeStream = function DecodeStreamClosure() {
192
243
  while (!this.eof) {
193
244
  this.readBlock();
194
245
  }
246
+
195
247
  end = this.bufferLength;
196
248
  }
249
+
197
250
  this.pos = end;
198
- return this.buffer.subarray(pos, end);
251
+ var subarray = this.buffer.subarray(pos, end);
252
+ return forceClamped && !(subarray instanceof Uint8ClampedArray) ? new Uint8ClampedArray(subarray) : subarray;
199
253
  },
200
254
  peekByte: function DecodeStream_peekByte() {
201
255
  var peekedByte = this.getByte();
202
256
  this.pos--;
203
257
  return peekedByte;
204
258
  },
205
- peekBytes: function DecodeStream_peekBytes(length) {
206
- var bytes = this.getBytes(length);
259
+ peekBytes: function peekBytes(length) {
260
+ var forceClamped = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
261
+ var bytes = this.getBytes(length, forceClamped);
207
262
  this.pos -= bytes.length;
208
263
  return bytes;
209
264
  },
210
265
  makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
211
266
  var end = start + length;
267
+
212
268
  while (this.bufferLength <= end && !this.eof) {
213
269
  this.readBlock();
214
270
  }
271
+
215
272
  return new Stream(this.buffer, start, length, dict);
216
273
  },
217
274
  skip: function DecodeStream_skip(n) {
218
275
  if (!n) {
219
276
  n = 1;
220
277
  }
278
+
221
279
  this.pos += n;
222
280
  },
223
281
  reset: function DecodeStream_reset() {
@@ -227,23 +285,43 @@ var DecodeStream = function DecodeStreamClosure() {
227
285
  if (this.str && this.str.getBaseStreams) {
228
286
  return this.str.getBaseStreams();
229
287
  }
288
+
230
289
  return [];
231
290
  }
232
291
  };
233
292
  return DecodeStream;
234
293
  }();
294
+
295
+ exports.DecodeStream = DecodeStream;
296
+
235
297
  var StreamsSequenceStream = function StreamsSequenceStreamClosure() {
236
298
  function StreamsSequenceStream(streams) {
237
299
  this.streams = streams;
238
- DecodeStream.call(this, null);
300
+ var maybeLength = 0;
301
+
302
+ for (var i = 0, ii = streams.length; i < ii; i++) {
303
+ var stream = streams[i];
304
+
305
+ if (stream instanceof DecodeStream) {
306
+ maybeLength += stream._rawMinBufferLength;
307
+ } else {
308
+ maybeLength += stream.length;
309
+ }
310
+ }
311
+
312
+ DecodeStream.call(this, maybeLength);
239
313
  }
314
+
240
315
  StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
316
+
241
317
  StreamsSequenceStream.prototype.readBlock = function streamSequenceStreamReadBlock() {
242
318
  var streams = this.streams;
319
+
243
320
  if (streams.length === 0) {
244
321
  this.eof = true;
245
322
  return;
246
323
  }
324
+
247
325
  var stream = streams.shift();
248
326
  var chunk = stream.getBytes();
249
327
  var bufferLength = this.bufferLength;
@@ -252,63 +330,83 @@ var StreamsSequenceStream = function StreamsSequenceStreamClosure() {
252
330
  buffer.set(chunk, bufferLength);
253
331
  this.bufferLength = newLength;
254
332
  };
333
+
255
334
  StreamsSequenceStream.prototype.getBaseStreams = function StreamsSequenceStream_getBaseStreams() {
256
335
  var baseStreams = [];
336
+
257
337
  for (var i = 0, ii = this.streams.length; i < ii; i++) {
258
338
  var stream = this.streams[i];
339
+
259
340
  if (stream.getBaseStreams) {
260
- _util.Util.appendToArray(baseStreams, stream.getBaseStreams());
341
+ baseStreams.push.apply(baseStreams, _toConsumableArray(stream.getBaseStreams()));
261
342
  }
262
343
  }
344
+
263
345
  return baseStreams;
264
346
  };
347
+
265
348
  return StreamsSequenceStream;
266
349
  }();
350
+
351
+ exports.StreamsSequenceStream = StreamsSequenceStream;
352
+
267
353
  var FlateStream = function FlateStreamClosure() {
268
354
  var codeLenCodeMap = new Int32Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
269
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]);
270
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]);
271
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];
272
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
+
273
360
  function FlateStream(str, maybeLength) {
274
361
  this.str = str;
275
362
  this.dict = str.dict;
276
363
  var cmf = str.getByte();
277
364
  var flg = str.getByte();
365
+
278
366
  if (cmf === -1 || flg === -1) {
279
- 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));
280
368
  }
369
+
281
370
  if ((cmf & 0x0f) !== 0x08) {
282
- 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));
283
372
  }
373
+
284
374
  if (((cmf << 8) + flg) % 31 !== 0) {
285
- 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));
286
376
  }
377
+
287
378
  if (flg & 0x20) {
288
- 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));
289
380
  }
381
+
290
382
  this.codeSize = 0;
291
383
  this.codeBuf = 0;
292
384
  DecodeStream.call(this, maybeLength);
293
385
  }
386
+
294
387
  FlateStream.prototype = Object.create(DecodeStream.prototype);
388
+
295
389
  FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
296
390
  var str = this.str;
297
391
  var codeSize = this.codeSize;
298
392
  var codeBuf = this.codeBuf;
299
393
  var b;
394
+
300
395
  while (codeSize < bits) {
301
396
  if ((b = str.getByte()) === -1) {
302
397
  throw new _util.FormatError('Bad encoding in flate stream');
303
398
  }
399
+
304
400
  codeBuf |= b << codeSize;
305
401
  codeSize += 8;
306
402
  }
403
+
307
404
  b = codeBuf & (1 << bits) - 1;
308
405
  this.codeBuf = codeBuf >> bits;
309
406
  this.codeSize = codeSize -= bits;
310
407
  return b;
311
408
  };
409
+
312
410
  FlateStream.prototype.getCode = function FlateStream_getCode(table) {
313
411
  var str = this.str;
314
412
  var codes = table[0];
@@ -316,87 +414,115 @@ var FlateStream = function FlateStreamClosure() {
316
414
  var codeSize = this.codeSize;
317
415
  var codeBuf = this.codeBuf;
318
416
  var b;
417
+
319
418
  while (codeSize < maxLen) {
320
419
  if ((b = str.getByte()) === -1) {
321
420
  break;
322
421
  }
422
+
323
423
  codeBuf |= b << codeSize;
324
424
  codeSize += 8;
325
425
  }
426
+
326
427
  var code = codes[codeBuf & (1 << maxLen) - 1];
327
428
  var codeLen = code >> 16;
328
429
  var codeVal = code & 0xffff;
430
+
329
431
  if (codeLen < 1 || codeSize < codeLen) {
330
432
  throw new _util.FormatError('Bad encoding in flate stream');
331
433
  }
434
+
332
435
  this.codeBuf = codeBuf >> codeLen;
333
436
  this.codeSize = codeSize - codeLen;
334
437
  return codeVal;
335
438
  };
439
+
336
440
  FlateStream.prototype.generateHuffmanTable = function flateStreamGenerateHuffmanTable(lengths) {
337
441
  var n = lengths.length;
338
442
  var maxLen = 0;
339
443
  var i;
444
+
340
445
  for (i = 0; i < n; ++i) {
341
446
  if (lengths[i] > maxLen) {
342
447
  maxLen = lengths[i];
343
448
  }
344
449
  }
450
+
345
451
  var size = 1 << maxLen;
346
452
  var codes = new Int32Array(size);
453
+
347
454
  for (var len = 1, code = 0, skip = 2; len <= maxLen; ++len, code <<= 1, skip <<= 1) {
348
455
  for (var val = 0; val < n; ++val) {
349
456
  if (lengths[val] === len) {
350
457
  var code2 = 0;
351
458
  var t = code;
459
+
352
460
  for (i = 0; i < len; ++i) {
353
461
  code2 = code2 << 1 | t & 1;
354
462
  t >>= 1;
355
463
  }
464
+
356
465
  for (i = code2; i < size; i += skip) {
357
466
  codes[i] = len << 16 | val;
358
467
  }
468
+
359
469
  ++code;
360
470
  }
361
471
  }
362
472
  }
473
+
363
474
  return [codes, maxLen];
364
475
  };
476
+
365
477
  FlateStream.prototype.readBlock = function FlateStream_readBlock() {
366
478
  var buffer, len;
367
479
  var str = this.str;
368
480
  var hdr = this.getBits(3);
481
+
369
482
  if (hdr & 1) {
370
483
  this.eof = true;
371
484
  }
485
+
372
486
  hdr >>= 1;
487
+
373
488
  if (hdr === 0) {
374
489
  var b;
490
+
375
491
  if ((b = str.getByte()) === -1) {
376
492
  throw new _util.FormatError('Bad block header in flate stream');
377
493
  }
494
+
378
495
  var blockLen = b;
496
+
379
497
  if ((b = str.getByte()) === -1) {
380
498
  throw new _util.FormatError('Bad block header in flate stream');
381
499
  }
500
+
382
501
  blockLen |= b << 8;
502
+
383
503
  if ((b = str.getByte()) === -1) {
384
504
  throw new _util.FormatError('Bad block header in flate stream');
385
505
  }
506
+
386
507
  var check = b;
508
+
387
509
  if ((b = str.getByte()) === -1) {
388
510
  throw new _util.FormatError('Bad block header in flate stream');
389
511
  }
512
+
390
513
  check |= b << 8;
514
+
391
515
  if (check !== (~blockLen & 0xffff) && (blockLen !== 0 || check !== 0)) {
392
516
  throw new _util.FormatError('Bad uncompressed block length in flate stream');
393
517
  }
518
+
394
519
  this.codeBuf = 0;
395
520
  this.codeSize = 0;
396
521
  var bufferLength = this.bufferLength;
397
522
  buffer = this.ensureBuffer(bufferLength + blockLen);
398
523
  var end = bufferLength + blockLen;
399
524
  this.bufferLength = end;
525
+
400
526
  if (blockLen === 0) {
401
527
  if (str.peekByte() === -1) {
402
528
  this.eof = true;
@@ -407,13 +533,17 @@ var FlateStream = function FlateStreamClosure() {
407
533
  this.eof = true;
408
534
  break;
409
535
  }
536
+
410
537
  buffer[n] = b;
411
538
  }
412
539
  }
540
+
413
541
  return;
414
542
  }
543
+
415
544
  var litCodeTable;
416
545
  var distCodeTable;
546
+
417
547
  if (hdr === 1) {
418
548
  litCodeTable = fixedLitCodeTab;
419
549
  distCodeTable = fixedDistCodeTab;
@@ -423,17 +553,21 @@ var FlateStream = function FlateStreamClosure() {
423
553
  var numCodeLenCodes = this.getBits(4) + 4;
424
554
  var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
425
555
  var i;
556
+
426
557
  for (i = 0; i < numCodeLenCodes; ++i) {
427
558
  codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
428
559
  }
560
+
429
561
  var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
430
562
  len = 0;
431
563
  i = 0;
432
564
  var codes = numLitCodes + numDistCodes;
433
565
  var codeLengths = new Uint8Array(codes);
434
566
  var bitsLength, bitsOffset, what;
567
+
435
568
  while (i < codes) {
436
569
  var code = this.getCode(codeLenCodeTab);
570
+
437
571
  if (code === 16) {
438
572
  bitsLength = 2;
439
573
  bitsOffset = 3;
@@ -450,75 +584,99 @@ var FlateStream = function FlateStreamClosure() {
450
584
  codeLengths[i++] = len = code;
451
585
  continue;
452
586
  }
587
+
453
588
  var repeatLength = this.getBits(bitsLength) + bitsOffset;
589
+
454
590
  while (repeatLength-- > 0) {
455
591
  codeLengths[i++] = what;
456
592
  }
457
593
  }
594
+
458
595
  litCodeTable = this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
459
596
  distCodeTable = this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
460
597
  } else {
461
598
  throw new _util.FormatError('Unknown block type in flate stream');
462
599
  }
600
+
463
601
  buffer = this.buffer;
464
602
  var limit = buffer ? buffer.length : 0;
465
603
  var pos = this.bufferLength;
604
+
466
605
  while (true) {
467
606
  var code1 = this.getCode(litCodeTable);
607
+
468
608
  if (code1 < 256) {
469
609
  if (pos + 1 >= limit) {
470
610
  buffer = this.ensureBuffer(pos + 1);
471
611
  limit = buffer.length;
472
612
  }
613
+
473
614
  buffer[pos++] = code1;
474
615
  continue;
475
616
  }
617
+
476
618
  if (code1 === 256) {
477
619
  this.bufferLength = pos;
478
620
  return;
479
621
  }
622
+
480
623
  code1 -= 257;
481
624
  code1 = lengthDecode[code1];
482
625
  var code2 = code1 >> 16;
626
+
483
627
  if (code2 > 0) {
484
628
  code2 = this.getBits(code2);
485
629
  }
630
+
486
631
  len = (code1 & 0xffff) + code2;
487
632
  code1 = this.getCode(distCodeTable);
488
633
  code1 = distDecode[code1];
489
634
  code2 = code1 >> 16;
635
+
490
636
  if (code2 > 0) {
491
637
  code2 = this.getBits(code2);
492
638
  }
639
+
493
640
  var dist = (code1 & 0xffff) + code2;
641
+
494
642
  if (pos + len >= limit) {
495
643
  buffer = this.ensureBuffer(pos + len);
496
644
  limit = buffer.length;
497
645
  }
646
+
498
647
  for (var k = 0; k < len; ++k, ++pos) {
499
648
  buffer[pos] = buffer[pos - dist];
500
649
  }
501
650
  }
502
651
  };
652
+
503
653
  return FlateStream;
504
654
  }();
655
+
656
+ exports.FlateStream = FlateStream;
657
+
505
658
  var PredictorStream = function PredictorStreamClosure() {
506
659
  function PredictorStream(str, maybeLength, params) {
507
660
  if (!(0, _primitives.isDict)(params)) {
508
661
  return str;
509
662
  }
663
+
510
664
  var predictor = this.predictor = params.get('Predictor') || 1;
665
+
511
666
  if (predictor <= 1) {
512
667
  return str;
513
668
  }
669
+
514
670
  if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
515
- throw new _util.FormatError('Unsupported predictor: ' + predictor);
671
+ throw new _util.FormatError("Unsupported predictor: ".concat(predictor));
516
672
  }
673
+
517
674
  if (predictor === 2) {
518
675
  this.readBlock = this.readBlockTiff;
519
676
  } else {
520
677
  this.readBlock = this.readBlockPng;
521
678
  }
679
+
522
680
  this.str = str;
523
681
  this.dict = str.dict;
524
682
  var colors = this.colors = params.get('Colors') || 1;
@@ -529,7 +687,9 @@ var PredictorStream = function PredictorStreamClosure() {
529
687
  DecodeStream.call(this, maybeLength);
530
688
  return this;
531
689
  }
690
+
532
691
  PredictorStream.prototype = Object.create(DecodeStream.prototype);
692
+
533
693
  PredictorStream.prototype.readBlockTiff = function predictorStreamReadBlockTiff() {
534
694
  var rowBytes = this.rowBytes;
535
695
  var bufferLength = this.bufferLength;
@@ -538,15 +698,18 @@ var PredictorStream = function PredictorStreamClosure() {
538
698
  var colors = this.colors;
539
699
  var rawBytes = this.str.getBytes(rowBytes);
540
700
  this.eof = !rawBytes.length;
701
+
541
702
  if (this.eof) {
542
703
  return;
543
704
  }
705
+
544
706
  var inbuf = 0,
545
707
  outbuf = 0;
546
708
  var inbits = 0,
547
709
  outbits = 0;
548
710
  var pos = bufferLength;
549
711
  var i;
712
+
550
713
  if (bits === 1 && colors === 1) {
551
714
  for (i = 0; i < rowBytes; ++i) {
552
715
  var c = rawBytes[i] ^ inbuf;
@@ -560,15 +723,18 @@ var PredictorStream = function PredictorStreamClosure() {
560
723
  for (i = 0; i < colors; ++i) {
561
724
  buffer[pos++] = rawBytes[i];
562
725
  }
726
+
563
727
  for (; i < rowBytes; ++i) {
564
728
  buffer[pos] = buffer[pos - colors] + rawBytes[i];
565
729
  pos++;
566
730
  }
567
731
  } else if (bits === 16) {
568
732
  var bytesPerPixel = colors * 2;
733
+
569
734
  for (i = 0; i < bytesPerPixel; ++i) {
570
735
  buffer[pos++] = rawBytes[i];
571
736
  }
737
+
572
738
  for (; i < rowBytes; i += 2) {
573
739
  var sum = ((rawBytes[i] & 0xFF) << 8) + (rawBytes[i + 1] & 0xFF) + ((buffer[pos - bytesPerPixel] & 0xFF) << 8) + (buffer[pos - bytesPerPixel + 1] & 0xFF);
574
740
  buffer[pos++] = sum >> 8 & 0xFF;
@@ -580,100 +746,129 @@ var PredictorStream = function PredictorStreamClosure() {
580
746
  var j = 0,
581
747
  k = bufferLength;
582
748
  var columns = this.columns;
749
+
583
750
  for (i = 0; i < columns; ++i) {
584
751
  for (var kk = 0; kk < colors; ++kk) {
585
752
  if (inbits < bits) {
586
753
  inbuf = inbuf << 8 | rawBytes[j++] & 0xFF;
587
754
  inbits += 8;
588
755
  }
756
+
589
757
  compArray[kk] = compArray[kk] + (inbuf >> inbits - bits) & bitMask;
590
758
  inbits -= bits;
591
759
  outbuf = outbuf << bits | compArray[kk];
592
760
  outbits += bits;
761
+
593
762
  if (outbits >= 8) {
594
763
  buffer[k++] = outbuf >> outbits - 8 & 0xFF;
595
764
  outbits -= 8;
596
765
  }
597
766
  }
598
767
  }
768
+
599
769
  if (outbits > 0) {
600
770
  buffer[k++] = (outbuf << 8 - outbits) + (inbuf & (1 << 8 - outbits) - 1);
601
771
  }
602
772
  }
773
+
603
774
  this.bufferLength += rowBytes;
604
775
  };
776
+
605
777
  PredictorStream.prototype.readBlockPng = function predictorStreamReadBlockPng() {
606
778
  var rowBytes = this.rowBytes;
607
779
  var pixBytes = this.pixBytes;
608
780
  var predictor = this.str.getByte();
609
781
  var rawBytes = this.str.getBytes(rowBytes);
610
782
  this.eof = !rawBytes.length;
783
+
611
784
  if (this.eof) {
612
785
  return;
613
786
  }
787
+
614
788
  var bufferLength = this.bufferLength;
615
789
  var buffer = this.ensureBuffer(bufferLength + rowBytes);
616
790
  var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
791
+
617
792
  if (prevRow.length === 0) {
618
793
  prevRow = new Uint8Array(rowBytes);
619
794
  }
795
+
620
796
  var i,
621
797
  j = bufferLength,
622
798
  up,
623
799
  c;
800
+
624
801
  switch (predictor) {
625
802
  case 0:
626
803
  for (i = 0; i < rowBytes; ++i) {
627
804
  buffer[j++] = rawBytes[i];
628
805
  }
806
+
629
807
  break;
808
+
630
809
  case 1:
631
810
  for (i = 0; i < pixBytes; ++i) {
632
811
  buffer[j++] = rawBytes[i];
633
812
  }
813
+
634
814
  for (; i < rowBytes; ++i) {
635
815
  buffer[j] = buffer[j - pixBytes] + rawBytes[i] & 0xFF;
636
816
  j++;
637
817
  }
818
+
638
819
  break;
820
+
639
821
  case 2:
640
822
  for (i = 0; i < rowBytes; ++i) {
641
823
  buffer[j++] = prevRow[i] + rawBytes[i] & 0xFF;
642
824
  }
825
+
643
826
  break;
827
+
644
828
  case 3:
645
829
  for (i = 0; i < pixBytes; ++i) {
646
830
  buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
647
831
  }
832
+
648
833
  for (; i < rowBytes; ++i) {
649
834
  buffer[j] = (prevRow[i] + buffer[j - pixBytes] >> 1) + rawBytes[i] & 0xFF;
650
835
  j++;
651
836
  }
837
+
652
838
  break;
839
+
653
840
  case 4:
654
841
  for (i = 0; i < pixBytes; ++i) {
655
842
  up = prevRow[i];
656
843
  c = rawBytes[i];
657
844
  buffer[j++] = up + c;
658
845
  }
846
+
659
847
  for (; i < rowBytes; ++i) {
660
848
  up = prevRow[i];
661
849
  var upLeft = prevRow[i - pixBytes];
662
850
  var left = buffer[j - pixBytes];
663
851
  var p = left + up - upLeft;
664
852
  var pa = p - left;
853
+
665
854
  if (pa < 0) {
666
855
  pa = -pa;
667
856
  }
857
+
668
858
  var pb = p - up;
859
+
669
860
  if (pb < 0) {
670
861
  pb = -pb;
671
862
  }
863
+
672
864
  var pc = p - upLeft;
865
+
673
866
  if (pc < 0) {
674
867
  pc = -pc;
675
868
  }
869
+
676
870
  c = rawBytes[i];
871
+
677
872
  if (pa <= pb && pa <= pc) {
678
873
  buffer[j++] = left + c;
679
874
  } else if (pb <= pc) {
@@ -682,14 +877,21 @@ var PredictorStream = function PredictorStreamClosure() {
682
877
  buffer[j++] = upLeft + c;
683
878
  }
684
879
  }
880
+
685
881
  break;
882
+
686
883
  default:
687
- throw new _util.FormatError('Unsupported predictor: ' + predictor);
884
+ throw new _util.FormatError("Unsupported predictor: ".concat(predictor));
688
885
  }
886
+
689
887
  this.bufferLength += rowBytes;
690
888
  };
889
+
691
890
  return PredictorStream;
692
891
  }();
892
+
893
+ exports.PredictorStream = PredictorStream;
894
+
693
895
  var DecryptStream = function DecryptStreamClosure() {
694
896
  function DecryptStream(str, maybeLength, decrypt) {
695
897
  this.str = str;
@@ -699,20 +901,25 @@ var DecryptStream = function DecryptStreamClosure() {
699
901
  this.initialized = false;
700
902
  DecodeStream.call(this, maybeLength);
701
903
  }
904
+
702
905
  var chunkSize = 512;
703
906
  DecryptStream.prototype = Object.create(DecodeStream.prototype);
907
+
704
908
  DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
705
909
  var chunk;
910
+
706
911
  if (this.initialized) {
707
912
  chunk = this.nextChunk;
708
913
  } else {
709
914
  chunk = this.str.getBytes(chunkSize);
710
915
  this.initialized = true;
711
916
  }
917
+
712
918
  if (!chunk || chunk.length === 0) {
713
919
  this.eof = true;
714
920
  return;
715
921
  }
922
+
716
923
  this.nextChunk = this.str.getBytes(chunkSize);
717
924
  var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
718
925
  var decrypt = this.decrypt;
@@ -721,104 +928,142 @@ var DecryptStream = function DecryptStreamClosure() {
721
928
  var i,
722
929
  n = chunk.length;
723
930
  var buffer = this.ensureBuffer(bufferLength + n);
931
+
724
932
  for (i = 0; i < n; i++) {
725
933
  buffer[bufferLength++] = chunk[i];
726
934
  }
935
+
727
936
  this.bufferLength = bufferLength;
728
937
  };
938
+
729
939
  return DecryptStream;
730
940
  }();
941
+
942
+ exports.DecryptStream = DecryptStream;
943
+
731
944
  var Ascii85Stream = function Ascii85StreamClosure() {
732
945
  function Ascii85Stream(str, maybeLength) {
733
946
  this.str = str;
734
947
  this.dict = str.dict;
735
948
  this.input = new Uint8Array(5);
949
+
736
950
  if (maybeLength) {
737
951
  maybeLength = 0.8 * maybeLength;
738
952
  }
953
+
739
954
  DecodeStream.call(this, maybeLength);
740
955
  }
956
+
741
957
  Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
958
+
742
959
  Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
743
960
  var TILDA_CHAR = 0x7E;
744
961
  var Z_LOWER_CHAR = 0x7A;
745
962
  var EOF = -1;
746
963
  var str = this.str;
747
964
  var c = str.getByte();
965
+
748
966
  while ((0, _util.isSpace)(c)) {
749
967
  c = str.getByte();
750
968
  }
969
+
751
970
  if (c === EOF || c === TILDA_CHAR) {
752
971
  this.eof = true;
753
972
  return;
754
973
  }
974
+
755
975
  var bufferLength = this.bufferLength,
756
976
  buffer;
757
977
  var i;
978
+
758
979
  if (c === Z_LOWER_CHAR) {
759
980
  buffer = this.ensureBuffer(bufferLength + 4);
981
+
760
982
  for (i = 0; i < 4; ++i) {
761
983
  buffer[bufferLength + i] = 0;
762
984
  }
985
+
763
986
  this.bufferLength += 4;
764
987
  } else {
765
988
  var input = this.input;
766
989
  input[0] = c;
990
+
767
991
  for (i = 1; i < 5; ++i) {
768
992
  c = str.getByte();
993
+
769
994
  while ((0, _util.isSpace)(c)) {
770
995
  c = str.getByte();
771
996
  }
997
+
772
998
  input[i] = c;
999
+
773
1000
  if (c === EOF || c === TILDA_CHAR) {
774
1001
  break;
775
1002
  }
776
1003
  }
1004
+
777
1005
  buffer = this.ensureBuffer(bufferLength + i - 1);
778
1006
  this.bufferLength += i - 1;
1007
+
779
1008
  if (i < 5) {
780
1009
  for (; i < 5; ++i) {
781
1010
  input[i] = 0x21 + 84;
782
1011
  }
1012
+
783
1013
  this.eof = true;
784
1014
  }
1015
+
785
1016
  var t = 0;
1017
+
786
1018
  for (i = 0; i < 5; ++i) {
787
1019
  t = t * 85 + (input[i] - 0x21);
788
1020
  }
1021
+
789
1022
  for (i = 3; i >= 0; --i) {
790
1023
  buffer[bufferLength + i] = t & 0xFF;
791
1024
  t >>= 8;
792
1025
  }
793
1026
  }
794
1027
  };
1028
+
795
1029
  return Ascii85Stream;
796
1030
  }();
1031
+
1032
+ exports.Ascii85Stream = Ascii85Stream;
1033
+
797
1034
  var AsciiHexStream = function AsciiHexStreamClosure() {
798
1035
  function AsciiHexStream(str, maybeLength) {
799
1036
  this.str = str;
800
1037
  this.dict = str.dict;
801
1038
  this.firstDigit = -1;
1039
+
802
1040
  if (maybeLength) {
803
1041
  maybeLength = 0.5 * maybeLength;
804
1042
  }
1043
+
805
1044
  DecodeStream.call(this, maybeLength);
806
1045
  }
1046
+
807
1047
  AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
1048
+
808
1049
  AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
809
1050
  var UPSTREAM_BLOCK_SIZE = 8000;
810
1051
  var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
1052
+
811
1053
  if (!bytes.length) {
812
1054
  this.eof = true;
813
1055
  return;
814
1056
  }
1057
+
815
1058
  var maxDecodeLength = bytes.length + 1 >> 1;
816
1059
  var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
817
1060
  var bufferLength = this.bufferLength;
818
1061
  var firstDigit = this.firstDigit;
1062
+
819
1063
  for (var i = 0, ii = bytes.length; i < ii; i++) {
820
1064
  var ch = bytes[i],
821
1065
  digit;
1066
+
822
1067
  if (ch >= 0x30 && ch <= 0x39) {
823
1068
  digit = ch & 0x0F;
824
1069
  } else if (ch >= 0x41 && ch <= 0x46 || ch >= 0x61 && ch <= 0x66) {
@@ -829,6 +1074,7 @@ var AsciiHexStream = function AsciiHexStreamClosure() {
829
1074
  } else {
830
1075
  continue;
831
1076
  }
1077
+
832
1078
  if (firstDigit < 0) {
833
1079
  firstDigit = digit;
834
1080
  } else {
@@ -836,34 +1082,46 @@ var AsciiHexStream = function AsciiHexStreamClosure() {
836
1082
  firstDigit = -1;
837
1083
  }
838
1084
  }
1085
+
839
1086
  if (firstDigit >= 0 && this.eof) {
840
1087
  buffer[bufferLength++] = firstDigit << 4;
841
1088
  firstDigit = -1;
842
1089
  }
1090
+
843
1091
  this.firstDigit = firstDigit;
844
1092
  this.bufferLength = bufferLength;
845
1093
  };
1094
+
846
1095
  return AsciiHexStream;
847
1096
  }();
1097
+
1098
+ exports.AsciiHexStream = AsciiHexStream;
1099
+
848
1100
  var RunLengthStream = function RunLengthStreamClosure() {
849
1101
  function RunLengthStream(str, maybeLength) {
850
1102
  this.str = str;
851
1103
  this.dict = str.dict;
852
1104
  DecodeStream.call(this, maybeLength);
853
1105
  }
1106
+
854
1107
  RunLengthStream.prototype = Object.create(DecodeStream.prototype);
1108
+
855
1109
  RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
856
1110
  var repeatHeader = this.str.getBytes(2);
1111
+
857
1112
  if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
858
1113
  this.eof = true;
859
1114
  return;
860
1115
  }
1116
+
861
1117
  var buffer;
862
1118
  var bufferLength = this.bufferLength;
863
1119
  var n = repeatHeader[0];
1120
+
864
1121
  if (n < 128) {
865
1122
  buffer = this.ensureBuffer(bufferLength + n + 1);
866
1123
  buffer[bufferLength++] = repeatHeader[1];
1124
+
867
1125
  if (n > 0) {
868
1126
  var source = this.str.getBytes(n);
869
1127
  buffer.set(source, bufferLength);
@@ -873,14 +1131,20 @@ var RunLengthStream = function RunLengthStreamClosure() {
873
1131
  n = 257 - n;
874
1132
  var b = repeatHeader[1];
875
1133
  buffer = this.ensureBuffer(bufferLength + n + 1);
1134
+
876
1135
  for (var i = 0; i < n; i++) {
877
1136
  buffer[bufferLength++] = b;
878
1137
  }
879
1138
  }
1139
+
880
1140
  this.bufferLength = bufferLength;
881
1141
  };
1142
+
882
1143
  return RunLengthStream;
883
1144
  }();
1145
+
1146
+ exports.RunLengthStream = RunLengthStream;
1147
+
884
1148
  var LZWStream = function LZWStreamClosure() {
885
1149
  function LZWStream(str, maybeLength, earlyChange) {
886
1150
  this.str = str;
@@ -898,40 +1162,51 @@ var LZWStream = function LZWStreamClosure() {
898
1162
  currentSequence: new Uint8Array(maxLzwDictionarySize),
899
1163
  currentSequenceLength: 0
900
1164
  };
1165
+
901
1166
  for (var i = 0; i < 256; ++i) {
902
1167
  lzwState.dictionaryValues[i] = i;
903
1168
  lzwState.dictionaryLengths[i] = 1;
904
1169
  }
1170
+
905
1171
  this.lzwState = lzwState;
906
1172
  DecodeStream.call(this, maybeLength);
907
1173
  }
1174
+
908
1175
  LZWStream.prototype = Object.create(DecodeStream.prototype);
1176
+
909
1177
  LZWStream.prototype.readBits = function LZWStream_readBits(n) {
910
1178
  var bitsCached = this.bitsCached;
911
1179
  var cachedData = this.cachedData;
1180
+
912
1181
  while (bitsCached < n) {
913
1182
  var c = this.str.getByte();
1183
+
914
1184
  if (c === -1) {
915
1185
  this.eof = true;
916
1186
  return null;
917
1187
  }
1188
+
918
1189
  cachedData = cachedData << 8 | c;
919
1190
  bitsCached += 8;
920
1191
  }
1192
+
921
1193
  this.bitsCached = bitsCached -= n;
922
1194
  this.cachedData = cachedData;
923
1195
  this.lastCode = null;
924
1196
  return cachedData >>> bitsCached & (1 << n) - 1;
925
1197
  };
1198
+
926
1199
  LZWStream.prototype.readBlock = function LZWStream_readBlock() {
927
1200
  var blockSize = 512;
928
1201
  var estimatedDecodedSize = blockSize * 2,
929
1202
  decodedSizeDelta = blockSize;
930
1203
  var i, j, q;
931
1204
  var lzwState = this.lzwState;
1205
+
932
1206
  if (!lzwState) {
933
1207
  return;
934
1208
  }
1209
+
935
1210
  var earlyChange = lzwState.earlyChange;
936
1211
  var nextCode = lzwState.nextCode;
937
1212
  var dictionaryValues = lzwState.dictionaryValues;
@@ -944,15 +1219,18 @@ var LZWStream = function LZWStreamClosure() {
944
1219
  var decodedLength = 0;
945
1220
  var currentBufferLength = this.bufferLength;
946
1221
  var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
1222
+
947
1223
  for (i = 0; i < blockSize; i++) {
948
1224
  var code = this.readBits(codeLength);
949
1225
  var hasPrev = currentSequenceLength > 0;
1226
+
950
1227
  if (code < 256) {
951
1228
  currentSequence[0] = code;
952
1229
  currentSequenceLength = 1;
953
1230
  } else if (code >= 258) {
954
1231
  if (code < nextCode) {
955
1232
  currentSequenceLength = dictionaryLengths[code];
1233
+
956
1234
  for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
957
1235
  currentSequence[j] = dictionaryValues[q];
958
1236
  q = dictionaryPrevCodes[q];
@@ -970,6 +1248,7 @@ var LZWStream = function LZWStreamClosure() {
970
1248
  delete this.lzwState;
971
1249
  break;
972
1250
  }
1251
+
973
1252
  if (hasPrev) {
974
1253
  dictionaryPrevCodes[nextCode] = prevCode;
975
1254
  dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
@@ -977,42 +1256,42 @@ var LZWStream = function LZWStreamClosure() {
977
1256
  nextCode++;
978
1257
  codeLength = nextCode + earlyChange & nextCode + earlyChange - 1 ? codeLength : Math.min(Math.log(nextCode + earlyChange) / 0.6931471805599453 + 1, 12) | 0;
979
1258
  }
1259
+
980
1260
  prevCode = code;
981
1261
  decodedLength += currentSequenceLength;
1262
+
982
1263
  if (estimatedDecodedSize < decodedLength) {
983
1264
  do {
984
1265
  estimatedDecodedSize += decodedSizeDelta;
985
1266
  } while (estimatedDecodedSize < decodedLength);
1267
+
986
1268
  buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
987
1269
  }
1270
+
988
1271
  for (j = 0; j < currentSequenceLength; j++) {
989
1272
  buffer[currentBufferLength++] = currentSequence[j];
990
1273
  }
991
1274
  }
1275
+
992
1276
  lzwState.nextCode = nextCode;
993
1277
  lzwState.codeLength = codeLength;
994
1278
  lzwState.prevCode = prevCode;
995
1279
  lzwState.currentSequenceLength = currentSequenceLength;
996
1280
  this.bufferLength = currentBufferLength;
997
1281
  };
1282
+
998
1283
  return LZWStream;
999
1284
  }();
1285
+
1286
+ exports.LZWStream = LZWStream;
1287
+
1000
1288
  var NullStream = function NullStreamClosure() {
1001
1289
  function NullStream() {
1002
1290
  Stream.call(this, new Uint8Array(0));
1003
1291
  }
1292
+
1004
1293
  NullStream.prototype = Stream.prototype;
1005
1294
  return NullStream;
1006
1295
  }();
1007
- exports.Ascii85Stream = Ascii85Stream;
1008
- exports.AsciiHexStream = AsciiHexStream;
1009
- exports.DecryptStream = DecryptStream;
1010
- exports.DecodeStream = DecodeStream;
1011
- exports.FlateStream = FlateStream;
1012
- exports.NullStream = NullStream;
1013
- exports.PredictorStream = PredictorStream;
1014
- exports.RunLengthStream = RunLengthStream;
1015
- exports.Stream = Stream;
1016
- exports.StreamsSequenceStream = StreamsSequenceStream;
1017
- exports.StringStream = StringStream;
1018
- exports.LZWStream = LZWStream;
1296
+
1297
+ exports.NullStream = NullStream;