pdfjs-dist 2.0.550 → 2.3.200

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pdfjs-dist might be problematic. Click here for more details.

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